Newsgroups: comp.parallel.mpi
From: llewins@msmail4.hac.com (Lloyd J Lewins)
Subject: MPI_Gather
Organization: Hughes Aerospace Electronics Co.
Date: Fri, 31 Mar 1995 11:25:46 -0800
Message-ID: <llewins-3103951125460001@x-147-16-95-58.es.hac.com>

Some time ago, Peter posted the following message:

>Is it possible to receive data into interleaved locations
>with a single call to MPI_Gather?  For example, suppose
>a C program contains the following definitions.
>
>    /* 10 processes */
>    float A[10][10];
>    float column[10];
>
>If each process initializes its copy of column, is it
>possible to gather the columns into A on, say, process 0
>with a single call to MPI_Gather?  Something like
>    
>    MPI_Type_vector(10,1,10,MPI_FLOAT, &recvtype);
>    MPI_Type_commit(&recvtype);
>    MPI_Gather(column, 10, MPI_FLOAT, A, 
>        1, recvtype, 0, MPI_COMM_WORLD);

>The standard implies this is not possible when it states
>that the effect is as if each process had executed
>
>    MPI_Send(column, 10, MPI_FLOAT, 0, . . .)
>
>and 0 had executed 10 calls to
>
>    MPI_Recv(A + i*EXTENT(recvtype), 1, recvtype, i, . . .)
>
>The public domain implementations (mpich, lam, and chimp) 
>also don't seem to allow it.
>
>Was this intended?
>
>Thanks,
>Peter Pacheco
>peter@mobydick.usfca.edu

This is possible, but requires an extra step which is missing. The default
extent for a vector type is (roughly) N times the stride. However, what is
required for this case is an extent of "sizeof (float)". This can be
acheived by explicitly setting the extent using MPI_UB in a "struct" type.

For the above example, the following should suffice:
 
    int          blens[2];
    MPI_Aint     displ[2];
    MPI_Datatype types[2];

    MPI_Type_vector(10,1,10,MPI_FLOAT, &temptype);     
    blens[0] = 1;
    blens[1] = 1;
    displ[0] = 1;
    displ[1] = sizeof (long);
    types[0] = temptype;
    types[1] = MPI_UB;
    MPI_Type_struct (2, blens, displ, types, &recvtype);
    MPI_Type_commit(&recvtype);
    MPI_Gather(column, 10, MPI_FLOAT, A, 
        1, recvtype, 0, MPI_COMM_WORLD);

--------------------------------------------------------------------------
Lloyd J Lewins                                  Mail Stop: RE/R1/B507
Hughes Aerospace and Electronics Co.            P.O. Box 92426
                                                Los Angeles, CA 90009-2426
Email: llewins@msmail4.hac.com                  USA
Tel: 1 (310) 334-1145
Any opinions are not neccessarily mine, let alone my employers!!

