Parallel Computing Primer


MPI Function Reference

<< Basic Message Passing | Table of Contents | >>
The Message Passing Interface library contains many functions and data types for use in creating parallel programs. This section provides a reference for the more common functions and data types. The reference is divided into the following groups.



Preliminaries


(:begfnct mpi_init:)

int MPI_Init( int *argc, char **argv[] )

Initializes the MPI environment. This routine must be the first MPI function called by each process in the virtual computer.

argc
the value of argc from main().
argv
the value of argv from main().

(:endfnct:)

(:begfnct mpi_finalize:)

int MPI_Finalize()

Terminates the MPI environment and should be called by at the end of the program by every process in the virtual computer. (:endfnct:)

(:begfnct mpi_rank:)

int MPI_Comm_rank( MPI_Comm comm, int *pid )

Used by a process to determine its rank or process id number within a communicator.

comm
the communicator to be examined.
pid
the process id number is stored in the location pointed to by pid.

(:endfnct:)

(:begfnct mpi_size:)

int MPI_Comm_size( MPI_Comm comm, int *size )

Used by a process to determine the total number of processes associated with a given communicator.

comm
the communicator to be examined.
size
the number of processes is stored in the integer variable at the given reference.

(:endfnct:)

(:begfnct mpi_barrier:)

int MPI_Barrier( MPI_Comm comm )

Blocks all processes in the given communicator group until all processes have executed the function call. (:endfnct:)

(:begfnct mpi_wtime:)

double MPI_Wtime()

Returns the elapsed time, in seconds, from some point in the past. (:endfnct:)

Message Passing


(:begfnct mpi_bcast:)

int MPI_Bcast( void *buf, int count, MPI_Datatype datatype,

int srcPid, MPI_Comm comm )

(:endfnct:)

(:begfnct mpi_send:)

int MPI_Send( void *buf, int count, MPI_Datatype datatype,

int destPid, int tag, MPI_Comm comm )

(:endfnct:)

(:begfnct mpi_recv:)

int MPI_Recv( void *buf, int count, MPI_Datatype datatype,

int srcPid, int tag, MPI_Comm comm, MPI_Status *status )
srcPid
The id of the process from whom you want to receive a message. This can be set to MPI_ANY_SOURCE to receive a message from any process within the give communications group.
tag
A code indicating the type of message to be received. This can be set to MPI_ANY_TAG to receive a message with any type of tag associated with it.

(:endfnct:)

(:begfnct mpi_reduce:)

int MPI_Reduce( void *sendbuf, void *recvbuf, int count,

MPI_Datatype datatype, MPI_Op op, int destPid, MPI_Comm comm )

(:endfnct:)

(:begfnct mpi_probe:)

int MPI_Probe( int srcPid, int tag, MPI_Comm comm, MPI_Status *status );

Blocks and waits for a message with the given data tag from the indicated process. The function does not actually receive the message. It can be used in conjunction with MPI_Get_count().

srcPid
the id of the process from which you are waiting for a message.
tag
the tag associated with the type of message for which you are waiting.
comm
the communications group being probed.
status
address of a struct into which information related to the message can be stored.

(:endfnct:)

(:begfnct mpi_getcount:)

int MPI_Get_count( MPI_Status *status, MPI_Datatype datatype, int *count )

Determines the number of data items contained in a message just received or the next message to be received. This function is used with either MPI_Recv() or MPI_Probe().

status
the address of the MPI_Status struct filled in by either the MPI_Recv() or MPI_Probe() function.
datatype
the type of data items being received.
count
the address of an integer variable into which the number of items received is stored.

The following code segment illustrates the use of this function

(:source lang=cpp:)
MPI_Status msgStatus;
int numItems;

MPI_Probe( ROOT_PROC, DATA_TAG, MPI_COMM_WORLD, &msgStatus );
MPI_Get_count( &msgStatus, MPI_DOUBLE, &numItems );

MPI Data Types


(:begfnct mpi_comm:)

MPI_Comm

Indicates the process communicator group. The most common entry for a parameter of this type is MPI_COMM_WORLD. (:endfnct:)

(:begfnct mpi_datatype:)

MPI_Datatype

Indicates the type of data being transmitted using one of the MPI message passing routines. An MPI_Datatype argument should be one of the following which represents a common C-language data type.

  MPI_CHAR
  MPI_DOUBLE
  MPI_FLOAT
  MPI_INT
  MPI_LONG
  MPI_LONG_DOUBLE
  MPI_LONG_LONG
  MPI_SHORT
  MPI_UNSIGNED_CHAR
  MPI_UNSIGNED_INT
  MPI_UNSIGNED_LONG
  MPI_UNSIGNED_SHORT
  MPI_UNSIGNED_LONG_LONG

(:endfnct:)

(:begfnct mpi_op:)

MPI_OP

Specifies the type of reduce operation to be performed by the MPI_Reduce() function. Legal values for this data type include

MPI_MAX Select the maximum value.
MPI_MIN Select the minimum value.
MPI_PROD Compute the product of the values.
MPI_SUM Compute the sum of the values.

(:endfnct:)
<< Basic Message Passing | Table of Contents | >>

Print - Changes - Search
Last modified: May 02, 2007, at 09:15 PM.