mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: use Improbe/Mrecv for NBX size exchange
- retains the queried message without secondary polling. Purported to be slightly faster. Better thread-safety.
This commit is contained in:
@ -131,14 +131,16 @@ int main(int argc, char *argv[])
|
|||||||
for (bool barrier_active = false, done = false; !done; /*nil*/)
|
for (bool barrier_active = false, done = false; !done; /*nil*/)
|
||||||
{
|
{
|
||||||
int flag = 0;
|
int flag = 0;
|
||||||
|
MPI_Message message;
|
||||||
MPI_Status status;
|
MPI_Status status;
|
||||||
|
|
||||||
MPI_Iprobe
|
MPI_Improbe
|
||||||
(
|
(
|
||||||
MPI_ANY_SOURCE,
|
MPI_ANY_SOURCE,
|
||||||
tag,
|
tag,
|
||||||
MPI_COMM_WORLD,
|
MPI_COMM_WORLD,
|
||||||
&flag,
|
&flag,
|
||||||
|
&message,
|
||||||
&status
|
&status
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -153,14 +155,12 @@ int main(int argc, char *argv[])
|
|||||||
auto& buf = recvBufs(fromProci);
|
auto& buf = recvBufs(fromProci);
|
||||||
buf.resize_nocopy(count);
|
buf.resize_nocopy(count);
|
||||||
|
|
||||||
MPI_Irecv
|
MPI_Imrecv
|
||||||
(
|
(
|
||||||
buf.data_bytes(),
|
buf.data_bytes(),
|
||||||
buf.size_bytes(),
|
buf.size_bytes(),
|
||||||
MPI_BYTE,
|
MPI_BYTE,
|
||||||
fromProci,
|
&message,
|
||||||
tag,
|
|
||||||
MPI_COMM_WORLD,
|
|
||||||
&recvRequests.emplace_back()
|
&recvRequests.emplace_back()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -157,15 +157,12 @@ void Foam::PstreamDetail::allReduce
|
|||||||
error::printStack(Pout);
|
error::printStack(Pout);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool handled(false);
|
|
||||||
|
|
||||||
#if defined(MPI_VERSION) && (MPI_VERSION >= 3)
|
#if defined(MPI_VERSION) && (MPI_VERSION >= 3)
|
||||||
// MPI-3 : eg, openmpi-1.7 (2013) and later
|
|
||||||
if (immediate)
|
if (immediate)
|
||||||
{
|
{
|
||||||
|
// MPI-3 : eg, openmpi-1.7 (2013) and later
|
||||||
profilingPstream::beginTiming();
|
profilingPstream::beginTiming();
|
||||||
|
|
||||||
handled = true;
|
|
||||||
MPI_Request request;
|
MPI_Request request;
|
||||||
|
|
||||||
if
|
if
|
||||||
@ -192,9 +189,8 @@ void Foam::PstreamDetail::allReduce
|
|||||||
PstreamGlobals::push_request(request, req, requestID);
|
PstreamGlobals::push_request(request, req, requestID);
|
||||||
profilingPstream::addRequestTime();
|
profilingPstream::addRequestTime();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!handled)
|
|
||||||
{
|
{
|
||||||
profilingPstream::beginTiming();
|
profilingPstream::beginTiming();
|
||||||
|
|
||||||
@ -281,15 +277,12 @@ void Foam::PstreamDetail::allToAll
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool handled(false);
|
|
||||||
|
|
||||||
#if defined(MPI_VERSION) && (MPI_VERSION >= 3)
|
#if defined(MPI_VERSION) && (MPI_VERSION >= 3)
|
||||||
// MPI-3 : eg, openmpi-1.7 (2013) and later
|
|
||||||
if (immediate)
|
if (immediate)
|
||||||
{
|
{
|
||||||
|
// MPI-3 : eg, openmpi-1.7 (2013) and later
|
||||||
profilingPstream::beginTiming();
|
profilingPstream::beginTiming();
|
||||||
|
|
||||||
handled = true;
|
|
||||||
MPI_Request request;
|
MPI_Request request;
|
||||||
|
|
||||||
if
|
if
|
||||||
@ -318,9 +311,8 @@ void Foam::PstreamDetail::allToAll
|
|||||||
PstreamGlobals::push_request(request, req, requestID);
|
PstreamGlobals::push_request(request, req, requestID);
|
||||||
profilingPstream::addRequestTime();
|
profilingPstream::addRequestTime();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!handled)
|
|
||||||
{
|
{
|
||||||
profilingPstream::beginTiming();
|
profilingPstream::beginTiming();
|
||||||
|
|
||||||
@ -432,15 +424,12 @@ void Foam::PstreamDetail::allToAllv
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool handled(false);
|
|
||||||
|
|
||||||
#if defined(MPI_VERSION) && (MPI_VERSION >= 3)
|
#if defined(MPI_VERSION) && (MPI_VERSION >= 3)
|
||||||
// MPI-3 : eg, openmpi-1.7 (2013) and later
|
|
||||||
if (immediate)
|
if (immediate)
|
||||||
{
|
{
|
||||||
|
// MPI-3 : eg, openmpi-1.7 (2013) and later
|
||||||
profilingPstream::beginTiming();
|
profilingPstream::beginTiming();
|
||||||
|
|
||||||
handled = true;
|
|
||||||
MPI_Request request;
|
MPI_Request request;
|
||||||
|
|
||||||
if
|
if
|
||||||
@ -470,9 +459,8 @@ void Foam::PstreamDetail::allToAllv
|
|||||||
PstreamGlobals::push_request(request, req, requestID);
|
PstreamGlobals::push_request(request, req, requestID);
|
||||||
profilingPstream::addRequestTime();
|
profilingPstream::addRequestTime();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!handled)
|
|
||||||
{
|
{
|
||||||
profilingPstream::beginTiming();
|
profilingPstream::beginTiming();
|
||||||
|
|
||||||
@ -621,6 +609,19 @@ void Foam::PstreamDetail::allToAllConsensus
|
|||||||
int flag = 0;
|
int flag = 0;
|
||||||
MPI_Status status;
|
MPI_Status status;
|
||||||
|
|
||||||
|
#if defined(MPI_VERSION) && (MPI_VERSION >= 3)
|
||||||
|
// MPI-3 : eg, openmpi-1.7 (2013) and later
|
||||||
|
MPI_Message message;
|
||||||
|
MPI_Improbe
|
||||||
|
(
|
||||||
|
MPI_ANY_SOURCE,
|
||||||
|
tag,
|
||||||
|
PstreamGlobals::MPICommunicators_[comm],
|
||||||
|
&flag,
|
||||||
|
&message,
|
||||||
|
&status
|
||||||
|
);
|
||||||
|
#else
|
||||||
MPI_Iprobe
|
MPI_Iprobe
|
||||||
(
|
(
|
||||||
MPI_ANY_SOURCE,
|
MPI_ANY_SOURCE,
|
||||||
@ -629,6 +630,7 @@ void Foam::PstreamDetail::allToAllConsensus
|
|||||||
&flag,
|
&flag,
|
||||||
&status
|
&status
|
||||||
);
|
);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (flag)
|
if (flag)
|
||||||
{
|
{
|
||||||
@ -641,12 +643,24 @@ void Foam::PstreamDetail::allToAllConsensus
|
|||||||
if (count != 1)
|
if (count != 1)
|
||||||
{
|
{
|
||||||
FatalErrorInFunction
|
FatalErrorInFunction
|
||||||
<< "Incorrect message size. Expected 1 but had "
|
<< "Incorrect message size from proc=" << proci
|
||||||
<< count << nl
|
<< ". Expected 1 but had " << count << nl
|
||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Regular receive (the data are small)
|
// Regular blocking receive [the data are small]
|
||||||
|
|
||||||
|
#if defined(MPI_VERSION) && (MPI_VERSION >= 3)
|
||||||
|
// MPI-3 : eg, openmpi-1.7 (2013) and later
|
||||||
|
MPI_Mrecv
|
||||||
|
(
|
||||||
|
&recvData[proci],
|
||||||
|
count, // count=1 (see above)
|
||||||
|
datatype,
|
||||||
|
&message,
|
||||||
|
MPI_STATUS_IGNORE
|
||||||
|
);
|
||||||
|
#else
|
||||||
MPI_Recv
|
MPI_Recv
|
||||||
(
|
(
|
||||||
&recvData[proci],
|
&recvData[proci],
|
||||||
@ -657,6 +671,7 @@ void Foam::PstreamDetail::allToAllConsensus
|
|||||||
PstreamGlobals::MPICommunicators_[comm],
|
PstreamGlobals::MPICommunicators_[comm],
|
||||||
MPI_STATUS_IGNORE
|
MPI_STATUS_IGNORE
|
||||||
);
|
);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (barrier_active)
|
if (barrier_active)
|
||||||
@ -800,6 +815,19 @@ void Foam::PstreamDetail::allToAllConsensus
|
|||||||
int flag = 0;
|
int flag = 0;
|
||||||
MPI_Status status;
|
MPI_Status status;
|
||||||
|
|
||||||
|
#if defined(MPI_VERSION) && (MPI_VERSION >= 3)
|
||||||
|
// MPI-3 : eg, openmpi-1.7 (2013) and later
|
||||||
|
MPI_Message message;
|
||||||
|
MPI_Improbe
|
||||||
|
(
|
||||||
|
MPI_ANY_SOURCE,
|
||||||
|
tag,
|
||||||
|
PstreamGlobals::MPICommunicators_[comm],
|
||||||
|
&flag,
|
||||||
|
&message,
|
||||||
|
&status
|
||||||
|
);
|
||||||
|
#else
|
||||||
MPI_Iprobe
|
MPI_Iprobe
|
||||||
(
|
(
|
||||||
MPI_ANY_SOURCE,
|
MPI_ANY_SOURCE,
|
||||||
@ -808,6 +836,7 @@ void Foam::PstreamDetail::allToAllConsensus
|
|||||||
&flag,
|
&flag,
|
||||||
&status
|
&status
|
||||||
);
|
);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (flag)
|
if (flag)
|
||||||
{
|
{
|
||||||
@ -821,14 +850,26 @@ void Foam::PstreamDetail::allToAllConsensus
|
|||||||
if (count != 1)
|
if (count != 1)
|
||||||
{
|
{
|
||||||
FatalErrorInFunction
|
FatalErrorInFunction
|
||||||
<< "Incorrect message size. Expected 1 but had "
|
<< "Incorrect message size from proc=" << proci
|
||||||
<< count << nl
|
<< ". Expected 1 but had " << count << nl
|
||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto& recvData = recvBufs(proci);
|
auto& recvData = recvBufs(proci);
|
||||||
|
|
||||||
// Regular receive [the data are small]
|
// Regular blocking receive [the data are small]
|
||||||
|
|
||||||
|
#if defined(MPI_VERSION) && (MPI_VERSION >= 3)
|
||||||
|
// MPI-3 : eg, openmpi-1.7 (2013) and later
|
||||||
|
MPI_Mrecv
|
||||||
|
(
|
||||||
|
&recvData,
|
||||||
|
count, // count=1 (see above)
|
||||||
|
datatype,
|
||||||
|
&message,
|
||||||
|
MPI_STATUS_IGNORE
|
||||||
|
);
|
||||||
|
#else
|
||||||
MPI_Recv
|
MPI_Recv
|
||||||
(
|
(
|
||||||
&recvData,
|
&recvData,
|
||||||
@ -839,6 +880,7 @@ void Foam::PstreamDetail::allToAllConsensus
|
|||||||
PstreamGlobals::MPICommunicators_[comm],
|
PstreamGlobals::MPICommunicators_[comm],
|
||||||
MPI_STATUS_IGNORE
|
MPI_STATUS_IGNORE
|
||||||
);
|
);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (barrier_active)
|
if (barrier_active)
|
||||||
@ -928,15 +970,12 @@ void Foam::PstreamDetail::gather
|
|||||||
error::printStack(Pout);
|
error::printStack(Pout);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool handled(false);
|
|
||||||
|
|
||||||
#if defined(MPI_VERSION) && (MPI_VERSION >= 3)
|
#if defined(MPI_VERSION) && (MPI_VERSION >= 3)
|
||||||
// MPI-3 : eg, openmpi-1.7 (2013) and later
|
|
||||||
if (immediate)
|
if (immediate)
|
||||||
{
|
{
|
||||||
|
// MPI-3 : eg, openmpi-1.7 (2013) and later
|
||||||
profilingPstream::beginTiming();
|
profilingPstream::beginTiming();
|
||||||
|
|
||||||
handled = true;
|
|
||||||
MPI_Request request;
|
MPI_Request request;
|
||||||
|
|
||||||
if
|
if
|
||||||
@ -965,9 +1004,8 @@ void Foam::PstreamDetail::gather
|
|||||||
PstreamGlobals::push_request(request, req, requestID);
|
PstreamGlobals::push_request(request, req, requestID);
|
||||||
profilingPstream::addRequestTime();
|
profilingPstream::addRequestTime();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!handled)
|
|
||||||
{
|
{
|
||||||
profilingPstream::beginTiming();
|
profilingPstream::beginTiming();
|
||||||
|
|
||||||
@ -1048,15 +1086,12 @@ void Foam::PstreamDetail::scatter
|
|||||||
error::printStack(Pout);
|
error::printStack(Pout);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool handled(false);
|
|
||||||
|
|
||||||
#if defined(MPI_VERSION) && (MPI_VERSION >= 3)
|
#if defined(MPI_VERSION) && (MPI_VERSION >= 3)
|
||||||
// MPI-3 : eg, openmpi-1.7 (2013) and later
|
|
||||||
if (immediate)
|
if (immediate)
|
||||||
{
|
{
|
||||||
|
// MPI-3 : eg, openmpi-1.7 (2013) and later
|
||||||
profilingPstream::beginTiming();
|
profilingPstream::beginTiming();
|
||||||
|
|
||||||
handled = true;
|
|
||||||
MPI_Request request;
|
MPI_Request request;
|
||||||
|
|
||||||
if
|
if
|
||||||
@ -1085,9 +1120,8 @@ void Foam::PstreamDetail::scatter
|
|||||||
PstreamGlobals::push_request(request, req, requestID);
|
PstreamGlobals::push_request(request, req, requestID);
|
||||||
profilingPstream::addRequestTime();
|
profilingPstream::addRequestTime();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!handled)
|
|
||||||
{
|
{
|
||||||
profilingPstream::beginTiming();
|
profilingPstream::beginTiming();
|
||||||
|
|
||||||
@ -1193,15 +1227,12 @@ void Foam::PstreamDetail::gatherv
|
|||||||
sendCount = 0;
|
sendCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool handled(false);
|
|
||||||
|
|
||||||
#if defined(MPI_VERSION) && (MPI_VERSION >= 3)
|
#if defined(MPI_VERSION) && (MPI_VERSION >= 3)
|
||||||
// MPI-3 : eg, openmpi-1.7 (2013) and later
|
|
||||||
if (immediate)
|
if (immediate)
|
||||||
{
|
{
|
||||||
|
// MPI-3 : eg, openmpi-1.7 (2013) and later
|
||||||
profilingPstream::beginTiming();
|
profilingPstream::beginTiming();
|
||||||
|
|
||||||
handled = true;
|
|
||||||
MPI_Request request;
|
MPI_Request request;
|
||||||
|
|
||||||
if
|
if
|
||||||
@ -1231,9 +1262,8 @@ void Foam::PstreamDetail::gatherv
|
|||||||
PstreamGlobals::push_request(request, req, requestID);
|
PstreamGlobals::push_request(request, req, requestID);
|
||||||
profilingPstream::addRequestTime();
|
profilingPstream::addRequestTime();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!handled)
|
|
||||||
{
|
{
|
||||||
profilingPstream::beginTiming();
|
profilingPstream::beginTiming();
|
||||||
|
|
||||||
@ -1333,15 +1363,12 @@ void Foam::PstreamDetail::scatterv
|
|||||||
<< Foam::abort(FatalError);
|
<< Foam::abort(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool handled(false);
|
|
||||||
|
|
||||||
#if defined(MPI_VERSION) && (MPI_VERSION >= 3)
|
#if defined(MPI_VERSION) && (MPI_VERSION >= 3)
|
||||||
// MPI-3 : eg, openmpi-1.7 (2013) and later
|
|
||||||
if (immediate)
|
if (immediate)
|
||||||
{
|
{
|
||||||
|
// MPI-3 : eg, openmpi-1.7 (2013) and later
|
||||||
profilingPstream::beginTiming();
|
profilingPstream::beginTiming();
|
||||||
|
|
||||||
handled = true;
|
|
||||||
MPI_Request request;
|
MPI_Request request;
|
||||||
|
|
||||||
if
|
if
|
||||||
@ -1371,9 +1398,8 @@ void Foam::PstreamDetail::scatterv
|
|||||||
PstreamGlobals::push_request(request, req, requestID);
|
PstreamGlobals::push_request(request, req, requestID);
|
||||||
profilingPstream::addRequestTime();
|
profilingPstream::addRequestTime();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!handled)
|
|
||||||
{
|
{
|
||||||
profilingPstream::beginTiming();
|
profilingPstream::beginTiming();
|
||||||
|
|
||||||
@ -1445,15 +1471,12 @@ void Foam::PstreamDetail::allGather
|
|||||||
error::printStack(Pout);
|
error::printStack(Pout);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool handled(false);
|
|
||||||
|
|
||||||
#if defined(MPI_VERSION) && (MPI_VERSION >= 3)
|
#if defined(MPI_VERSION) && (MPI_VERSION >= 3)
|
||||||
// MPI-3 : eg, openmpi-1.7 (2013) and later
|
|
||||||
if (immediate)
|
if (immediate)
|
||||||
{
|
{
|
||||||
|
// MPI-3 : eg, openmpi-1.7 (2013) and later
|
||||||
profilingPstream::beginTiming();
|
profilingPstream::beginTiming();
|
||||||
|
|
||||||
handled = true;
|
|
||||||
MPI_Request request;
|
MPI_Request request;
|
||||||
|
|
||||||
if
|
if
|
||||||
@ -1475,9 +1498,8 @@ void Foam::PstreamDetail::allGather
|
|||||||
PstreamGlobals::push_request(request, req, requestID);
|
PstreamGlobals::push_request(request, req, requestID);
|
||||||
profilingPstream::addRequestTime();
|
profilingPstream::addRequestTime();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!handled)
|
|
||||||
{
|
{
|
||||||
profilingPstream::beginTiming();
|
profilingPstream::beginTiming();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user