Skip to content

Persistent communication request provokes segfault in Java bindings. #369

Closed
@osvegis

Description

@osvegis

MPI corrupts the memory space of Java.
The following example provokes segfault in Java bindings.
Please, see the comments in the example.

import mpi.*;                                                                         
import java.nio.*;                                                                    

public class CrashTest
{
    private static final int STEPS = 1000000000,
        SIZE  = 4096;

    public static void main(String...args) throws MPIException
    {
        MPI.Init(args);
        int rank = MPI.COMM_WORLD.getRank();
        StringBuilder s = new StringBuilder();

        if(MPI.COMM_WORLD.getSize() != 2)
            throw new MPIException("I need exactly 2 processes.");

        // Only one buffer is needed,                                                 
        // but the test works ok if you only use one.                                 
        ByteBuffer sendBuf = MPI.newByteBuffer(SIZE),
            recvBuf = MPI.newByteBuffer(SIZE);

        Prequest req = MPI.COMM_WORLD.recvInit(recvBuf, SIZE, MPI.BYTE, 0, 0);

        for(int i = 1; i <= STEPS; i++)
            {
                // Allocate memory to provoke GC work and crash.                      
                // If you comment the following line, the test works ok.              
                (s = new StringBuilder(SIZE).append(i)).trimToSize();

                if(rank == 0)
                    {
                        if(i % 100000 == 0)
                            {
                                s.setLength(0);
                                System.out.println(i + s.toString());
                            }

                        MPI.COMM_WORLD.send(sendBuf, SIZE, MPI.BYTE, 1, 0);
                    }
                else
                    {
                        req.start();
                        req.waitFor();
                    }
            }

        MPI.Finalize();
    }

} // CrashTest

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions