HP-MPI User's Guide (11th Edition)
Example applications
sort.C
Appendix A274
MPI_Wait(&sortRequest, &status);
aBlock->setRightShadow(Entry(recvVal));
}
//
// Everyone except 0 posts for the left's leftShadow.
//
if (myRank != 0) {
MPI_Irecv(&recvVal, 1, MPI_INT, myRank-1,
MPI_ANY_TAG, MPI_COMM_WORLD,
&sortRequest);
}
//
// Everyone except numRanks-1 sends its rightEnd right.
//
if (myRank != (numRanks-1)) {
sendVal = aBlock->getRightEnd().getValue();
MPI_Send(&sendVal, 1, MPI_INT,
myRank+1, 1, MPI_COMM_WORLD);
}
if (myRank != 0) {
MPI_Wait(&sortRequest, &status);
aBlock->setLeftShadow(Entry(recvVal));
}
//
// Have each rank fix up its entries.
//
aBlock->singleStepOddEntries();
aBlock->singleStepEvenEntries();
}
//
// Print and verify the result.
//
if (myRank == 0) {
intsendVal;
aBlock->printEntries(myRank);
aBlock->verifyEntries(myRank, INT_MIN);
sendVal = aBlock->getRightEnd().getValue();
if (numRanks > 1)
MPI_Send(&sendVal, 1, MPI_INT, 1, 2,
MPI_COMM_WORLD);