mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: simplify Pstream broadcast stream construction
- the rootProcNo is usually == UPstream::masterNo()
This commit is contained in:
@ -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-2024 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -34,7 +34,7 @@ License
|
|||||||
Foam::UIPBstream::UIPBstream
|
Foam::UIPBstream::UIPBstream
|
||||||
(
|
(
|
||||||
const UPstream::commsTypes commsType,
|
const UPstream::commsTypes commsType,
|
||||||
const int fromProcNo,
|
const int rootProcNo,
|
||||||
DynamicList<char>& receiveBuf,
|
DynamicList<char>& receiveBuf,
|
||||||
label& receiveBufPosition,
|
label& receiveBufPosition,
|
||||||
const int tag,
|
const int tag,
|
||||||
@ -45,11 +45,11 @@ Foam::UIPBstream::UIPBstream
|
|||||||
:
|
:
|
||||||
UIPstreamBase
|
UIPstreamBase
|
||||||
(
|
(
|
||||||
commsType,
|
commsType, // irrelevant
|
||||||
fromProcNo,
|
rootProcNo, // normally UPstream::masterNo()
|
||||||
receiveBuf,
|
receiveBuf,
|
||||||
receiveBufPosition,
|
receiveBufPosition,
|
||||||
tag,
|
tag, // irrelevant
|
||||||
comm,
|
comm,
|
||||||
clearAtEnd,
|
clearAtEnd,
|
||||||
fmt
|
fmt
|
||||||
@ -62,7 +62,7 @@ Foam::UIPBstream::UIPBstream
|
|||||||
Foam::IPBstream::IPBstream
|
Foam::IPBstream::IPBstream
|
||||||
(
|
(
|
||||||
const UPstream::commsTypes commsType,
|
const UPstream::commsTypes commsType,
|
||||||
const int fromProcNo,
|
const int rootProcNo,
|
||||||
const label bufSize,
|
const label bufSize,
|
||||||
const int tag,
|
const int tag,
|
||||||
const label comm,
|
const label comm,
|
||||||
@ -72,11 +72,11 @@ Foam::IPBstream::IPBstream
|
|||||||
Pstream(commsType, bufSize),
|
Pstream(commsType, bufSize),
|
||||||
UIPBstream
|
UIPBstream
|
||||||
(
|
(
|
||||||
commsType,
|
commsType, // irrelevant
|
||||||
fromProcNo,
|
rootProcNo, // normally UPstream::masterNo()
|
||||||
Pstream::transferBuf_,
|
Pstream::transferBuf_,
|
||||||
UIPstreamBase::storedRecvBufPos_, // Internal only
|
UIPstreamBase::storedRecvBufPos_, // Internal only
|
||||||
tag,
|
tag, // irrelevant
|
||||||
comm,
|
comm,
|
||||||
false, // Do not clear Pstream::transferBuf_ if at end
|
false, // Do not clear Pstream::transferBuf_ if at end
|
||||||
fmt
|
fmt
|
||||||
@ -86,7 +86,7 @@ Foam::IPBstream::IPBstream
|
|||||||
|
|
||||||
Foam::IPBstream::IPBstream
|
Foam::IPBstream::IPBstream
|
||||||
(
|
(
|
||||||
const int fromProcNo,
|
const int rootProcNo,
|
||||||
const label comm,
|
const label comm,
|
||||||
IOstreamOption::streamFormat fmt
|
IOstreamOption::streamFormat fmt
|
||||||
)
|
)
|
||||||
@ -94,7 +94,25 @@ Foam::IPBstream::IPBstream
|
|||||||
IPBstream
|
IPBstream
|
||||||
(
|
(
|
||||||
UPstream::commsTypes::scheduled, // irrelevant
|
UPstream::commsTypes::scheduled, // irrelevant
|
||||||
fromProcNo,
|
rootProcNo,
|
||||||
|
label(0), // bufSize
|
||||||
|
UPstream::msgType(), // irrelevant
|
||||||
|
comm,
|
||||||
|
fmt
|
||||||
|
)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::IPBstream::IPBstream
|
||||||
|
(
|
||||||
|
const label comm,
|
||||||
|
IOstreamOption::streamFormat fmt
|
||||||
|
)
|
||||||
|
:
|
||||||
|
IPBstream
|
||||||
|
(
|
||||||
|
UPstream::commsTypes::scheduled, // irrelevant
|
||||||
|
UPstream::masterNo(), // rootProcNo
|
||||||
label(0), // bufSize
|
label(0), // bufSize
|
||||||
UPstream::msgType(), // irrelevant
|
UPstream::msgType(), // irrelevant
|
||||||
comm,
|
comm,
|
||||||
|
|||||||
@ -127,11 +127,19 @@ public:
|
|||||||
IOstreamOption::streamFormat fmt = IOstreamOption::BINARY
|
IOstreamOption::streamFormat fmt = IOstreamOption::BINARY
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Construct for broadcast root with optional communicator,
|
//- Construct for broadcast root and communicator,
|
||||||
//- write format
|
//- with optional read format
|
||||||
explicit IPBstream
|
IPBstream
|
||||||
(
|
(
|
||||||
const int rootProcNo, //!< normally UPstream::masterNo()
|
const int rootProcNo, //!< normally UPstream::masterNo()
|
||||||
|
const label comm,
|
||||||
|
IOstreamOption::streamFormat fmt = IOstreamOption::BINARY
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Construct with optional communicator and read format.
|
||||||
|
//- Uses UPstream::masterNo() root
|
||||||
|
explicit IPBstream
|
||||||
|
(
|
||||||
const label comm = UPstream::worldComm,
|
const label comm = UPstream::worldComm,
|
||||||
IOstreamOption::streamFormat fmt = IOstreamOption::BINARY
|
IOstreamOption::streamFormat fmt = IOstreamOption::BINARY
|
||||||
);
|
);
|
||||||
|
|||||||
@ -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-2024 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -34,7 +34,7 @@ License
|
|||||||
Foam::UOPBstream::UOPBstream
|
Foam::UOPBstream::UOPBstream
|
||||||
(
|
(
|
||||||
const UPstream::commsTypes commsType,
|
const UPstream::commsTypes commsType,
|
||||||
const int toProcNo,
|
const int rootProcNo,
|
||||||
DynamicList<char>& sendBuf,
|
DynamicList<char>& sendBuf,
|
||||||
const int tag,
|
const int tag,
|
||||||
const label comm,
|
const label comm,
|
||||||
@ -42,14 +42,23 @@ Foam::UOPBstream::UOPBstream
|
|||||||
IOstreamOption::streamFormat fmt
|
IOstreamOption::streamFormat fmt
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
UOPstreamBase(commsType, toProcNo, sendBuf, tag, comm, sendAtDestruct, fmt)
|
UOPstreamBase
|
||||||
|
(
|
||||||
|
commsType, // irrelevant
|
||||||
|
rootProcNo, // normally UPstream::masterNo()
|
||||||
|
sendBuf,
|
||||||
|
tag, // irrelevant
|
||||||
|
comm,
|
||||||
|
sendAtDestruct,
|
||||||
|
fmt
|
||||||
|
)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
|
||||||
Foam::OPBstream::OPBstream
|
Foam::OPBstream::OPBstream
|
||||||
(
|
(
|
||||||
const UPstream::commsTypes commsType,
|
const UPstream::commsTypes commsType,
|
||||||
const int toProcNo,
|
const int rootProcNo,
|
||||||
const label bufSize,
|
const label bufSize,
|
||||||
const int tag,
|
const int tag,
|
||||||
const label comm,
|
const label comm,
|
||||||
@ -59,10 +68,10 @@ Foam::OPBstream::OPBstream
|
|||||||
Pstream(commsType, bufSize),
|
Pstream(commsType, bufSize),
|
||||||
UOPBstream
|
UOPBstream
|
||||||
(
|
(
|
||||||
commsType,
|
commsType, // irrelevant
|
||||||
toProcNo,
|
rootProcNo, // normally UPstream::masterNo()
|
||||||
Pstream::transferBuf_,
|
Pstream::transferBuf_,
|
||||||
tag,
|
tag, // irrelevant
|
||||||
comm,
|
comm,
|
||||||
true, // sendAtDestruct
|
true, // sendAtDestruct
|
||||||
fmt
|
fmt
|
||||||
@ -72,7 +81,7 @@ Foam::OPBstream::OPBstream
|
|||||||
|
|
||||||
Foam::OPBstream::OPBstream
|
Foam::OPBstream::OPBstream
|
||||||
(
|
(
|
||||||
const int toProcNo,
|
const int rootProcNo,
|
||||||
const label comm,
|
const label comm,
|
||||||
IOstreamOption::streamFormat fmt
|
IOstreamOption::streamFormat fmt
|
||||||
)
|
)
|
||||||
@ -80,7 +89,25 @@ Foam::OPBstream::OPBstream
|
|||||||
OPBstream
|
OPBstream
|
||||||
(
|
(
|
||||||
UPstream::commsTypes::scheduled, // irrelevant
|
UPstream::commsTypes::scheduled, // irrelevant
|
||||||
toProcNo,
|
rootProcNo,
|
||||||
|
label(0), // bufSize
|
||||||
|
UPstream::msgType(), // irrelevant
|
||||||
|
comm,
|
||||||
|
fmt
|
||||||
|
)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
Foam::OPBstream::OPBstream
|
||||||
|
(
|
||||||
|
const label comm,
|
||||||
|
IOstreamOption::streamFormat fmt
|
||||||
|
)
|
||||||
|
:
|
||||||
|
OPBstream
|
||||||
|
(
|
||||||
|
UPstream::commsTypes::scheduled, // irrelevant
|
||||||
|
UPstream::masterNo(), // rootProcNo
|
||||||
label(0), // bufSize
|
label(0), // bufSize
|
||||||
UPstream::msgType(), // irrelevant
|
UPstream::msgType(), // irrelevant
|
||||||
comm,
|
comm,
|
||||||
|
|||||||
@ -144,11 +144,19 @@ public:
|
|||||||
IOstreamOption::streamFormat fmt = IOstreamOption::BINARY
|
IOstreamOption::streamFormat fmt = IOstreamOption::BINARY
|
||||||
);
|
);
|
||||||
|
|
||||||
//- Construct for broadcast root with optional communicator,
|
//- Construct for broadcast root and communicator,
|
||||||
//- write format
|
//- with optional write format
|
||||||
explicit OPBstream
|
OPBstream
|
||||||
(
|
(
|
||||||
const int rootProcNo, //!< normally UPstream::masterNo()
|
const int rootProcNo, //!< normally UPstream::masterNo()
|
||||||
|
const label comm,
|
||||||
|
IOstreamOption::streamFormat fmt = IOstreamOption::BINARY
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Construct with optional communicator and write format.
|
||||||
|
//- Uses UPstream::masterNo() root
|
||||||
|
explicit OPBstream
|
||||||
|
(
|
||||||
const label comm = UPstream::worldComm,
|
const label comm = UPstream::worldComm,
|
||||||
IOstreamOption::streamFormat fmt = IOstreamOption::BINARY
|
IOstreamOption::streamFormat fmt = IOstreamOption::BINARY
|
||||||
);
|
);
|
||||||
|
|||||||
@ -41,20 +41,19 @@ void Foam::Pstream::broadcast(Type& value, const label comm)
|
|||||||
(
|
(
|
||||||
reinterpret_cast<char*>(&value),
|
reinterpret_cast<char*>(&value),
|
||||||
sizeof(Type),
|
sizeof(Type),
|
||||||
comm,
|
comm
|
||||||
UPstream::masterNo()
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else if (UPstream::is_parallel(comm))
|
else if (UPstream::is_parallel(comm))
|
||||||
{
|
{
|
||||||
if (UPstream::master(comm))
|
if (UPstream::master(comm))
|
||||||
{
|
{
|
||||||
OPBstream os(UPstream::masterNo(), comm);
|
OPBstream os(comm);
|
||||||
os << value;
|
os << value;
|
||||||
}
|
}
|
||||||
else // UPstream::is_subrank(comm)
|
else // UPstream::is_subrank(comm)
|
||||||
{
|
{
|
||||||
IPBstream is(UPstream::masterNo(), comm);
|
IPBstream is(comm);
|
||||||
is >> value;
|
is >> value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -68,12 +67,12 @@ void Foam::Pstream::broadcasts(const label comm, Type& arg1, Args&&... args)
|
|||||||
{
|
{
|
||||||
if (UPstream::master(comm))
|
if (UPstream::master(comm))
|
||||||
{
|
{
|
||||||
OPBstream os(UPstream::masterNo(), comm);
|
OPBstream os(comm);
|
||||||
Detail::outputLoop(os, arg1, std::forward<Args>(args)...);
|
Detail::outputLoop(os, arg1, std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
else // UPstream::is_subrank(comm)
|
else // UPstream::is_subrank(comm)
|
||||||
{
|
{
|
||||||
IPBstream is(UPstream::masterNo(), comm);
|
IPBstream is(comm);
|
||||||
Detail::inputLoop(is, arg1, std::forward<Args>(args)...);
|
Detail::inputLoop(is, arg1, std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -98,8 +97,7 @@ void Foam::Pstream::broadcastList(ListType& list, const label comm)
|
|||||||
(
|
(
|
||||||
reinterpret_cast<char*>(&len),
|
reinterpret_cast<char*>(&len),
|
||||||
sizeof(label),
|
sizeof(label),
|
||||||
comm,
|
comm
|
||||||
UPstream::masterNo()
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (UPstream::is_subrank(comm))
|
if (UPstream::is_subrank(comm))
|
||||||
@ -113,8 +111,7 @@ void Foam::Pstream::broadcastList(ListType& list, const label comm)
|
|||||||
(
|
(
|
||||||
list.data_bytes(),
|
list.data_bytes(),
|
||||||
list.size_bytes(),
|
list.size_bytes(),
|
||||||
comm,
|
comm
|
||||||
UPstream::masterNo()
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -125,12 +122,12 @@ void Foam::Pstream::broadcastList(ListType& list, const label comm)
|
|||||||
|
|
||||||
if (UPstream::master(comm))
|
if (UPstream::master(comm))
|
||||||
{
|
{
|
||||||
OPBstream os(UPstream::masterNo(), comm);
|
OPBstream os(comm);
|
||||||
os << list;
|
os << list;
|
||||||
}
|
}
|
||||||
else // UPstream::is_subrank(comm)
|
else // UPstream::is_subrank(comm)
|
||||||
{
|
{
|
||||||
IPBstream is(UPstream::masterNo(), comm);
|
IPBstream is(comm);
|
||||||
is >> list;
|
is >> list;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2195,26 +2195,18 @@ bool Foam::fileOperations::masterUncollatedFileOperation::read
|
|||||||
io.note()
|
io.note()
|
||||||
);
|
);
|
||||||
|
|
||||||
if (Pstream::master(UPstream::worldComm))
|
if (UPstream::master(UPstream::worldComm))
|
||||||
{
|
{
|
||||||
OPBstream toAll
|
OPBstream os(UPstream::worldComm, format);
|
||||||
(
|
|
||||||
UPstream::masterNo(),
|
bool okWrite = io.writeData(os);
|
||||||
UPstream::worldComm,
|
|
||||||
format
|
|
||||||
);
|
|
||||||
bool okWrite = io.writeData(toAll);
|
|
||||||
ok = ok && okWrite;
|
ok = ok && okWrite;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
IPBstream fromMaster
|
IPBstream is(UPstream::worldComm, format);
|
||||||
(
|
|
||||||
UPstream::masterNo(),
|
ok = io.readData(is);
|
||||||
UPstream::worldComm,
|
|
||||||
format
|
|
||||||
);
|
|
||||||
ok = io.readData(fromMaster);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -752,24 +752,16 @@ bool Foam::fileOperations::uncollatedFileOperation::read
|
|||||||
|
|
||||||
if (UPstream::master(UPstream::worldComm))
|
if (UPstream::master(UPstream::worldComm))
|
||||||
{
|
{
|
||||||
OPBstream toAll
|
OPBstream os(UPstream::worldComm, format);
|
||||||
(
|
|
||||||
UPstream::masterNo(),
|
bool okWrite = io.writeData(os);
|
||||||
UPstream::worldComm,
|
|
||||||
format
|
|
||||||
);
|
|
||||||
bool okWrite = io.writeData(toAll);
|
|
||||||
ok = ok && okWrite;
|
ok = ok && okWrite;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
IPBstream fromMaster
|
IPBstream is(UPstream::worldComm, format);
|
||||||
(
|
|
||||||
UPstream::masterNo(),
|
ok = io.readData(is);
|
||||||
UPstream::worldComm,
|
|
||||||
format
|
|
||||||
);
|
|
||||||
ok = io.readData(fromMaster);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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-2024 OpenCFD Ltd.
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
This file is part of OpenFOAM.
|
This file is part of OpenFOAM.
|
||||||
@ -270,7 +270,7 @@ void Foam::fieldsDistributor::readFieldsImpl
|
|||||||
// Broadcast zero sized fields everywhere (if needed)
|
// Broadcast zero sized fields everywhere (if needed)
|
||||||
// Send like a list of dictionaries
|
// Send like a list of dictionaries
|
||||||
|
|
||||||
OPBstream toProcs(UPstream::masterNo()); // worldComm
|
OPBstream toProcs(UPstream::worldComm);
|
||||||
|
|
||||||
const label nDicts = (subsetter ? fields.size() : label(0));
|
const label nDicts = (subsetter ? fields.size() : label(0));
|
||||||
|
|
||||||
@ -299,7 +299,7 @@ void Foam::fieldsDistributor::readFieldsImpl
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Receive the broadcast...
|
// Receive the broadcast...
|
||||||
IPBstream fromMaster(UPstream::masterNo()); // worldComm
|
IPBstream fromMaster(UPstream::worldComm);
|
||||||
|
|
||||||
// But only consume where needed...
|
// But only consume where needed...
|
||||||
if (!haveMeshOnProc.test(UPstream::myProcNo()))
|
if (!haveMeshOnProc.test(UPstream::myProcNo()))
|
||||||
|
|||||||
Reference in New Issue
Block a user