From fb69a54bc309f5893e2bb49de4741749b8d51c0e Mon Sep 17 00:00:00 2001 From: Mark Olesen <Mark.Olesen@esi-group.com> Date: Tue, 14 Feb 2023 11:24:22 +0100 Subject: [PATCH] ENH: avoid prior communication when using mapDistribute - in most cases can simply construct mapDistribute with the sendMap and have it take care of communication and addressing for the corresponding constructMap. This removes code duplication, which in some cases was also using much less efficient mechanisms (eg, combineReduce on list of lists, or an allGatherList on the send sizes etc) and also reduces the number of places where Pstream::exchange/exchangeSizes is being called. ENH: reduce communication in turbulentDFSEMInlet - was doing an allGatherList to populate a mapDistribute. Now simply use PstreamBuffers mechanisms directly. --- applications/test/parallel/Test-parallel.C | 46 +---- .../DelaunayMesh/DistributedDelaunayMesh.C | 45 +---- .../backgroundMeshDecomposition.C | 45 +---- .../parLagrangianDistributor.C | 36 ++-- .../turbulentDFSEMInletFvPatchVectorField.C | 101 +++-------- .../basic/InteractionLists/InteractionLists.C | 47 +----- .../advancingFrontAMIParallelOps.C | 43 +---- .../nearestFaceAMI/nearestFaceAMI.C | 1 - src/meshTools/processorLOD/box/box.C | 63 +------ src/meshTools/processorLOD/box/box.H | 10 -- .../distributedTriSurfaceMesh.C | 159 +++++------------- .../meshToMesh/meshToMeshParallelOps.C | 39 +---- 12 files changed, 103 insertions(+), 532 deletions(-) diff --git a/applications/test/parallel/Test-parallel.C b/applications/test/parallel/Test-parallel.C index b6ac4f7e288..580ae453a8a 100644 --- a/applications/test/parallel/Test-parallel.C +++ b/applications/test/parallel/Test-parallel.C @@ -67,54 +67,24 @@ void testMapDistribute() labelList nSend(Pstream::nProcs(), Zero); forAll(complexData, i) { - const label procI = complexData[i].first(); - nSend[procI]++; + const label proci = complexData[i].first(); + nSend[proci]++; } // Collect items to be sent labelListList sendMap(Pstream::nProcs()); - forAll(sendMap, procI) + forAll(sendMap, proci) { - sendMap[procI].setSize(nSend[procI]); + sendMap[proci].resize_nocopy(nSend[proci]); + nSend[proci] = 0; } - nSend = 0; forAll(complexData, i) { - const label procI = complexData[i].first(); - sendMap[procI][nSend[procI]++] = i; + const label proci = complexData[i].first(); + sendMap[proci][nSend[proci]++] = i; } - // Sync how many to send - labelList nRecv; - Pstream::exchangeSizes(sendMap, nRecv); - - // Collect items to be received - labelListList recvMap(Pstream::nProcs()); - forAll(recvMap, procI) - { - recvMap[procI].setSize(nRecv[procI]); - } - - label constructSize = 0; - // Construct with my own elements first - forAll(recvMap[Pstream::myProcNo()], i) - { - recvMap[Pstream::myProcNo()][i] = constructSize++; - } - // Construct from other processors - forAll(recvMap, procI) - { - if (procI != Pstream::myProcNo()) - { - forAll(recvMap[procI], i) - { - recvMap[procI][i] = constructSize++; - } - } - } - - // Construct distribute map (destructively) - mapDistribute map(constructSize, std::move(sendMap), std::move(recvMap)); + mapDistribute map(std::move(sendMap)); // Distribute complexData map.distribute(complexData); diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/DelaunayMesh/DistributedDelaunayMesh.C b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/DelaunayMesh/DistributedDelaunayMesh.C index 3000cf0aedc..01c14c7060e 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/DelaunayMesh/DistributedDelaunayMesh.C +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/DelaunayMesh/DistributedDelaunayMesh.C @@ -54,7 +54,6 @@ Foam::DistributedDelaunayMesh<Triangulation>::buildMap forAll(toProc, i) { label proci = toProc[i]; - nSend[proci]++; } @@ -64,8 +63,7 @@ Foam::DistributedDelaunayMesh<Triangulation>::buildMap forAll(nSend, proci) { - sendMap[proci].setSize(nSend[proci]); - + sendMap[proci].resize_nocopy(nSend[proci]); nSend[proci] = 0; } @@ -73,49 +71,10 @@ Foam::DistributedDelaunayMesh<Triangulation>::buildMap forAll(toProc, i) { label proci = toProc[i]; - sendMap[proci][nSend[proci]++] = i; } - // 4. Send over how many I need to receive - labelList recvSizes; - Pstream::exchangeSizes(sendMap, recvSizes); - - - // Determine receive map - // ~~~~~~~~~~~~~~~~~~~~~ - - labelListList constructMap(Pstream::nProcs()); - - // Local transfers first - constructMap[Pstream::myProcNo()] = identity - ( - sendMap[Pstream::myProcNo()].size() - ); - - label constructSize = constructMap[Pstream::myProcNo()].size(); - - forAll(constructMap, proci) - { - if (proci != Pstream::myProcNo()) - { - label nRecv = recvSizes[proci]; - - constructMap[proci].setSize(nRecv); - - for (label i = 0; i < nRecv; i++) - { - constructMap[proci][i] = constructSize++; - } - } - } - - return autoPtr<mapDistribute>::New - ( - constructSize, - std::move(sendMap), - std::move(constructMap) - ); + return autoPtr<mapDistribute>::New(std::move(sendMap)); } diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/backgroundMeshDecomposition/backgroundMeshDecomposition.C b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/backgroundMeshDecomposition/backgroundMeshDecomposition.C index a224a42ebdb..3589c67ba88 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/backgroundMeshDecomposition/backgroundMeshDecomposition.C +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/backgroundMeshDecomposition/backgroundMeshDecomposition.C @@ -59,7 +59,6 @@ Foam::autoPtr<Foam::mapDistribute> Foam::backgroundMeshDecomposition::buildMap forAll(toProc, i) { label proci = toProc[i]; - nSend[proci]++; } @@ -69,8 +68,7 @@ Foam::autoPtr<Foam::mapDistribute> Foam::backgroundMeshDecomposition::buildMap forAll(nSend, proci) { - sendMap[proci].setSize(nSend[proci]); - + sendMap[proci].resize_nocopy(nSend[proci]); nSend[proci] = 0; } @@ -78,49 +76,10 @@ Foam::autoPtr<Foam::mapDistribute> Foam::backgroundMeshDecomposition::buildMap forAll(toProc, i) { label proci = toProc[i]; - sendMap[proci][nSend[proci]++] = i; } - // 4. Send over how many I need to receive - labelList recvSizes; - Pstream::exchangeSizes(sendMap, recvSizes); - - - // Determine receive map - // ~~~~~~~~~~~~~~~~~~~~~ - - labelListList constructMap(Pstream::nProcs()); - - // Local transfers first - constructMap[Pstream::myProcNo()] = identity - ( - sendMap[Pstream::myProcNo()].size() - ); - - label constructSize = constructMap[Pstream::myProcNo()].size(); - - forAll(constructMap, proci) - { - if (proci != Pstream::myProcNo()) - { - label nRecv = recvSizes[proci]; - - constructMap[proci].setSize(nRecv); - - for (label i = 0; i < nRecv; i++) - { - constructMap[proci][i] = constructSize++; - } - } - } - - return autoPtr<mapDistribute>::New - ( - constructSize, - std::move(sendMap), - std::move(constructMap) - ); + return autoPtr<mapDistribute>::New(std::move(sendMap)); } diff --git a/applications/utilities/parallelProcessing/redistributePar/parLagrangianDistributor.C b/applications/utilities/parallelProcessing/redistributePar/parLagrangianDistributor.C index ef20c1cec0f..0b7dbb462eb 100644 --- a/applications/utilities/parallelProcessing/redistributePar/parLagrangianDistributor.C +++ b/applications/utilities/parallelProcessing/redistributePar/parLagrangianDistributor.C @@ -146,7 +146,6 @@ Foam::parLagrangianDistributor::distributeLagrangianPositions labelListList subMap; - // Allocate transfer buffers PstreamBuffers pBufs(Pstream::commsTypes::nonBlocking); @@ -283,33 +282,24 @@ Foam::parLagrangianDistributor::distributeLagrangianPositions lpi.rename(cloudName); } - // Work the send indices (subMap) into a mapDistributeBase - labelListList sizes(Pstream::nProcs()); - labelList& nsTransPs = sizes[Pstream::myProcNo()]; - nsTransPs.setSize(Pstream::nProcs()); - forAll(subMap, sendProcI) - { - nsTransPs[sendProcI] = subMap[sendProcI].size(); - } - // Send sizes across. Note: blocks. - Pstream::combineReduce(sizes, Pstream::listEq()); + // Until now (FEB-2023) we have always used processor ordering for the + // construct map (whereas mapDistribute has local transfers first), + // so we'll stick with that for now, but can likely just use the subMap + // directly with mapDistribute and have it determine the constructMap. - labelListList constructMap(Pstream::nProcs()); - label constructSize = 0; - forAll(constructMap, procI) - { - const label nRecv = sizes[procI][UPstream::myProcNo()]; + labelList recvSizes; + Pstream::exchangeSizes(subMap, recvSizes); - labelList& map = constructMap[procI]; + label constructSize = 0; + labelListList constructMap(Pstream::nProcs()); - map.setSize(nRecv); - forAll(map, i) - { - map[i] = constructSize++; - } + forAll(constructMap, proci) + { + const label len = recvSizes[proci]; + constructMap[proci] = identity(len, constructSize); + constructSize += len; } - return autoPtr<mapDistributeBase>::New ( constructSize, diff --git a/src/finiteVolume/fields/fvPatchFields/derived/turbulentDFSEMInlet/turbulentDFSEMInletFvPatchVectorField.C b/src/finiteVolume/fields/fvPatchFields/derived/turbulentDFSEMInlet/turbulentDFSEMInletFvPatchVectorField.C index 8d391878897..1e7508dc474 100644 --- a/src/finiteVolume/fields/fvPatchFields/derived/turbulentDFSEMInlet/turbulentDFSEMInletFvPatchVectorField.C +++ b/src/finiteVolume/fields/fvPatchFields/derived/turbulentDFSEMInlet/turbulentDFSEMInletFvPatchVectorField.C @@ -450,13 +450,16 @@ void Foam::turbulentDFSEMInletFvPatchVectorField::convectEddies } } - reduce(nRecycled, sumOp<label>()); - - if (debug && nRecycled > 0) + if (debug) { - Info<< "Patch: " << patch().patch().name() - << " recycled " << nRecycled << " eddies" - << endl; + reduce(nRecycled, sumOp<label>()); + + if (nRecycled) + { + Info<< "Patch: " << patch().patch().name() + << " recycled " << nRecycled << " eddies" + << endl; + } } } @@ -492,11 +495,11 @@ void Foam::turbulentDFSEMInletFvPatchVectorField::calcOverlappingProcEddies Pstream::allGatherList(patchBBs); // Per processor indices into all segments to send - List<DynamicList<label>> dynSendMap(Pstream::nProcs()); + List<DynamicList<label>> sendMap(UPstream::nProcs()); + // Collect overlapping eddies forAll(eddies_, i) { - // Collect overlapping eddies const eddy& e = eddies_[i]; // Eddy bounds @@ -505,91 +508,41 @@ void Foam::turbulentDFSEMInletFvPatchVectorField::calcOverlappingProcEddies ebb.min() += x; ebb.max() += x; - forAll(patchBBs, procI) + forAll(patchBBs, proci) { // Not including intersection with local patch - if (procI != Pstream::myProcNo()) + if (proci != Pstream::myProcNo()) { - if (ebb.overlaps(patchBBs[procI])) + if (ebb.overlaps(patchBBs[proci])) { - dynSendMap[procI].append(i); + sendMap[proci].push_back(i); } } } } - labelListList sendMap(Pstream::nProcs()); - forAll(sendMap, procI) - { - sendMap[procI].transfer(dynSendMap[procI]); - } - - // Send the number of eddies for local processors to receive - labelListList sendSizes(Pstream::nProcs()); - sendSizes[Pstream::myProcNo()].setSize(Pstream::nProcs()); - forAll(sendMap, procI) - { - sendSizes[Pstream::myProcNo()][procI] = sendMap[procI].size(); - } - Pstream::allGatherList(sendSizes); - - // Determine order of receiving - labelListList constructMap(Pstream::nProcs()); - - // Local segment first - constructMap[Pstream::myProcNo()] = identity - ( - sendMap[Pstream::myProcNo()].size() - ); - - label segmentI = constructMap[Pstream::myProcNo()].size(); - forAll(constructMap, procI) - { - if (procI != Pstream::myProcNo()) - { - // What I need to receive is what other processor is sending to me - const label nRecv = sendSizes[procI][Pstream::myProcNo()]; - constructMap[procI].setSize(nRecv); - - for (label i = 0; i < nRecv; ++i) - { - constructMap[procI][i] = segmentI++; - } - } - } - - mapDistribute map(segmentI, std::move(sendMap), std::move(constructMap)); - PstreamBuffers pBufs(Pstream::commsTypes::nonBlocking); + PstreamBuffers pBufs(UPstream::commsTypes::nonBlocking); - for (const int domain : Pstream::allProcs()) + forAll(sendMap, proci) { - const labelList& sendElems = map.subMap()[domain]; - - if (domain != Pstream::myProcNo() && sendElems.size()) + if (proci != Pstream::myProcNo() && !sendMap[proci].empty()) { - List<eddy> subEddies(UIndirectList<eddy>(eddies_, sendElems)); + UOPstream os(proci, pBufs); - UOPstream toDomain(domain, pBufs); - - toDomain<< subEddies; + os << UIndirectList<eddy>(eddies_, sendMap[proci]); } } - // Start receiving pBufs.finishedSends(); - // Consume - for (const int domain : Pstream::allProcs()) + for (const int proci : pBufs.allProcs()) { - const labelList& recvElems = map.constructMap()[domain]; - - if (domain != Pstream::myProcNo() && recvElems.size()) + if (proci != Pstream::myProcNo() && pBufs.recvDataCount(proci)) { - UIPstream str(domain, pBufs); - { - str >> overlappingEddies[domain]; - } + UIPstream is(proci, pBufs); + + is >> overlappingEddies[proci]; } } @@ -1001,10 +954,8 @@ void Foam::turbulentDFSEMInletFvPatchVectorField::updateCoeffs() List<List<eddy>> overlappingEddies(Pstream::nProcs()); calcOverlappingProcEddies(overlappingEddies); - forAll(overlappingEddies, procI) + for (const List<eddy>& eddies : overlappingEddies) { - const List<eddy>& eddies = overlappingEddies[procI]; - if (eddies.size()) { forAll(U, faceI) diff --git a/src/lagrangian/basic/InteractionLists/InteractionLists.C b/src/lagrangian/basic/InteractionLists/InteractionLists.C index 5084b4956ec..bd3ccbbd567 100644 --- a/src/lagrangian/basic/InteractionLists/InteractionLists.C +++ b/src/lagrangian/basic/InteractionLists/InteractionLists.C @@ -822,8 +822,7 @@ void Foam::InteractionLists<ParticleType>::buildMap forAll(nSend, proci) { - sendMap[proci].setSize(nSend[proci]); - + sendMap[proci].resize_nocopy(nSend[proci]); nSend[proci] = 0; } @@ -831,52 +830,10 @@ void Foam::InteractionLists<ParticleType>::buildMap forAll(toProc, i) { label proci = toProc[i]; - sendMap[proci][nSend[proci]++] = i; } - // 4. Send over how many I need to receive - labelList recvSizes; - Pstream::exchangeSizes(sendMap, recvSizes); - - - // Determine receive map - // ~~~~~~~~~~~~~~~~~~~~~ - - labelListList constructMap(Pstream::nProcs()); - - // Local transfers first - constructMap[Pstream::myProcNo()] = identity - ( - sendMap[Pstream::myProcNo()].size() - ); - - label constructSize = constructMap[Pstream::myProcNo()].size(); - - forAll(constructMap, proci) - { - if (proci != Pstream::myProcNo()) - { - const label nRecv = recvSizes[proci]; - - constructMap[proci].setSize(nRecv); - - for (label i = 0; i < nRecv; i++) - { - constructMap[proci][i] = constructSize++; - } - } - } - - mapPtr.reset - ( - new mapDistribute - ( - constructSize, - std::move(sendMap), - std::move(constructMap) - ) - ); + mapPtr.reset(new mapDistribute(std::move(sendMap))); } diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/advancingFrontAMI/advancingFrontAMIParallelOps.C b/src/meshTools/AMIInterpolation/AMIInterpolation/advancingFrontAMI/advancingFrontAMIParallelOps.C index f199d573141..31bad5e4d84 100644 --- a/src/meshTools/AMIInterpolation/AMIInterpolation/advancingFrontAMI/advancingFrontAMIParallelOps.C +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/advancingFrontAMI/advancingFrontAMIParallelOps.C @@ -344,48 +344,7 @@ Foam::autoPtr<Foam::mapDistribute> Foam::advancingFrontAMI::calcProcMap } } - - // Send over how many faces I need to receive - labelListList sendSizes(Pstream::nProcs()); - sendSizes[Pstream::myProcNo()].setSize(Pstream::nProcs()); - forAll(sendMap, proci) - { - sendSizes[Pstream::myProcNo()][proci] = sendMap[proci].size(); - } - Pstream::allGatherList(sendSizes); - - - // Determine order of receiving - labelListList constructMap(Pstream::nProcs()); - - // My local segment first - constructMap[Pstream::myProcNo()] = identity - ( - sendMap[Pstream::myProcNo()].size() - ); - - label segmentI = constructMap[Pstream::myProcNo()].size(); - forAll(constructMap, proci) - { - if (proci != Pstream::myProcNo()) - { - // What I need to receive is what other processor is sending to me - label nRecv = sendSizes[proci][Pstream::myProcNo()]; - constructMap[proci].setSize(nRecv); - - for (label i = 0; i < nRecv; ++i) - { - constructMap[proci][i] = segmentI++; - } - } - } - - return autoPtr<mapDistribute>::New - ( - segmentI, // size after construction - std::move(sendMap), - std::move(constructMap) - ); + return autoPtr<mapDistribute>::New(std::move(sendMap)); } diff --git a/src/meshTools/AMIInterpolation/AMIInterpolation/nearestFaceAMI/nearestFaceAMI.C b/src/meshTools/AMIInterpolation/AMIInterpolation/nearestFaceAMI/nearestFaceAMI.C index d952925d3c0..9b8054fa848 100644 --- a/src/meshTools/AMIInterpolation/AMIInterpolation/nearestFaceAMI/nearestFaceAMI.C +++ b/src/meshTools/AMIInterpolation/AMIInterpolation/nearestFaceAMI/nearestFaceAMI.C @@ -80,7 +80,6 @@ Foam::autoPtr<Foam::mapDistribute> Foam::nearestFaceAMI::calcFaceMap labelListList sendMap(Pstream::nProcs()); forAll(sendMap, proci) { - dynSendMap[proci].shrink(); sendMap[proci].transfer(dynSendMap[proci]); if (debug) diff --git a/src/meshTools/processorLOD/box/box.C b/src/meshTools/processorLOD/box/box.C index c6c867f350e..015acd34350 100644 --- a/src/meshTools/processorLOD/box/box.C +++ b/src/meshTools/processorLOD/box/box.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2017-2022 OpenCFD Ltd. + Copyright (C) 2017-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -511,7 +511,7 @@ Foam::autoPtr<Foam::mapDistribute> Foam::processorLODs::box::createMap allIDs.insert(elems); } - sendElems[proci] = allIDs.toc(); + sendElems[proci] = allIDs.sortedToc(); } } @@ -530,59 +530,7 @@ Foam::autoPtr<Foam::mapDistribute> Foam::processorLODs::box::createMap } } - return createLODMap(sendElems); -} - - -Foam::autoPtr<Foam::mapDistribute> Foam::processorLODs::box::createLODMap -( - List<labelList>& sendElems -) const -{ - // Send over how many objects I need to receive - const label localProci = Pstream::myProcNo(); - labelListList sendSizes(Pstream::nProcs()); - sendSizes[localProci].setSize(Pstream::nProcs()); - forAll(sendElems, proci) - { - sendSizes[localProci][proci] = sendElems[proci].size(); - } - Pstream::allGatherList(sendSizes); - - - // Determine order of receiving - labelListList constructMap(Pstream::nProcs()); - - // My local segment first - constructMap[localProci] = identity(sendElems[localProci].size()); - - label segmenti = constructMap[localProci].size(); - forAll(constructMap, proci) - { - if (proci != localProci) - { - // What I need to receive is what other processor is sending to me - label nRecv = sendSizes[proci][localProci]; - constructMap[proci].setSize(nRecv); - - for (label& addr : constructMap[proci]) - { - addr = segmenti++; - } - } - } - - autoPtr<mapDistribute> mapPtr - ( - new mapDistribute - ( - segmenti, // size after construction - std::move(sendElems), - std::move(constructMap) - ) - ); - - return mapPtr; + return autoPtr<mapDistribute>::New(std::move(sendElems)); } @@ -618,9 +566,8 @@ Foam::processorLODs::box::box treeBoundBox srcBb(srcPoints_); srcBb.inflate(0.01); - DynamicList<treeBoundBox> newProcBoxes(1); - newProcBoxes.append(srcBb); - procBoxes.transfer(newProcBoxes); + procBoxes.resize(1); + procBoxes.front() = srcBb; } } } diff --git a/src/meshTools/processorLOD/box/box.H b/src/meshTools/processorLOD/box/box.H index 55e8e3d18de..029425a23c5 100644 --- a/src/meshTools/processorLOD/box/box.H +++ b/src/meshTools/processorLOD/box/box.H @@ -49,7 +49,6 @@ Description namespace Foam { - namespace processorLODs { @@ -165,12 +164,6 @@ protected: const label nTgtElems ); - //- Use the current list of send elements to create the mapDistribute - autoPtr<mapDistribute> createLODMap - ( - List<labelList>& sendElems - ) const; - public: @@ -195,9 +188,6 @@ public: // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace processorLODs - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - } // End namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C b/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C index d81f9cba21c..f68410fbd8f 100644 --- a/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C +++ b/src/parallel/distributed/distributedTriSurfaceMesh/distributedTriSurfaceMesh.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation - Copyright (C) 2015-2022 OpenCFD Ltd. + Copyright (C) 2015-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -608,10 +608,9 @@ Foam::distributedTriSurfaceMesh::distributeSegments } // Convert dynamicList to labelList - sendMap.setSize(Pstream::nProcs()); + sendMap.resize_nocopy(Pstream::nProcs()); forAll(sendMap, proci) { - dynSendMap[proci].shrink(); sendMap[proci].transfer(dynSendMap[proci]); } @@ -875,14 +874,9 @@ Foam::distributedTriSurfaceMesh::calcLocalQueries // Pack into distribution map - // ~~~~~~~~~~~~~~~~~~~~~~~~~~ - - autoPtr<mapDistribute> mapPtr(new mapDistribute(std::move(sendMap))); - + auto mapPtr = autoPtr<mapDistribute>::New(std::move(sendMap)); // Send over queries - // ~~~~~~~~~~~~~~~~~ - mapPtr().distribute(triangleIndex); return mapPtr; @@ -1119,10 +1113,9 @@ Foam::distributedTriSurfaceMesh::calcLocalQueries } // Convert dynamicList to labelList - sendMap.setSize(Pstream::nProcs()); + sendMap.resize_nocopy(Pstream::nProcs()); forAll(sendMap, proci) { - dynSendMap[proci].shrink(); sendMap[proci].transfer(dynSendMap[proci]); } @@ -4198,7 +4191,7 @@ void Foam::distributedTriSurfaceMesh::getVolumeType labelListList sendMap(Pstream::nProcs()); { // 1. Count - labelList nSend(Pstream::nProcs(), 0); + labelList nSend(Pstream::nProcs(), Zero); forAll(samples, samplei) { // Find the processors this sample overlaps. @@ -4224,9 +4217,9 @@ void Foam::distributedTriSurfaceMesh::getVolumeType forAll(nSend, proci) { - sendMap[proci].setSize(nSend[proci]); + sendMap[proci].resize_nocopy(nSend[proci]); + nSend[proci] = 0; } - nSend = 0; // 2. Fill forAll(samples, samplei) @@ -4236,8 +4229,7 @@ void Foam::distributedTriSurfaceMesh::getVolumeType { if (contains(procBb_[proci], samples[samplei])) { - labelList& procSend = sendMap[proci]; - procSend[nSend[proci]++] = samplei; + sendMap[proci][nSend[proci]++] = samplei; } } } @@ -4525,7 +4517,7 @@ Foam::distributedTriSurfaceMesh::localQueries // cheap we do a multi-pass algorithm to save some memory temporarily. // 1. Count - labelList nSend(Pstream::nProcs(), 0); + labelList nSend(Pstream::nProcs(), Zero); forAll(info, i) { @@ -4540,7 +4532,7 @@ Foam::distributedTriSurfaceMesh::localQueries labelListList sendMap(Pstream::nProcs()); forAll(nSend, proci) { - sendMap[proci].setSize(nSend[proci]); + sendMap[proci].resize_nocopy(nSend[proci]); nSend[proci] = 0; } @@ -4560,65 +4552,11 @@ Foam::distributedTriSurfaceMesh::localQueries } - // Send over how many i need to receive - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - labelListList sendSizes(Pstream::nProcs()); - sendSizes[Pstream::myProcNo()].setSize(Pstream::nProcs()); - forAll(sendMap, proci) - { - sendSizes[Pstream::myProcNo()][proci] = sendMap[proci].size(); - } - Pstream::allGatherList(sendSizes); - - - // Determine receive map - // ~~~~~~~~~~~~~~~~~~~~~ - - labelListList constructMap(Pstream::nProcs()); - - // My local segments first - constructMap[Pstream::myProcNo()] = identity - ( - sendMap[Pstream::myProcNo()].size() - ); - - label segmenti = constructMap[Pstream::myProcNo()].size(); - forAll(constructMap, proci) - { - if (proci != Pstream::myProcNo()) - { - // What i need to receive is what other processor is sending to me. - label nRecv = sendSizes[proci][Pstream::myProcNo()]; - constructMap[proci].setSize(nRecv); - - for (label i = 0; i < nRecv; i++) - { - constructMap[proci][i] = segmenti++; - } - } - } - - // Pack into distribution map - // ~~~~~~~~~~~~~~~~~~~~~~~~~~ - - autoPtr<mapDistribute> mapPtr - ( - new mapDistribute - ( - segmenti, // size after construction - std::move(sendMap), - std::move(constructMap) - ) - ); - const mapDistribute& map = mapPtr(); - + auto mapPtr = autoPtr<mapDistribute>::New(std::move(sendMap)); // Send over queries - // ~~~~~~~~~~~~~~~~~ - - map.distribute(triangleIndex); + mapPtr().distribute(triangleIndex); return mapPtr; } @@ -4770,13 +4708,6 @@ void Foam::distributedTriSurfaceMesh::distribute } - // Send over how many faces/points i need to receive - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - labelList faceRecvSizes; - Pstream::exchangeSizes(faceSendMap, faceRecvSizes); - - // Exchange surfaces // ~~~~~~~~~~~~~~~~~ @@ -4821,61 +4752,55 @@ void Foam::distributedTriSurfaceMesh::distribute // Send all // ~~~~~~~~ - PstreamBuffers pBufs(Pstream::defaultCommsType); + PstreamBuffers pBufs(UPstream::commsTypes::nonBlocking); forAll(faceSendMap, proci) { - if (proci != Pstream::myProcNo()) + if (proci != Pstream::myProcNo() && !faceSendMap[proci].empty()) { - if (faceSendMap[proci].size() > 0) - { - UOPstream str(proci, pBufs); + UOPstream os(proci, pBufs); - labelList pointMap; - triSurface subSurface + labelList pointMap; + triSurface subSurface + ( + subsetMesh ( - subsetMesh - ( - *this, - faceSendMap[proci], - pointMap - ) - ); - str << subSurface; - } + *this, + faceSendMap[proci], + pointMap + ) + ); + os << subSurface; } } - pBufs.finishedSends(); // no-op for blocking + pBufs.finishedSends(); // Receive and merge all // ~~~~~~~~~~~~~~~~~~~~~ - forAll(faceRecvSizes, proci) + for (const int proci : pBufs.allProcs()) { - if (proci != Pstream::myProcNo()) + if (proci != Pstream::myProcNo() && pBufs.recvDataCount(proci)) { - if (faceRecvSizes[proci] > 0) - { - UIPstream str(proci, pBufs); + UIPstream is(proci, pBufs); - // Receive - triSurface subSurface(str); + // Receive + triSurface subSurface(is); - // Merge into allSurf - merge - ( - mergeDist_, - subSurface, - subSurface.points(), + // Merge into allSurf + merge + ( + mergeDist_, + subSurface, + subSurface.points(), - allTris, - allPoints, - faceConstructMap[proci], - pointConstructMap[proci] - ); - } + allTris, + allPoints, + faceConstructMap[proci], + pointConstructMap[proci] + ); } } diff --git a/src/sampling/meshToMesh/meshToMeshParallelOps.C b/src/sampling/meshToMesh/meshToMeshParallelOps.C index a07a5ea3474..180290a4694 100644 --- a/src/sampling/meshToMesh/meshToMeshParallelOps.C +++ b/src/sampling/meshToMesh/meshToMeshParallelOps.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2012-2017 OpenFOAM Foundation - Copyright (C) 2015-2022 OpenCFD Ltd. + Copyright (C) 2015-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -232,42 +232,7 @@ Foam::autoPtr<Foam::mapDistribute> Foam::meshToMesh::calcProcMap } } - - // send over how many tgt cells I need to receive from each - // processor - labelListList sendSizes(Pstream::nProcs()); - sendSizes[Pstream::myProcNo()].resize(Pstream::nProcs()); - forAll(sendMap, proci) - { - sendSizes[Pstream::myProcNo()][proci] = sendMap[proci].size(); - } - Pstream::allGatherList(sendSizes); - - - // determine order of receiving - labelListList constructMap(Pstream::nProcs()); - - label segmentI = 0; - forAll(constructMap, proci) - { - // what I need to receive is what other processor is sending - // to me - label nRecv = sendSizes[proci][Pstream::myProcNo()]; - constructMap[proci].setSize(nRecv); - - for (label i = 0; i < nRecv; i++) - { - constructMap[proci][i] = segmentI++; - } - } - - return autoPtr<mapDistribute>::New - ( - segmentI, // size after construction - std::move(sendMap), - std::move(constructMap) - ); - + return autoPtr<mapDistribute>::New(std::move(sendMap)); break; } } -- GitLab