我将为我的项目创建一个新的集群api。所以这些天我开始学习,我只是用这种方式编写了使用分散和聚集的程序。但我得到了零点exception.No的想法,什么时候错了?
这是我的密码
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)... 发布于 2015-03-29 15:56:15
尝试为每个进程初始化sendbuf= new int[unitSize*size];。删除if(rank==root)条件并查看它是否有效。
分散查找sendbuf数组为null,这就是它抛出NullPointerException的原因
发布于 2015-03-29 14:54:44
我认为散乱的对象(int数组)在未初始化。您能否尝试将sendbuf初始化为一些虚拟值,然后再试一次。
发布于 2019-01-29 10:17:11
而不是代码
if (rank == root)
{
send_buffer = new int [unitsize * size];
}继续往前走。
send_buffer = new int [unitsize * size];您的输出将是: MPJ (0.44)在多核配置中启动
0 0 0 1 1 1 2 2 2 3 3 3
https://stackoverflow.com/questions/29321198
复制相似问题