next up previous index
Next: Particles Again Up: Derived Data Types Previous: Commit and free

Counting the elements

The function

MPI_Get_elements(MPI_Status *status, MPI_Datatype datatype, int *count)
returns the number of basic elements of datatype received in a message. There is a subtle difference between this function and MPI_Get_count, and it shows in the situations in which datatype is used to define a complex layout of data in the receiver memory and does not represent a basic unit of data for transfers.

Example:

...
call mpi_type_contiguous(2, MPI_REAL, type2, ierr)
call mpi_type_commit(type2, ierr)
...
call mpi_comm_rank(comm, rank, ierr)
if(rank .eq. 0) then
   call mpi_send(a, 2, mpi_real, 1, 0, comm, ierr)
   call mpi_send(a, 3, mpi_real, 1, 0, comm, ierr)
else
   call mpi_recv(a, 2, type2, 0, 0, comm, stat, ierr)
   call mpi_get_count(stat, type2, i, ierr)    ! returns i = 1
   call mpi_get_elements(stat, type2, i, ierr) ! returns i = 2
   call mpi_recv(a, 2, type2, 0, 0, comm, stat, ierr)
   call mpi_get_count(stat, type2, i, ierr)    ! returns i = MPI_UNDEFINED
   call mpi_get_elements(stat, type2, i, ierr) ! returns i = 3
end if



Zdzislaw Meglicki
2001-02-26