COMP: missing default parameters for UIPstream::read

ENH: support UIPstream::read, UOPstream::write with UList, SubList
This commit is contained in:
Mark Olesen
2023-01-26 10:53:42 +01:00
parent 94a79ef24f
commit c1cdacc0b4
3 changed files with 203 additions and 27 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2019-2020 OpenCFD Ltd.
Copyright (C) 2019-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -309,32 +309,45 @@ int main(int argc, char *argv[])
if (Pstream::parRun())
{
// Fixed buffer would also work, but want to test using UList
List<labelPair> buffer;
const label startOfRequests = UPstream::nRequests();
if (Pstream::master())
{
buffer.resize(UPstream::nProcs());
buffer[0] = labelPair(0, UPstream::myProcNo());
for (const int proci : Pstream::subProcs())
{
IPstream fromSlave(Pstream::commsTypes::blocking, proci);
FixedList<label, 2> list3(fromSlave);
Serr<< "Receiving from " << proci
<< " : " << list3 << endl;
UIPstream::read
(
UPstream::commsTypes::nonBlocking,
proci,
buffer.slice(proci, 1)
);
}
}
else
{
Perr<< "Sending to master" << endl;
buffer.resize(1);
buffer[0] = labelPair(0, UPstream::myProcNo());
OPstream toMaster
Perr<< "Sending to master: " << buffer << endl;
UOPstream::write
(
Pstream::commsTypes::blocking,
Pstream::masterNo()
UPstream::commsTypes::nonBlocking,
UPstream::masterNo(),
buffer.slice(0, 1) // OK
/// buffer // Also OK
);
FixedList<label, 2> list3;
list3[0] = 0;
list3[1] = Pstream::myProcNo();
toMaster << list3;
}
UPstream::waitRequests(startOfRequests);
Info<< "Gathered: " << buffer << endl;
}
return 0;

View File

@ -251,8 +251,8 @@ public:
// Static Functions
//- Read buffer contents from given processor
// \return the message size
//- Read buffer contents from given processor.
// \return the message size (bytes read)
static label read
(
const UPstream::commsTypes commsType,
@ -265,8 +265,8 @@ public:
UPstream::Request* req = nullptr
);
//- Read buffer contents (non-blocking) from given processor
// \return the message size
//- Read buffer contents (non-blocking) from given processor.
// \return the message size (bytes read)
inline static label read
(
//! [out] request information
@ -274,8 +274,8 @@ public:
const int fromProcNo,
char* buf,
const std::streamsize bufSize,
const int tag,
const label communicator
const int tag = UPstream::msgType(),
const label comm = UPstream::worldComm
)
{
return UIPstream::read
@ -285,7 +285,113 @@ public:
buf,
bufSize,
tag,
communicator,
comm,
&req
);
}
//- Read into UList storage from given processor.
// Only valid for contiguous data types.
// \return the message size (bytes read). May change in the future
template<class Type>
inline static label read
(
const UPstream::commsTypes commsType,
const int fromProcNo,
UList<Type>& buffer,
const int tag = UPstream::msgType(),
const label comm = UPstream::worldComm,
//! [out] request information (for non-blocking)
UPstream::Request* req = nullptr
)
{
return UIPstream::read
(
commsType,
fromProcNo,
buffer.data_bytes(),
buffer.size_bytes(),
tag,
comm,
req
);
}
//- Read into SubList storage from given processor.
// Only valid for contiguous data types.
// \return the message size (bytes read). May change in the future
template<class Type>
inline static label read
(
const UPstream::commsTypes commsType,
const int fromProcNo,
SubList<Type> buffer, // passed by shallow copy
const int tag = UPstream::msgType(),
const label comm = UPstream::worldComm,
//! [out] request information (for non-blocking)
UPstream::Request* req = nullptr
)
{
return UIPstream::read
(
commsType,
fromProcNo,
buffer.data_bytes(),
buffer.size_bytes(),
tag,
comm,
req
);
}
//- Read into UList storage (non-blocking) from given processor.
// Only valid for contiguous data types.
// \return the message size (bytes read). May change in the future
template<class Type>
inline static label read
(
//! [out] request information
UPstream::Request& req,
const int fromProcNo,
UList<Type>& buffer,
const int tag = UPstream::msgType(),
const label comm = UPstream::worldComm
)
{
return UIPstream::read
(
UPstream::commsTypes::nonBlocking,
fromProcNo,
buffer.data_bytes(),
buffer.size_bytes(),
tag,
comm,
&req
);
}
//- Read into SubList storage (non-blocking) from given processor.
// Only valid for contiguous data types.
// \return the message size (bytes read). May change in the future
template<class Type>
inline static label read
(
//! [out] request information
UPstream::Request& req,
const int fromProcNo,
SubList<Type> buffer, // passed by shallow copy
const int tag = UPstream::msgType(),
const label comm = UPstream::worldComm
)
{
return UIPstream::read
(
UPstream::commsTypes::nonBlocking,
fromProcNo,
buffer.data_bytes(),
buffer.size_bytes(),
tag,
comm,
&req
);
}
@ -317,11 +423,11 @@ public:
//- and IO format
UIPBstream
(
const UPstream::commsTypes, //!< ignored
const UPstream::commsTypes, //!< irrelevant
const int rootProcNo, //!< normally UPstream::masterNo()
DynamicList<char>& receiveBuf,
label& receiveBufPosition,
const int tag = UPstream::msgType(), //!< ignored
const int tag = UPstream::msgType(), //!< irrelevant
const label comm = UPstream::worldComm,
const bool clearAtEnd = false, //!< destroy receiveBuf if at end
IOstreamOption::streamFormat fmt = IOstreamOption::BINARY
@ -341,7 +447,7 @@ public:
// Static Functions
//- Wrapped version of UPstream::broadcast
// \return the message size
// \return the message size (bytes read)
static label read
(
const int rootProcNo, //!< normally UPstream::masterNo()

View File

@ -364,6 +364,63 @@ public:
sendMode
);
}
//- Write UList contents to given processor.
// Only valid for contiguous data types.
// \return True on success
template<class Type>
inline static bool write
(
const UPstream::commsTypes commsType,
const int toProcNo,
const UList<Type>& buffer,
const int tag = UPstream::msgType(),
const label comm = UPstream::worldComm,
//! [out] request information (for non-blocking)
UPstream::Request* req = nullptr,
const UPstream::sendModes sendMode = UPstream::sendModes::normal
)
{
return UOPstream::write
(
commsType,
toProcNo,
buffer.cdata_bytes(),
buffer.size_bytes(),
tag,
comm,
req,
sendMode
);
}
//- Write UList contents (non-blocking) to given processor.
// Only valid for contiguous data types.
// \return True on success
template<class Type>
inline static bool write
(
//! [out] request information
UPstream::Request& req,
const int toProcNo,
const UList<Type>& buffer,
const int tag = UPstream::msgType(),
const label comm = UPstream::worldComm,
const UPstream::sendModes sendMode = UPstream::sendModes::normal
)
{
return UOPstream::write
(
UPstream::commsTypes::nonBlocking,
toProcNo,
buffer.cdata_bytes(),
buffer.size_bytes(),
tag,
comm,
&req,
sendMode
);
}
};
@ -394,10 +451,10 @@ public:
//- and IO format
UOPBstream
(
const UPstream::commsTypes, //!< ignored
const UPstream::commsTypes, //!< irrelevant
const int toProcNo, //!< normally UPstream::masterNo()
DynamicList<char>& sendBuf,
const int tag = UPstream::msgType(), //!< ignored
const int tag = UPstream::msgType(), //!< irrelevant
const label comm = UPstream::worldComm,
const bool sendAtDestruct = true,
IOstreamOption::streamFormat fmt = IOstreamOption::BINARY