0

I am trying to use MPI.COMM_WORLD.Scatter() to divide an array of Object into several chunks and send it to the other processes, but it always gets the NullPointer error at the line of Scatter, is there any way the solve the problem? I find that if the sendbuf is an array of primitive type, there will be no problem.

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();
    }
}

The Location Class is very simple as shown below:

public class Location {
    int id;
    public Location(int id) {
        this.id = id;
    }
}
Bread
  • 31
  • 4
  • well if `Location[] locationArray = null;` how can you iterate ? try `Location[] locationArray = new Location[100];` – Scary Wombat Mar 28 '17 at 02:47
  • @ScaryWombat Thx for your reply. Actually, the length of the array is unknown before. I read data from a file and create Location object into a ArrayList, then transform it to the Location[], I have updated the code above – Bread Mar 28 '17 at 03:21
  • Scatter only cares about the input buffer argument at the root rank. Perhaps it is `recvbuf` that is `null`. – Hristo Iliev Mar 28 '17 at 07:37

0 Answers0