MPJ Express-如何使用散布将对象数组发送到Java中的其他进程
我试图使用MPI.COMM_WORLD.Scatter()将一个对象数组分成几个块并发送给其他进程,但它总是在分散线处出现空指针错误,有什么办法解决这个问题吗?我发现如果sendbuf是一个基元类型的数组,就不会有问题MPJ Express-如何使用散布将对象数组发送到Java中的其他进程,java,mpi,mpj-express,Java,Mpi,Mpj Express,我试图使用MPI.COMM_WORLD.Scatter()将一个对象数组分成几个块并发送给其他进程,但它总是在分散线处出现空指针错误,有什么办法解决这个问题吗?我发现如果sendbuf是一个基元类型的数组,就不会有问题 import mpi.* public class Demo { public static void main(String args[]) { MPI.Init(args); int rank = MPI.COMM_WORLD.R
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();
}
}
如果
Location[]locationArray=null,则为井代码>如何进行迭代?尝试Location[]locationArray=新位置[100]代码>@ScaryWombat Thx,谢谢你的回复。实际上,数组的长度以前是未知的。我从文件中读取数据并将Location对象创建到ArrayList中,然后将其转换到Location[],我更新了上面的代码。我只关心根列的输入缓冲区参数。可能是recvbuf
为null
。
public class Location {
int id;
public Location(int id) {
this.id = id;
}
}