[mpich-discuss] MPI_Gather

Wei-keng Liao wkliao at ece.northwestern.edu
Fri Nov 4 18:41:57 CDT 2011


I have a simple program that calls MPI_Gather().
It fails when the receive buffer pointer on the 
non-root processes is invalid.

According to the MPI standard: 
"The receive buffer is ignored for all non-root processes."
So, MPICH should not even check this buffer
pointer. Is my understanding of MPI correct?

The code is provided at the bottom.
If the macro FIX is defined, the code runs fine.

(I tested it on mpich2-1.4)

Wei-keng
----------------------------------

#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>

#define LEN 100
int main(int argc, char* argv[]) {
    char sbuf[LEN], **rbuf=NULL, *tmp=NULL;
    int rank, nprocs;

    MPI_Init(&argc, &argv);
    MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);

    if (rank == 0) {
        rbuf = (char**) malloc(nprocs * sizeof(char*));
        rbuf[0] = (char *) malloc(nprocs * LEN * sizeof(char));
        tmp = rbuf[0];
    }

#ifdef FIX
    MPI_Gather(sbuf, LEN, MPI_CHAR, tmp,     LEN, MPI_CHAR, 0, MPI_COMM_WORLD);
#else
    MPI_Gather(sbuf, LEN, MPI_CHAR, rbuf[0], LEN, MPI_CHAR, 0, MPI_COMM_WORLD);
#endif

    MPI_Finalize();
    return 0;
}





More information about the mpich-discuss mailing list