In a distributed-memory machine each processor has access only to its own memory. There is no common or shared memory that processors can access.
Therefore, processors can interact only by explicitly transmitting packages of data between each other. In the roundRobin program this interaction was accomplised using MPI function calls MPI_Send () , MPI_Recv () and MPI_Bcast () ; these functions are explained below.
Before a processor can send information, it has to pack the relevant data into a "send buffer" located in its own memory.
Similary, when a processor receives data from another process, it has to unpack the data sitting in its own "receive buffer".
In C the MPI function to send data is:
int MPI_Send( void* sendBuf, int count, MPI_Datatype datatype, int destinationRank, int tag, MPI_Comm comm )
sendBuf is the send buffer or array packed with the data to be sent.
count is the length of the sendBuf array.
datatype is the datatype of the sendBuf array, typically MPI_INT, MPI_FLOAT , or MPI_DOUBLE.
destinationRank is the rank of the intended receiving processor.
tag is an identifier that may be used to distinguish among multiple transmissions between the same two processors.
comm is the communication domain. In this workshop, we will always specify the default communicator MPI_COMM_WORLD which consists of all processors.
Be aware that a processor executing an MPI_Send will "block", i.e. it will not proceed executing subsequent code until the send is completed.
The MPI receive function in C looks as shown in the roundRobin program is:
int MPI_Recv( void* recvBuf, int count, MPI_Datatype datatype, int sourceRank, int tag, MPI_Comm comm, MPI_Status *status )
recvBuf is the receive buffer or array into which the MPI API will place the transmitted data.
count is the length of the recvBuf array.
datatype is the datatype of the recvBuf array, typically MPI_INT, MPI_FLOAT , or MPI_DOUBLE .
sourceRank is the rank of the sending processor.
tag is an identifier that may be used to distinguish among multiple transmissions between the same two processors.
comm is the communication domain.
status is a pointer to information about the state of the receive. In this workshop, we will not make use of this status information.
Similar to what was explained in the case of MPI_Send () , a processor executing an MPI_Recv will "block", i.e. it will not proceed executing subsequent code, until the receive is completed.
And finally, if a process is expected to send some information to all the other processes, then we can use the MPI_Bcast () command.
int MPI_Bcast ( void* buffer, int count, MPI_Datatype datatype, int root, MPI_Comm comm )
The parameters to the above MPI function are similar to the ones in MPI_Send () and MPI_Recv () functions.
MPI_Comm_Size () tells the participating processes about the total number of processes in this communicator. This is also something they need to know. For example, if the program is to work on a very long array, the processes will have to know how many of them there are in the pool in order to work out for themselves which portion of the array they should work on.
Misc: MPI has a function called MPI_Wtime () that can be used to time your program (or sections of it). It measures wall-clock time down to a microsecond, very accurate indeed. Of course using a tool like Intel Trace Analyzer would give you an even better idea about how your program is performing.
| Previous: RoundRobin - Message... | Up: Table of Contents | Next: Data Decomposition |
|---|