diff --git a/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalIndex.H b/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalIndex.H index 6d955f1ec1796e337929ada39bbbda251d98fb31..4e9240148901a344c9261ebf307d317005a3d8e1 100644 --- a/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalIndex.H +++ b/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalIndex.H @@ -162,6 +162,17 @@ public: const int tag = UPstream::msgType() ) const; + //- Inplace collect data in processor order on master + // (== procIDs[0]). Needs offsets only on master. + template<class Type> + void gather + ( + const label comm, + const labelList& procIDs, + List<Type>& fld, + const int tag = UPstream::msgType() + ) const; + //- Distribute data in processor order. Requires fld to be sized! template<class Type> void scatter diff --git a/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalIndexTemplates.C b/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalIndexTemplates.C index 9712f5c41c49568ea4b771f693ad4023ff672146..2beb2cfe7aad50bc264500bf042b051686de9260 100644 --- a/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalIndexTemplates.C +++ b/src/OpenFOAM/meshes/polyMesh/globalMeshData/globalIndexTemplates.C @@ -109,6 +109,89 @@ void Foam::globalIndex::gather } +template<class Type> +void Foam::globalIndex::gather +( + const label comm, + const labelList& procIDs, + List<Type>& fld, + const int tag +) const +{ + if (Pstream::myProcNo(comm) == procIDs[0]) + { + List<Type> allFld(size()); + + // Assign my local data + SubList<Type>(allFld, fld.size(), 0).assign(fld); + + for (label i = 1; i < procIDs.size(); i++) + { + SubList<Type> procSlot + ( + allFld, + offsets_[i+1]-offsets_[i], + offsets_[i] + ); + + if (contiguous<Type>()) + { + IPstream::read + ( + Pstream::scheduled, + procIDs[i], + reinterpret_cast<char*>(procSlot.begin()), + procSlot.byteSize(), + tag, + comm + ); + } + else + { + IPstream fromSlave + ( + Pstream::scheduled, + procIDs[i], + 0, + tag, + comm + ); + fromSlave >> procSlot; + } + } + + fld.transfer(allFld); + } + else + { + if (contiguous<Type>()) + { + OPstream::write + ( + Pstream::scheduled, + procIDs[0], + reinterpret_cast<const char*>(fld.begin()), + fld.byteSize(), + tag, + comm + ); + } + else + { + OPstream toMaster + ( + Pstream::scheduled, + procIDs[0], + 0, + tag, + comm + ); + toMaster << fld; + } + } +} + + template<class Type> void Foam::globalIndex::scatter (