user2870
user2870

Reputation: 487

mpi file read is not ending

I am trying to read a txt file using mpi in the following way:

"The master node should load the data, divide and distribute it among the worker processors."

However my code is not ending.

Here is the corresponding code piece:

MPI_File_open(MPI_COMM_WORLD, argv[1], MPI_MODE_RDONLY, MPI_INFO_NULL, &in);

if (rank == 0){

    printf("OK\n");   

    MPI_Offset filesize;
    MPI_Offset localsize;
    MPI_Offset start;
    MPI_Offset end;
    char *chunk;

    MPI_File_get_size(in, &filesize);
//localsize = filesize/size;
    start = 0;
    end   = filesize - 1;
    printf("OK\n");

localsize =  end - start + 1;

/* allocate memory */
    chunk = malloc( (localsize + 1)*sizeof(char));

    MPI_File_read_at_all(in, start, chunk, localsize, MPI_CHAR, MPI_STATUS_IGNORE);
    printf("OK\n");
    chunk[localsize] = '\0';
}

MPI_Finalize();

The code above doesnt print the third "OK". Therefore the problem is in MPI_File_read_at_all(), I guess.

What could be the problem?

Upvotes: 0

Views: 387

Answers (1)

Hristo Iliev
Hristo Iliev

Reputation: 74355

MPI_File_read_at_all is a collective version of MPI_File_read_at. Collective operations only complete once all ranks in the given communicator have made the call. In your case the open operation encompasses MPI_COMM_WORLD while you only call MPI_File_read_at_all in rank 0.

You should replace it with the non-collective MPI_File_read_at or, even better, use the standard C I/O routines instead.

Upvotes: 3

Related Questions