STYLE: unify some handling of warn communicator, minor code cleanup
This commit is contained in:
parent
e041af9481
commit
2783e78ae2
@ -82,50 +82,40 @@ inline void checkCommunicator(int comm, int rank)
|
||||
}
|
||||
}
|
||||
|
||||
//- True if warn communicator is active and not equal to given communicator
|
||||
inline bool warnCommunicator(int comm) noexcept
|
||||
{
|
||||
return (UPstream::warnComm >= 0 && comm != UPstream::warnComm);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Requests * * * * * * * * * * * * * * * * //
|
||||
|
||||
//- Reset UPstream::Request to null and/or the index of the outstanding
|
||||
//- request to -1.
|
||||
// Does not affect the stack of outstanding requests.
|
||||
inline void reset_request
|
||||
(
|
||||
UPstream::Request* requestPtr,
|
||||
label* requestIdx = nullptr
|
||||
)
|
||||
//- Reset UPstream::Request to MPI_REQUEST_NULL
|
||||
// Does not affect the stack of outstanding requests
|
||||
inline void reset_request(UPstream::Request* req) noexcept
|
||||
{
|
||||
if (requestPtr) *requestPtr = UPstream::Request(MPI_REQUEST_NULL);
|
||||
if (requestIdx) *requestIdx = -1;
|
||||
if (req) *req = UPstream::Request(MPI_REQUEST_NULL);
|
||||
}
|
||||
|
||||
|
||||
//- Transcribe MPI_Request to UPstream::Request
|
||||
//- (does not affect the stack of outstanding requests)
|
||||
//- or else push onto list of outstanding requests
|
||||
//- and (optionally) record its location
|
||||
inline void push_request
|
||||
(
|
||||
MPI_Request request,
|
||||
UPstream::Request* requestPtr = nullptr,
|
||||
label* requestIdx = nullptr
|
||||
UPstream::Request* req = nullptr
|
||||
)
|
||||
{
|
||||
if (requestPtr)
|
||||
if (req)
|
||||
{
|
||||
// Transcribe as UPstream::Request
|
||||
*requestPtr = UPstream::Request(request);
|
||||
|
||||
// Not on stack of outstanding requests
|
||||
if (requestIdx) *requestIdx = -1;
|
||||
*req = UPstream::Request(request);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (requestIdx)
|
||||
{
|
||||
// Its index into outstanding requests
|
||||
*requestIdx = PstreamGlobals::outstandingRequests_.size();
|
||||
}
|
||||
|
||||
// Push onto list of requests
|
||||
PstreamGlobals::outstandingRequests_.push_back(request);
|
||||
}
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ static std::streamsize UPstream_mpi_receive
|
||||
}
|
||||
#endif
|
||||
|
||||
if (UPstream::warnComm >= 0 && communicator != UPstream::warnComm)
|
||||
if (FOAM_UNLIKELY(PstreamGlobals::warnCommunicator(communicator)))
|
||||
{
|
||||
Perr<< "UIPstream::read : starting read from:" << fromProcNo
|
||||
<< " size:" << label(bufSize)
|
||||
@ -76,7 +76,7 @@ static std::streamsize UPstream_mpi_receive
|
||||
<< Foam::endl;
|
||||
error::printStack(Perr);
|
||||
}
|
||||
else if (UPstream::debug)
|
||||
else if (FOAM_UNLIKELY(UPstream::debug))
|
||||
{
|
||||
Perr<< "UIPstream::read : starting read from:" << fromProcNo
|
||||
<< " size:" << label(bufSize)
|
||||
@ -121,7 +121,7 @@ static std::streamsize UPstream_mpi_receive
|
||||
<< Foam::abort(FatalError);
|
||||
return 0;
|
||||
}
|
||||
else if (UPstream::debug)
|
||||
else if (FOAM_UNLIKELY(UPstream::debug))
|
||||
{
|
||||
Perr<< "UIPstream::read : finished recv from:"
|
||||
<< fromProcNo
|
||||
@ -196,7 +196,7 @@ static std::streamsize UPstream_mpi_receive
|
||||
profilingPstream::addRequestTime();
|
||||
|
||||
|
||||
if (UPstream::debug)
|
||||
if (FOAM_UNLIKELY(UPstream::debug))
|
||||
{
|
||||
Perr<< "UIPstream::read : started non-blocking recv from:"
|
||||
<< fromProcNo
|
||||
@ -223,7 +223,7 @@ static std::streamsize UPstream_mpi_receive
|
||||
void Foam::UIPstream::bufferIPCrecv()
|
||||
{
|
||||
// Called by constructor
|
||||
if (UPstream::debug)
|
||||
if (FOAM_UNLIKELY(UPstream::debug))
|
||||
{
|
||||
Perr<< "UIPstream IPC read buffer :"
|
||||
<< " from:" << fromProcNo_
|
||||
@ -289,7 +289,7 @@ void Foam::UIPstream::bufferIPCrecv()
|
||||
<< Foam::abort(FatalError);
|
||||
}
|
||||
|
||||
if (UPstream::debug)
|
||||
if (FOAM_UNLIKELY(UPstream::debug))
|
||||
{
|
||||
Perr<< "UIPstream::UIPstream : probed size:"
|
||||
<< label(count) << Foam::endl;
|
||||
|
@ -72,7 +72,7 @@ bool Foam::UOPstream::write
|
||||
}
|
||||
#endif
|
||||
|
||||
if (UPstream::warnComm >= 0 && communicator != UPstream::warnComm)
|
||||
if (FOAM_UNLIKELY(PstreamGlobals::warnCommunicator(communicator)))
|
||||
{
|
||||
Perr<< "UOPstream::write : starting write to:" << toProcNo
|
||||
<< " size:" << label(bufSize)
|
||||
@ -82,7 +82,7 @@ bool Foam::UOPstream::write
|
||||
<< Foam::endl;
|
||||
error::printStack(Perr);
|
||||
}
|
||||
else if (UPstream::debug)
|
||||
else if (FOAM_UNLIKELY(UPstream::debug))
|
||||
{
|
||||
Perr<< "UOPstream::write : starting write to:" << toProcNo
|
||||
<< " size:" << label(bufSize)
|
||||
@ -112,7 +112,7 @@ bool Foam::UOPstream::write
|
||||
// Assume these are from scatters ...
|
||||
profilingPstream::addScatterTime();
|
||||
|
||||
if (UPstream::debug)
|
||||
if (FOAM_UNLIKELY(UPstream::debug))
|
||||
{
|
||||
Perr<< "UOPstream::write : finished buffered send to:"
|
||||
<< toProcNo
|
||||
@ -150,7 +150,7 @@ bool Foam::UOPstream::write
|
||||
// Assume these are from scatters ...
|
||||
profilingPstream::addScatterTime();
|
||||
|
||||
if (UPstream::debug)
|
||||
if (FOAM_UNLIKELY(UPstream::debug))
|
||||
{
|
||||
Perr<< "UOPstream::write : finished send to:"
|
||||
<< toProcNo
|
||||
@ -189,7 +189,7 @@ bool Foam::UOPstream::write
|
||||
);
|
||||
}
|
||||
|
||||
if (UPstream::debug)
|
||||
if (FOAM_UNLIKELY(UPstream::debug))
|
||||
{
|
||||
Perr<< "UOPstream::write : started non-blocking send to:"
|
||||
<< toProcNo
|
||||
|
@ -39,8 +39,6 @@ License
|
||||
#include <numeric>
|
||||
#include <string>
|
||||
|
||||
#undef Pstream_use_MPI_Get_count
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
// The min value and default for MPI buffer length
|
||||
@ -1178,33 +1176,28 @@ Foam::UPstream::probeMessage
|
||||
// Unlikely to be used with large amounts of data,
|
||||
// but use MPI_Get_elements_x() instead of MPI_Count() anyhow
|
||||
|
||||
#ifdef Pstream_use_MPI_Get_count
|
||||
int count(0);
|
||||
MPI_Get_count(&status, MPI_BYTE, &count);
|
||||
#else
|
||||
MPI_Count count(0);
|
||||
MPI_Get_elements_x(&status, MPI_BYTE, &count);
|
||||
#endif
|
||||
MPI_Count num_recv(0);
|
||||
MPI_Get_elements_x(&status, MPI_BYTE, &num_recv);
|
||||
|
||||
// Errors
|
||||
if (count == MPI_UNDEFINED || int64_t(count) < 0)
|
||||
if (num_recv == MPI_UNDEFINED || int64_t(num_recv) < 0)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "MPI_Get_count() or MPI_Get_elements_x() : "
|
||||
<< "MPI_Get_elements_x() : "
|
||||
"returned undefined or negative value"
|
||||
<< Foam::abort(FatalError);
|
||||
}
|
||||
else if (int64_t(count) > int64_t(INT_MAX))
|
||||
else if (int64_t(num_recv) > int64_t(INT_MAX))
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "MPI_Get_count() or MPI_Get_elements_x() : "
|
||||
"count is larger than INI_MAX bytes"
|
||||
<< "MPI_Get_elements_x() : "
|
||||
"count is larger than INT_MAX bytes"
|
||||
<< Foam::abort(FatalError);
|
||||
}
|
||||
|
||||
|
||||
result.first = status.MPI_SOURCE;
|
||||
result.second = int64_t(count);
|
||||
result.second = int64_t(num_recv);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -47,7 +47,7 @@ bool Foam::UPstream::broadcast
|
||||
|
||||
//Needed? PstreamGlobals::checkCommunicator(comm, rootProcNo);
|
||||
|
||||
if (UPstream::warnComm >= 0 && comm != UPstream::warnComm)
|
||||
if (FOAM_UNLIKELY(PstreamGlobals::warnCommunicator(comm)))
|
||||
{
|
||||
Perr<< "UPstream::broadcast : root:" << rootProcNo
|
||||
<< " comm:" << comm
|
||||
@ -56,7 +56,7 @@ bool Foam::UPstream::broadcast
|
||||
<< Foam::endl;
|
||||
error::printStack(Perr);
|
||||
}
|
||||
else if (UPstream::debug)
|
||||
else if (FOAM_UNLIKELY(UPstream::debug))
|
||||
{
|
||||
Perr<< "UPstream::broadcast : root:" << rootProcNo
|
||||
<< " comm:" << comm
|
||||
|
@ -48,13 +48,14 @@ namespace PstreamDetail
|
||||
{
|
||||
|
||||
// MPI_Bcast, using root=0
|
||||
// No fail/abort handling
|
||||
template<class Type>
|
||||
void broadcast0
|
||||
bool broadcast0
|
||||
(
|
||||
Type* values,
|
||||
int count,
|
||||
MPI_Datatype datatype,
|
||||
const label comm
|
||||
const int communicator
|
||||
);
|
||||
|
||||
// MPI_Reduce, using root=0
|
||||
@ -65,7 +66,8 @@ void reduce0
|
||||
int count,
|
||||
MPI_Datatype datatype,
|
||||
MPI_Op optype,
|
||||
const label comm
|
||||
const int communicator, // Communicator
|
||||
UPstream::Request* req = nullptr // Non-null for non-blocking
|
||||
);
|
||||
|
||||
// MPI_Allreduce or MPI_Iallreduce
|
||||
@ -76,9 +78,8 @@ void allReduce
|
||||
int count,
|
||||
MPI_Datatype datatype,
|
||||
MPI_Op optype,
|
||||
const label comm, // Communicator
|
||||
UPstream::Request* req = nullptr, // Non-null for non-blocking
|
||||
label* requestID = nullptr // (alternative to UPstream::Request)
|
||||
const int communicator, // Communicator
|
||||
UPstream::Request* req = nullptr // Non-null for non-blocking
|
||||
);
|
||||
|
||||
|
||||
@ -89,9 +90,8 @@ void allToAll
|
||||
const UList<Type>& sendData,
|
||||
UList<Type>& recvData,
|
||||
MPI_Datatype datatype,
|
||||
const label comm, // Communicator
|
||||
UPstream::Request* req = nullptr, // Non-null for non-blocking
|
||||
label* requestID = nullptr // (alternative to UPstream::Request)
|
||||
const int communicator, // Communicator
|
||||
UPstream::Request* req = nullptr // Non-null for non-blocking
|
||||
);
|
||||
|
||||
|
||||
@ -108,9 +108,8 @@ void allToAllv
|
||||
const UList<int>& recvOffsets,
|
||||
|
||||
MPI_Datatype datatype,
|
||||
const label comm, // Communicator
|
||||
UPstream::Request* req = nullptr, // Non-null for non-blocking
|
||||
label* requestID = nullptr // (alternative to UPstream::Request)
|
||||
const int communicator, // Communicator
|
||||
UPstream::Request* req = nullptr // Non-null for non-blocking
|
||||
);
|
||||
|
||||
|
||||
@ -122,7 +121,7 @@ void allToAllConsensus
|
||||
UList<Type>& recvData,
|
||||
MPI_Datatype datatype,
|
||||
const int tag, // Message tag
|
||||
const label comm // Communicator
|
||||
const int communicator // Communicator
|
||||
);
|
||||
|
||||
|
||||
@ -134,7 +133,7 @@ void allToAllConsensus
|
||||
Map<Type>& recvData,
|
||||
MPI_Datatype datatype,
|
||||
const int tag, // Message tag
|
||||
const label comm // Communicator
|
||||
const int communicator // Communicator
|
||||
);
|
||||
|
||||
|
||||
@ -147,9 +146,8 @@ void gather
|
||||
Type* recvData, // On master: recv buffer. Ignored elsewhere
|
||||
int count, // Per rank send/recv count. Globally consistent!
|
||||
MPI_Datatype datatype, // The send/recv data type
|
||||
const label comm, // Communicator
|
||||
UPstream::Request* req = nullptr, // Non-null for non-blocking
|
||||
label* requestID = nullptr // (alternative to UPstream::Request)
|
||||
const int communicator, // Communicator
|
||||
UPstream::Request* req = nullptr // Non-null for non-blocking
|
||||
);
|
||||
|
||||
|
||||
@ -162,9 +160,8 @@ void scatter
|
||||
Type* recvData, // Local recv value
|
||||
int count, // Per rank send/recv count. Globally consistent!
|
||||
MPI_Datatype datatype, // The send/recv data type
|
||||
const label comm, // Communicator
|
||||
UPstream::Request* req = nullptr, // Non-null for non-blocking
|
||||
label* requestID = nullptr // (alternative to UPstream::Request)
|
||||
const int communicator, // Communicator
|
||||
UPstream::Request* req = nullptr // Non-null for non-blocking
|
||||
);
|
||||
|
||||
|
||||
@ -180,9 +177,8 @@ void gatherv
|
||||
const UList<int>& recvOffsets, // Ignored on non-root rank
|
||||
|
||||
MPI_Datatype datatype, // The send/recv data type
|
||||
const label comm, // Communicator
|
||||
UPstream::Request* req = nullptr, // Non-null for non-blocking
|
||||
label* requestID = nullptr // (alternative to UPstream::Request)
|
||||
const int communicator, // Communicator
|
||||
UPstream::Request* req = nullptr // Non-null for non-blocking
|
||||
);
|
||||
|
||||
|
||||
@ -198,9 +194,8 @@ void scatterv
|
||||
int recvCount,
|
||||
|
||||
MPI_Datatype datatype, // The send/recv data type
|
||||
const label comm, // Communicator
|
||||
UPstream::Request* req = nullptr, // Non-null for non-blocking
|
||||
label* requestID = nullptr // (alternative to UPstream::Request)
|
||||
const int communicator, // Communicator
|
||||
UPstream::Request* req = nullptr // Non-null for non-blocking
|
||||
);
|
||||
|
||||
|
||||
@ -212,9 +207,8 @@ void allGather
|
||||
int count, // The send/recv count per element
|
||||
|
||||
MPI_Datatype datatype, // The send/recv data type
|
||||
const label comm, // Communicator
|
||||
UPstream::Request* req = nullptr, // Non-null for non-blocking
|
||||
label* requestID = nullptr // (alternative to UPstream::Request)
|
||||
const int communicator, // Communicator
|
||||
UPstream::Request* req = nullptr // Non-null for non-blocking
|
||||
);
|
||||
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user