STYLE: more consistency in communicator types (int vs label)

This commit is contained in:
Mark Olesen
2025-02-26 11:50:14 +01:00
parent d4b5280742
commit 8c395357f3
23 changed files with 181 additions and 132 deletions

View File

@ -508,7 +508,7 @@ int main(int argc, char *argv[])
#include "setRootCase.H" #include "setRootCase.H"
const bool useLocalComms = UPstream::usingNodeComms(); const bool useLocalComms = UPstream::usingNodeComms(UPstream::worldComm);
bool useWindow = args.found("window"); bool useWindow = args.found("window");
bool useBuiltin = args.found("builtin"); bool useBuiltin = args.found("builtin");

View File

@ -61,14 +61,13 @@ public:
// Constructors // Constructors
//- Construct given process index to read from //- Construct given process index to read from
//- and optional buffer size, read format
IPstream IPstream
( (
const UPstream::commsTypes commsType, const UPstream::commsTypes commsType,
const int fromProcNo, const int fromProcNo,
const label bufSize = 0, const int bufferSize = 0, //!< optional buffer size
const int tag = UPstream::msgType(), const int tag = UPstream::msgType(),
const label comm = UPstream::worldComm, const int communicator = UPstream::worldComm,
IOstreamOption::streamFormat fmt = IOstreamOption::BINARY IOstreamOption::streamFormat fmt = IOstreamOption::BINARY
); );
@ -83,7 +82,7 @@ public:
Type& value, Type& value,
const int fromProcNo, const int fromProcNo,
const int tag = UPstream::msgType(), const int tag = UPstream::msgType(),
const label comm = UPstream::worldComm, const int communicator = UPstream::worldComm,
IOstreamOption::streamFormat fmt = IOstreamOption::BINARY IOstreamOption::streamFormat fmt = IOstreamOption::BINARY
) )
{ {
@ -91,9 +90,9 @@ public:
( (
UPstream::commsTypes::scheduled, // ie, MPI_Recv() UPstream::commsTypes::scheduled, // ie, MPI_Recv()
fromProcNo, fromProcNo,
0, // bufSize 0, // bufferSize
tag, tag,
comm, communicator,
fmt fmt
); );
is >> value; is >> value;

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2022-2023 OpenCFD Ltd. Copyright (C) 2022-2025 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -38,7 +38,7 @@ Foam::UIPstream::UIPstream
DynamicList<char>& receiveBuf, DynamicList<char>& receiveBuf,
label& receiveBufPosition, label& receiveBufPosition,
const int tag, const int tag,
const label comm, const int communicator,
const bool clearAtEnd, const bool clearAtEnd,
IOstreamOption::streamFormat fmt IOstreamOption::streamFormat fmt
) )
@ -50,7 +50,7 @@ Foam::UIPstream::UIPstream
receiveBuf, receiveBuf,
receiveBufPosition, receiveBufPosition,
tag, tag,
comm, communicator,
clearAtEnd, clearAtEnd,
fmt fmt
) )
@ -105,13 +105,13 @@ Foam::IPstream::IPstream
( (
const UPstream::commsTypes commsType, const UPstream::commsTypes commsType,
const int fromProcNo, const int fromProcNo,
const label bufSize, const int bufferSize,
const int tag, const int tag,
const label comm, const int communicator,
IOstreamOption::streamFormat fmt IOstreamOption::streamFormat fmt
) )
: :
Pstream(commsType, bufSize), Pstream(commsType, bufferSize),
UIPstream UIPstream
( (
commsType, commsType,
@ -119,7 +119,7 @@ Foam::IPstream::IPstream
Pstream::transferBuf_, Pstream::transferBuf_,
UIPstreamBase::storedRecvBufPos_, // Internal only UIPstreamBase::storedRecvBufPos_, // Internal only
tag, tag,
comm, communicator,
false, // Do not clear Pstream::transferBuf_ if at end false, // Do not clear Pstream::transferBuf_ if at end
fmt fmt
) )

View File

@ -61,14 +61,13 @@ public:
// Constructors // Constructors
//- Construct for given process index to send to //- Construct for given process index to send to
//- and optional buffer size, write format
OPstream OPstream
( (
const UPstream::commsTypes commsType, const UPstream::commsTypes commsType,
const int toProcNo, const int toProcNo,
const label bufSize = 0, const int bufferSize = 0, //!< optional buffer size
const int tag = UPstream::msgType(), const int tag = UPstream::msgType(),
const label comm = UPstream::worldComm, const int communicator = UPstream::worldComm,
IOstreamOption::streamFormat fmt = IOstreamOption::BINARY IOstreamOption::streamFormat fmt = IOstreamOption::BINARY
); );
@ -81,15 +80,15 @@ public:
static void send static void send
( (
const Type& value, const Type& value,
//! blocking or scheduled only! //! buffered or scheduled only!
const UPstream::commsTypes commsType, const UPstream::commsTypes commsType,
const int toProcNo, const int toProcNo,
const int tag = UPstream::msgType(), const int tag = UPstream::msgType(),
const label comm = UPstream::worldComm, const int communicator = UPstream::worldComm,
IOstreamOption::streamFormat fmt = IOstreamOption::BINARY IOstreamOption::streamFormat fmt = IOstreamOption::BINARY
) )
{ {
OPstream os(commsType, toProcNo, 0, tag, comm, fmt); OPstream os(commsType, toProcNo, 0, tag, communicator, fmt);
os << value; os << value;
} }
@ -101,7 +100,7 @@ public:
const Type& value, const Type& value,
const int toProcNo, const int toProcNo,
const int tag = UPstream::msgType(), const int tag = UPstream::msgType(),
const label comm = UPstream::worldComm, const int communicator = UPstream::worldComm,
IOstreamOption::streamFormat fmt = IOstreamOption::BINARY IOstreamOption::streamFormat fmt = IOstreamOption::BINARY
) )
{ {
@ -111,7 +110,7 @@ public:
UPstream::commsTypes::scheduled, // ie, MPI_Send() UPstream::commsTypes::scheduled, // ie, MPI_Send()
toProcNo, toProcNo,
tag, tag,
comm, communicator,
fmt fmt
); );
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2022-2024 OpenCFD Ltd. Copyright (C) 2022-2025 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -37,7 +37,7 @@ Foam::UOPstream::UOPstream
const int toProcNo, const int toProcNo,
DynamicList<char>& sendBuf, DynamicList<char>& sendBuf,
const int tag, const int tag,
const label comm, const int comm,
const bool sendAtDestruct, const bool sendAtDestruct,
IOstreamOption::streamFormat fmt IOstreamOption::streamFormat fmt
) )
@ -66,20 +66,20 @@ Foam::OPstream::OPstream
( (
const UPstream::commsTypes commsType, const UPstream::commsTypes commsType,
const int toProcNo, const int toProcNo,
const label bufSize, const int bufferSize,
const int tag, const int tag,
const label comm, const int communicator,
IOstreamOption::streamFormat fmt IOstreamOption::streamFormat fmt
) )
: :
Pstream(commsType, bufSize), Pstream(commsType, bufferSize),
UOPstream UOPstream
( (
commsType, commsType,
toProcNo, toProcNo,
Pstream::transferBuf_, Pstream::transferBuf_,
tag, tag,
comm, communicator,
true, // sendAtDestruct true, // sendAtDestruct
fmt fmt
) )

View File

@ -75,18 +75,20 @@ public:
// Constructors // Constructors
//- Construct for given communication type, with optional buffer size //- Construct for communication type with empty buffer
explicit Pstream explicit Pstream(const UPstream::commsTypes commsType) noexcept
( :
const UPstream::commsTypes commsType, UPstream(commsType)
const label bufSize = 0 {}
)
//- Construct for communication type with given buffer size
Pstream(const UPstream::commsTypes commsType, int bufferSize)
: :
UPstream(commsType) UPstream(commsType)
{ {
if (bufSize > 0) if (bufferSize > 0)
{ {
transferBuf_.setCapacity(bufSize + 2*sizeof(scalar) + 1); transferBuf_.setCapacity(bufferSize + 2*sizeof(scalar) + 1);
} }
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2021-2023 OpenCFD Ltd. Copyright (C) 2021-2025 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -300,7 +300,7 @@ Foam::PstreamBuffers::PstreamBuffers
( (
UPstream::commsTypes commsType, UPstream::commsTypes commsType,
int tag, int tag,
label communicator, int communicator,
IOstreamOption::streamFormat fmt IOstreamOption::streamFormat fmt
) )
: :
@ -313,7 +313,7 @@ Foam::PstreamBuffers::PstreamBuffers
nProcs_(UPstream::nProcs(comm_)), nProcs_(UPstream::nProcs(comm_)),
sendBuffers_(nProcs_), sendBuffers_(nProcs_),
recvBuffers_(nProcs_), recvBuffers_(nProcs_),
recvPositions_(nProcs_, Zero) recvPositions_(nProcs_, Foam::zero{})
{ {
DebugPoutInFunction DebugPoutInFunction
<< "tag:" << tag_ << "tag:" << tag_

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2021-2023 OpenCFD Ltd. Copyright (C) 2021-2025 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -182,10 +182,10 @@ class PstreamBuffers
const int tag_; const int tag_;
//- Communicator //- Communicator
const label comm_; const int comm_;
//- Number of ranks associated with PstreamBuffers (at construction) //- Number of ranks associated with PstreamBuffers (at construction)
const label nProcs_; const int nProcs_;
// Buffer storage // Buffer storage
@ -266,7 +266,7 @@ public:
( (
UPstream::commsTypes commsType = UPstream::commsTypes::nonBlocking, UPstream::commsTypes commsType = UPstream::commsTypes::nonBlocking,
int tag = UPstream::msgType(), int tag = UPstream::msgType(),
label communicator = UPstream::worldComm, int communicator = UPstream::worldComm,
IOstreamOption::streamFormat fmt = IOstreamOption::BINARY IOstreamOption::streamFormat fmt = IOstreamOption::BINARY
); );
@ -274,7 +274,7 @@ public:
//- (default: nonBlocking), message tag, IO format (default: binary) //- (default: nonBlocking), message tag, IO format (default: binary)
explicit PstreamBuffers explicit PstreamBuffers
( (
label communicator, int communicator,
UPstream::commsTypes commsType = UPstream::commsTypes::nonBlocking, UPstream::commsTypes commsType = UPstream::commsTypes::nonBlocking,
int tag = UPstream::msgType(), int tag = UPstream::msgType(),
IOstreamOption::streamFormat fmt = IOstreamOption::BINARY IOstreamOption::streamFormat fmt = IOstreamOption::BINARY
@ -287,7 +287,7 @@ public:
//- (default: nonBlocking), IO format (default: binary) //- (default: nonBlocking), IO format (default: binary)
PstreamBuffers PstreamBuffers
( (
label communicator, int communicator,
int tag, int tag,
UPstream::commsTypes commsType = UPstream::commsTypes::nonBlocking, UPstream::commsTypes commsType = UPstream::commsTypes::nonBlocking,
IOstreamOption::streamFormat fmt = IOstreamOption::BINARY IOstreamOption::streamFormat fmt = IOstreamOption::BINARY
@ -306,34 +306,19 @@ public:
// Attributes // Attributes
//- The associated buffer format (ascii | binary) //- The associated buffer format (ascii | binary)
IOstreamOption::streamFormat format() const noexcept IOstreamOption::streamFormat format() const noexcept { return format_; }
{
return format_;
}
//- The communications type of the stream //- The communications type of the stream
UPstream::commsTypes commsType() const noexcept UPstream::commsTypes commsType() const noexcept { return commsType_; }
{
return commsType_;
}
//- The transfer message tag //- The transfer message tag
int tag() const noexcept int tag() const noexcept { return tag_; }
{
return tag_;
}
//- The communicator index //- The communicator index
label comm() const noexcept int comm() const noexcept { return comm_; }
{
return comm_;
}
//- Number of ranks associated with PstreamBuffers //- Number of ranks associated with PstreamBuffers
label nProcs() const noexcept int nProcs() const noexcept { return nProcs_; }
{
return nProcs_;
}
// Sizing // Sizing

View File

@ -124,7 +124,7 @@ protected:
DynamicList<char>& receiveBuf, DynamicList<char>& receiveBuf,
label& receiveBufPosition, label& receiveBufPosition,
const int tag = UPstream::msgType(), const int tag = UPstream::msgType(),
const label comm = UPstream::worldComm, const int communicator = UPstream::worldComm,
const bool clearAtEnd = false, // destroy receiveBuf if at end const bool clearAtEnd = false, // destroy receiveBuf if at end
IOstreamOption::streamFormat fmt = IOstreamOption::BINARY IOstreamOption::streamFormat fmt = IOstreamOption::BINARY
); );
@ -252,7 +252,7 @@ public:
DynamicList<char>& receiveBuf, DynamicList<char>& receiveBuf,
label& receiveBufPosition, label& receiveBufPosition,
const int tag = UPstream::msgType(), const int tag = UPstream::msgType(),
const label comm = UPstream::worldComm, const int communicator = UPstream::worldComm,
const bool clearAtEnd = false, // destroy receiveBuf if at end const bool clearAtEnd = false, // destroy receiveBuf if at end
IOstreamOption::streamFormat fmt = IOstreamOption::BINARY IOstreamOption::streamFormat fmt = IOstreamOption::BINARY
); );
@ -292,7 +292,7 @@ public:
char* buf, char* buf,
const std::streamsize bufSize, const std::streamsize bufSize,
const int tag = UPstream::msgType(), const int tag = UPstream::msgType(),
const label comm = UPstream::worldComm, const int communicator = UPstream::worldComm,
//! [out] request information (for non-blocking) //! [out] request information (for non-blocking)
UPstream::Request* req = nullptr UPstream::Request* req = nullptr
); );
@ -307,7 +307,7 @@ public:
char* buf, char* buf,
const std::streamsize bufSize, const std::streamsize bufSize,
const int tag = UPstream::msgType(), const int tag = UPstream::msgType(),
const label comm = UPstream::worldComm const int communicator = UPstream::worldComm
) )
{ {
return UIPstream::read return UIPstream::read
@ -317,7 +317,7 @@ public:
buf, buf,
bufSize, bufSize,
tag, tag,
comm, communicator,
&req &req
); );
} }
@ -332,7 +332,7 @@ public:
const int fromProcNo, const int fromProcNo,
UList<Type>& buffer, UList<Type>& buffer,
const int tag = UPstream::msgType(), const int tag = UPstream::msgType(),
const label comm = UPstream::worldComm, const int communicator = UPstream::worldComm,
//! [out] request information (for non-blocking) //! [out] request information (for non-blocking)
UPstream::Request* req = nullptr UPstream::Request* req = nullptr
) )
@ -344,7 +344,7 @@ public:
buffer.data_bytes(), buffer.data_bytes(),
buffer.size_bytes(), buffer.size_bytes(),
tag, tag,
comm, communicator,
req req
); );
} }
@ -359,7 +359,7 @@ public:
const int fromProcNo, const int fromProcNo,
SubList<Type> buffer, // passed by shallow copy SubList<Type> buffer, // passed by shallow copy
const int tag = UPstream::msgType(), const int tag = UPstream::msgType(),
const label comm = UPstream::worldComm, const int communicator = UPstream::worldComm,
//! [out] request information (for non-blocking) //! [out] request information (for non-blocking)
UPstream::Request* req = nullptr UPstream::Request* req = nullptr
) )
@ -371,7 +371,7 @@ public:
buffer.data_bytes(), buffer.data_bytes(),
buffer.size_bytes(), buffer.size_bytes(),
tag, tag,
comm, communicator,
req req
); );
} }
@ -387,7 +387,7 @@ public:
const int fromProcNo, const int fromProcNo,
UList<Type>& buffer, UList<Type>& buffer,
const int tag = UPstream::msgType(), const int tag = UPstream::msgType(),
const label comm = UPstream::worldComm const int communicator = UPstream::worldComm
) )
{ {
return UIPstream::read return UIPstream::read
@ -397,7 +397,7 @@ public:
buffer.data_bytes(), buffer.data_bytes(),
buffer.size_bytes(), buffer.size_bytes(),
tag, tag,
comm, communicator,
&req &req
); );
} }
@ -413,7 +413,7 @@ public:
const int fromProcNo, const int fromProcNo,
SubList<Type> buffer, // passed by shallow copy SubList<Type> buffer, // passed by shallow copy
const int tag = UPstream::msgType(), const int tag = UPstream::msgType(),
const label comm = UPstream::worldComm const int communicator = UPstream::worldComm
) )
{ {
return UIPstream::read return UIPstream::read
@ -423,7 +423,7 @@ public:
buffer.data_bytes(), buffer.data_bytes(),
buffer.size_bytes(), buffer.size_bytes(),
tag, tag,
comm, communicator,
&req &req
); );
} }

View File

@ -167,7 +167,7 @@ Foam::UIPstreamBase::UIPstreamBase
DynamicList<char>& receiveBuf, DynamicList<char>& receiveBuf,
label& receiveBufPosition, label& receiveBufPosition,
const int tag, const int tag,
const label comm, const int communicator,
const bool clearAtEnd, const bool clearAtEnd,
IOstreamOption::streamFormat fmt IOstreamOption::streamFormat fmt
) )
@ -176,7 +176,7 @@ Foam::UIPstreamBase::UIPstreamBase
Istream(fmt), Istream(fmt),
fromProcNo_(fromProcNo), fromProcNo_(fromProcNo),
tag_(tag), tag_(tag),
comm_(comm), comm_(communicator),
messageSize_(0), messageSize_(0),
storedRecvBufPos_(0), storedRecvBufPos_(0),
clearAtEnd_(clearAtEnd), clearAtEnd_(clearAtEnd),

View File

@ -121,7 +121,7 @@ protected:
const int toProcNo, const int toProcNo,
DynamicList<char>& sendBuf, DynamicList<char>& sendBuf,
const int tag = UPstream::msgType(), const int tag = UPstream::msgType(),
const label comm = UPstream::worldComm, const int communicator = UPstream::worldComm,
const bool sendAtDestruct = true, const bool sendAtDestruct = true,
IOstreamOption::streamFormat fmt = IOstreamOption::BINARY IOstreamOption::streamFormat fmt = IOstreamOption::BINARY
); );
@ -325,7 +325,7 @@ public:
const int toProcNo, const int toProcNo,
DynamicList<char>& sendBuf, DynamicList<char>& sendBuf,
const int tag = UPstream::msgType(), const int tag = UPstream::msgType(),
const label comm = UPstream::worldComm, const int communicator = UPstream::worldComm,
const bool sendAtDestruct = true, const bool sendAtDestruct = true,
IOstreamOption::streamFormat fmt = IOstreamOption::BINARY IOstreamOption::streamFormat fmt = IOstreamOption::BINARY
); );
@ -367,7 +367,7 @@ public:
const char* buf, const char* buf,
const std::streamsize bufSize, const std::streamsize bufSize,
const int tag = UPstream::msgType(), const int tag = UPstream::msgType(),
const label comm = UPstream::worldComm, const int communicator = UPstream::worldComm,
//! [out] request information (for non-blocking) //! [out] request information (for non-blocking)
UPstream::Request* req = nullptr, UPstream::Request* req = nullptr,
const UPstream::sendModes sendMode = UPstream::sendModes::normal const UPstream::sendModes sendMode = UPstream::sendModes::normal
@ -383,7 +383,7 @@ public:
const char* buf, const char* buf,
const std::streamsize bufSize, const std::streamsize bufSize,
const int tag = UPstream::msgType(), const int tag = UPstream::msgType(),
const label comm = UPstream::worldComm, const int communicator = UPstream::worldComm,
const UPstream::sendModes sendMode = UPstream::sendModes::normal const UPstream::sendModes sendMode = UPstream::sendModes::normal
) )
{ {
@ -394,7 +394,7 @@ public:
buf, buf,
bufSize, bufSize,
tag, tag,
comm, communicator,
&req, &req,
sendMode sendMode
); );
@ -410,7 +410,7 @@ public:
const int toProcNo, const int toProcNo,
const UList<Type>& buffer, const UList<Type>& buffer,
const int tag = UPstream::msgType(), const int tag = UPstream::msgType(),
const label comm = UPstream::worldComm, const int communicator = UPstream::worldComm,
//! [out] request information (for non-blocking) //! [out] request information (for non-blocking)
UPstream::Request* req = nullptr, UPstream::Request* req = nullptr,
const UPstream::sendModes sendMode = UPstream::sendModes::normal const UPstream::sendModes sendMode = UPstream::sendModes::normal
@ -423,7 +423,7 @@ public:
buffer.cdata_bytes(), buffer.cdata_bytes(),
buffer.size_bytes(), buffer.size_bytes(),
tag, tag,
comm, communicator,
req, req,
sendMode sendMode
); );
@ -440,7 +440,7 @@ public:
const int toProcNo, const int toProcNo,
const UList<Type>& buffer, const UList<Type>& buffer,
const int tag = UPstream::msgType(), const int tag = UPstream::msgType(),
const label comm = UPstream::worldComm, const int communicator = UPstream::worldComm,
const UPstream::sendModes sendMode = UPstream::sendModes::normal const UPstream::sendModes sendMode = UPstream::sendModes::normal
) )
{ {
@ -451,7 +451,7 @@ public:
buffer.cdata_bytes(), buffer.cdata_bytes(),
buffer.size_bytes(), buffer.size_bytes(),
tag, tag,
comm, communicator,
&req, &req,
sendMode sendMode
); );

View File

@ -146,7 +146,7 @@ Foam::UOPstreamBase::UOPstreamBase
const int toProcNo, const int toProcNo,
DynamicList<char>& sendBuf, DynamicList<char>& sendBuf,
const int tag, const int tag,
const label comm, const int communicator,
const bool sendAtDestruct, const bool sendAtDestruct,
IOstreamOption::streamFormat fmt IOstreamOption::streamFormat fmt
) )
@ -155,7 +155,7 @@ Foam::UOPstreamBase::UOPstreamBase
Ostream(fmt), Ostream(fmt),
toProcNo_(toProcNo), toProcNo_(toProcNo),
tag_(tag), tag_(tag),
comm_(comm), comm_(communicator),
sendAtDestruct_(sendAtDestruct), sendAtDestruct_(sendAtDestruct),
sendBuf_(sendBuf) sendBuf_(sendBuf)
{ {

View File

@ -112,7 +112,7 @@ void Foam::UPstream::printTopoControl(Ostream& os)
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * 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); parRun_ = (nProcs > 0);
haveThreads_ = haveThreads; 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 // Starting point must be "real" world-communicator
// ("real" means without any local trickery with worldComm) // ("real" means without any local trickery with worldComm)
@ -849,10 +849,10 @@ Foam::DynamicList<Foam::UPstream::commsStructList>
Foam::UPstream::treeCommunication_(16); Foam::UPstream::treeCommunication_(16);
Foam::label Foam::UPstream::constWorldComm_(0); int Foam::UPstream::constWorldComm_(0);
Foam::label Foam::UPstream::numNodes_(1); int Foam::UPstream::commInterNode_(-1);
Foam::label Foam::UPstream::commInterNode_(-1); int Foam::UPstream::commLocalNode_(-1);
Foam::label Foam::UPstream::commLocalNode_(-1); int Foam::UPstream::numNodes_(1);
Foam::label Foam::UPstream::worldComm(0); // Initially same as constWorldComm_ Foam::label Foam::UPstream::worldComm(0); // Initially same as constWorldComm_
Foam::label Foam::UPstream::warnComm(-1); Foam::label Foam::UPstream::warnComm(-1);
@ -860,7 +860,7 @@ Foam::label Foam::UPstream::warnComm(-1);
// Predefine world and self communicator slots. // Predefine world and self communicator slots.
// These are overwritten in parallel mode (by UPstream::setParRun()) // These are overwritten in parallel mode (by UPstream::setParRun())
const Foam::label nPredefinedComm = []() const int nPredefinedComm = []()
{ {
// 0: COMM_WORLD : commGlobal(), constWorldComm_, worldComm // 0: COMM_WORLD : commGlobal(), constWorldComm_, worldComm
(void) Foam::UPstream::newCommunicator(-1, Foam::labelRange(1), false); (void) Foam::UPstream::newCommunicator(-1, Foam::labelRange(1), false);
@ -894,7 +894,6 @@ registerOptSwitch
Foam::UPstream::nodeCommsMin_ Foam::UPstream::nodeCommsMin_
); );
int Foam::UPstream::topologyControl_ int Foam::UPstream::topologyControl_
( (
Foam::debug::optimisationSwitch("topoControl", 0) Foam::debug::optimisationSwitch("topoControl", 0)

View File

@ -389,18 +389,18 @@ private:
//- Index to the world-communicator as defined at startup //- Index to the world-communicator as defined at startup
//- (after any multi-world definitions). //- (after any multi-world definitions).
//- Is unaffected by any later changes to worldComm. //- Is unaffected by any later changes to worldComm.
static label constWorldComm_; static int constWorldComm_;
//- The number of shared/host nodes in the (const) world communicator.
static label numNodes_;
//- Index to the inter-node communicator (between nodes), //- Index to the inter-node communicator (between nodes),
//- defined based on constWorldComm_ //- defined based on constWorldComm_
static label commInterNode_; static int commInterNode_;
//- Index to the intra-host communicator (within a node), //- Index to the intra-host communicator (within a node),
//- defined based on constWorldComm_ //- 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 //- Names of all worlds
static wordList allWorlds_; static wordList allWorlds_;
@ -433,7 +433,7 @@ private:
// Private Member Functions // Private Member Functions
//- Set data for parallel running //- 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. //- Initialise entries for new communicator.
// //
@ -557,16 +557,16 @@ public:
//- Communicator for all ranks, irrespective of any local worlds. //- Communicator for all ranks, irrespective of any local worlds.
// This value \em never changes during a simulation. // 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 //- Communicator within the current rank only
// This value \em never changes during a simulation. // 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). //- Communicator for all ranks (respecting any local worlds).
// This value \em never changes after startup. Unlike the commWorld() // This value \em never changes after startup. Unlike the commWorld()
// which can be temporarily overriden. // 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) //- Communicator for all ranks (respecting any local worlds)
static label commWorld() noexcept { return worldComm; } static label commWorld() noexcept { return worldComm; }
@ -601,13 +601,13 @@ public:
// Host Communicators // Host Communicators
//- Communicator between nodes/hosts (respects any local worlds) //- Communicator between nodes/hosts (respects any local worlds)
static label commInterNode() noexcept static int commInterNode() noexcept
{ {
return (parRun_ ? commInterNode_ : constWorldComm_); return (parRun_ ? commInterNode_ : constWorldComm_);
} }
//- Communicator within the node/host (respects any local worlds) //- Communicator within the node/host (respects any local worlds)
static label commLocalNode() noexcept static int commLocalNode() noexcept
{ {
return (parRun_ ? commLocalNode_ : constWorldComm_); return (parRun_ ? commLocalNode_ : constWorldComm_);
} }
@ -626,7 +626,7 @@ public:
//- it is running in parallel, the starting point is the //- it is running in parallel, the starting point is the
//- world-communicator and it is not an odd corner case //- world-communicator and it is not an odd corner case
//- (ie, all processes on one node, all processes on different nodes) //- (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 // Constructors
@ -1168,19 +1168,16 @@ public:
} }
//- The number of shared/host nodes in the (const) world communicator. //- The number of shared/host nodes in the (const) world communicator.
static label numNodes() noexcept static int numNodes() noexcept { return numNodes_; }
{
return numNodes_;
}
//- The parent communicator //- The parent communicator
static label parent(const label communicator) static label parent(int communicator)
{ {
return parentComm_(communicator); return parentComm_(communicator);
} }
//- The list of ranks within a given communicator //- The list of ranks within a given communicator
static List<int>& procID(const label communicator) static List<int>& procID(int communicator)
{ {
return procIDs_[communicator]; return procIDs_[communicator];
} }
@ -1694,7 +1691,7 @@ public:
// UPstream::Communicator::lookup(UPstream::commWorld()) // UPstream::Communicator::lookup(UPstream::commWorld())
// ) // )
// \endcode // \endcode
static Communicator lookup(const label comm); static Communicator lookup(const int comm);
// Member Functions // Member Functions
@ -1713,6 +1710,9 @@ public:
//- Reset to default constructed value (MPI_COMM_NULL) //- Reset to default constructed value (MPI_COMM_NULL)
void reset() noexcept; void reset() noexcept;
//- The number of ranks associated with the communicator
int size() const;
}; };

View File

@ -137,6 +137,11 @@ public:
//- Reset to default constructed value (MPI_WIN_NULL) //- Reset to default constructed value (MPI_WIN_NULL)
void reset() noexcept; 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;
}; };

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2021-2024 OpenCFD Ltd. Copyright (C) 2021-2025 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -45,7 +45,7 @@ std::streamsize Foam::UIPstream::read
char* buf, char* buf,
const std::streamsize bufSize, const std::streamsize bufSize,
const int tag, const int tag,
const label communicator, const int communicator,
UPstream::Request* req UPstream::Request* req
) )
{ {

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2022-2023 OpenCFD Ltd. Copyright (C) 2022-2025 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -46,7 +46,7 @@ bool Foam::UOPstream::write
const char* buf, const char* buf,
const std::streamsize bufSize, const std::streamsize bufSize,
const int tag, const int tag,
const label communicator, const int communicator,
UPstream::Request* req, UPstream::Request* req,
const UPstream::sendModes sendMode const UPstream::sendModes sendMode
) )

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2024 OpenCFD Ltd. Copyright (C) 2024-2025 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -38,7 +38,7 @@ Foam::UPstream::Communicator::Communicator() noexcept
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
Foam::UPstream::Communicator Foam::UPstream::Communicator
Foam::UPstream::Communicator::lookup(const label comm) Foam::UPstream::Communicator::lookup(const int comm)
{ {
return UPstream::Communicator(nullptr); return UPstream::Communicator(nullptr);
} }
@ -56,4 +56,10 @@ void Foam::UPstream::Communicator::reset() noexcept
{} {}
int Foam::UPstream::Communicator::size() const
{
return 0;
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -47,4 +47,10 @@ void Foam::UPstream::Window::reset() noexcept
{} {}
int Foam::UPstream::Window::size() const
{
return 0;
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2019-2024 OpenCFD Ltd. Copyright (C) 2019-2025 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -47,7 +47,7 @@ static std::streamsize UPstream_mpi_receive
const std::streamsize bufSize, const std::streamsize bufSize,
const int fromProcNo, const int fromProcNo,
const int tag, const int tag,
const Foam::label communicator, const int communicator,
Foam::UPstream::Request* req Foam::UPstream::Request* req
) )
{ {
@ -344,7 +344,7 @@ std::streamsize Foam::UIPstream::read
char* buf, char* buf,
const std::streamsize bufSize, const std::streamsize bufSize,
const int tag, const int tag,
const label communicator, const int communicator,
UPstream::Request* req UPstream::Request* req
) )
{ {

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2019-2023 OpenCFD Ltd. Copyright (C) 2019-2025 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -55,7 +55,7 @@ bool Foam::UOPstream::write
const char* buf, const char* buf,
const std::streamsize bufSize, const std::streamsize bufSize,
const int tag, const int tag,
const label communicator, const int communicator,
UPstream::Request* req, UPstream::Request* req,
const UPstream::sendModes sendMode const UPstream::sendModes sendMode
) )

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2024 OpenCFD Ltd. Copyright (C) 2024-2025 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -39,7 +39,7 @@ Foam::UPstream::Communicator::Communicator() noexcept
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
Foam::UPstream::Communicator Foam::UPstream::Communicator
Foam::UPstream::Communicator::lookup(const label comm) Foam::UPstream::Communicator::lookup(const int comm)
{ {
if (comm < 0 || comm >= PstreamGlobals::MPICommunicators_.size()) 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;
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -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;
}
// ************************************************************************* // // ************************************************************************* //