Nature Language: masteronlyPingping:Two processes send a message to each other using the MPI_Isend, MPI_Recv and MPI_Wait routines. Inter-process communication takes place outside of the parallel region.
  
CPP: int masteronlyPingping(int totalReps, int dataSize){\\n\n int repIter, i;\\n\n int destRank;\\n\n if (myMPIRank == pingRankA){\\n\n   destRank = pingRankB;\\n\n } else if (myMPIRank == pingRankB){\\n\n   destRank = pingRankA;\\n\n }\\n\n for (repIter = 0; repIter < totalReps; repIter++){\\n\n   if (myMPIRank == pingRankA || myMPIRank == pingRankB){\\n\n     #pragma omp parallel for default(none) \\n\n     private(i) \\n\n     shared(pingSendBuf,dataSize,sizeofBuffer,globalIDarray) \\n\n     schedule(static,dataSize)\\n\n     for (i=0; i<sizeofBuffer; i++){\\n\n       pingSendBuf[i] = globalIDarray[myThreadID];\\n\n     }\\n\n     MPI_Isend(pingSendBuf, sizeofBuffer, MPI_INT, destRank, \\n\n     TAG, comm, &requestID);\\n\n     MPI_Recv(pingRecvBuf, sizeofBuffer, MPI_INT, destRank, \\n\n     TAG, comm, &status);\\n\n     MPI_Wait(&requestID, &status);\\n\n     #pragma omp parallel for default(none) \\n\n     private(i) \\n\n     shared(finalRecvBuf,dataSize,sizeofBuffer,pingRecvBuf) \\n\n     schedule(static,dataSize)\\n\n     for (i=0; i<sizeofBuffer; i++){\\n\n       finalRecvBuf[i] = pingRecvBuf[i];\\n\n     }\\n\n   }\\n\n }\\n\n return 0;\\n\n}",
  
Fortran: SUBROUTINE masteronlyPingping(totalReps, dataSize)\n integer, intent(in) :: totalReps, dataSize\n integer :: repIter, i\n integer :: destRank\n\n !set destRank to ID of other process\n IF (myMPIRank == pingRankA) THEN\n destRank = pingRankB\n ELSE IF (myMPIRank == pingRankB) THEN\n destRank = pingRankA\n END IF\n\n DO repIter = 1, totalReps !loop totalReps times\n\n IF(myMPIRank == pingRankA .or. myMPIRank == pingRankB) THEN\n\n !Each thread writes its globalID to pingSendBuf\n !using a PARALLEL DO directive.\n!$OMP PARALLEL DO DEFAULT(NONE), &\n!$OMP PRIVATE(i), &\n!$OMP SHARED(pingSendBuf,dataSize,sizeofBuffer,globalIDarray), &\n!$OMP SCHEDULE(STATIC,dataSize)\n DO i = 1, sizeofBuffer\n pingSendBuf(i) = globalIDarray(myThreadID)\n END DO\n!$OMP END PARALLEL DO\n\n !Process calls non-blocking send to start transfer of\n !pingSendBuf to other process.\n CALL MPI_ISend(pingSendBuf, sizeofBuffer, MPI_INTEGER, &\n destRank, tag, comm, requestID, ierr)\n\n !Process then waits for message from other process.\n CALL MPI_Recv(pingRecvBuf, sizeofBuffer, MPI_INTEGER, &\n destRank, tag, comm, status, ierr)\n\n !Finish the Send operation with an MPI_Wait\n CALL MPI_Wait(requestID, status, ierr)\n\n !Each thread under the MPI process now reads its part \n !of the received buffer.\n!$OMP PARALLEL DO DEFAULT(NONE), &\n!$OMP PRIVATE(i), &\n!$OMP SHARED(finalRecvBuf,dataSize,sizeofBuffer,pingRecvBuf), &\n!$OMP SCHEDULE(STATIC,dataSize)\n DO i = 1, sizeofBuffer\n finalRecvBuf(i) = pingRecvBuf(i)\n END DO\n!$OMP END PARALLEL DO\n\n END IF\n\n END DO !End repetitions loop\n END SUBROUTINE masteronlyPingping
  