Nature Language: allReduce:Implements the allreduce mixed mode benchmark. Each thread under every MPI process combines its local buffer. All MPI processes then combine this value to the overall reduction value at each process.
  
CPP: int allReduceKernel(int totalReps, int dataSize){\n    int repIter, i, j;\n    int startPos;\n\n    for (repIter=0; repIter<totalReps; repIter++){\n\n        #pragma omp parallel default(none) \\\n            private(i,j) \\\n            shared(tempBuf,globalIDarray,dataSize,numThreads) \\\n            shared(localReduceBuf)\n        {\n            #pragma omp for schedule(static,dataSize)\n            for(i=0; i<(numThreads * dataSize); i++){\n                tempBuf[i] = globalIDarray[myThreadID];\n            }\n\n            #pragma omp for\n            for(i=0; i<dataSize; i++){\n                localReduceBuf[i] = 0;\n\n                for (j=0; j<numThreads; j++){\n                    localReduceBuf[i] += tempBuf[(j*dataSize)+i];\n                }\n            }\n        }\n\n        MPI_Allreduce(localReduceBuf, globalReduceBuf, \\\n            dataSize, MPI_INTEGER, MPI_SUM, comm);\n\n        #pragma omp parallel default(none) \\\n            private(i,startPos) \\\n            shared(dataSize,finalReduceBuf,globalReduceBuf)\n        {\n            startPos = (myThreadID * dataSize);\n\n            for (i=0; i<dataSize; i++){\n                finalReduceBuf[startPos + i] = globalReduceBuf[i];\n            }\n        }\n    }\n\n    return 0;\n}",
  
Fortran: SUBROUTINE allReduceKernel(totalReps, dataSize)\ninteger, intent(in) :: totalReps, dataSize\ninteger :: repIter,i\ninteger :: startPos\n!Decalre array which each thread reduces into\ninteger, dimension(dataSize) :: localReduceBuf\n\n DO repIter = 1, totalReps !loop for totalReps\n\n !initialise all reduce arrays to ensure correct results\n localReduceBuf = 0\n globalReduceBuf = 0\n finalReduceBuf = 0\n\n !Open the parallel region and declare localReduceBuf\n !as a reduction variable.\n!$OMP PARALLEL DEFAULT(NONE), &\n!$OMP PRIVATE(i),&\n!$OMP SHARED(dataSize,globalIDarray),&\n!$OMP REDUCTION(+:localReduceBuf)\n DO i = 1, dataSize\n localReduceBuf(i) = localReduceBuf(i) + globalIDarray(myThreadID)\n END DO\n!$OMP END PARALLEL\n\n !Perform an all reduce of localReduceBuf across \n !the MPI processes.\n CALL MPI_Allreduce(localReduceBuf, globalReduceBuf, &\n dataSize, MPI_INTEGER, MPI_SUM, comm, ierr)\n \n !Each thread copies globalReduceBuf into its portion \n !of finalReduceBuf\n!$OMP PARALLEL DEFAULT(NONE), &\n!$OMP PRIVATE(i,startPos), &\n!$OMP SHARED(dataSize,finalReduceBuf,globalReduceBuf)\n\n !Calculate the start of each threads portion of finalReduceBuf\n startPos = ((myThreadID-1) * dataSize)\n DO i = 1, dataSize\n finalReduceBuf(startPos + i) = globalReduceBuf(i)\n END DO\n!$OMP END PARALLEL\n\nEND DO !End repetitions loop\n\nEND SUBROUTINE allReduceKernel
  