我要为我的项目创建一个新的集群 api。所以这几天我开始学习MP J Express。我只是用这种方式使用Scatter和Gather编写程序。但我得到空点异常。不知道什么时候出错?
这是我的代码
import mpi.MPI;
public class ScatterGather {
public static void main(String args[]){
MPI.Init(args);
int rank = MPI.COMM_WORLD.Rank();
int size = MPI.COMM_WORLD.Size();
int unitSize=4,root=0;
int sendbuf[]=null;
if(rank==root){
sendbuf= new int[unitSize*size];
}
int recvbuf[] = new int[unitSize];
MPI.COMM_WORLD.Scatter(sendbuf,0,unitSize,MPI.INT,recvbuf,0,unitSize,MPI.INT,root);
if(rank!=root){
for(int i=0;i<unitSize;i++){
recvbuf[i]=rank;
}
}
MPI.COMM_WORLD.Gather(recvbuf,0,unitSize,MPI.INT,sendbuf,0,unitSize,MPI.INT,root);
if(rank==root){
for(int i=0;i<unitSize;i++){
System.out.println(sendbuf[i]+ " ");
}
}
MPI.Finalize();
}
}
这是错误日志
MPJ Express (0.43) is started in the multicore configuration
mpi.MPIException: java.lang.NullPointerException
at mpi.SimplePackerInt.unpack(SimplePackerInt.java:112)
at mpi.Comm.recv(Comm.java:1499)
at mpi.PureIntracomm.MST_Scatter(PureIntracomm.java:1102)
at mpi.PureIntracomm.Scatter(PureIntracomm.java:1066)
at mpi.Intracomm.Scatter(Intracomm.java:420)
at ScatterGather.main(ScatterGather.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)...