Nature Language: multiPingPong:Driver subroutine for the multi-pingpong benchmark.
  
CPP: int multiPingPong(int benchmarkType){\n    int dataSizeIter;\n    int pongWorldRank;\n    char pongProcName[MPI_MAX_PROCESSOR_NAME];\n    int balance;\n    pingNode = 0;\n    pongNode = 1;\n\n    balance = crossCommBalance(pingNode, pongNode);\n    if (balance == FALSE){\n        if (myMPIRank == 0){\n            printBalanceError();\n        }\n        return 1;\n    }\n\n    exchangeWorldRanks(pingNode, pongNode, &pongWorldRank);\n    sendProcName(pingNode, pongNode, pongProcName);\n    printMultiProcInfo(pingNode, pongWorldRank, pongProcName);\n    MPI_Barrier(comm);\n\n    if (myMPIRank == 0){\n        printBenchHeader();\n    }\n\n    repsToDo = defaultReps;\n    dataSizeIter = minDataSize; /* initialise dataSizeIter to minDataSize */\n\n    while (dataSizeIter <= maxDataSize){\n        sizeofBuffer = dataSizeIter * numThreads;\n        allocateMultiPingpongData(sizeofBuffer);\n\n        if (benchmarkType == MASTERONLY){\n            masteronlyMultiPingpong(warmUpIters, dataSizeIter);\n        } else if (benchmarkType == FUNNELLED){\n            funnelledMultiPingpong(warmUpIters, dataSizeIter);\n        } else if (benchmarkType == MULTIPLE){\n            multipleMultiPingpong(warmUpIters, dataSizeIter);\n        }\n\n        testMultiPingpong(sizeofBuffer, dataSizeIter);\n        benchComplete = FALSE;\n\n        while (benchComplete != TRUE){\n            /* Then start the timer. */\n            MPI_Barrier(comm);\n            startTime = MPI_Wtime();\n\n            if (benchmarkType == MASTERONLY){\n                masteronlyMultiPingpong(repsToDo, dataSizeIter);\n            } else if (benchmarkType == FUNNELLED){\n                funnelledMultiPingpong(repsToDo, dataSizeIter);\n            } else if (benchmarkType == MULTIPLE){\n                multipleMultiPingpong(repsToDo, dataSizeIter);\n            }\n\n            /* for more accurate timing. */\n            MPI_Barrier(comm);\n            finishTime = MPI_Wtime();\n            totalTime = finishTime - startTime;\n\n            if (myMPIRank==0){\n                benchComplete = repTimeCheck(totalTime, repsToDo);\n            }\n\n            MPI_Bcast(&benchComplete, 1, MPI_INT, 0, comm);\n            MPI_Bcast(&repsToDo,",
  
Fortran: SUBROUTINE multiPingPong(benchmarkType)\n integer, intent(in) :: benchmarkType\n integer :: dataSizeIter\n integer :: pongWorldRank\n character (len = MPI_MAX_PROCESSOR_NAME) :: pongProcName\n logical :: balance\n\n pingNode = 0\n pongNode = 1\n\n !Check if there's a balance in num of MPI processes on\n !pingNode and pongNode.\n balance = crossCommBalance(pingNode, pongNode)\n !If not balanced..\n IF (balance .EQV. .false.) THEN\n !..Master prints error\n IF (myMPIRank == 0) THEN\n CALL printBalanceError()\n END IF\n !..and all processes return from subroutine.\n RETURN\n END IF\n \n !Exchange MPI_COMM_WORLD ranks for processes in same crossComm\n CALL exchangeWorldRanks(pingNode, pongNode, pongWorldRank)\n\n !Processes on pongNode send processor name to pingNode procs\n CALL sendProcName(pingNode, pongNode, pongProcName)\n\n !Print comm world ranks & processor names of\n !processes taking part in multi-pingpong benchmark.\n CALL printMultiProcInfo(pingNode, pongWorldRank, pongProcName)\n\n !Barrier to ensure that all procs have completed\n !printMultiProcInfo before printing column headings\n CALL MPI_Barrier(comm, ierr)\n !Master process then prints report column headings\n IF (myMPIRank == 0) THEN\n CALL printBenchHeader()\n END IF\n\n !initialise repsToDo to defaultReps at start of benchmark\n repsToDo = defaultReps\n\n !Loop over data sizes\n dataSizeIter = minDataSize !initialise dataSizeIter to minDataSize\n DO WHILE (dataSizeIter <= maxDataSize)\n \n !set sizeofBuffer\n sizeofBuffer = dataSizeIter * numThreads\n\n !Allocate space for the main data arrays\n CALL allocateData(sizeofBuffer)\n\n !Warm-up for either masteronly, funnelled or multiple\n IF (benchmarkType == MASTERONLY) THEN\n !Perform masteronly warm-up sweep\n CALL masteronlyMultiPingpong(warmUpIters, dataSizeIter)\n ELSE IF (benchmarkType == FUNNELLED) THEN\n !Funnelled warm-up sweep\n CALL funnelledMultiPingpong(warmUpIters, dataSizeIter)\n ELSE IF (benchmarkType == MULTIPLE) THEN\n !Mutiple pingpong warmup\n CALL multipleMultiPingpong(warmUpIters, dataSizeIter)\n END IF\n\n !Verification test for multi-pingpong\n CALL testMultiPingpong(sizeofBuffer, dataSizeIter)\n\n !Initialise benchmark\n benchComplete = .false.\n !Keep executing benchmark until target time is reached\n DO WHILE (benchComplete .NEQV. .true.)\n \n !Start the timer...MPI_Barrier to synchronise\n !processes for more accurate timing.\n CALL MPI_Barrier(comm, ierr)\n startTime = MPI_Wtime()\n \n IF (benchmarkType == MASTERONLY) THEN\n !Execute masteronly multipingpong repsToDo times\n CALL masteronlyMultiPingpong(repsToDo, dataSizeIter)\n ELSE IF (benchmarkType == FUNNELLED) THEN\n !Execute funnelled multipingpong\n CALL funnelledMultiPingpong(repsToDo, dataSizeIter)\n ELSE IF (benchmarkType == MULTIPLE) THEN\n !Exexute multiple multipingpong\n CALL multipleMultiPingpong(repsToDo, dataSizeIter)\n END IF\n\n !Stop the timer...MPI_Barrier to synchronise processes\n !for more accurate timing.\n CALL MPI_Barrier(comm, ierr)\n finishTime = MPI_Wtime()\n totalTime = finishTime - startTime\n\n !Call repTimeCheck function to test if target time\n !is reached.\n if (myMPIRank==0) then \n benchComplete = repTimeCheck(totalTime, repsToDo)\n end if\n !Ensure all procs have the same value of benchComplete\n !and repsToDo\n call MPI_Bcast(benchComplete, 1, MPI_INTEGER, 0, comm, ierr)\n call MPI_Bcast(repsToDo, 1, MPI_INTEGER, 0, comm, ierr)\n\n END DO !end of loop to check if benchComplete is true\n\n !Master process sets benchmark results\n IF (myMPIRank == 0) THEN\n CALL setReportParams(dataSizeIter, repsToDo, totalTime)\n CALL printReport()\n END IF\n\n !Free the allocated space for the main data arrays\n CALL freeData()\n\n !Update dataSize before next iteration\n dataSizeIter = dataSizeIter * 2 !double data size\n\n END DO !end of loop over data sizes.\n\n END SUBROUTINE multiPingPong
  