LAM/MPI logo

LAM/MPI General User's Mailing List Archives

  |   Home   |   Download   |   Documentation   |   FAQ   |   all just in this list

From: Steve Lowder (slowder_at_[hidden])
Date: 2005-05-09 11:29:03


Hello,

  I have an MPI application where I need to "gather" a 3D array into one
process that does not provide data to the array.

  For example, I have a distributed 3D array across 20 processors and I want
to gather it to a 21st processor. The only I know to do this easily is with
SEND/RECV and derived datatypes. There are a number of instances of this
software posted on the web.

 

 Here is a typical example, I want to put this into a subroutine to cache
some datatypes.

 

 ------------------------------------- sample code begin
-----------------------------
 
      REAL a(100,100,100), e(9,9,9)
      INTEGER oneslice, twoslice, threeslice, sizeofreal, myrank, ierr
      INTEGER status(MPI_STATUS_SIZE)

      CALL MPI_COMM_RANK(MPI_COMM_WORLD, myrank)

      CALL MPI_TYPE_EXTENT( MPI_REAL, sizeofreal, ierr)

C create datatype for a 1D section

      CALL MPI_TYPE_VECTOR( 9, 1, 2, MPI_REAL, oneslice, ierr)

C create datatype for a 2D section

      CALL MPI_TYPE_HVECTOR(9, 1, 100*sizeofreal, oneslice, twoslice, ierr)

C create datatype for the entire section

      CALL MPI_TYPE_HVECTOR( 9, 1, 100*100*sizeofreal, twoslice, 1,

                             threeslice, ierr)

      CALL MPI_TYPE_COMMIT( threeslice, ierr)

      CALL MPI_SENDRECV(a(1,3,2), 1, threeslice, myrank, 0, e, 9*9*9,
MPI_REAL, myrank, 0, MPI_COMM_WORLD, status, ierr)

------------ sample code end
---------------------------------------------------------

 

I'm trying to understand some of the memory allocation issues about this
code.

 

1. When the first two derived types are created, I assume that memory
is allocated for opaque objects and the handle is stored in the variables
oneslice and twoslice. If this was inside a subroutine and called many
times, I would assume I need to explicitly free these objects inside the
subroutine prior to exit otherwise I have small memory leak. Is this
correct?
2. When the third type is created (threeslice), does it copy the info
from the previous type (twoslice) so I could free twoslice or does it just
keep a reference implying that I can not free twoslice? I know that freeing
threeslice does no affect twoslice, but what would freeing twoslice do to
threeslice?
3. Some versions of this code have a MPI_TYPE_FREE of threeslice which
I think leads people to believe that the free is necessary only because of
the MPI_TYPE_COMMIT. I don't know if the COMMIT creates more objects but I'm
guessing the FREE is necessary first because of the initial object creation
of threeslice. Is this correct?

 

I've read some of the MPI standard and I what I understand from it is, if
you create it (any derived type), you free it, period. Is this correct? I
have heard people comment that if this code is inside a subroutine then the
local variables (handles) will automatically mark their respective objects
for deallocation on exit. I doubt this is true. Yes? No?

 

Thank you,

Steve Lowder

NRL Monterey