diff --git a/applications/test/parallel/Test-parallel.C b/applications/test/parallel/Test-parallel.C index b6ac4f7e288e5e1271eed62a365713a71d84fcda..580ae453a8ac75694f0bc61c3ccf1498752b3fe7 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 3000cf0aedc64441c1d1214b781db8de9aaffa0f..01c14c7060eedb0ab261c1ced3b8e8a9ddacb27f 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 a224a42ebdb035d0a574ec9a197653f9812facdd..3589c67ba881a81860d7a6f575101144957b6298 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 ef20c1cec0f0bc2fe24ecc7c7c1b8ef015f4094b..0b7dbb462eb030228c4952c81e5342227f7d5028 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 8d391878897f28a1cabaa5a42f3c9797e61e2900..1e7508dc47474f626bb96fdd4d4237ab46f1b1f5 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 5084b4956ece5452255877cbef7dbac86cd5cd46..bd3ccbbd56760779ffda3a108dca423ae6485249 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 f199d57314103c0ed69d679346a3bb2de6568227..31bad5e4d84ae6d20ebdabaaaa8a478c6ab7ce88 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 d952925d3c02e60974a9e3578affb41d0c8ba99e..9b8054fa84838da94befe620c29ce3204c5a8f38 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 c6c867f350e57cb13dd333fb6188c4e306fdca10..015acd3435053a751d4f5263c8812afca7b6e98c 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 55e8e3d18dee3cc27036147d8b5ef88b3fe2dad8..029425a23c5f006299a204a526fe3ad95d0d24f5 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 d81f9cba21c5707be20d71d2327676aef05fcaef..f68410fbd8f69d121b298491e196b9c46e5a632b 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 a07a5ea34742ae01aa9c9a66167693b2239b8929..180290a469402e5386779fd89c6f116d3c4ac7ce 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; } }