diff --git a/src/lagrangian/basic/Cloud/Cloud.C b/src/lagrangian/basic/Cloud/Cloud.C index 5ffa5ecdc7..91e095a94a 100644 --- a/src/lagrangian/basic/Cloud/Cloud.C +++ b/src/lagrangian/basic/Cloud/Cloud.C @@ -105,20 +105,15 @@ void Foam::Cloud::move(TrackingData& td) const globalMeshData& pData = polyMesh_.globalData(); const labelList& processorPatches = pData.processorPatches(); const labelList& processorPatchIndices = pData.processorPatchIndices(); - const labelList& processorPatchNeighbours = - pData.processorPatchNeighbours(); - // Initialise the setpFraction moved for the particles + // Initialise the stepFraction moved for the particles forAllIter(typename Cloud, *this, pIter) { pIter().stepFraction() = 0; } - // Assume there will be particles to transfer - bool transfered = true; - // While there are particles to transfer - while (transfered) + while (true) { // List of lists of particles to be transfered for all the processor // patches @@ -158,104 +153,93 @@ void Foam::Cloud::move(TrackingData& td) } } - if (Pstream::parRun()) + if (!Pstream::parRun()) { - // List of the numbers of particles to be transfered across the - // processor patches - labelList nsTransPs(transferList.size()); + break; + } - forAll(transferList, i) + + // Allocate transfer buffers + PstreamBuffers pBufs(Pstream::nonBlocking); + + // Stream into send buffers + forAll(transferList, i) + { + if (transferList[i].size()) { - nsTransPs[i] = transferList[i].size(); - } - - // List of the numbers of particles to be transfered across the - // processor patches for all the processors - labelListList allNTrans(Pstream::nProcs()); - allNTrans[Pstream::myProcNo()] = nsTransPs; - combineReduce(allNTrans, UPstream::listEq()); - - transfered = false; - - forAll(allNTrans, i) - { - forAll(allNTrans[i], j) - { - if (allNTrans[i][j]) - { - transfered = true; - break; - } - } - } - - if (!transfered) - { - break; - } - - forAll(transferList, i) - { - if (transferList[i].size()) - { - OPstream particleStream - ( - Pstream::blocking, - refCast - ( - pMesh().boundaryMesh()[processorPatches[i]] - ).neighbProcNo() - ); - - particleStream << transferList[i]; - } - } - - forAll(processorPatches, i) - { - label patchi = processorPatches[i]; - - const processorPolyPatch& procPatch = + UOPstream particleStream + ( refCast - (pMesh().boundaryMesh()[patchi]); + ( + pMesh().boundaryMesh()[processorPatches[i]] + ).neighbProcNo(), + pBufs + ); - label neighbProci = - procPatch.neighbProcNo() - Pstream::masterNo(); + particleStream << transferList[i]; + } + } - label neighbProcPatchi = processorPatchNeighbours[patchi]; + // Set up transfers when in non-blocking mode. Returns sizes (in bytes) + // to be sent/received. + labelListList allNTrans(Pstream::nProcs()); + pBufs.finishedSends(allNTrans); - label nRecPs = allNTrans[neighbProci][neighbProcPatchi]; + bool transfered = false; - if (nRecPs) + forAll(allNTrans, i) + { + forAll(allNTrans[i], j) + { + if (allNTrans[i][j]) { - IPstream particleStream - ( - Pstream::blocking, - procPatch.neighbProcNo() - ); - IDLList newParticles - ( - particleStream, - typename ParticleType::iNew(*this) - ); - - forAllIter - ( - typename Cloud, - newParticles, - newpIter - ) - { - ParticleType& newp = newpIter(); - newp.correctAfterParallelTransfer(patchi, td); - addParticle(newParticles.remove(&newp)); - } + transfered = true; + break; } } } - else + + if (!transfered) { - transfered = false; + break; + } + + + // Retrieve from receive buffers + forAll(processorPatches, i) + { + label patchi = processorPatches[i]; + + const processorPolyPatch& procPatch = + refCast + (pMesh().boundaryMesh()[patchi]); + + label neighbProci = procPatch.neighbProcNo(); + + label nRecPs = allNTrans[neighbProci][Pstream::myProcNo()]; + + if (nRecPs) + { + UIPstream particleStream(neighbProci, pBufs); + + IDLList newParticles + ( + particleStream, + typename ParticleType::iNew(*this) + ); + + forAllIter + ( + typename Cloud, + newParticles, + newpIter + ) + { + ParticleType& newp = newpIter(); + newp.correctAfterParallelTransfer(patchi, td); + addParticle(newParticles.remove(&newp)); + } + } } } }