package mpi; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.Date; import mpi.MPI; import mpi.Status; public class ObjectCommunication2 implements Serializable{ private static final long serialVersionUID = 1L; int myX = (int)(Math.random() * 10000.0); String myString = "quo vadis"; Date date = new Date(); public String toString(){ return "X="+myX+" '"+myString+"' created on "+date; } /** * STANDALONE TEST PROGRAM */ public static void main(String[] args) throws IOException, ClassNotFoundException { MPI.Init(args); if (MPI.COMM_WORLD.Size() != 2 ){ System.err.println("Only use this program by running 2 processes and not "+MPI.COMM_WORLD.Size()); MPI.Finalize(); return; } final int myRank = MPI.COMM_WORLD.Rank(); if (myRank == 0){ ObjectCommunication2 obj = new ObjectCommunication2(); MPI.COMM_WORLD.Send(new Object[]{obj}, 0, 1, MPI.OBJECT, 1, 0); System.out.println("Object '"+obj+"' send to process 1"); } else { Object[] buffer = new Object[1]; MPI.COMM_WORLD.Recv(buffer, 0, 1, MPI.OBJECT, 0, 0); Object obj = buffer[0]; System.out.println("Object '"+obj+"' (class "+obj.getClass()+") received from process 0"); } MPI.Finalize(); // Don't forget!! } }