Nature Language: alltoallKernel:Implements the all to all benchmark. Each thread sends/receives dataSize items to/from every other process.
  
CPP: int alltoallKernel(int totalReps, int dataSize){ int repIter, i, j; int dataForEachProc, numsToWrite; int blockNum, startOffset; numsToWrite = numThreads * dataSize; dataForEachProc = numThreads * numThreads * dataSize; for (repIter=0; repIter<totalReps; repIter++){ #pragma omp parallel default(none) private(blockNum,i,j) shared(numsToWrite,dataForEachProc,globalIDarray) shared(alltoallSendBuf,numMPIprocs) { blockNum = (myThreadID)* numsToWrite; for (i=0; i<numMPIprocs; i++){ for (j=0; j<numsToWrite; j++){ alltoallSendBuf[blockNum +(i * dataForEachProc) + j] = globalIDarray[myThreadID]; } } } MPI_Alltoall(alltoallSendBuf, dataForEachProc, MPI_INT, alltoallRecvBuf, dataForEachProc, MPI_INT, comm); #pragma omp parallel default(none) private(blockNum,startOffset,i,j) shared(alltoallRecvBuf,alltoallFinalBuf,numMPIprocs) shared(dataForEachProc,numsToWrite,dataSize,globalIDarray) shared(numThreads) { blockNum = myThreadID * dataSize; startOffset = (numsToWrite * numMPIprocs) * myThreadID; for (i=0; i<(numThreads * numMPIprocs); i++){ for (j=0; j<dataSize; j++){ alltoallFinalBuf[startOffset + (i * dataSize) + j] = alltoallRecvBuf[blockNum + (i * numsToWrite) + j]; } } } } return 0; }
  
Fortran: SUBROUTINE alltoallKernel(totalReps,dataSize)\n\tinteger, intent(in) :: totalReps, dataSize\n\tinteger :: repIter, i, j\n\tinteger :: dataForEachProc, numsToWrite\n\tinteger :: blockNum, startOffset\n\n\t!Calculate how much data each thread sends to each process\n\tnumsToWrite = numThreads * dataSize\n\t!Calculate total amount of data each process gets\n\t!from any other process...\n\t!..each thread gets dataSize items from every other thread.\n\tdataForEachProc = numThreads * numThreads * dataSize\n\t\n\tDO repIter = 1, totalReps\n\t\t\n\t\t!Each thread writes to numsToWrite items for each\n\t\t!MPI process to alltoallSendBuf.\n\t\t!$OMP PARALLEL DEFAULT(NONE), &\n\t\t!$OMP PRIVATE(blockNum,i,j), &\n\t\t!$OMP SHARED(numsToWrite,dataForEachProc,globalIDarray), &\n\t\t!$OMP SHARED(alltoallSendBuf,numMPIprocs)\n\t\t!Calculate the blockNum of a thread.\n\t\t!This is used to find which portion of the\n\t\t!dataForEachProc elements a thread will be responsible.\n\t\tblockNum = (myThreadID - 1)*numsToWrite\n\t\t\n\t\t!Write threadID to correct location in alltoallSendBuf\n\t\tDO i = 1, numMPIprocs !loop over MPI processes\n\t\t\tDO j = 1, numsToWrite !loop over data to write\n\t\t\t\talltoallSendBuf(blockNum + ((i-1)*dataForEachProc + j)) = &\n\t\t\t\t\tglobalIDarray(myThreadID)\n\t\t\tEND DO\n\t\tEND DO\n\t\t!$OMP END PARALLEL\n\t\t\n\t\t!Call MPI_AlltoAll\n\t\tCALL MPI_Alltoall(alltoallSendBuf, dataForEachProc, MPI_INTEGER, &\n\t\t\talltoallRecvBuf, dataForEachProc, MPI_INTEGER, &\n\t\t\tcomm, ierr)\n\t\t\n\t\t!Each thread now reads the receive buffer so that\n\t\t!it gets dataSize values from every other thread\n\t\t!in its portion of alltoallFinalBuf\n\t\t!$OMP PARALLEL DEFAULT(NONE), &\n\t\t!$OMP PRIVATE(blockNum,startOffset,i,j),&\n\t\t!$OMP SHARED(alltoallRecvBuf,alltoallFinalBuf,numMPIprocs),&\n\t\t!$OMP SHARED(dataForEachProc,numsToWrite,dataSize,globalIDarray),&\n\t\t!$OMP SHARED(numThreads)\n\t\t\n\t\t!Calculate the blockNum.\n\t\t!This which portion of the data from each process\n\t\t!a thread is responsible for.\n\t\tblockNum = (myThreadID-1)dataSize\n\t\t\n\t\t!Calculate offset into the each MPI processes finalBuf where\n\t\t!each thread will start to write its data...\n\t\t!1) Calculate amount of data for each thread..\n\t\tstartOffset = (numsToWrite * numMPIprocs)\n\t\t!2) Find which block in finalBuf for each thread\n\t\tstartOffset = startOffset * (myThreadID -1)\n\t\t\n\t\t!Loop over all processors (threads & processes)\n\t\tDO i = 1, (numThreadsnumMPIprocs)\n\t\t\tDO j = 1, dataSize\n\t\t\t\talltoallFinalBuf(startOffset + ((i-1)*dataSize) + j ) = &\n\t\t\t\t\talltoallRecvBuf(blockNum + ((i-1)*numsToWrite) + j)\n\t\t\tEND DO\n\t\tEND DO\n\n\t\t!$OMP END PARALLEL\n\n\n\tEND DO !End loop over repetitions\n\nEND SUBROUTINE alltoallKernel
  