diff --git a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistribute.C b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistribute.C index 34e244d517..fa0fdc0809 100644 --- a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistribute.C +++ b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistribute.C @@ -222,7 +222,7 @@ Foam::mapDistribute::mapDistribute : mapDistributeBase(comm) { - const label myRank = Pstream::myProcNo(comm); + const label myRank = UPstream::myProcNo(comm); // Construct per processor compact addressing of the global elements // needed. The ones from the local processor are not included since @@ -330,7 +330,7 @@ Foam::mapDistribute::mapDistribute : mapDistributeBase(comm) { - const label myRank = Pstream::myProcNo(comm); + const label myRank = UPstream::myProcNo(comm); // Construct per processor compact addressing of the global elements // needed. The ones from the local processor are not included since diff --git a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistribute.H b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistribute.H index 81c4e12b38..6391a83ed4 100644 --- a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistribute.H +++ b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistribute.H @@ -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. @@ -409,7 +409,7 @@ public: // Access //- For every globalIndexAndTransform::transformPermutations - // gives the elements that need to be transformed + //- gives the elements that need to be transformed const labelListList& transformElements() const noexcept { return transformElements_; @@ -433,7 +433,8 @@ public: //- Transfer the contents of the argument and annul the argument. void transfer(mapDistribute& map); - //- Distribute data using default commsType. + //- Distribute List data using default commsType, + //- default flip/negate operator template void distribute ( @@ -442,7 +443,40 @@ public: const int tag = UPstream::msgType() ) const; - //- Distribute data using default commsType. + //- Distribute DynamicList data using default commsType, + //- default flip/negate operator + template + void distribute + ( + DynamicList& fld, + const bool dummyTransform = true, + const int tag = UPstream::msgType() + ) const; + + //- Distribute List data using specified commsType, + //- default flip/negate operator + template + void distribute + ( + const UPstream::commsTypes commsType, + List& fld, + const bool dummyTransform = true, + const int tag = UPstream::msgType() + ) const; + + //- Distribute DynamicList data using specified commsType, + //- default flip/negate operator + template + void distribute + ( + const UPstream::commsTypes commsType, + DynamicList& fld, + const bool dummyTransform = true, + const int tag = UPstream::msgType() + ) const; + + //- Distribute List data using default commsType + //- and the specified negate operator (for flips). template void distribute ( @@ -452,11 +486,14 @@ public: const int tag = UPstream::msgType() ) const; - //- Distribute data using default commsType. - template + //- Distribute List data using specified commsType + //- and the specified negate operator (for flips). + template void distribute ( - DynamicList& fld, + const UPstream::commsTypes commsType, + List& fld, + const NegateOp& negOp, const bool dummyTransform = true, const int tag = UPstream::msgType() ) const; @@ -471,6 +508,17 @@ public: const int tag = UPstream::msgType() ) const; + //- Reverse distribute data using specified commsType. + template + void reverseDistribute + ( + const UPstream::commsTypes commsType, + const label constructSize, + List& fld, + const bool dummyTransform = true, + const int tag = UPstream::msgType() + ) const; + //- Reverse distribute data using default commsType. // Since constructSize might be larger than supplied size supply // a nullValue @@ -484,6 +532,20 @@ public: const int tag = UPstream::msgType() ) const; + //- Reverse distribute data using specified commsType. + // Since constructSize might be larger than supplied size supply + // a nullValue + template + void reverseDistribute + ( + const UPstream::commsTypes commsType, + const label constructSize, + const T& nullValue, + List& fld, + const bool dummyTransform = true, + const int tag = UPstream::msgType() + ) const; + //- Distribute with transforms template void distribute @@ -494,6 +556,18 @@ public: const int tag = UPstream::msgType() ) const; + + //- Distribute with transforms + template + void distribute + ( + const UPstream::commsTypes commsType, + const globalIndexAndTransform&, + List& fld, + const TransformOp& top, + const int tag = UPstream::msgType() + ) const; + //- Reverse distribute with transforms template void reverseDistribute @@ -509,6 +583,31 @@ public: template void reverseDistribute ( + const UPstream::commsTypes commsType, + const globalIndexAndTransform&, + const label constructSize, + List& fld, + const TransformOp& top, + const int tag = UPstream::msgType() + ) const; + + //- Reverse distribute with transforms + template + void reverseDistribute + ( + const globalIndexAndTransform&, + const label constructSize, + const T& nullValue, + List& fld, + const TransformOp& top, + const int tag = UPstream::msgType() + ) const; + + //- Reverse distribute with transforms + template + void reverseDistribute + ( + const UPstream::commsTypes commsType, const globalIndexAndTransform&, const label constructSize, const T& nullValue, diff --git a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeBase.C b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeBase.C index e6b7537cc7..a31c38f3ab 100644 --- a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeBase.C +++ b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeBase.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2015-2017 OpenFOAM Foundation - Copyright (C) 2015-2022 OpenCFD Ltd. + Copyright (C) 2015-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -191,8 +191,8 @@ Foam::List Foam::mapDistributeBase::schedule const label comm ) { - const label myRank = Pstream::myProcNo(comm); - const label nProcs = Pstream::nProcs(comm); + const label myRank = UPstream::myProcNo(comm); + const label nProcs = UPstream::nProcs(comm); // Communications: send and receive processor List allComms; @@ -222,14 +222,14 @@ Foam::List Foam::mapDistributeBase::schedule // Gather/reduce - if (Pstream::master(comm)) + if (UPstream::master(comm)) { // Receive and merge - for (const int proci : Pstream::subProcs(comm)) + for (const int proci : UPstream::subProcs(comm)) { IPstream fromProc ( - Pstream::commsTypes::scheduled, + UPstream::commsTypes::scheduled, proci, 0, tag, @@ -245,12 +245,12 @@ Foam::List Foam::mapDistributeBase::schedule } else { - if (Pstream::parRun()) + if (UPstream::parRun()) { OPstream toMaster ( - Pstream::commsTypes::scheduled, - Pstream::masterNo(), + UPstream::commsTypes::scheduled, + UPstream::masterNo(), 0, tag, comm @@ -310,8 +310,8 @@ const Foam::List& Foam::mapDistributeBase::whichSchedule void Foam::mapDistributeBase::printLayout(Ostream& os) const { - const label myRank = Pstream::myProcNo(comm_); - const label nProcs = Pstream::nProcs(comm_); + const label myRank = UPstream::myProcNo(comm_); + const label nProcs = UPstream::nProcs(comm_); // Determine offsets of remote data. labelList minIndex(nProcs, labelMax); @@ -391,8 +391,8 @@ void Foam::mapDistributeBase::calcCompactAddressing List>& compactMap ) const { - const label myRank = Pstream::myProcNo(comm_); - const label nProcs = Pstream::nProcs(comm_); + const label myRank = UPstream::myProcNo(comm_); + const label nProcs = UPstream::nProcs(comm_); // Count all (non-local) elements needed. Just for presizing map. labelList nNonLocal(nProcs, Zero); @@ -439,8 +439,8 @@ void Foam::mapDistributeBase::calcCompactAddressing List>& compactMap ) const { - const label myRank = Pstream::myProcNo(comm_); - const label nProcs = Pstream::nProcs(comm_); + const label myRank = UPstream::myProcNo(comm_); + const label nProcs = UPstream::nProcs(comm_); // Count all (non-local) elements needed. Just for presizing map. labelList nNonLocal(nProcs, Zero); @@ -495,8 +495,8 @@ void Foam::mapDistributeBase::exchangeAddressing labelList& compactStart ) { - const label myRank = Pstream::myProcNo(comm_); - const label nProcs = Pstream::nProcs(comm_); + const label myRank = UPstream::myProcNo(comm_); + const label nProcs = UPstream::nProcs(comm_); // The overall compact addressing is // - myProcNo data first (uncompacted) @@ -575,8 +575,8 @@ void Foam::mapDistributeBase::exchangeAddressing labelList& compactStart ) { - const label myRank = Pstream::myProcNo(comm_); - const label nProcs = Pstream::nProcs(comm_); + const label myRank = UPstream::myProcNo(comm_); + const label nProcs = UPstream::nProcs(comm_); // The overall compact addressing is // - myProcNo data first (uncompacted) @@ -724,8 +724,8 @@ Foam::mapDistributeBase::mapDistributeBase comm_(comm), schedulePtr_(nullptr) { - const label myRank = Pstream::myProcNo(comm_); - const label nProcs = Pstream::nProcs(comm_); + const label myRank = UPstream::myProcNo(comm_); + const label nProcs = UPstream::nProcs(comm_); if (sendProcs.size() != recvProcs.size()) { @@ -922,6 +922,7 @@ Foam::mapDistributeBase::mapDistributeBase Foam::mapDistributeBase::mapDistributeBase ( + const layoutTypes constructLayout, labelListList&& subMap, const bool subHasFlip, const bool constructHasFlip, @@ -936,30 +937,21 @@ Foam::mapDistributeBase::mapDistributeBase comm_(comm), schedulePtr_(nullptr) { - const label myRank = Pstream::myProcNo(comm_); - const label nProcs = Pstream::nProcs(comm_); + const label myRank = UPstream::myProcNo(comm_); + const label nProcs = UPstream::nProcs(comm_); // Send over how many i need to receive. labelList recvSizes; Pstream::exchangeSizes(subMap_, recvSizes, comm_); - // Determine order of receiving constructSize_ = 0; constructMap_.resize(nProcs); + // The order of receiving: - // My data first + if (constructLayout == layoutTypes::linear) { - const label len = recvSizes[myRank]; - - constructMap_[myRank] = identity(len, constructSize_); - constructSize_ += len; - } - - // What the other processors are sending to me - forAll(constructMap_, proci) - { - if (proci != myRank) + forAll(constructMap_, proci) { const label len = recvSizes[proci]; @@ -967,9 +959,52 @@ Foam::mapDistributeBase::mapDistributeBase constructSize_ += len; } } + else + { + // layoutTypes::localFirst + + // My data first + { + const label len = recvSizes[myRank]; + + constructMap_[myRank] = identity(len, constructSize_); + constructSize_ += len; + } + + // What the other processors are sending to me + forAll(constructMap_, proci) + { + if (proci != myRank) + { + const label len = recvSizes[proci]; + + constructMap_[proci] = identity(len, constructSize_); + constructSize_ += len; + } + } + } } +Foam::mapDistributeBase::mapDistributeBase +( + labelListList&& subMap, + const bool subHasFlip, + const bool constructHasFlip, + const label comm +) +: + mapDistributeBase + ( + layoutTypes::localFirst, + std::move(subMap), + subHasFlip, + constructHasFlip, + comm + ) +{} + + // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // Foam::labelList Foam::mapDistributeBase::subMapSizes() const diff --git a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeBase.H b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeBase.H index a86b0d2beb..f0db8eea61 100644 --- a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeBase.H +++ b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeBase.H @@ -107,6 +107,18 @@ Ostream& operator<<(Ostream&, const InfoProxy&); class mapDistributeBase { +public: + + //- The map layout (eg, of the constructMap) + enum class layoutTypes : char + { + linear, //!< In processor-order + localFirst //!< Local processor first, others in linear order + }; + + +private: + // Private Data //- Size of reconstructed data @@ -432,6 +444,17 @@ public: const label comm = UPstream::worldComm ); + //- Construct from my elements to send, targetting the specified + //- constructMap layout + explicit mapDistributeBase + ( + const layoutTypes constructLayout, + labelListList&& subMap, + const bool subHasFlip = false, + const bool constructHasFlip = false, + const label comm = UPstream::worldComm + ); + //- Construct from my elements to send. // Assumes layout is my elements first followed by elements // from all other processors in consecutive order. @@ -792,7 +815,7 @@ public: template static void distribute ( - const Pstream::commsTypes commsType, + const UPstream::commsTypes commsType, const List& schedule, const label constructSize, const labelListList& subMap, @@ -812,7 +835,7 @@ public: template static void distribute ( - const Pstream::commsTypes commsType, + const UPstream::commsTypes commsType, const List& schedule, const label constructSize, const labelListList& subMap, @@ -828,7 +851,9 @@ public: ); - //- Distribute data using default commsType + // Distribute (simpler interface) + + //- Distribute List data using default commsType //- and the default flip/negate operator. template void distribute @@ -837,7 +862,7 @@ public: const int tag = UPstream::msgType() ) const; - //- Distribute data using default commsType + //- Distribute DynamicList data using default commsType //- and the default flip/negate operator. template void distribute @@ -846,6 +871,26 @@ public: const int tag = UPstream::msgType() ) const; + //- Distribute List data using specified commsType + //- and the default flip/negate operator. + template + void distribute + ( + const UPstream::commsTypes commsType, + List& values, + const int tag = UPstream::msgType() + ) const; + + //- Distribute DynamicList data using specified commsType + //- and the default flip/negate operator. + template + void distribute + ( + const UPstream::commsTypes commsType, + DynamicList& values, + const int tag = UPstream::msgType() + ) const; + //- Distribute data using default commsType //- and the specified negate operator (for flips). template @@ -864,7 +909,7 @@ public: template void distribute ( - const Pstream::commsTypes commsType, + const UPstream::commsTypes commsType, List& values, const NegateOp& negOp, const int tag = UPstream::msgType() @@ -878,7 +923,7 @@ public: template void distribute ( - const Pstream::commsTypes commsType, + const UPstream::commsTypes commsType, const T& nullValue, List& values, const NegateOp& negOp, @@ -886,6 +931,8 @@ public: ) const; + // Reverse Distribute (simpler interface) + //- Reverse distribute data using default commsType //- and the default flip/negate operator template @@ -914,7 +961,7 @@ public: template void reverseDistribute ( - const Pstream::commsTypes commsType, + const UPstream::commsTypes commsType, const label constructSize, List& values, const int tag = UPstream::msgType() @@ -925,7 +972,7 @@ public: template void reverseDistribute ( - const Pstream::commsTypes commsType, + const UPstream::commsTypes commsType, const label constructSize, List& values, const NegateOp& negOp, @@ -939,7 +986,7 @@ public: template void reverseDistribute ( - const Pstream::commsTypes commsType, + const UPstream::commsTypes commsType, const label constructSize, const T& nullValue, List& values, @@ -947,6 +994,8 @@ public: ) const; + // Send/Receive + //- Do all sends using PstreamBuffers template void send(PstreamBuffers& pBufs, const List& field) const; diff --git a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeBaseSubset.C b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeBaseSubset.C index 207b6852da..11ebd0d077 100644 --- a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeBaseSubset.C +++ b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeBaseSubset.C @@ -216,7 +216,7 @@ void Foam::mapDistributeBase::unionCombineMasks << Foam::abort(FatalError); } - if (Pstream::parRun()) + if (UPstream::parRun()) { // Scratch buffers for union operations List scratch(recvMasks.size()); @@ -254,7 +254,7 @@ void Foam::mapDistributeBase::unionCombineMasks else { // Non-parallel: 'synchronize' myself - const label myRank = Pstream::myProcNo(comm); + const label myRank = UPstream::myProcNo(comm); recvMasks[myRank] &= sendMasks[myRank]; sendMasks[myRank] = recvMasks[myRank]; diff --git a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeBaseTemplates.C b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeBaseTemplates.C index a4fed62e7d..3dcd1988a3 100644 --- a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeBaseTemplates.C +++ b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeBaseTemplates.C @@ -417,7 +417,7 @@ void Foam::mapDistributeBase::receive template void Foam::mapDistributeBase::distribute ( - const Pstream::commsTypes commsType, + const UPstream::commsTypes commsType, const List& schedule, const label constructSize, const labelListList& subMap, @@ -430,10 +430,10 @@ void Foam::mapDistributeBase::distribute const label comm ) { - const label myRank = Pstream::myProcNo(comm); - const label nProcs = Pstream::nProcs(comm); + const label myRank = UPstream::myProcNo(comm); + const label nProcs = UPstream::nProcs(comm); - if (!Pstream::parRun()) + if (!UPstream::parRun()) { // Do only me to me. @@ -460,13 +460,13 @@ void Foam::mapDistributeBase::distribute return; } - if (commsType == Pstream::commsTypes::blocking) + if (commsType == UPstream::commsTypes::blocking) { // Since buffered sending can reuse the field to collect the // received data. // Send sub field to neighbour - for (const int domain : Pstream::allProcs(comm)) + for (const int domain : UPstream::allProcs(comm)) { const labelList& map = subMap[domain]; @@ -474,7 +474,7 @@ void Foam::mapDistributeBase::distribute { OPstream toNbr ( - Pstream::commsTypes::blocking, + UPstream::commsTypes::blocking, domain, 0, tag, @@ -514,7 +514,7 @@ void Foam::mapDistributeBase::distribute } // Receive sub field from neighbour - for (const int domain : Pstream::allProcs(comm)) + for (const int domain : UPstream::allProcs(comm)) { const labelList& map = constructMap[domain]; @@ -522,7 +522,7 @@ void Foam::mapDistributeBase::distribute { IPstream fromNbr ( - Pstream::commsTypes::blocking, + UPstream::commsTypes::blocking, domain, 0, tag, @@ -544,7 +544,7 @@ void Foam::mapDistributeBase::distribute } } } - else if (commsType == Pstream::commsTypes::scheduled) + else if (commsType == UPstream::commsTypes::scheduled) { // Need to make sure I don't overwrite field with received data // since the data might need to be sent to another processor. So @@ -587,7 +587,7 @@ void Foam::mapDistributeBase::distribute { OPstream toNbr ( - Pstream::commsTypes::scheduled, + UPstream::commsTypes::scheduled, recvProc, 0, tag, @@ -605,7 +605,7 @@ void Foam::mapDistributeBase::distribute { IPstream fromNbr ( - Pstream::commsTypes::scheduled, + UPstream::commsTypes::scheduled, recvProc, 0, tag, @@ -634,7 +634,7 @@ void Foam::mapDistributeBase::distribute { IPstream fromNbr ( - Pstream::commsTypes::scheduled, + UPstream::commsTypes::scheduled, sendProc, 0, tag, @@ -659,7 +659,7 @@ void Foam::mapDistributeBase::distribute { OPstream toNbr ( - Pstream::commsTypes::scheduled, + UPstream::commsTypes::scheduled, sendProc, 0, tag, @@ -678,16 +678,16 @@ void Foam::mapDistributeBase::distribute } field.transfer(newField); } - else if (commsType == Pstream::commsTypes::nonBlocking) + else if (commsType == UPstream::commsTypes::nonBlocking) { - const label nOutstanding = Pstream::nRequests(); + const label nOutstanding = UPstream::nRequests(); if (!is_contiguous::value) { - PstreamBuffers pBufs(Pstream::commsTypes::nonBlocking, tag, comm); + PstreamBuffers pBufs(UPstream::commsTypes::nonBlocking, tag, comm); // Stream data into buffer - for (const int domain : Pstream::allProcs(comm)) + for (const int domain : UPstream::allProcs(comm)) { const labelList& map = subMap[domain]; @@ -733,10 +733,10 @@ void Foam::mapDistributeBase::distribute } // Block ourselves, waiting only for the current comms - Pstream::waitRequests(nOutstanding); + UPstream::waitRequests(nOutstanding); // Consume - for (const int domain : Pstream::allProcs(comm)) + for (const int domain : UPstream::allProcs(comm)) { const labelList& map = constructMap[domain]; @@ -765,7 +765,7 @@ void Foam::mapDistributeBase::distribute List> sendFields(nProcs); - for (const int domain : Pstream::allProcs(comm)) + for (const int domain : UPstream::allProcs(comm)) { const labelList& map = subMap[domain]; @@ -776,7 +776,7 @@ void Foam::mapDistributeBase::distribute UOPstream::write ( - Pstream::commsTypes::nonBlocking, + UPstream::commsTypes::nonBlocking, domain, sendFields[domain].cdata_bytes(), sendFields[domain].size_bytes(), @@ -790,7 +790,7 @@ void Foam::mapDistributeBase::distribute List> recvFields(nProcs); - for (const int domain : Pstream::allProcs(comm)) + for (const int domain : UPstream::allProcs(comm)) { const labelList& map = constructMap[domain]; @@ -799,7 +799,7 @@ void Foam::mapDistributeBase::distribute recvFields[domain].resize(map.size()); UIPstream::read ( - Pstream::commsTypes::nonBlocking, + UPstream::commsTypes::nonBlocking, domain, recvFields[domain].data_bytes(), recvFields[domain].size_bytes(), @@ -839,12 +839,12 @@ void Foam::mapDistributeBase::distribute // Wait for outstanding requests - Pstream::waitRequests(nOutstanding); + UPstream::waitRequests(nOutstanding); // Collect neighbour fields - for (const int domain : Pstream::allProcs(comm)) + for (const int domain : UPstream::allProcs(comm)) { const labelList& map = constructMap[domain]; @@ -879,7 +879,7 @@ void Foam::mapDistributeBase::distribute template void Foam::mapDistributeBase::distribute ( - const Pstream::commsTypes commsType, + const UPstream::commsTypes commsType, const List& schedule, const label constructSize, const labelListList& subMap, @@ -894,10 +894,10 @@ void Foam::mapDistributeBase::distribute const label comm ) { - const label myRank = Pstream::myProcNo(comm); - const label nProcs = Pstream::nProcs(comm); + const label myRank = UPstream::myProcNo(comm); + const label nProcs = UPstream::nProcs(comm); - if (!Pstream::parRun()) + if (!UPstream::parRun()) { // Do only me to me. @@ -917,13 +917,13 @@ void Foam::mapDistributeBase::distribute return; } - if (commsType == Pstream::commsTypes::blocking) + if (commsType == UPstream::commsTypes::blocking) { // Since buffered sending can reuse the field to collect the // received data. // Send sub field to neighbour - for (const int domain : Pstream::allProcs(comm)) + for (const int domain : UPstream::allProcs(comm)) { const labelList& map = subMap[domain]; @@ -931,7 +931,7 @@ void Foam::mapDistributeBase::distribute { OPstream toNbr ( - Pstream::commsTypes::blocking, + UPstream::commsTypes::blocking, domain, 0, tag, @@ -971,7 +971,7 @@ void Foam::mapDistributeBase::distribute } // Receive sub field from neighbour - for (const int domain : Pstream::allProcs(comm)) + for (const int domain : UPstream::allProcs(comm)) { const labelList& map = constructMap[domain]; @@ -979,7 +979,7 @@ void Foam::mapDistributeBase::distribute { IPstream fromNbr ( - Pstream::commsTypes::blocking, + UPstream::commsTypes::blocking, domain, 0, tag, @@ -1001,7 +1001,7 @@ void Foam::mapDistributeBase::distribute } } } - else if (commsType == Pstream::commsTypes::scheduled) + else if (commsType == UPstream::commsTypes::scheduled) { // Need to make sure I don't overwrite field with received data // since the data might need to be sent to another processor. So @@ -1045,7 +1045,7 @@ void Foam::mapDistributeBase::distribute { OPstream toNbr ( - Pstream::commsTypes::scheduled, + UPstream::commsTypes::scheduled, recvProc, 0, tag, @@ -1064,7 +1064,7 @@ void Foam::mapDistributeBase::distribute { IPstream fromNbr ( - Pstream::commsTypes::scheduled, + UPstream::commsTypes::scheduled, recvProc, 0, tag, @@ -1092,7 +1092,7 @@ void Foam::mapDistributeBase::distribute { IPstream fromNbr ( - Pstream::commsTypes::scheduled, + UPstream::commsTypes::scheduled, sendProc, 0, tag, @@ -1116,7 +1116,7 @@ void Foam::mapDistributeBase::distribute { OPstream toNbr ( - Pstream::commsTypes::scheduled, + UPstream::commsTypes::scheduled, sendProc, 0, tag, @@ -1136,16 +1136,16 @@ void Foam::mapDistributeBase::distribute } field.transfer(newField); } - else if (commsType == Pstream::commsTypes::nonBlocking) + else if (commsType == UPstream::commsTypes::nonBlocking) { - const label nOutstanding = Pstream::nRequests(); + const label nOutstanding = UPstream::nRequests(); if (!is_contiguous::value) { - PstreamBuffers pBufs(Pstream::commsTypes::nonBlocking, tag, comm); + PstreamBuffers pBufs(UPstream::commsTypes::nonBlocking, tag, comm); // Stream data into buffer - for (const int domain : Pstream::allProcs(comm)) + for (const int domain : UPstream::allProcs(comm)) { const labelList& map = subMap[domain]; @@ -1192,10 +1192,10 @@ void Foam::mapDistributeBase::distribute } // Block ourselves, waiting only for the current comms - Pstream::waitRequests(nOutstanding); + UPstream::waitRequests(nOutstanding); // Consume - for (const int domain : Pstream::allProcs(comm)) + for (const int domain : UPstream::allProcs(comm)) { const labelList& map = constructMap[domain]; @@ -1224,7 +1224,7 @@ void Foam::mapDistributeBase::distribute List> sendFields(nProcs); - for (const int domain : Pstream::allProcs(comm)) + for (const int domain : UPstream::allProcs(comm)) { const labelList& map = subMap[domain]; @@ -1235,7 +1235,7 @@ void Foam::mapDistributeBase::distribute UOPstream::write ( - Pstream::commsTypes::nonBlocking, + UPstream::commsTypes::nonBlocking, domain, sendFields[domain].cdata_bytes(), sendFields[domain].size_bytes(), @@ -1249,7 +1249,7 @@ void Foam::mapDistributeBase::distribute List> recvFields(nProcs); - for (const int domain : Pstream::allProcs(comm)) + for (const int domain : UPstream::allProcs(comm)) { const labelList& map = constructMap[domain]; @@ -1258,7 +1258,7 @@ void Foam::mapDistributeBase::distribute recvFields[domain].resize(map.size()); UIPstream::read ( - Pstream::commsTypes::nonBlocking, + UPstream::commsTypes::nonBlocking, domain, recvFields[domain].data_bytes(), recvFields[domain].size_bytes(), @@ -1298,12 +1298,12 @@ void Foam::mapDistributeBase::distribute // Wait for outstanding requests - Pstream::waitRequests(nOutstanding); + UPstream::waitRequests(nOutstanding); // Collect neighbour fields - for (const int domain : Pstream::allProcs(comm)) + for (const int domain : UPstream::allProcs(comm)) { const labelList& map = constructMap[domain]; @@ -1340,7 +1340,7 @@ void Foam::mapDistributeBase::send(PstreamBuffers& pBufs, const List& field) const { // Stream data into buffer - for (const int domain : Pstream::allProcs(comm_)) + for (const int domain : UPstream::allProcs(comm_)) { const labelList& map = subMap_[domain]; @@ -1370,7 +1370,7 @@ const // Consume field.resize_nocopy(constructSize_); - for (const int domain : Pstream::allProcs(comm_)) + for (const int domain : UPstream::allProcs(comm_)) { const labelList& map = constructMap_[domain]; @@ -1405,7 +1405,7 @@ const template void Foam::mapDistributeBase::distribute ( - const Pstream::commsTypes commsType, + const UPstream::commsTypes commsType, List& values, const NegateOp& negOp, const int tag @@ -1431,7 +1431,7 @@ void Foam::mapDistributeBase::distribute template void Foam::mapDistributeBase::distribute ( - const Pstream::commsTypes commsType, + const UPstream::commsTypes commsType, const T& nullValue, List& values, const NegateOp& negOp, @@ -1475,11 +1475,41 @@ void Foam::mapDistributeBase::distribute template void Foam::mapDistributeBase::distribute ( + const UPstream::commsTypes commsType, List& values, const int tag ) const { - distribute(values, flipOp(), tag); + distribute(commsType, values, flipOp(), tag); +} + + +template +void Foam::mapDistributeBase::distribute +( + const UPstream::commsTypes commsType, + DynamicList& values, + const int tag +) const +{ + values.shrink(); + + List& list = static_cast&>(values); + + distribute(commsType, list, tag); + + values.setCapacity(list.size()); +} + + +template +void Foam::mapDistributeBase::distribute +( + List& values, + const int tag +) const +{ + distribute(UPstream::defaultCommsType, values, tag); } @@ -1490,20 +1520,14 @@ void Foam::mapDistributeBase::distribute const int tag ) const { - values.shrink(); - - List& list = static_cast&>(values); - - distribute(list, tag); - - values.setCapacity(list.size()); + distribute(UPstream::defaultCommsType, values, tag); } template void Foam::mapDistributeBase::reverseDistribute ( - const Pstream::commsTypes commsType, + const UPstream::commsTypes commsType, const label constructSize, List& values, const int tag @@ -1523,7 +1547,7 @@ void Foam::mapDistributeBase::reverseDistribute template void Foam::mapDistributeBase::reverseDistribute ( - const Pstream::commsTypes commsType, + const UPstream::commsTypes commsType, const label constructSize, List& values, const NegateOp& negOp, @@ -1550,7 +1574,7 @@ void Foam::mapDistributeBase::reverseDistribute template void Foam::mapDistributeBase::reverseDistribute ( - const Pstream::commsTypes commsType, + const UPstream::commsTypes commsType, const label constructSize, const T& nullValue, List& values, diff --git a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeTemplates.C b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeTemplates.C index e08a276922..9921ae3fe8 100644 --- a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeTemplates.C +++ b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeTemplates.C @@ -6,6 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2016 OpenFOAM Foundation + Copyright (C) 2023 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -39,7 +40,6 @@ void Foam::mapDistribute::applyDummyTransforms(List& field) const forAll(transformElements_, trafoI) { const labelList& elems = transformElements_[trafoI]; - label n = transformStart_[trafoI]; forAll(elems, i) @@ -129,13 +129,14 @@ void Foam::mapDistribute::applyInverseTransforms template void Foam::mapDistribute::distribute ( + const UPstream::commsTypes commsType, List& fld, const NegateOp& negOp, const bool dummyTransform, const int tag ) const { - mapDistributeBase::distribute(fld, negOp, tag); + mapDistributeBase::distribute(commsType, fld, negOp, tag); //- Fill in transformed slots with copies if (dummyTransform) @@ -145,6 +146,32 @@ void Foam::mapDistribute::distribute } +template +void Foam::mapDistribute::distribute +( + List& fld, + const NegateOp& negOp, + const bool dummyTransform, + const int tag +) const +{ + distribute(UPstream::defaultCommsType, fld, negOp, dummyTransform, tag); +} + + +template +void Foam::mapDistribute::distribute +( + const UPstream::commsTypes commsType, + List& fld, + const bool dummyTransform, + const int tag +) const +{ + distribute(commsType, fld, flipOp(), dummyTransform, tag); +} + + template void Foam::mapDistribute::distribute ( @@ -153,7 +180,26 @@ void Foam::mapDistribute::distribute const int tag ) const { - distribute(fld, flipOp(), dummyTransform, tag); + distribute(UPstream::defaultCommsType, fld, dummyTransform, tag); +} + + +template +void Foam::mapDistribute::distribute +( + const UPstream::commsTypes commsType, + DynamicList& fld, + const bool dummyTransform, + const int tag +) const +{ + fld.shrink(); + + List& list = static_cast&>(fld); + + distribute(commsType, list, dummyTransform, tag); + + fld.setCapacity(list.size()); } @@ -165,13 +211,26 @@ void Foam::mapDistribute::distribute const int tag ) const { - fld.shrink(); + distribute(UPstream::defaultCommsType, fld, dummyTransform, tag); +} - List& list = static_cast&>(fld); - distribute(list, dummyTransform, tag); +template +void Foam::mapDistribute::reverseDistribute +( + const UPstream::commsTypes commsType, + const label constructSize, + List& fld, + const bool dummyTransform, + const int tag +) const +{ + if (dummyTransform) + { + applyDummyInverseTransforms(fld); + } - fld.setCapacity(list.size()); + mapDistributeBase::reverseDistribute(commsType, constructSize, fld, tag); } @@ -183,13 +242,42 @@ void Foam::mapDistribute::reverseDistribute const bool dummyTransform, const int tag ) const +{ + reverseDistribute + ( + UPstream::defaultCommsType, + constructSize, + fld, + dummyTransform, + tag + ); +} + + +template +void Foam::mapDistribute::reverseDistribute +( + const UPstream::commsTypes commsType, + const label constructSize, + const T& nullValue, + List& fld, + const bool dummyTransform, + const int tag +) const { if (dummyTransform) { applyDummyInverseTransforms(fld); } - mapDistributeBase::reverseDistribute(constructSize, fld, tag); + mapDistributeBase::reverseDistribute + ( + commsType, + constructSize, + nullValue, + fld, + tag + ); } @@ -203,12 +291,33 @@ void Foam::mapDistribute::reverseDistribute const int tag ) const { - if (dummyTransform) - { - applyDummyInverseTransforms(fld); - } + reverseDistribute + ( + UPstream::defaultCommsType, + constructSize, + nullValue, + fld, + dummyTransform, + tag + ); +} - mapDistributeBase::reverseDistribute(constructSize, nullValue, fld, tag); + +template +void Foam::mapDistribute::distribute +( + const UPstream::commsTypes commsType, + const globalIndexAndTransform& git, + List& fld, + const TransformOp& top, + const int tag +) const +{ + // Distribute. Leave out dummy transforms since we're doing them ourselves + distribute(commsType, fld, false, tag); + + // Do transforms + applyTransforms(git, fld, top); } @@ -222,10 +331,28 @@ void Foam::mapDistribute::distribute ) const { // Distribute. Leave out dummy transforms since we're doing them ourselves - distribute(fld, false, tag); + distribute(UPstream::defaultCommsType, git, fld, top, tag); +} - // Do transforms - applyTransforms(git, fld, top); + +template +void Foam::mapDistribute::reverseDistribute +( + const UPstream::commsTypes commsType, + const globalIndexAndTransform& git, + const label constructSize, + List& fld, + const TransformOp& top, + const int tag +) const +{ + // Fill slots with reverse-transformed data. Note that it also copies + // back into the non-remote part of fld even though these values are not + // used. + applyInverseTransforms(git, fld, top); + + // And send back (the remote slots). Disable dummy transformations. + reverseDistribute(commsType, constructSize, fld, false, tag); } @@ -252,6 +379,7 @@ void Foam::mapDistribute::reverseDistribute template void Foam::mapDistribute::reverseDistribute ( + const UPstream::commsTypes commsType, const globalIndexAndTransform& git, const label constructSize, const T& nullValue, @@ -266,7 +394,39 @@ void Foam::mapDistribute::reverseDistribute applyInverseTransforms(git, fld, top); //, eqOp()); // And send back (the remote slots) Disable dummy transformations. - reverseDistribute(constructSize, nullValue, fld, false, tag); + reverseDistribute + ( + commsType, + constructSize, + nullValue, + fld, + false, + tag + ); +} + + +template +void Foam::mapDistribute::reverseDistribute +( + const globalIndexAndTransform& git, + const label constructSize, + const T& nullValue, + List& fld, + const TransformOp& top, + const int tag +) const +{ + reverseDistribute + ( + UPstream::defaultCommsType, + git, + constructSize, + nullValue, + fld, + top, + tag + ); }