diff --git a/applications/test/treeComms/Test-treeComms.C b/applications/test/treeComms/Test-treeComms.C index 832f1459f7..7408358464 100644 --- a/applications/test/treeComms/Test-treeComms.C +++ b/applications/test/treeComms/Test-treeComms.C @@ -51,7 +51,7 @@ void printConnection(Ostream& os, const label proci, const labelUList& below) // The number of receives - as per gatherList (v2112) void printRecvCount_gatherList ( - const UList& comms, + const UPstream::commsStructList& comms, const label comm = UPstream::worldComm ) { @@ -91,7 +91,7 @@ void printRecvCount_gatherList // The number of sends - as per scatterList (v2112) void printSendCount_scatterList ( - const UList& comms, + const UPstream::commsStructList& comms, const label comm = UPstream::worldComm ) { @@ -131,7 +131,7 @@ void printSendCount_scatterList // Transmission widths (contiguous data) void printWidths ( - const UList& comms, + const UPstream::commsStructList& comms, const label comm = UPstream::worldComm ) { diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/Pstream.H b/src/OpenFOAM/db/IOstreams/Pstreams/Pstream.H index 04e3009503..05dc64eb51 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/Pstream.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/Pstream.H @@ -310,7 +310,7 @@ public: template static void gatherList ( - const UList& comms, + const UPstream::commsStructList& comms, //! [in,out] UList& values, const int tag, @@ -349,7 +349,7 @@ public: template static void scatterList ( - const UList& comms, + const UPstream::commsStructList& comms, UList& values, const int tag, const label comm diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/PstreamGatherList.C b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamGatherList.C index 267d3d1c98..edc269a067 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/PstreamGatherList.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamGatherList.C @@ -45,7 +45,7 @@ Description template void Foam::Pstream::gatherList ( - const UList& comms, + const UPstream::commsStructList& comms, UList& values, const int tag, const label comm @@ -190,7 +190,7 @@ void Foam::Pstream::gatherList template void Foam::Pstream::scatterList ( - const UList& comms, + const UPstream::commsStructList& comms, UList& values, const int tag, const label comm diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.C b/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.C index cd8641607f..4f47d5f983 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.C @@ -183,8 +183,8 @@ Foam::label Foam::UPstream::getAvailableCommIndex(const label parentIndex) procIDs_.emplace_back(); // Sizing and filling are demand-driven - linearCommunication_.emplace_back(); - treeCommunication_.emplace_back(); + linearCommunication_.emplace_back(index); + treeCommunication_.emplace_back(index); } return index; @@ -616,26 +616,24 @@ Foam::label Foam::UPstream::procNo } -const Foam::List& +const Foam::UPstream::commsStructList& Foam::UPstream::linearCommunication(const label communicator) { if (linearCommunication_[communicator].empty()) { - linearCommunication_[communicator] = - List(UPstream::nProcs(communicator)); + linearCommunication_[communicator].init(communicator); } return linearCommunication_[communicator]; } -const Foam::List& +const Foam::UPstream::commsStructList& Foam::UPstream::treeCommunication(const label communicator) { if (treeCommunication_[communicator].empty()) { - treeCommunication_[communicator] = - List(UPstream::nProcs(communicator)); + treeCommunication_[communicator].init(communicator); } return treeCommunication_[communicator]; @@ -648,7 +646,7 @@ void Foam::UPstream::printCommTree(const label communicator) if (UPstream::master(communicator)) { - commsStruct::printGraph(Info(), comms); + comms.printGraph(Info()); } } @@ -692,10 +690,10 @@ Foam::DynamicList> Foam::UPstream::procIDs_(16); Foam::DynamicList Foam::UPstream::parentComm_(16); Foam::DynamicList Foam::UPstream::freeComms_; -Foam::DynamicList> +Foam::DynamicList Foam::UPstream::linearCommunication_(16); -Foam::DynamicList> +Foam::DynamicList Foam::UPstream::treeCommunication_(16); diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H b/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H index b7e802aa6c..b7df5c279e 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H @@ -151,19 +151,10 @@ public: // Member Functions - //- Print un-directed graph in graphviz dot format - static void printGraph - ( - Ostream& os, - const UList& comms, - const label proci = 0 // starting node - ); - - // Access //- The number of processors addressed by the structure - label nProcs() const; + label nProcs() const noexcept; //- The procID of the processor \em directly above label above() const noexcept { return above_; } @@ -188,8 +179,14 @@ public: //- Reset to default constructed state void reset(); - //- Reset with automatic linear/tree selection - void reset(const label procID, const label numProcs); + //- Reset (automatic linear/tree selection), + //- possibly with communicator-specific adjustments + void reset + ( + const label procID, + const label numProcs, + const label comm = -1 + ); // Member / Friend Operators @@ -200,6 +197,67 @@ public: friend Ostream& operator<<(Ostream&, const commsStruct&); }; + //- Collection of communication structures + class commsStructList + { + // Private Data + + //- The communicator index + label comm_; + + //- The communication tree + List tree_; + + public: + + // Constructors + + //- Construct empty with invalid communicator + commsStructList() noexcept : comm_(-1) {} + + //- Construct empty with given communicator + commsStructList(label comm) noexcept : comm_(comm) {} + + + // Static Functions + + //- An empty structure. Used for placeholders etc. + static const commsStructList& null(); + + + // Member Functions + + //- True if communicator is non-negative (ie, was assigned) + bool good() const noexcept { return (comm_ >= 0); } + + //- The communicator label + label comm() const noexcept { return comm_; } + + //- Clear the list + void clear() { return tree_.clear(); } + + //- True if the list is empty + bool empty() const noexcept { return tree_.empty(); } + + //- The number of entries + label size() const noexcept { return tree_.size(); } + + //- Reset communicator index and clear demand-driven entries + void init(const label comm); + + //- Get existing or create (demand-driven) entry + const UPstream::commsStruct& get(const label proci) const; + + //- Get existing or create (demand-driven) entry + const UPstream::commsStruct& operator[](const label proci) const + { + return get(proci); + } + + //- Print un-directed graph in graphviz dot format + void printGraph(Ostream& os, label proci = 0) const; + }; + private: @@ -258,10 +316,10 @@ private: static DynamicList