Hi,

I want to load a saved object using java mpi. Without MPI there is no problem in reading the file and casting it to the correct type. I tried to open the file as a byte array and convert this to an object. I checked that all bytes are read correctly. Here I have an example where the saved file is a Serializable double array and I tried files with a size up to 120MB without a problem. When trying the same with an ArrayList, a few kb file size leads to segmentation faults.


// creating the file

        int num = 1000000;
        Random r = new Random(1234);
        ArrayList<Serializable> obj0 = new ArrayList<>(num);
        double[] obj1 = new double[num];
        for (int j = 0; j < num; j++) {
            double d = r.nextGaussian();
            obj0.add(d);
            obj1[j] = d;
        }
        obj0.trimToSize();

################################################

// trying to read the file

        String filename = "testfile";
        byte[] readbuf;

        File myfile = new File(MPI.COMM_SELF, filename, MPI.MODE_RDONLY);
        int filesize = (int) myfile.getSize();
        readbuf = new byte[filesize];

        byte[] copyarray = new byte[filesize];
        Status status = myfile.read(readbuf, filesize, MPI.BYTE);
        Object test = null;
        if (myrank == 0) {
            ByteArrayInputStream in = new ByteArrayInputStream(readbuf);
            ObjectInputStream is = new ObjectInputStream(in);
test = is.readObject(); // This line causes a segmnentation fault
        }


Thanks for your help
Marko

Reply via email to