Nature Language: masteronlyHaloexchange:Each process exchanges a message with its left and right neighbour. Communication takes place outside of the parallel region.
  
CPP: int masteronlyHaloexchange(int totalReps, int dataSize){\n    int repIter, i;\n    \n    for (repIter=0; repIter<totalReps; repIter++){\n        \n        /* Fill leftSendBuf and rightSendBuf using a parallel for directive. */\n        #pragma omp parallel for default(none) \\\n        private(i) \\\n        shared(leftSendBuf,rightSendBuf,dataSize) \\\n        shared(sizeofBuffer,globalIDarray) \\\n        schedule(static,dataSize)\n        for (i=0; i<sizeofBuffer; i++){\n            leftSendBuf[i] = globalIDarray[myThreadID];\n            rightSendBuf[i] = globalIDarray[myThreadID];\n        }\n        \n        /* Send data to leftNeighbour and rightNeighbour using non-blocking send... */\n        MPI_Isend(leftSendBuf, sizeofBuffer, MPI_INT, leftNeighbour, \\\n        TAG, commCart, &requestArray[0]);\n        MPI_Isend(rightSendBuf, sizeofBuffer, MPI_INT, rightNeighbour, \\\n        TAG, commCart, &requestArray[1]);\n        MPI_Irecv(leftRecvBuf, sizeofBuffer, MPI_INT, leftNeighbour, \\\n        TAG, commCart, &requestArray[2]);\n        MPI_Irecv(rightRecvBuf, sizeofBuffer, MPI_INT, rightNeighbour, \\\n        TAG, commCart, &requestArray[3]);\n        \n        MPI_Waitall(4, requestArray, statusArray);\n        \n        #pragma omp parallel for default(none) \\\n        private(i) \\\n        shared(leftRecvBuf,rightRecvBuf,dataSize,sizeofBuffer) \\\n        shared(finalLeftBuf,finalRightBuf) \\\n        schedule(static,dataSize)\n        for (i=0; i<sizeofBuffer; i++){\n            finalLeftBuf[i] = leftRecvBuf[i];\n            finalRightBuf[i] = rightRecvBuf[i];\n        }\n    }\n    return 0;\n}",
  
Fortran: SUBROUTINE masteronlyHaloexchange(totalReps, dataSize)\ninteger, intent(in) :: totalReps, dataSize\ninteger :: repIter, i\nDO repIter = 1, totalReps\n\n!Each thread writes its globalID to rightSendBuf\n!and leftSendBuf with a parallel do directive\n!$OMP PARALLEL DO DEFAULT(NONE), &\n!$OMP PRIVATE(i), &\n!$OMP SHARED(leftSendBuf,rightSendBuf,dataSize,sizeofBuffer), &\n!$OMP SHARED(globalIDarray),&\n!$OMP SCHEDULE(STATIC,dataSize)\nDO i = 1, sizeofBuffer\nleftSendBuf(i) = globalIDarray(myThreadID)\nrightSendBuf(i) = globalIDarray(myThreadID)\nEND DO\n!$OMP END PARALLEL DO\n\n!Process starts send of data to leftNeighbour and\n!rightNeighbour using non-blocking send...\n!..to leftNeighbour\nCALL MPI_ISend(leftSendBuf, sizeofBuffer, MPI_INTEGER, &\nleftNeighbour, tag, comm, requestArray(1), ierr)\n!..to rightNeighbour\nCALL MPI_ISend(rightSendBuf, sizeofBuffer, MPI_INTEGER, &\nrightNeighbour, tag, comm, requestArray(2), ierr)\n\n!Process then waits for messages from leftNeighbour and\n!rightNeighbour.\n!Receive leftRecvBuf from leftNeighbour\nCALL MPI_IRecv(leftRecvBuf, sizeofBuffer, MPI_INTEGER, &\nleftNeighbour, tag, comm, requestArray(3), ierr)\n!Receive rightRecvBuf from rightNeighbour\nCALL MPI_IRecv(rightRecvBuf, sizeofBuffer, MPI_INTEGER, &\nrightNeighbour, tag, comm, requestArray(4), ierr)\n\n!Finish the sends with an MPI_Waitall on the requests\nCALL MPI_Waitall(4, requestArray, statusArray, ierr) \n\n!Each thread now reads its part of the left and right\n!received buffers.\n!$OMP PARALLEL DO DEFAULT(NONE), &\n!$OMP PRIVATE(i), &\n!$OMP SHARED(leftRecvBuf,rightRecvBuf,dataSize,sizeofBuffer),&\n!$OMP SHARED(finalLeftBuf,finalRightBuf), &\n!$OMP SCHEDULE(STATIC,dataSize)\nDO i = 1, sizeofBuffer\nfinalLeftBuf(i) = leftRecvBuf(i)\nfinalRightBuf(i) = rightRecvBuf(i)\nEND DO\n!$OMP END PARALLEL DO\n\nEND DO\n\nEND SUBROUTINE masteronlyHaloexchange
  