I am trying to use MPI.COMM_WORLD.Scatter() to divide an array of Object into several chunks and send it to the other processes, but it always gets the NullPointer error at the line of Scatter, is there any way the solve the problem? I find that if the sendbuf is an array of primitive type, there will be no problem.
import mpi.*
public class Demo {
public static void main(String args[]) {
MPI.Init(args);
int rank = MPI.COMM_WORLD.Rank();
int size = MPI.COMM_WORLD.Size();
int master = 0;
int num = 0;
ArrayList<Location> locationList = null;
Location[] locationArray = null;
if(rank == master) {
locationList = XXX; // XXX means read data from a file and create Location object into the list, the number of the objects is unknown
locationArray = locationList.toArray(new Location[locationList.size()]);
}
// num - calculate the number of objects that each process will get
MPI.COMM_WORLD.Scatter(locationArray, 0, num, MPI.OBJECT, recvbuf, 0, num, MPI.OBJECT, 0);
// The others processes does some operations on the recvbuf
MPI.COMM_WORLD.Gater(new_locationArray, 0, num, MPI.OBJECT, new_recvbuf, 0, num, MPI.OBJECT, 0);
// the master process does some operations on the new_recvbuf
MPI.Finalize();
}
}
The Location Class is very simple as shown below:
public class Location {
int id;
public Location(int id) {
this.id = id;
}
}