Title: CS 420 Design of Algorithms
1CS 420 Design of Algorithms
- MPI Data Types
- Basic Message Passing - sends/receives
2MPI Data Types
- MPI has a set of its own data type definitions
- Most MPI types correspond to C types although
some are unique to MPI - C types may vary by implementation
- MPI types are consistent across implementations
- Supports portability in parallel applications
3MPI types and C types
4MPI types and C types
5Other MPI Data Types
- MPI_BYTE
- MPI_PACKED
- May be others depending on the implementation
6MPI send and receive
- MPI_Send and MPI_Recv are the most elemental
forms of MPI data communications - Provide the core set of functions
- MPI_Send and MPI_Recv are blocking communications
- Processing cannot proceed until the communication
process is complete.
7MPI_Send send a message
MPI_Send( void message, int count, MPI_
Datatype datatype, int dest, int tag, M
PI_Comm comm)
8MPI_Send
MPI_Send(a,1,MPI_FLOAT,myrank1,11,MPI_COMM_WORLD)
sends a single float to the next process in
MPI_COMM_WORLD and attaches a tag of 11.
MPI_Send(vect,100, MPI_FLOAT,5,12,
MPI_COMM_WORLD) sends a vector of 100
floats to process 5 in MPI_COMM_WORLD and uses a
tag of 12.
9MPI_Recv
int MPI_Recv( void message, int count, MP
I_Datatype datatype, int source, int tag, M
PI_Comm comm, MPI_Status status)
10MPI_Recv
MPI_Recv(x, 1, MPI_FLOAT, lsource, 11,
MPI_COMM_WORLD, status) picks up a message
with a tag11,from the source lsource in
MPI_COMM_WORLD. The status of the transaction is
stored in status. MPI_Recv(xarray, 100,
MPI_FLOAT, xproc, 12, MPI_COMM_WORLD,
status) picks up a message tagged 12 from the
source xproc in MPI_COMM_WORLD. That status of
the transaction is stored in status.
11MPI_Recv - wildcards
- MPI_ANY_SOURCE
- lets MPI_Recv take a message from any source.
Use as the source parameter - MPI_ANY_TAG
- lets MPI_Recv take a message regardless of its
tag.
12Wildcards
- No wildcards for MPI_Send
- No wildcards for communicator
- Send must specify a tag
- Recv must specify a matching tag or use a
wildcard
13MPI_ANY_SOURCE
- To receive from any process
- MPI_Recv(x, 1, MPI_FLOAT, MPI_ANY_SOURCE, 11,
MPI_COMM_WORLD, status) - and if you dont care what the tag is-
- MPI_Recv(x, 1, MPI_FLOAT, lsource, MPI_ANY_TAG,
MPI_COMM_WORLD,status)
14MPI_Status
- Return variable for the results of the
communication process. - A structure
- Roughly
- struct MPI_STATUS
- MPI_SOURCE source
- MPI_TAG tag
- MPI_ERROR errormsg
15MPI_Status
- Note no byte count in status variable (how many
bytes received in the message) - MPI_Get_count(
- MPI_Status status,
- MPI_Datatype datatype,
- int count_ptr)
16MPI Basic Core Functions
- MPI_Init
- MPI_Comm_rank
- MPI_Comm_size
- MPI_Send
- MPI_Recv
- MPI_Finalize
17(No Transcript)