HP-MPI User's Guide (11th Edition)
Example applications
sort.C
Appendix A 273
//
// Have each rank build its block of entries for the global
sort.
//
int numEntries;
BlockOfEntries *aBlock = new BlockOfEntries(&numEntries,
myRank);
//
// Compute the total number of entries and sort them.
//
numEntries *= numRanks;
for(int j = 0; j < numEntries / 2; j++) {
//
// Synchronize and then update the shadow entries.
//
MPI_Barrier(MPI_COMM_WORLD);
int recvVal, sendVal;
MPI_Request sortRequest;
MPI_Status status;
//
// Everyone except numRanks-1 posts a receive for the right's
rightShadow.
//
if (myRank != (numRanks-1)) {
MPI_Irecv(&recvVal, 1, MPI_INT, myRank+1,
MPI_ANY_TAG, MPI_COMM_WORLD,
&sortRequest);
}
//
// Everyone except 0 sends its leftEnd to the left.
//
if (myRank != 0) {
sendVal = aBlock->getLeftEnd().getValue();
MPI_Send(&sendVal, 1, MPI_INT,
myRank-1, 1, MPI_COMM_WORLD);
}
if (myRank != (numRanks-1)) {