Nature Language: masteronlyMultiPingping:All Processes with rank of pingNodeA or pingNodeB in crossComm send a message to each other. MPI communication takes place outside of the parallel region.
  
CPP: int masteronlyMultiPingping(int totalReps, int dataSize){\n  int repIter, i;\n  int destRank;\n\n  /* set destRank to ID of other process */\n  if (crossCommRank == pingNodeA){\n    destRank = pingNodeB;\n  }\n  else if (crossCommRank == pingNodeB){\n    destRank = pingNodeA;\n  }\n\n  /* loop totalRep times */\n  for (repIter=1; repIter<=totalReps; repIter++){\n\n    if ((crossCommRank == pingNodeA) || (crossCommRank == pingNodeB) ){\n\n      /* Each thread writes its globalID to pingSendBuf\n       * with a parallel for directive.\n       */\n#pragma omp parallel for default(none)\n  private(i)\n  shared(pingSendBuf,dataSize,sizeofBuffer,globalIDarray)\n  schedule(static,dataSize)\n\n      for (i=0; i<sizeofBuffer; i++){\n\tpingSendBuf[i] = globalIDarray[myThreadID];\n      }\n\n      /* Process calls non-blocking send to start transfer of\n       * pingSendBuf to other process.\n       */\n      MPI_Isend(pingSendBuf, sizeofBuffer, MPI_INT, destRank, TAG,\n\t\tcrossComm, &requestID);\n\n      /* Processes then wait for message from other process. */\n      MPI_Recv(pingRecvBuf, sizeofBuffer, MPI_INT, destRank, TAG, \n\t       crossComm, &status);\n\n      /* Finish the send operation with an MPI_Wait */\n      MPI_Wait(&requestID, &status);\n\n      /* Threads under the MPI processes read their part of the\n       * received buffer.\n       */\n#pragma omp parallel for default(none)\n  private(i)\n  shared(finalRecvBuf,dataSize,sizeofBuffer,pingRecvBuf)\n  schedule(static,dataSize)\n\n      for (i=0; i<sizeofBuffer; i++){\n\tfinalRecvBuf[i] = pingRecvBuf[i];\n      }\n\n    }\n  } /* End repetitions loop */\n\n  return 0;\n}
  
Fortran: SUBROUTINE masteronlyMultiPingping(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 (crossCommRank == pingNodeA) THEN\n destRank = pingNodeB\n ELSE IF (crossCommRank == pingNodeB) THEN\n destRank = pingNodeA\n END IF\n\n DO repIter = 1, totalReps !loop totalRep times\n\n IF (crossCommRank == pingNodeA .or. &\n crossCommRank == pingNodeB) THEN\n \n !Each thread writes its globalID to pingSendBuf\n !with 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\n DO i = 1, sizeofBuffer\n pingSendBuf(i) = globalIDarray(myThreadID)\n END DO\n\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, crossComm, requestID, ierr)\n\n !Processes then waits for message from other process.\n CALL MPI_Recv(pingRecvBuf, sizeofBuffer, MPI_INTEGER, &\n destRank, tag, crossComm, status, ierr)\n\n !Finish the send operation with an MPI_Wait\n CALL MPI_Wait(requestID, status, ierr)\n\n !The threads under the MPI processes read their \n !part 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\n END SUBROUTINE masteronlyMultiPingping
  