2
votes

I'm trying to read from a file for an MPI application. The cluster has 4 nodes with 12 cores in each node. I have tried running a basic program to compute rank and that works. When I added MPI_File_open it throws an exception at runtime

BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES = EXIT CODE: 139

The cluster has MPICH2 installed and has a Network File System. I check MPI_File_open with different parameters like ReadOnly mode, MPI_COMM_WORLD etc.

Can I use MPI_File_open with Network File System?

int main(int argc, char* argv[])
{
    int myrank          = 0;
    int nprocs          = 0;
    int i               = 0;
    MPI_Comm    icomm   = MPI_COMM_WORLD;
    MPI_Status  status;

    MPI_Info    info;
    MPI_File    *fh     = NULL;

    int         error       = 0;

    MPI_Init(&argc, &argv);
    MPI_Barrier(MPI_COMM_WORLD);        // Wait for all processor to start

    MPI_Comm_size(MPI_COMM_WORLD, &nprocs); // Get number of processes
    MPI_Comm_rank(MPI_COMM_WORLD, &myrank); // Get own rank

    usleep(myrank*100000);
    if ( myrank == 1 || myrank == 0 )
        printf("Hello from %d\r\n", myrank);

    if (myrank == 0)
    {
        error = MPI_File_open( MPI_COMM_SELF, "lw1.wei", MPI_MODE_UNIQUE_OPEN,
                               MPI_INFO_NULL, fh);
        if ( error )
        {
            printf("Error in opening file\r\n");
        }
        else
        {
            printf("File successfully opened\r\n");
        }
        MPI_File_close(fh);
    }

    MPI_Barrier(MPI_COMM_WORLD);        //! Wait for all the processors to end
    MPI_Finalize();

    if ( myrank == 0 )
    {
        printf("Number of Processes %d\n\r", nprocs);
    }

    return 0;
}
1

1 Answers

3
votes

You forgot to allocate an MPI_File object before opening the file. You may either change this line:

MPI_File    *fh     = NULL;

into:

MPI_File     fh;

and open file by giving fh's address to MPI_File_open(..., &fh). Or you may simply allocate memory from heap using malloc().

MPI_File    *fh      = malloc(sizeof(MPI_File));