Nature Language: masteronlyMultiPingpong:All MPI processes in crossComm = pingNode sends a single fixed length message to the neighbouring process in crossComm = pongNode. The neighbouring processes then sends the message back to the first process.
  
CPP: int masteronlyMultiPingpong(int totalReps, int dataSize){\n    int repIter, i;\n    for (repIter = 1; repIter <= totalReps; repIter++){\n        if (crossCommRank == pingNode){\n            #pragma omp parallel for default(none) \\\n            private(i) \\\n            shared(pingSendBuf,dataSize,sizeofBuffer,globalIDarray) \\\n            schedule(static,dataSize)\n            for (i=0; i<sizeofBuffer; i++){\n                pingSendBuf[i] = globalIDarray[myThreadID];\n            }\n            MPI_Send(pingSendBuf, sizeofBuffer, MPI_INT, pongNode, TAG, crossComm);\n            MPI_Recv(pongRecvBuf, sizeofBuffer, MPI_INT, pongNode, \\\n            TAG, crossComm, &status);\n            #pragma omp parallel for default(none) \\\n            private(i) \\\n            shared(pongRecvBuf,finalRecvBuf,dataSize,sizeofBuffer) \\\n            schedule(static,dataSize)\n            for (i=0; i<sizeofBuffer; i++){\n                finalRecvBuf[i] = pongRecvBuf[i];\n            }\n        } else if (crossCommRank == pongNode){\n            MPI_Recv(pingRecvBuf, sizeofBuffer, MPI_INT, pingNode,\\\n            TAG, crossComm, &status);\n            #pragma omp parallel for default(none) \\\n            private(i) \\\n            shared(pongSendBuf,pingRecvBuf,dataSize,sizeofBuffer) \\\n            schedule(static,dataSize)\n            for (i=0; i<sizeofBuffer; i++){\n                pongSendBuf[i] = pingRecvBuf[i];\n            }\n            MPI_Send(pongSendBuf, sizeofBuffer, MPI_INT, pingNode, \\\n            TAG, crossComm);\n        }\n    }\n    return 0;\n}",
  
Fortran: SUBROUTINE masteronlyMultiPingpong(totalReps, dataSize)\n integer, intent(in) :: totalReps, dataSize\n integer :: repIter, i\n\n DO repIter = 1, totalReps !loop totalRep times\n\n !All threads under each MPI process with \n !crossCommRank = pingNode write to pingSendBuf array\n !using a PARALLEL DO directive.\n IF (crossCommRank == pingNode) THEN\n \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!$OMP END PARALLEL DO\n\n !Each process with crossCommRank = pingNode sends\n !buffer to MPI process with rank = pongNode in crossComm.\n CALL MPI_Send(pingSendBuf, sizeofBuffer, MPI_INTEGER,&\n pongNode, tag, crossComm, ierr)\n\n !The processes then wait for a message from pong process\n !and each thread reads its part of the received buffer.\n CALL MPI_Recv(pongRecvBuf, sizeofBuffer, MPI_INTEGER,&\n pongNode, tag, crossComm, status, ierr)\n\n!$OMP PARALLEL DO DEFAULT(NONE), &\n!$OMP PRIVATE(i), &\n!$OMP SHARED(pongRecvBuf,finalRecvBuf,dataSize,sizeofBuffer), &\n!$OMP SCHEDULE(STATIC,dataSize)\n DO i = 1, sizeofBuffer\n finalRecvBuf(i) = pongRecvBuf(i)\n END DO\n!$OMP END PARALLEL DO\n\n ELSEIF (crossCommRank == pongNode) THEN\n\n !Each process with crossCommRank = pongNode receives\n !the message from the pingNode processes.\n CALL MPI_Recv(pingRecvBuf, sizeofBuffer, MPI_INTEGER,&\n pingNode, tag, crossComm, status, ierr)\n\n !Each thread copies its part of the received buffer\n !to pongSendBuf.\n!$OMP PARALLEL DO DEFAULT(NONE), &\n!$OMP PRIVATE(i), &\n!$OMP SHARED(pongSendBuf,pingRecvBuf,dataSize,sizeofBuffer),&\n!$OMP SCHEDULE(STATIC,dataSize)\n DO i = 1,sizeofBuffer\n pongSendBuf(i) = pingRecvBuf(i)\n END DO\n!$OMP END PARALLEL DO\n\n !The processes now send pongSendBuf to processes\n !with crossCommRank = pingNode.\n CALL MPI_Send(pongSendBuf, sizeofBuffer, MPI_INTEGER, &\n pingNode, tag, crossComm, ierr)\n \n END IF\n\n END DO !End repetitions loop\n\n END SUBROUTINE masteronlyMultiPingpong
  