0

我正在尝试使用 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;
    }
}
4

0 回答 0