NERSC logo National Energy Research Scientific Computing Center
  A DOE Office of Science User Facility
  at Lawrence Berkeley National Laboratory
 

Basic Receive

Once you've sent a message, you must receive it on another task. The MPI_RECV call is similar to the send call.

Fortran

FORTRAN_TYPE::  rbuf
INTEGER:: count, source, tag, status(MPI_STATUS_SIZE), ierr

CALL MPI_RECV(rbuf, count, MPI_TYPE, source, tag, comm, status, ierr)

C

int MPI_Recv( void *rbuf, int count, MPI_Datatype datatype, int source,
	int tag, MPI_Comm comm, MPI_Status *status )

The arguments that are different from those in MPI_SEND are

  • rbuf : This is the name of the variable where you'll be storing the received data.
  • source : This replaces the destination in the send command. This is the return ID of the sender.
  • status : You can check this variable to see if the receive was completed.

Example: simple send and receive

This example, pingpong.f90, available in $EXAMPLES/mpi/intro/simple, demonstrates these calls.

If we compile and run

franklin% ftn -o pingpong pingpong.f90

the output looks like this:

franklin% qsun -I -lmppwidth=2
franklin% cd $PBS_O_WORKDIR
franklin% aprun -n 2 ./pingpong 
   0: TASK # 0  sent  0
   0: TASK # 0  received  1
   1: TASK # 1  sent  1
   1: TASK # 1  received  0

LBNL Home
Page last modified: Fri, 07 Mar 2008 21:41:06 GMT
Page URL: http://www.nersc.gov/nusers/help/tutorials/mpi/intro/receive.php
Web contact: webmaster@nersc.gov
Computing questions: consult@nersc.gov

Privacy and Security Notice
DOE Office of Science