[mpich-discuss] MPI_Gather

Rajeev Thakur thakur at mcs.anl.gov
Fri Nov 4 19:35:53 CDT 2011


Since rbuf is NULL on non-root ranks, rbuf[0] cannot be evaluated even to pass the parameter to the function. (Replace MPI_Gather with your own function FOO(buf) and pass rbuf[0] to it. It will fail.)

Rajeev

On Nov 4, 2011, at 6:41 PM, Wei-keng Liao wrote:

> 
> 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;
> }
> 
> 
> 
> _______________________________________________
> mpich-discuss mailing list     mpich-discuss at mcs.anl.gov
> To manage subscription options or unsubscribe:
> https://lists.mcs.anl.gov/mailman/listinfo/mpich-discuss



More information about the mpich-discuss mailing list