我正在尝试使用MPI.COMM_WORLD.Scatter()将一个Object数组分成几个块并将其发送到其他进程,但它总是在Scatter行中得到NullPointer错误,有什么办法吗?解决这个问题?我发现如果sendbuf是一个原始类型的数组,那就不会有问题了。
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();
}
}
位置等级非常简单,如下所示:
public class Location {
int id;
public Location(int id) {
this.id = id;
}
}