46 namespace PstreamDetail
65 template<
class Container,
class Type>
73 const bool wait =
true,
86 for (
auto& buf : recvBufs)
98 if (sendBufs.
size() > numProc)
101 <<
"Send buffers:" << sendBufs.
size() <<
" > numProcs:" << numProc
104 if (recvBufs.size() < numProc)
107 <<
"Recv buffers:" << recvBufs.size() <<
" < numProcs:" << numProc
115 recvBufs[myProci] = sendBufs[myProci];
116 if (myProci < recvSizes.
size())
118 recvSizes[myProci] = recvBufs.
size();
135 for (label proci = 0; proci < numProc; ++proci)
137 const auto& sendData = sendBufs[proci];
139 if (sendData.empty())
143 else if (proci == myProci)
146 recvBufs[proci] = sendData;
147 if (proci < recvSizes.
size())
149 recvSizes[proci] = sendData.
size();
158 sendRequests.emplace_back(),
160 sendData.cdata_bytes(),
161 sendData.size_bytes(),
174 for (
bool barrier_active =
false, done =
false; !done; )
176 std::pair<int, int> probed =
185 if (probed.second > 0)
190 const label proci = probed.first;
191 const label
count = (probed.second /
sizeof(Type));
193 auto& recvData = recvBufs[proci];
194 recvData.resize_nocopy(
count);
196 if (proci < recvSizes.
size())
198 recvSizes[proci] =
count;
206 recvData.data_bytes(),
207 recvData.size_bytes(),
228 barrier_active =
true;
253 template<
class Container,
class Type>
260 const bool wait =
true,
282 const auto iter = sendBufs.
find(myProci);
285 const auto& sendData = iter.val();
287 if (!sendData.empty())
290 recvBufs(iter.key()) = sendData;
304 const label proci = iter.key();
305 const auto& sendData = iter.val();
311 <<
"Send buffer:" << proci <<
" >= numProcs:" 317 if (sendData.empty())
321 else if (proci == myProci)
324 recvBufs(proci) = sendData;
332 sendRequests.emplace_back(),
334 sendData.cdata_bytes(),
335 sendData.size_bytes(),
348 for (
bool barrier_active =
false, done =
false; !done; )
350 std::pair<int, int> probed =
359 if (probed.second > 0)
364 const label proci = probed.first;
365 const label
count = (probed.second /
sizeof(Type));
367 auto& recvData = recvBufs(proci);
368 recvData.resize_nocopy(
count);
375 recvData.data_bytes(),
376 recvData.size_bytes(),
396 barrier_active =
true;
414 template<
class Container,
class Type>
429 <<
"Send buffers size:" << sendBufs.
size()
450 template<
class Container,
class Type>
void size(const label n)
Older name for setAddressableSize.
Inter-processor communication reduction functions.
static label read(const UPstream::commsTypes commsType, const int fromProcNo, char *buf, const std::streamsize bufSize, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm, UPstream::Request *req=nullptr)
Read buffer contents from given processor.
commsTypes
Communications types.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
static label nRequests() noexcept
Number of outstanding requests (on the internal list of requests)
static bool finishedRequest(const label i)
Non-blocking comms: has request i finished? Corresponds to MPI_Test()
void resize_nocopy(const label len)
Adjust allocated size of list without necessarily.
static int myProcNo(const label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Can be negative if the process i...
static void waitRequests()
Wait for all requests to finish.
static int tuning_NBX_
Tuning parameters for non-blocking exchange (NBX)
label size() const noexcept
The number of elements in table.
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run. ...
static bool is_rank(const label communicator=worldComm)
True if process corresponds to any rank (master or sub-rank) in the given communicator.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
An opaque wrapper for MPI_Request with a vendor-independent representation independent of any <mpi...
iterator find(const label &key)
Find and return an iterator set at the hashed entry.
#define forAllIters(container, iter)
Iterate across all elements in the container object.
static bool is_parallel(const label communicator=worldComm)
True if parallel algorithm or exchange is required.
errorManip< error > abort(error &err)
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
A template class to specify that a data type can be considered as being contiguous in memory...
static std::pair< int, int > probeMessage(const UPstream::commsTypes commsType, const int fromProcNo, const int tag=UPstream::msgType(), const label communicator=worldComm)
Probe for an incoming message.
static bool write(const UPstream::commsTypes commsType, const int toProcNo, const char *buf, const std::streamsize bufSize, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm, UPstream::Request *req=nullptr, const UPstream::sendModes sendMode=UPstream::sendModes::normal)
Write buffer contents to given processor.
"nonBlocking" : (MPI_Isend, MPI_Irecv)
static void exchangeConsensus(const UList< Container > &sendBufs, List< Container > &recvBufs, const int tag, const label comm, const bool wait=true)
Exchange contiguous data using non-blocking consensus Sends sendData, receives into recvData...
void exchangeConsensus(const UList< Container > &sendBufs, UList< Container > &recvBufs, labelUList &recvSizes, const int tag, const label comm, const bool wait=true, const UPstream::commsTypes recvCommType=UPstream::commsTypes::nonBlocking)
Exchange contiguous data using non-blocking consensus exchange with optional tracking of the receive ...
forAllConstIters(mixture.phases(), phase)
A HashTable to objects of type <T> with a label key.
static void barrier(const label communicator, UPstream::Request *req=nullptr)
Impose a synchronisation barrier (optionally non-blocking)
static bool finishedRequests(const label pos, label len=-1)
Non-blocking comms: have all requests (from position onwards) finished? Corresponds to MPI_Testall() ...
static constexpr const zero Zero
Global zero (0)