diff --git a/applications/test/globalIndex3/Test-globalIndex3.cxx b/applications/test/globalIndex3/Test-globalIndex3.cxx index 19a72499d3..d6ae4a658e 100644 --- a/applications/test/globalIndex3/Test-globalIndex3.cxx +++ b/applications/test/globalIndex3/Test-globalIndex3.cxx @@ -508,7 +508,7 @@ int main(int argc, char *argv[]) #include "setRootCase.H" - const bool useLocalComms = UPstream::usingNodeComms(); + const bool useLocalComms = UPstream::usingNodeComms(UPstream::worldComm); bool useWindow = args.found("window"); bool useBuiltin = args.found("builtin"); diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.H b/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.H index 472353a2cd..056d3dd0fb 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/IPstream.H @@ -61,14 +61,13 @@ public: // Constructors //- Construct given process index to read from - //- and optional buffer size, read format IPstream ( const UPstream::commsTypes commsType, const int fromProcNo, - const label bufSize = 0, + const int bufferSize = 0, //!< optional buffer size const int tag = UPstream::msgType(), - const label comm = UPstream::worldComm, + const int communicator = UPstream::worldComm, IOstreamOption::streamFormat fmt = IOstreamOption::BINARY ); @@ -83,7 +82,7 @@ public: Type& value, const int fromProcNo, const int tag = UPstream::msgType(), - const label comm = UPstream::worldComm, + const int communicator = UPstream::worldComm, IOstreamOption::streamFormat fmt = IOstreamOption::BINARY ) { @@ -91,9 +90,9 @@ public: ( UPstream::commsTypes::scheduled, // ie, MPI_Recv() fromProcNo, - 0, // bufSize + 0, // bufferSize tag, - comm, + communicator, fmt ); is >> value; diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/IPstreams.C b/src/OpenFOAM/db/IOstreams/Pstreams/IPstreams.C index 340f0a2f99..667970803b 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/IPstreams.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/IPstreams.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2022-2023 OpenCFD Ltd. + Copyright (C) 2022-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -38,7 +38,7 @@ Foam::UIPstream::UIPstream DynamicList& receiveBuf, label& receiveBufPosition, const int tag, - const label comm, + const int communicator, const bool clearAtEnd, IOstreamOption::streamFormat fmt ) @@ -50,7 +50,7 @@ Foam::UIPstream::UIPstream receiveBuf, receiveBufPosition, tag, - comm, + communicator, clearAtEnd, fmt ) @@ -105,13 +105,13 @@ Foam::IPstream::IPstream ( const UPstream::commsTypes commsType, const int fromProcNo, - const label bufSize, + const int bufferSize, const int tag, - const label comm, + const int communicator, IOstreamOption::streamFormat fmt ) : - Pstream(commsType, bufSize), + Pstream(commsType, bufferSize), UIPstream ( commsType, @@ -119,7 +119,7 @@ Foam::IPstream::IPstream Pstream::transferBuf_, UIPstreamBase::storedRecvBufPos_, // Internal only tag, - comm, + communicator, false, // Do not clear Pstream::transferBuf_ if at end fmt ) diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.H b/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.H index dcdcbda797..8513b4fbf1 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/OPstream.H @@ -61,14 +61,13 @@ public: // Constructors //- Construct for given process index to send to - //- and optional buffer size, write format OPstream ( const UPstream::commsTypes commsType, const int toProcNo, - const label bufSize = 0, + const int bufferSize = 0, //!< optional buffer size const int tag = UPstream::msgType(), - const label comm = UPstream::worldComm, + const int communicator = UPstream::worldComm, IOstreamOption::streamFormat fmt = IOstreamOption::BINARY ); @@ -81,15 +80,15 @@ public: static void send ( const Type& value, - //! blocking or scheduled only! + //! buffered or scheduled only! const UPstream::commsTypes commsType, const int toProcNo, const int tag = UPstream::msgType(), - const label comm = UPstream::worldComm, + const int communicator = UPstream::worldComm, IOstreamOption::streamFormat fmt = IOstreamOption::BINARY ) { - OPstream os(commsType, toProcNo, 0, tag, comm, fmt); + OPstream os(commsType, toProcNo, 0, tag, communicator, fmt); os << value; } @@ -101,7 +100,7 @@ public: const Type& value, const int toProcNo, const int tag = UPstream::msgType(), - const label comm = UPstream::worldComm, + const int communicator = UPstream::worldComm, IOstreamOption::streamFormat fmt = IOstreamOption::BINARY ) { @@ -111,7 +110,7 @@ public: UPstream::commsTypes::scheduled, // ie, MPI_Send() toProcNo, tag, - comm, + communicator, fmt ); } diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/OPstreams.C b/src/OpenFOAM/db/IOstreams/Pstreams/OPstreams.C index fc8312f674..281bc01a68 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/OPstreams.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/OPstreams.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011 OpenFOAM Foundation - Copyright (C) 2022-2024 OpenCFD Ltd. + Copyright (C) 2022-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -37,7 +37,7 @@ Foam::UOPstream::UOPstream const int toProcNo, DynamicList& sendBuf, const int tag, - const label comm, + const int comm, const bool sendAtDestruct, IOstreamOption::streamFormat fmt ) @@ -66,20 +66,20 @@ Foam::OPstream::OPstream ( const UPstream::commsTypes commsType, const int toProcNo, - const label bufSize, + const int bufferSize, const int tag, - const label comm, + const int communicator, IOstreamOption::streamFormat fmt ) : - Pstream(commsType, bufSize), + Pstream(commsType, bufferSize), UOPstream ( commsType, toProcNo, Pstream::transferBuf_, tag, - comm, + communicator, true, // sendAtDestruct fmt ) diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/Pstream.H b/src/OpenFOAM/db/IOstreams/Pstreams/Pstream.H index 84d97ee64f..ef8acb773b 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/Pstream.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/Pstream.H @@ -75,18 +75,20 @@ public: // Constructors - //- Construct for given communication type, with optional buffer size - explicit Pstream - ( - const UPstream::commsTypes commsType, - const label bufSize = 0 - ) + //- Construct for communication type with empty buffer + explicit Pstream(const UPstream::commsTypes commsType) noexcept + : + UPstream(commsType) + {} + + //- Construct for communication type with given buffer size + Pstream(const UPstream::commsTypes commsType, int bufferSize) : UPstream(commsType) { - if (bufSize > 0) + if (bufferSize > 0) { - transferBuf_.setCapacity(bufSize + 2*sizeof(scalar) + 1); + transferBuf_.setCapacity(bufferSize + 2*sizeof(scalar) + 1); } } diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/PstreamBuffers.C b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamBuffers.C index 391c094bea..5332f3cf89 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/PstreamBuffers.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamBuffers.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2021-2023 OpenCFD Ltd. + Copyright (C) 2021-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -300,7 +300,7 @@ Foam::PstreamBuffers::PstreamBuffers ( UPstream::commsTypes commsType, int tag, - label communicator, + int communicator, IOstreamOption::streamFormat fmt ) : @@ -313,7 +313,7 @@ Foam::PstreamBuffers::PstreamBuffers nProcs_(UPstream::nProcs(comm_)), sendBuffers_(nProcs_), recvBuffers_(nProcs_), - recvPositions_(nProcs_, Zero) + recvPositions_(nProcs_, Foam::zero{}) { DebugPoutInFunction << "tag:" << tag_ diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/PstreamBuffers.H b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamBuffers.H index 97cb68fe9a..d80607d379 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/PstreamBuffers.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/PstreamBuffers.H @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2021-2023 OpenCFD Ltd. + Copyright (C) 2021-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -182,10 +182,10 @@ class PstreamBuffers const int tag_; //- Communicator - const label comm_; + const int comm_; //- Number of ranks associated with PstreamBuffers (at construction) - const label nProcs_; + const int nProcs_; // Buffer storage @@ -266,7 +266,7 @@ public: ( UPstream::commsTypes commsType = UPstream::commsTypes::nonBlocking, int tag = UPstream::msgType(), - label communicator = UPstream::worldComm, + int communicator = UPstream::worldComm, IOstreamOption::streamFormat fmt = IOstreamOption::BINARY ); @@ -274,7 +274,7 @@ public: //- (default: nonBlocking), message tag, IO format (default: binary) explicit PstreamBuffers ( - label communicator, + int communicator, UPstream::commsTypes commsType = UPstream::commsTypes::nonBlocking, int tag = UPstream::msgType(), IOstreamOption::streamFormat fmt = IOstreamOption::BINARY @@ -287,7 +287,7 @@ public: //- (default: nonBlocking), IO format (default: binary) PstreamBuffers ( - label communicator, + int communicator, int tag, UPstream::commsTypes commsType = UPstream::commsTypes::nonBlocking, IOstreamOption::streamFormat fmt = IOstreamOption::BINARY @@ -306,34 +306,19 @@ public: // Attributes //- The associated buffer format (ascii | binary) - IOstreamOption::streamFormat format() const noexcept - { - return format_; - } + IOstreamOption::streamFormat format() const noexcept { return format_; } //- The communications type of the stream - UPstream::commsTypes commsType() const noexcept - { - return commsType_; - } + UPstream::commsTypes commsType() const noexcept { return commsType_; } //- The transfer message tag - int tag() const noexcept - { - return tag_; - } + int tag() const noexcept { return tag_; } //- The communicator index - label comm() const noexcept - { - return comm_; - } + int comm() const noexcept { return comm_; } //- Number of ranks associated with PstreamBuffers - label nProcs() const noexcept - { - return nProcs_; - } + int nProcs() const noexcept { return nProcs_; } // Sizing diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.H b/src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.H index dbce6dc010..33b40e8a22 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/UIPstream.H @@ -124,7 +124,7 @@ protected: DynamicList& receiveBuf, label& receiveBufPosition, const int tag = UPstream::msgType(), - const label comm = UPstream::worldComm, + const int communicator = UPstream::worldComm, const bool clearAtEnd = false, // destroy receiveBuf if at end IOstreamOption::streamFormat fmt = IOstreamOption::BINARY ); @@ -252,7 +252,7 @@ public: DynamicList& receiveBuf, label& receiveBufPosition, const int tag = UPstream::msgType(), - const label comm = UPstream::worldComm, + const int communicator = UPstream::worldComm, const bool clearAtEnd = false, // destroy receiveBuf if at end IOstreamOption::streamFormat fmt = IOstreamOption::BINARY ); @@ -292,7 +292,7 @@ public: char* buf, const std::streamsize bufSize, const int tag = UPstream::msgType(), - const label comm = UPstream::worldComm, + const int communicator = UPstream::worldComm, //! [out] request information (for non-blocking) UPstream::Request* req = nullptr ); @@ -307,7 +307,7 @@ public: char* buf, const std::streamsize bufSize, const int tag = UPstream::msgType(), - const label comm = UPstream::worldComm + const int communicator = UPstream::worldComm ) { return UIPstream::read @@ -317,7 +317,7 @@ public: buf, bufSize, tag, - comm, + communicator, &req ); } @@ -332,7 +332,7 @@ public: const int fromProcNo, UList& buffer, const int tag = UPstream::msgType(), - const label comm = UPstream::worldComm, + const int communicator = UPstream::worldComm, //! [out] request information (for non-blocking) UPstream::Request* req = nullptr ) @@ -344,7 +344,7 @@ public: buffer.data_bytes(), buffer.size_bytes(), tag, - comm, + communicator, req ); } @@ -359,7 +359,7 @@ public: const int fromProcNo, SubList buffer, // passed by shallow copy const int tag = UPstream::msgType(), - const label comm = UPstream::worldComm, + const int communicator = UPstream::worldComm, //! [out] request information (for non-blocking) UPstream::Request* req = nullptr ) @@ -371,7 +371,7 @@ public: buffer.data_bytes(), buffer.size_bytes(), tag, - comm, + communicator, req ); } @@ -387,7 +387,7 @@ public: const int fromProcNo, UList& buffer, const int tag = UPstream::msgType(), - const label comm = UPstream::worldComm + const int communicator = UPstream::worldComm ) { return UIPstream::read @@ -397,7 +397,7 @@ public: buffer.data_bytes(), buffer.size_bytes(), tag, - comm, + communicator, &req ); } @@ -413,7 +413,7 @@ public: const int fromProcNo, SubList buffer, // passed by shallow copy const int tag = UPstream::msgType(), - const label comm = UPstream::worldComm + const int communicator = UPstream::worldComm ) { return UIPstream::read @@ -423,7 +423,7 @@ public: buffer.data_bytes(), buffer.size_bytes(), tag, - comm, + communicator, &req ); } diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UIPstreamBase.C b/src/OpenFOAM/db/IOstreams/Pstreams/UIPstreamBase.C index 9ea930111f..c9444e6735 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/UIPstreamBase.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/UIPstreamBase.C @@ -167,7 +167,7 @@ Foam::UIPstreamBase::UIPstreamBase DynamicList& receiveBuf, label& receiveBufPosition, const int tag, - const label comm, + const int communicator, const bool clearAtEnd, IOstreamOption::streamFormat fmt ) @@ -176,7 +176,7 @@ Foam::UIPstreamBase::UIPstreamBase Istream(fmt), fromProcNo_(fromProcNo), tag_(tag), - comm_(comm), + comm_(communicator), messageSize_(0), storedRecvBufPos_(0), clearAtEnd_(clearAtEnd), diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.H b/src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.H index 34c4968511..d1550c4d9c 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/UOPstream.H @@ -121,7 +121,7 @@ protected: const int toProcNo, DynamicList& sendBuf, const int tag = UPstream::msgType(), - const label comm = UPstream::worldComm, + const int communicator = UPstream::worldComm, const bool sendAtDestruct = true, IOstreamOption::streamFormat fmt = IOstreamOption::BINARY ); @@ -325,7 +325,7 @@ public: const int toProcNo, DynamicList& sendBuf, const int tag = UPstream::msgType(), - const label comm = UPstream::worldComm, + const int communicator = UPstream::worldComm, const bool sendAtDestruct = true, IOstreamOption::streamFormat fmt = IOstreamOption::BINARY ); @@ -367,7 +367,7 @@ public: const char* buf, const std::streamsize bufSize, const int tag = UPstream::msgType(), - const label comm = UPstream::worldComm, + const int communicator = UPstream::worldComm, //! [out] request information (for non-blocking) UPstream::Request* req = nullptr, const UPstream::sendModes sendMode = UPstream::sendModes::normal @@ -383,7 +383,7 @@ public: const char* buf, const std::streamsize bufSize, const int tag = UPstream::msgType(), - const label comm = UPstream::worldComm, + const int communicator = UPstream::worldComm, const UPstream::sendModes sendMode = UPstream::sendModes::normal ) { @@ -394,7 +394,7 @@ public: buf, bufSize, tag, - comm, + communicator, &req, sendMode ); @@ -410,7 +410,7 @@ public: const int toProcNo, const UList& buffer, const int tag = UPstream::msgType(), - const label comm = UPstream::worldComm, + const int communicator = UPstream::worldComm, //! [out] request information (for non-blocking) UPstream::Request* req = nullptr, const UPstream::sendModes sendMode = UPstream::sendModes::normal @@ -423,7 +423,7 @@ public: buffer.cdata_bytes(), buffer.size_bytes(), tag, - comm, + communicator, req, sendMode ); @@ -440,7 +440,7 @@ public: const int toProcNo, const UList& buffer, const int tag = UPstream::msgType(), - const label comm = UPstream::worldComm, + const int communicator = UPstream::worldComm, const UPstream::sendModes sendMode = UPstream::sendModes::normal ) { @@ -451,7 +451,7 @@ public: buffer.cdata_bytes(), buffer.size_bytes(), tag, - comm, + communicator, &req, sendMode ); diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UOPstreamBase.C b/src/OpenFOAM/db/IOstreams/Pstreams/UOPstreamBase.C index e07c5320e8..cc665f0cb6 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/UOPstreamBase.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/UOPstreamBase.C @@ -146,7 +146,7 @@ Foam::UOPstreamBase::UOPstreamBase const int toProcNo, DynamicList& sendBuf, const int tag, - const label comm, + const int communicator, const bool sendAtDestruct, IOstreamOption::streamFormat fmt ) @@ -155,7 +155,7 @@ Foam::UOPstreamBase::UOPstreamBase Ostream(fmt), toProcNo_(toProcNo), tag_(tag), - comm_(comm), + comm_(communicator), sendAtDestruct_(sendAtDestruct), sendBuf_(sendBuf) { diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.C b/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.C index d3b8e489e3..2c1d72b143 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.C @@ -112,7 +112,7 @@ void Foam::UPstream::printTopoControl(Ostream& os) // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -void Foam::UPstream::setParRun(const label nProcs, const bool haveThreads) +void Foam::UPstream::setParRun(const int nProcs, const bool haveThreads) { parRun_ = (nProcs > 0); haveThreads_ = haveThreads; @@ -725,7 +725,7 @@ void Foam::UPstream::printCommTree } -bool Foam::UPstream::usingNodeComms(const label communicator) +bool Foam::UPstream::usingNodeComms(const int communicator) { // Starting point must be "real" world-communicator // ("real" means without any local trickery with worldComm) @@ -849,10 +849,10 @@ Foam::DynamicList Foam::UPstream::treeCommunication_(16); -Foam::label Foam::UPstream::constWorldComm_(0); -Foam::label Foam::UPstream::numNodes_(1); -Foam::label Foam::UPstream::commInterNode_(-1); -Foam::label Foam::UPstream::commLocalNode_(-1); +int Foam::UPstream::constWorldComm_(0); +int Foam::UPstream::commInterNode_(-1); +int Foam::UPstream::commLocalNode_(-1); +int Foam::UPstream::numNodes_(1); Foam::label Foam::UPstream::worldComm(0); // Initially same as constWorldComm_ Foam::label Foam::UPstream::warnComm(-1); @@ -860,7 +860,7 @@ Foam::label Foam::UPstream::warnComm(-1); // Predefine world and self communicator slots. // These are overwritten in parallel mode (by UPstream::setParRun()) -const Foam::label nPredefinedComm = []() +const int nPredefinedComm = []() { // 0: COMM_WORLD : commGlobal(), constWorldComm_, worldComm (void) Foam::UPstream::newCommunicator(-1, Foam::labelRange(1), false); @@ -894,7 +894,6 @@ registerOptSwitch Foam::UPstream::nodeCommsMin_ ); - int Foam::UPstream::topologyControl_ ( Foam::debug::optimisationSwitch("topoControl", 0) diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H b/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H index a18d46128e..3ce948183f 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H @@ -389,18 +389,18 @@ private: //- Index to the world-communicator as defined at startup //- (after any multi-world definitions). //- Is unaffected by any later changes to worldComm. - static label constWorldComm_; - - //- The number of shared/host nodes in the (const) world communicator. - static label numNodes_; + static int constWorldComm_; //- Index to the inter-node communicator (between nodes), //- defined based on constWorldComm_ - static label commInterNode_; + static int commInterNode_; //- Index to the intra-host communicator (within a node), //- defined based on constWorldComm_ - static label commLocalNode_; + static int commLocalNode_; + + //- The number of shared/host nodes in the (const) world communicator. + static int numNodes_; //- Names of all worlds static wordList allWorlds_; @@ -433,7 +433,7 @@ private: // Private Member Functions //- Set data for parallel running - static void setParRun(const label nProcs, const bool haveThreads); + static void setParRun(const int nProcs, const bool haveThreads); //- Initialise entries for new communicator. // @@ -557,16 +557,16 @@ public: //- Communicator for all ranks, irrespective of any local worlds. // This value \em never changes during a simulation. - static constexpr label commGlobal() noexcept { return 0; } + static constexpr int commGlobal() noexcept { return 0; } //- Communicator within the current rank only // This value \em never changes during a simulation. - static constexpr label commSelf() noexcept { return 1; } + static constexpr int commSelf() noexcept { return 1; } //- Communicator for all ranks (respecting any local worlds). // This value \em never changes after startup. Unlike the commWorld() // which can be temporarily overriden. - static label commConstWorld() noexcept { return constWorldComm_; } + static int commConstWorld() noexcept { return constWorldComm_; } //- Communicator for all ranks (respecting any local worlds) static label commWorld() noexcept { return worldComm; } @@ -601,13 +601,13 @@ public: // Host Communicators //- Communicator between nodes/hosts (respects any local worlds) - static label commInterNode() noexcept + static int commInterNode() noexcept { return (parRun_ ? commInterNode_ : constWorldComm_); } //- Communicator within the node/host (respects any local worlds) - static label commLocalNode() noexcept + static int commLocalNode() noexcept { return (parRun_ ? commLocalNode_ : constWorldComm_); } @@ -626,7 +626,7 @@ public: //- it is running in parallel, the starting point is the //- world-communicator and it is not an odd corner case //- (ie, all processes on one node, all processes on different nodes) - static bool usingNodeComms(const label communicator = worldComm); + static bool usingNodeComms(const int communicator); // Constructors @@ -1168,19 +1168,16 @@ public: } //- The number of shared/host nodes in the (const) world communicator. - static label numNodes() noexcept - { - return numNodes_; - } + static int numNodes() noexcept { return numNodes_; } //- The parent communicator - static label parent(const label communicator) + static label parent(int communicator) { return parentComm_(communicator); } //- The list of ranks within a given communicator - static List& procID(const label communicator) + static List& procID(int communicator) { return procIDs_[communicator]; } @@ -1694,7 +1691,7 @@ public: // UPstream::Communicator::lookup(UPstream::commWorld()) // ) // \endcode - static Communicator lookup(const label comm); + static Communicator lookup(const int comm); // Member Functions @@ -1713,6 +1710,9 @@ public: //- Reset to default constructed value (MPI_COMM_NULL) void reset() noexcept; + + //- The number of ranks associated with the communicator + int size() const; }; diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UPstreamWindow.H b/src/OpenFOAM/db/IOstreams/Pstreams/UPstreamWindow.H index aa3ef233f8..54ce90aecc 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/UPstreamWindow.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/UPstreamWindow.H @@ -137,6 +137,11 @@ public: //- Reset to default constructed value (MPI_WIN_NULL) void reset() noexcept; + + //- The number of ranks associated with the window group. + // The same as querying the original communicator, assuming the + // communicator is available within the current code scope. + int size() const; }; diff --git a/src/Pstream/dummy/UIPstreamRead.C b/src/Pstream/dummy/UIPstreamRead.C index c8b7286fdf..7c82adb7f3 100644 --- a/src/Pstream/dummy/UIPstreamRead.C +++ b/src/Pstream/dummy/UIPstreamRead.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2021-2024 OpenCFD Ltd. + Copyright (C) 2021-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -45,7 +45,7 @@ std::streamsize Foam::UIPstream::read char* buf, const std::streamsize bufSize, const int tag, - const label communicator, + const int communicator, UPstream::Request* req ) { diff --git a/src/Pstream/dummy/UOPstreamWrite.C b/src/Pstream/dummy/UOPstreamWrite.C index 24078ca924..dfd4be78af 100644 --- a/src/Pstream/dummy/UOPstreamWrite.C +++ b/src/Pstream/dummy/UOPstreamWrite.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2015 OpenFOAM Foundation - Copyright (C) 2022-2023 OpenCFD Ltd. + Copyright (C) 2022-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -46,7 +46,7 @@ bool Foam::UOPstream::write const char* buf, const std::streamsize bufSize, const int tag, - const label communicator, + const int communicator, UPstream::Request* req, const UPstream::sendModes sendMode ) diff --git a/src/Pstream/dummy/UPstreamCommunicator.C b/src/Pstream/dummy/UPstreamCommunicator.C index e7c713f85c..29055a6da2 100644 --- a/src/Pstream/dummy/UPstreamCommunicator.C +++ b/src/Pstream/dummy/UPstreamCommunicator.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2024 OpenCFD Ltd. + Copyright (C) 2024-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -38,7 +38,7 @@ Foam::UPstream::Communicator::Communicator() noexcept // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // Foam::UPstream::Communicator -Foam::UPstream::Communicator::lookup(const label comm) +Foam::UPstream::Communicator::lookup(const int comm) { return UPstream::Communicator(nullptr); } @@ -56,4 +56,10 @@ void Foam::UPstream::Communicator::reset() noexcept {} +int Foam::UPstream::Communicator::size() const +{ + return 0; +} + + // ************************************************************************* // diff --git a/src/Pstream/dummy/UPstreamWindow.C b/src/Pstream/dummy/UPstreamWindow.C index 4c8e5b7906..9af10b6e91 100644 --- a/src/Pstream/dummy/UPstreamWindow.C +++ b/src/Pstream/dummy/UPstreamWindow.C @@ -47,4 +47,10 @@ void Foam::UPstream::Window::reset() noexcept {} +int Foam::UPstream::Window::size() const +{ + return 0; +} + + // ************************************************************************* // diff --git a/src/Pstream/mpi/UIPstreamRead.C b/src/Pstream/mpi/UIPstreamRead.C index 4f94257e71..4f5fe7e2a7 100644 --- a/src/Pstream/mpi/UIPstreamRead.C +++ b/src/Pstream/mpi/UIPstreamRead.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2019-2024 OpenCFD Ltd. + Copyright (C) 2019-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -47,7 +47,7 @@ static std::streamsize UPstream_mpi_receive const std::streamsize bufSize, const int fromProcNo, const int tag, - const Foam::label communicator, + const int communicator, Foam::UPstream::Request* req ) { @@ -344,7 +344,7 @@ std::streamsize Foam::UIPstream::read char* buf, const std::streamsize bufSize, const int tag, - const label communicator, + const int communicator, UPstream::Request* req ) { diff --git a/src/Pstream/mpi/UOPstreamWrite.C b/src/Pstream/mpi/UOPstreamWrite.C index d2e1da2ec6..8ebb237546 100644 --- a/src/Pstream/mpi/UOPstreamWrite.C +++ b/src/Pstream/mpi/UOPstreamWrite.C @@ -6,7 +6,7 @@ \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2017 OpenFOAM Foundation - Copyright (C) 2019-2023 OpenCFD Ltd. + Copyright (C) 2019-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -55,7 +55,7 @@ bool Foam::UOPstream::write const char* buf, const std::streamsize bufSize, const int tag, - const label communicator, + const int communicator, UPstream::Request* req, const UPstream::sendModes sendMode ) diff --git a/src/Pstream/mpi/UPstreamCommunicator.C b/src/Pstream/mpi/UPstreamCommunicator.C index 9040f2f0dc..adff0a7ea3 100644 --- a/src/Pstream/mpi/UPstreamCommunicator.C +++ b/src/Pstream/mpi/UPstreamCommunicator.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2024 OpenCFD Ltd. + Copyright (C) 2024-2025 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -39,7 +39,7 @@ Foam::UPstream::Communicator::Communicator() noexcept // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // Foam::UPstream::Communicator -Foam::UPstream::Communicator::lookup(const label comm) +Foam::UPstream::Communicator::lookup(const int comm) { if (comm < 0 || comm >= PstreamGlobals::MPICommunicators_.size()) { @@ -70,4 +70,27 @@ void Foam::UPstream::Communicator::reset() noexcept } +int Foam::UPstream::Communicator::size() const +{ + int val = 0; + + MPI_Comm comm = PstreamUtils::Cast::to_mpi(*this); + + if (MPI_COMM_SELF == comm) + { + return 1; + } + else if + ( + (MPI_COMM_NULL == comm) + || (MPI_SUCCESS != MPI_Comm_size(comm, &val)) + ) + { + val = 0; + } + + return val; +} + + // ************************************************************************* // diff --git a/src/Pstream/mpi/UPstreamWindow.C b/src/Pstream/mpi/UPstreamWindow.C index 8bcce43014..0657c86096 100644 --- a/src/Pstream/mpi/UPstreamWindow.C +++ b/src/Pstream/mpi/UPstreamWindow.C @@ -50,4 +50,29 @@ void Foam::UPstream::Window::reset() noexcept } +int Foam::UPstream::Window::size() const +{ + int val = 0; + + MPI_Win win = PstreamUtils::Cast::to_mpi(*this); + MPI_Group group; + + // Get num of ranks from the group information + if + ( + (MPI_WIN_NULL != win) + && (MPI_SUCCESS == MPI_Win_get_group(win, &group)) + ) + { + if (MPI_SUCCESS != MPI_Group_size(group, &val)) + { + val = 0; + } + MPI_Group_free(&group); + } + + return val; +} + + // ************************************************************************* //