Nature Language: reduction:Driver subroutine for the reduce and allReduce benchmarks.
  
CPP: int reduction(int benchmarkType){\n    int dataSizeIter, sizeofBuf;\n    repsToDo = defaultReps;\n    dataSizeIter = minDataSize;\n\n    while (dataSizeIter <= maxDataSize){\n        allocateReduceData(dataSizeIter);\n\n        if (benchmarkType == REDUCE){\n            reduceKernel(warmUpIters, dataSizeIter);\n\n            if (myMPIRank == 0){\n                testReduce(dataSizeIter, benchmarkType);\n            }\n        } else if (benchmarkType == ALLREDUCE){\n            sizeofBuf = dataSizeIter * numThreads;\n            allReduceKernel(warmUpIters, dataSizeIter);\n            testReduce(sizeofBuf, benchmarkType);\n        }\n\n        benchComplete = FALSE;\n\n        while (benchComplete != TRUE){\n            MPI_Barrier(comm);\n            startTime = MPI_Wtime();\n\n            if (benchmarkType == REDUCE){\n                reduceKernel(repsToDo, dataSizeIter);\n            } else if (benchmarkType == ALLREDUCE){\n                allReduceKernel(repsToDo, dataSizeIter);\n            }\n\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, 1, MPI_INT, 0, comm);\n        }\n\n        if (myMPIRank == 0){\n            setReportParams(dataSizeIter, repsToDo, totalTime);\n            printReport();\n        }\n\n        freeReduceData();\n        dataSizeIter = dataSizeIter * 2;\n    }\n\n    return 0;\n}",
  
Fortran: SUBROUTINE reduction(benchmarkType)\ninteger, intent(in) :: benchmarkType\ninteger :: dataSizeIter\ninteger :: sizeofBuf !for allReduce operation\n!initialise repsToDo to defaultReps\nrepsToDo = defaultReps\n!Start loop over data sizes\ndataSizeIter = minDataSize !initialise dataSizeIter\nDO WHILE (dataSizeIter <= maxDataSize)\n!allocate space for the main data arrays..\nCALL allocateData(dataSizeIter)\n!Perform benchmark warm-up\nIF (benchmarkType == REDUCE) THEN\nCALL reduceKernel(warmUpIters,dataSizeIter)\n!Master process tests if reduce was success\nIF (myMPIRank == 0) THEN\nCALL testReduce(dataSizeIter,benchmarkType)\nEND IF\nELSE IF (benchmarkType == ALLREDUCE) THEN\n!calculate sizeofBuf for test\nsizeofBuf = dataSizeIter * numThreads\nCALL allReduceKernel(warmUpIters, dataSizeIter)\n!All processes need to perform unit test\nCALL testReduce(sizeofBuf,benchmarkType)\nEND IF\n!Initialise the benchmark\nbenchComplete = .false.\n!Execute benchmark until target time is reached\nDO WHILE (benchComplete .NEQV. .true.)\n!Start timer\nCALL MPI_Barrier(comm, ierr)\nstartTime = MPI_Wtime()\n!Execute reduce for repsToDo repetitions\nIF (benchmarkType == REDUCE) THEN\nCALL reduceKernel(repsToDo, dataSizeIter)\nELSE IF (benchmarkType == ALLREDUCE) THEN\nCALL allReduceKernel(repsToDo, dataSizeIter)\nEND IF\n!Stop timer\nCALL MPI_Barrier(comm, ierr)\nfinishTime = MPI_Wtime()\ntotalTime = finishTime - startTime\n!Test if target time was reached with the number of reps\nif (myMPIRank==0) then\nbenchComplete = repTimeCheck(totalTime, repsToDo)\nend if\n!Ensure all procs have the same value of benchComplete\n!and repsToDo\ncall MPI_Bcast(benchComplete, 1, MPI_INTEGER, 0, comm, ierr)\ncall MPI_Bcast(repsToDo, 1, MPI_INTEGER, 0, comm, ierr)\nEND DO\n!Master process sets benchmark result for reporting\nIF (myMPIRank == 0) THEN\nCALL setReportParams(dataSizeIter,repsToDo,totalTime)\nCALL printReport()\nEND IF\n!Free allocated data\nCALL freeData()\n!Double dataSize and loop again\ndataSizeIter = dataSizeIter * 2\nEND DO\n!End loop over data sizes\nEND SUBROUTINE reduction
  