mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: use UList instead of List for some Pstream gather/scatter
- can use UList signature since the routines do not resize the list or attempt to broadcast it: useful for SubList handling. ENH: add IPstream/OPstream send/recv static methods
This commit is contained in:
@ -50,37 +50,37 @@ scalar sumReduce
|
||||
)
|
||||
{
|
||||
scalar sum = 0;
|
||||
if (Pstream::parRun())
|
||||
if (UPstream::parRun())
|
||||
{
|
||||
if (UPstream::master(comm))
|
||||
{
|
||||
// Add master value and all slaves
|
||||
// Add master value and all sub-procs
|
||||
sum = localValue;
|
||||
|
||||
for (const int slave : UPstream::subProcs(comm))
|
||||
for (const int proci : UPstream::subProcs(comm))
|
||||
{
|
||||
scalar slaveValue;
|
||||
scalar procValue;
|
||||
UIPstream::read
|
||||
(
|
||||
Pstream::commsTypes::blocking,
|
||||
slave,
|
||||
reinterpret_cast<char*>(&slaveValue),
|
||||
UPstream::commsTypes::blocking,
|
||||
proci,
|
||||
reinterpret_cast<char*>(&procValue),
|
||||
sizeof(scalar),
|
||||
UPstream::msgType(), // tag
|
||||
comm // communicator
|
||||
);
|
||||
|
||||
sum += slaveValue;
|
||||
sum += procValue;
|
||||
}
|
||||
|
||||
// Send back to slaves
|
||||
// Send back
|
||||
|
||||
for (const int slave : UPstream::subProcs(comm))
|
||||
for (const int proci : UPstream::subProcs(comm))
|
||||
{
|
||||
UOPstream::write
|
||||
(
|
||||
UPstream::commsTypes::blocking,
|
||||
slave,
|
||||
proci,
|
||||
reinterpret_cast<const char*>(&sum),
|
||||
sizeof(scalar),
|
||||
UPstream::msgType(), // tag
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2016-2020 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2024 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -52,27 +52,27 @@ void testMapDistribute()
|
||||
|
||||
// Generate random data.
|
||||
List<Tuple2<label, List<scalar>>> complexData(100);
|
||||
forAll(complexData, i)
|
||||
for (auto& data : complexData)
|
||||
{
|
||||
complexData[i].first() = rndGen.position(0, Pstream::nProcs()-1);
|
||||
complexData[i].second().setSize(3);
|
||||
complexData[i].second()[0] = 1;
|
||||
complexData[i].second()[1] = 2;
|
||||
complexData[i].second()[2] = 3;
|
||||
data.first() = rndGen.position(0, UPstream::nProcs()-1);
|
||||
data.second().resize(3);
|
||||
data.second()[0] = 1;
|
||||
data.second()[1] = 2;
|
||||
data.second()[2] = 3;
|
||||
}
|
||||
|
||||
// Send all ones to processor indicated by .first()
|
||||
|
||||
// Count how many to send
|
||||
labelList nSend(Pstream::nProcs(), Zero);
|
||||
forAll(complexData, i)
|
||||
labelList nSend(UPstream::nProcs(), Foam::zero{});
|
||||
for (const auto& data : complexData)
|
||||
{
|
||||
const label proci = complexData[i].first();
|
||||
const label proci = data.first();
|
||||
nSend[proci]++;
|
||||
}
|
||||
|
||||
// Collect items to be sent
|
||||
labelListList sendMap(Pstream::nProcs());
|
||||
labelListList sendMap(UPstream::nProcs());
|
||||
forAll(sendMap, proci)
|
||||
{
|
||||
sendMap[proci].resize_nocopy(nSend[proci]);
|
||||
@ -116,40 +116,31 @@ void testTransfer(const T& input)
|
||||
{
|
||||
T data = input;
|
||||
|
||||
if (Pstream::master())
|
||||
if (UPstream::master())
|
||||
{
|
||||
Perr<<"test transfer (" << (typeid(T).name()) << "): ";
|
||||
perrInfo(data) << nl << endl;
|
||||
}
|
||||
|
||||
if (Pstream::master())
|
||||
{
|
||||
for (const int slave : Pstream::subProcs())
|
||||
for (const int proci : UPstream::subProcs())
|
||||
{
|
||||
Perr<< "master receiving from slave " << slave << endl;
|
||||
IPstream fromSlave(Pstream::commsTypes::blocking, slave);
|
||||
fromSlave >> data;
|
||||
Perr<< "master receiving from proc:" << proci << endl;
|
||||
IPstream::recv(data, proci);
|
||||
perrInfo(data) << endl;
|
||||
}
|
||||
|
||||
for (const int slave : Pstream::subProcs())
|
||||
for (const int proci : UPstream::subProcs())
|
||||
{
|
||||
Perr<< "master sending to slave " << slave << endl;
|
||||
OPstream toSlave(Pstream::commsTypes::blocking, slave);
|
||||
toSlave << data;
|
||||
Perr<< "master sending to proc:" << proci << endl;
|
||||
OPstream::bsend(data, proci);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
Perr<< "slave sending to master " << Pstream::masterNo() << endl;
|
||||
OPstream toMaster(Pstream::commsTypes::blocking, Pstream::masterNo());
|
||||
toMaster << data;
|
||||
}
|
||||
Perr<< "proc sending to master" << endl;
|
||||
OPstream::bsend(data, UPstream::masterNo());
|
||||
|
||||
Perr<< "slave receiving from master " << Pstream::masterNo() << endl;
|
||||
IPstream fromMaster(Pstream::commsTypes::blocking, Pstream::masterNo());
|
||||
fromMaster >> data;
|
||||
Perr<< "proc receiving from master" << endl;
|
||||
IPstream::recv(data, UPstream::masterNo());
|
||||
perrInfo(data) << endl;
|
||||
}
|
||||
}
|
||||
@ -160,49 +151,31 @@ void testTokenized(const T& data)
|
||||
{
|
||||
token tok;
|
||||
|
||||
if (Pstream::master())
|
||||
if (UPstream::master())
|
||||
{
|
||||
Perr<<"test tokenized \"" << data << "\"" << nl << endl;
|
||||
}
|
||||
Perr<< "test tokenized \"" << data << "\"" << nl << endl;
|
||||
|
||||
if (Pstream::master())
|
||||
{
|
||||
for (const int slave : Pstream::subProcs())
|
||||
for (const int proci : UPstream::subProcs())
|
||||
{
|
||||
Perr<< "master receiving from slave " << slave << endl;
|
||||
IPstream fromSlave(Pstream::commsTypes::blocking, slave);
|
||||
fromSlave >> tok;
|
||||
Perr<< "master receiving from proc:" << proci << endl;
|
||||
IPstream::recv(tok, proci);
|
||||
Perr<< tok.info() << endl;
|
||||
}
|
||||
|
||||
for (const int slave : Pstream::subProcs())
|
||||
for (const int proci : UPstream::subProcs())
|
||||
{
|
||||
Perr<< "master sending to slave " << slave << endl;
|
||||
OPstream toSlave(Pstream::commsTypes::blocking, slave);
|
||||
toSlave << data;
|
||||
Perr<< "master sending to proc:" << proci << endl;
|
||||
OPstream::bsend(tok, proci);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
Perr<< "slave sending to master " << Pstream::masterNo() << endl;
|
||||
OPstream toMaster
|
||||
(
|
||||
Pstream::commsTypes::blocking,
|
||||
Pstream::masterNo()
|
||||
);
|
||||
Perr<< "proc sending to master" << endl;
|
||||
OPstream::bsend(tok, UPstream::masterNo());
|
||||
|
||||
toMaster << data;
|
||||
}
|
||||
Perr<< "proc receiving from master" << endl;
|
||||
IPstream::recv(tok, UPstream::masterNo());
|
||||
|
||||
Perr<< "slave receiving from master " << Pstream::masterNo() << endl;
|
||||
IPstream fromMaster
|
||||
(
|
||||
Pstream::commsTypes::blocking,
|
||||
Pstream::masterNo()
|
||||
);
|
||||
|
||||
fromMaster >> tok;
|
||||
Perr<< tok.info() << endl;
|
||||
}
|
||||
}
|
||||
@ -212,12 +185,14 @@ void testTokenized(const T& data)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
argList::noCheckProcessorDirectories();
|
||||
|
||||
#include "setRootCase.H"
|
||||
#include "createTime.H"
|
||||
|
||||
testMapDistribute();
|
||||
|
||||
if (!Pstream::parRun())
|
||||
if (!UPstream::parRun())
|
||||
{
|
||||
Info<< "\nWarning: not parallel - skipping further tests\n" << endl;
|
||||
return 0;
|
||||
|
||||
@ -51,7 +51,7 @@ void printConnection(Ostream& os, const label proci, const labelUList& below)
|
||||
// The number of receives - as per gatherList (v2112)
|
||||
void printRecvCount_gatherList
|
||||
(
|
||||
const List<UPstream::commsStruct>& comms,
|
||||
const UList<UPstream::commsStruct>& comms,
|
||||
const label comm = UPstream::worldComm
|
||||
)
|
||||
{
|
||||
@ -91,7 +91,7 @@ void printRecvCount_gatherList
|
||||
// The number of sends - as per scatterList (v2112)
|
||||
void printSendCount_scatterList
|
||||
(
|
||||
const List<UPstream::commsStruct>& comms,
|
||||
const UList<UPstream::commsStruct>& comms,
|
||||
const label comm = UPstream::worldComm
|
||||
)
|
||||
{
|
||||
@ -131,7 +131,7 @@ void printSendCount_scatterList
|
||||
// Transmission widths (contiguous data)
|
||||
void printWidths
|
||||
(
|
||||
const List<UPstream::commsStruct>& comms,
|
||||
const UList<UPstream::commsStruct>& comms,
|
||||
const label comm = UPstream::worldComm
|
||||
)
|
||||
{
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||
Copyright (C) 2021-2023 OpenCFD Ltd.
|
||||
Copyright (C) 2021-2024 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -71,6 +71,33 @@ public:
|
||||
const label comm = UPstream::worldComm,
|
||||
IOstreamOption::streamFormat fmt = IOstreamOption::BINARY
|
||||
);
|
||||
|
||||
|
||||
// Static Functions
|
||||
|
||||
//- Receive and deserialize a value.
|
||||
//- Uses \c operator>> for de-serialization
|
||||
template<class Type>
|
||||
static void recv
|
||||
(
|
||||
Type& value,
|
||||
const int fromProcNo,
|
||||
const int tag = UPstream::msgType(),
|
||||
const label comm = UPstream::worldComm,
|
||||
IOstreamOption::streamFormat fmt = IOstreamOption::BINARY
|
||||
)
|
||||
{
|
||||
IPstream is
|
||||
(
|
||||
UPstream::commsTypes::scheduled,
|
||||
fromProcNo,
|
||||
0, // bufSize
|
||||
tag,
|
||||
comm,
|
||||
fmt
|
||||
);
|
||||
is >> value;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||
Copyright (C) 2021-2023 OpenCFD Ltd.
|
||||
Copyright (C) 2021-2024 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -71,6 +71,73 @@ public:
|
||||
const label comm = UPstream::worldComm,
|
||||
IOstreamOption::streamFormat fmt = IOstreamOption::BINARY
|
||||
);
|
||||
|
||||
|
||||
// Static Functions
|
||||
|
||||
//- Serialize a value and send (buffered/blocking or standard mode).
|
||||
//- Uses \c operator<< for serialization
|
||||
template<class Type>
|
||||
static void send
|
||||
(
|
||||
const Type& value,
|
||||
//! blocking or scheduled only!
|
||||
const UPstream::commsTypes commsType,
|
||||
const int toProcNo,
|
||||
const int tag = UPstream::msgType(),
|
||||
const label comm = UPstream::worldComm,
|
||||
IOstreamOption::streamFormat fmt = IOstreamOption::BINARY
|
||||
)
|
||||
{
|
||||
OPstream os(commsType, toProcNo, 0, tag, comm, fmt);
|
||||
os << value;
|
||||
}
|
||||
|
||||
//- Serialize a value and send (buffered/blocking mode).
|
||||
//- Uses \c operator<< for serialization
|
||||
template<class Type>
|
||||
static void bsend
|
||||
(
|
||||
const Type& value,
|
||||
const int toProcNo,
|
||||
const int tag = UPstream::msgType(),
|
||||
const label comm = UPstream::worldComm,
|
||||
IOstreamOption::streamFormat fmt = IOstreamOption::BINARY
|
||||
)
|
||||
{
|
||||
OPstream::send
|
||||
(
|
||||
value,
|
||||
UPstream::commsTypes::blocking,
|
||||
toProcNo,
|
||||
tag,
|
||||
comm,
|
||||
fmt
|
||||
);
|
||||
}
|
||||
|
||||
//- Serialize a value and send (standard mode).
|
||||
//- Uses \c operator<< for serialization
|
||||
template<class Type>
|
||||
static void send
|
||||
(
|
||||
const Type& value,
|
||||
const int toProcNo,
|
||||
const int tag = UPstream::msgType(),
|
||||
const label comm = UPstream::worldComm,
|
||||
IOstreamOption::streamFormat fmt = IOstreamOption::BINARY
|
||||
)
|
||||
{
|
||||
OPstream::send
|
||||
(
|
||||
value,
|
||||
UPstream::commsTypes::scheduled,
|
||||
toProcNo,
|
||||
tag,
|
||||
comm,
|
||||
fmt
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2016-2023 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2024 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -170,7 +170,7 @@ public:
|
||||
|
||||
// Gather/combine data
|
||||
// Inplace combine values from processors.
|
||||
// (Uses construct from Istream instead of <<)
|
||||
// (Uses construct from Istream instead of \c << operator)
|
||||
|
||||
//- Gather data, applying \c cop to inplace combine \c value
|
||||
//- from different processors.
|
||||
@ -178,6 +178,7 @@ public:
|
||||
template<class T, class CombineOp>
|
||||
static void combineGather
|
||||
(
|
||||
//! [in,out]
|
||||
T& value,
|
||||
const CombineOp& cop,
|
||||
const int tag = UPstream::msgType(),
|
||||
@ -193,6 +194,7 @@ public:
|
||||
template<class T, class CombineOp>
|
||||
static void combineReduce
|
||||
(
|
||||
//! [in,out]
|
||||
T& value,
|
||||
const CombineOp& cop,
|
||||
const int tag = UPstream::msgType(),
|
||||
@ -220,7 +222,8 @@ public:
|
||||
template<class T, class CombineOp>
|
||||
static void listCombineGather
|
||||
(
|
||||
List<T>& values,
|
||||
//! [in,out]
|
||||
UList<T>& values,
|
||||
const CombineOp& cop,
|
||||
const int tag = UPstream::msgType(),
|
||||
const label comm = UPstream::worldComm
|
||||
@ -232,6 +235,7 @@ public:
|
||||
template<class T, class CombineOp>
|
||||
static void listCombineReduce
|
||||
(
|
||||
//! [in,out] - List (not UList) due to broadcast()
|
||||
List<T>& values,
|
||||
const CombineOp& cop,
|
||||
const int tag = UPstream::msgType(),
|
||||
@ -242,6 +246,7 @@ public:
|
||||
template<class T, class CombineOp>
|
||||
static void listCombineAllGather
|
||||
(
|
||||
//! [in,out] - List (not UList) due to broadcast()
|
||||
List<T>& values,
|
||||
const CombineOp& cop,
|
||||
const int tag = UPstream::msgType(),
|
||||
@ -305,8 +310,9 @@ public:
|
||||
template<class T>
|
||||
static void gatherList
|
||||
(
|
||||
const List<commsStruct>& comms,
|
||||
List<T>& values,
|
||||
const UList<commsStruct>& comms,
|
||||
//! [in,out]
|
||||
UList<T>& values,
|
||||
const int tag,
|
||||
const label comm
|
||||
);
|
||||
@ -316,7 +322,8 @@ public:
|
||||
template<class T>
|
||||
static void gatherList
|
||||
(
|
||||
List<T>& values,
|
||||
//! [in,out]
|
||||
UList<T>& values,
|
||||
const int tag = UPstream::msgType(),
|
||||
const label comm = UPstream::worldComm
|
||||
);
|
||||
@ -328,73 +335,35 @@ public:
|
||||
template<class T>
|
||||
static void allGatherList
|
||||
(
|
||||
List<T>& values,
|
||||
//! [in,out]
|
||||
UList<T>& values,
|
||||
const int tag = UPstream::msgType(),
|
||||
const label comm = UPstream::worldComm
|
||||
);
|
||||
|
||||
|
||||
// Scatter
|
||||
// Scatter
|
||||
|
||||
//- Broadcast data
|
||||
template<class T>
|
||||
FOAM_DEPRECATED_FOR(2024-01, "broadcast()")
|
||||
static void scatter
|
||||
(
|
||||
T& value,
|
||||
const int tag = UPstream::msgType(), //!< ignored
|
||||
const label comm = UPstream::worldComm
|
||||
);
|
||||
//- Inverse of gatherList.
|
||||
//- Uses the specified communication schedule.
|
||||
template<class T>
|
||||
static void scatterList
|
||||
(
|
||||
const UList<commsStruct>& comms,
|
||||
UList<T>& values,
|
||||
const int tag,
|
||||
const label comm
|
||||
);
|
||||
|
||||
//- Broadcast data
|
||||
template<class T>
|
||||
FOAM_DEPRECATED_FOR(2024-01, "broadcast()")
|
||||
static void combineScatter
|
||||
(
|
||||
T& value,
|
||||
const int tag = UPstream::msgType(), //!< ignored
|
||||
const label comm = UPstream::worldComm
|
||||
);
|
||||
|
||||
//- Broadcast data
|
||||
template<class T>
|
||||
FOAM_DEPRECATED_FOR(2024-01, "broadcast()")
|
||||
static void listCombineScatter
|
||||
(
|
||||
List<T>& value,
|
||||
const int tag = UPstream::msgType(), //!< ignored
|
||||
const label comm = UPstream::worldComm
|
||||
);
|
||||
|
||||
//- Broadcast data
|
||||
template<class Container>
|
||||
FOAM_DEPRECATED_FOR(2024-01, "broadcast()")
|
||||
static void mapCombineScatter
|
||||
(
|
||||
Container& values,
|
||||
const int tag = UPstream::msgType(), //!< ignored
|
||||
const label comm = UPstream::worldComm
|
||||
);
|
||||
|
||||
|
||||
//- Scatter data. Reverse of gatherList
|
||||
template<class T>
|
||||
static void scatterList
|
||||
(
|
||||
const List<commsStruct>& comms,
|
||||
List<T>& values,
|
||||
const int tag,
|
||||
const label comm
|
||||
);
|
||||
|
||||
//- Like above but switches between linear/tree communication
|
||||
template<class T>
|
||||
static void scatterList
|
||||
(
|
||||
List<T>& values,
|
||||
const int tag = UPstream::msgType(),
|
||||
const label comm = UPstream::worldComm
|
||||
);
|
||||
//- Inverse of gatherList.
|
||||
//- Uses linear/tree communication.
|
||||
template<class T>
|
||||
static void scatterList
|
||||
(
|
||||
UList<T>& values,
|
||||
const int tag = UPstream::msgType(),
|
||||
const label comm = UPstream::worldComm
|
||||
);
|
||||
|
||||
|
||||
// Exchange
|
||||
@ -573,6 +542,61 @@ public:
|
||||
const label comm,
|
||||
const bool wait = true //!< (ignored)
|
||||
);
|
||||
|
||||
|
||||
// Housekeeping
|
||||
|
||||
//- \deprecated(2024-01) Broadcast data
|
||||
template<class T>
|
||||
FOAM_DEPRECATED_FOR(2024-01, "Pstream::broadcast()")
|
||||
static void scatter
|
||||
(
|
||||
T& value,
|
||||
const int tag = UPstream::msgType(), //!< ignored
|
||||
const label comm = UPstream::worldComm
|
||||
)
|
||||
{
|
||||
Pstream::broadcast(value, comm);
|
||||
}
|
||||
|
||||
//- \deprecated(2024-01) Broadcast data
|
||||
template<class T>
|
||||
FOAM_DEPRECATED_FOR(2024-01, "Pstream::broadcast()")
|
||||
static void combineScatter
|
||||
(
|
||||
T& value,
|
||||
const int tag = UPstream::msgType(), //!< ignored
|
||||
const label comm = UPstream::worldComm
|
||||
)
|
||||
{
|
||||
Pstream::broadcast(value, comm);
|
||||
}
|
||||
|
||||
//- \deprecated(2024-01) Broadcast data
|
||||
template<class T>
|
||||
FOAM_DEPRECATED_FOR(2024-01, "Pstream::broadcast()")
|
||||
static void listCombineScatter
|
||||
(
|
||||
List<T>& value,
|
||||
const int tag = UPstream::msgType(), //!< ignored
|
||||
const label comm = UPstream::worldComm
|
||||
)
|
||||
{
|
||||
Pstream::broadcast(value, comm);
|
||||
}
|
||||
|
||||
//- \deprecated(2024-01) Broadcast data
|
||||
template<class Container>
|
||||
FOAM_DEPRECATED_FOR(2024-01, "Pstream::broadcast()")
|
||||
static void mapCombineScatter
|
||||
(
|
||||
Container& values,
|
||||
const int tag = UPstream::msgType(), //!< ignored
|
||||
const label comm = UPstream::worldComm
|
||||
)
|
||||
{
|
||||
Pstream::broadcast(values, comm);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -148,7 +148,11 @@ namespace Foam
|
||||
|
||||
//- Return a broadcasted value (uses a copy internally)
|
||||
template<class Type>
|
||||
Type returnBroadcast(const Type& value, const label comm)
|
||||
Type returnBroadcast
|
||||
(
|
||||
const Type& value,
|
||||
const label comm = UPstream::worldComm
|
||||
)
|
||||
{
|
||||
Type work(value);
|
||||
Pstream::broadcast(work, comm);
|
||||
|
||||
@ -107,7 +107,7 @@ void Foam::Pstream::combineGather
|
||||
}
|
||||
|
||||
// Send up value
|
||||
if (myComm.above() != -1)
|
||||
if (myComm.above() >= 0)
|
||||
{
|
||||
if (debug & 2)
|
||||
{
|
||||
@ -166,7 +166,7 @@ void Foam::Pstream::combineReduce
|
||||
template<class T, class CombineOp>
|
||||
void Foam::Pstream::listCombineGather
|
||||
(
|
||||
List<T>& values,
|
||||
UList<T>& values,
|
||||
const CombineOp& cop,
|
||||
const int tag,
|
||||
const label comm
|
||||
@ -233,7 +233,7 @@ void Foam::Pstream::listCombineGather
|
||||
}
|
||||
|
||||
// Send up values
|
||||
if (myComm.above() != -1)
|
||||
if (myComm.above() >= 0)
|
||||
{
|
||||
if (debug & 2)
|
||||
{
|
||||
@ -349,7 +349,7 @@ void Foam::Pstream::mapCombineGather
|
||||
}
|
||||
|
||||
// Send up values
|
||||
if (myComm.above() != -1)
|
||||
if (myComm.above() >= 0)
|
||||
{
|
||||
if (debug & 2)
|
||||
{
|
||||
|
||||
@ -26,7 +26,7 @@ License
|
||||
|
||||
Description
|
||||
Gather data from all processors onto single processor according to some
|
||||
communication schedule (usually linear-to-master or tree-to-master).
|
||||
communication schedule (usually tree-to-master).
|
||||
The gathered data will be a single value constructed from the values
|
||||
on individual processors using a user-specified operator.
|
||||
|
||||
@ -88,7 +88,7 @@ void Foam::Pstream::gather
|
||||
}
|
||||
|
||||
// Send up value
|
||||
if (myComm.above() != -1)
|
||||
if (myComm.above() >= 0)
|
||||
{
|
||||
if (is_contiguous<T>::value)
|
||||
{
|
||||
|
||||
@ -26,7 +26,7 @@ License
|
||||
|
||||
Description
|
||||
Gather data from all processors onto single processor according to some
|
||||
communication schedule (usually linear-to-master or tree-to-master).
|
||||
communication schedule (usually tree-to-master).
|
||||
The gathered data will be a list with element procID the data from processor
|
||||
procID. Before calling every processor should insert its value into
|
||||
values[UPstream::myProcNo(comm)].
|
||||
@ -45,24 +45,27 @@ Description
|
||||
template<class T>
|
||||
void Foam::Pstream::gatherList
|
||||
(
|
||||
const List<UPstream::commsStruct>& comms,
|
||||
List<T>& values,
|
||||
const UList<UPstream::commsStruct>& comms,
|
||||
UList<T>& values,
|
||||
const int tag,
|
||||
const label comm
|
||||
)
|
||||
{
|
||||
if (!comms.empty() && UPstream::is_parallel(comm))
|
||||
{
|
||||
if (values.size() < UPstream::nProcs(comm))
|
||||
const label myProci = UPstream::myProcNo(comm);
|
||||
const label numProc = UPstream::nProcs(comm);
|
||||
|
||||
if (values.size() < numProc)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "List of values is too small:" << values.size()
|
||||
<< " vs numProcs:" << UPstream::nProcs(comm) << nl
|
||||
<< "List of values:" << values.size()
|
||||
<< " < numProcs:" << numProc << nl
|
||||
<< Foam::abort(FatalError);
|
||||
}
|
||||
|
||||
// My communication order
|
||||
const auto& myComm = comms[UPstream::myProcNo(comm)];
|
||||
const auto& myComm = comms[myProci];
|
||||
|
||||
// Receive from my downstairs neighbours
|
||||
for (const label belowID : myComm.below())
|
||||
@ -127,21 +130,21 @@ void Foam::Pstream::gatherList
|
||||
// Send up from values:
|
||||
// - my own value first
|
||||
// - all belowLeaves next
|
||||
if (myComm.above() != -1)
|
||||
if (myComm.above() >= 0)
|
||||
{
|
||||
const labelList& belowLeaves = myComm.allBelow();
|
||||
|
||||
if (debug & 2)
|
||||
{
|
||||
Pout<< " sending to " << myComm.above()
|
||||
<< " data from me:" << UPstream::myProcNo(comm)
|
||||
<< " data:" << values[UPstream::myProcNo(comm)] << endl;
|
||||
<< " data from me:" << myProci
|
||||
<< " data:" << values[myProci] << endl;
|
||||
}
|
||||
|
||||
if (is_contiguous<T>::value)
|
||||
{
|
||||
List<T> sending(belowLeaves.size() + 1);
|
||||
sending[0] = values[UPstream::myProcNo(comm)];
|
||||
sending[0] = values[myProci];
|
||||
|
||||
forAll(belowLeaves, leafI)
|
||||
{
|
||||
@ -168,7 +171,7 @@ void Foam::Pstream::gatherList
|
||||
tag,
|
||||
comm
|
||||
);
|
||||
toAbove << values[UPstream::myProcNo(comm)];
|
||||
toAbove << values[myProci];
|
||||
|
||||
for (const label leafID : belowLeaves)
|
||||
{
|
||||
@ -189,8 +192,8 @@ void Foam::Pstream::gatherList
|
||||
template<class T>
|
||||
void Foam::Pstream::scatterList
|
||||
(
|
||||
const List<UPstream::commsStruct>& comms,
|
||||
List<T>& values,
|
||||
const UList<UPstream::commsStruct>& comms,
|
||||
UList<T>& values,
|
||||
const int tag,
|
||||
const label comm
|
||||
)
|
||||
@ -201,19 +204,22 @@ void Foam::Pstream::scatterList
|
||||
|
||||
if (!comms.empty() && UPstream::is_parallel(comm))
|
||||
{
|
||||
if (values.size() < UPstream::nProcs(comm))
|
||||
const label myProci = UPstream::myProcNo(comm);
|
||||
const label numProc = UPstream::nProcs(comm);
|
||||
|
||||
if (values.size() < numProc)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "List of values is too small:" << values.size()
|
||||
<< " vs numProcs:" << UPstream::nProcs(comm) << nl
|
||||
<< "List of values:" << values.size()
|
||||
<< " < numProcs:" << numProc << nl
|
||||
<< Foam::abort(FatalError);
|
||||
}
|
||||
|
||||
// My communication order
|
||||
const auto& myComm = comms[UPstream::myProcNo(comm)];
|
||||
const auto& myComm = comms[myProci];
|
||||
|
||||
// Receive from up
|
||||
if (myComm.above() != -1)
|
||||
if (myComm.above() >= 0)
|
||||
{
|
||||
const labelList& notBelowLeaves = myComm.allNotBelow();
|
||||
|
||||
@ -318,7 +324,7 @@ void Foam::Pstream::scatterList
|
||||
template<class T>
|
||||
void Foam::Pstream::gatherList
|
||||
(
|
||||
List<T>& values,
|
||||
UList<T>& values,
|
||||
const int tag,
|
||||
const label comm
|
||||
)
|
||||
@ -337,7 +343,7 @@ void Foam::Pstream::gatherList
|
||||
template<class T>
|
||||
void Foam::Pstream::scatterList
|
||||
(
|
||||
List<T>& values,
|
||||
UList<T>& values,
|
||||
const int tag,
|
||||
const label comm
|
||||
)
|
||||
@ -355,7 +361,7 @@ void Foam::Pstream::scatterList
|
||||
template<class T>
|
||||
void Foam::Pstream::allGatherList
|
||||
(
|
||||
List<T>& values,
|
||||
UList<T>& values,
|
||||
const int tag,
|
||||
const label comm
|
||||
)
|
||||
|
||||
@ -1202,6 +1202,7 @@ public:
|
||||
|
||||
//- Process index of first sub-process
|
||||
// \deprecated(2020-09) use subProcs() method instead
|
||||
FOAM_DEPRECATED_FOR(2020-09, "subProcs() method")
|
||||
static constexpr int firstSlave() noexcept
|
||||
{
|
||||
return 1;
|
||||
@ -1209,6 +1210,7 @@ public:
|
||||
|
||||
//- Process index of last sub-process
|
||||
// \deprecated(2020-09) use subProcs() method instead
|
||||
FOAM_DEPRECATED_FOR(2020-09, "subProcs() or allProcs() method")
|
||||
static int lastSlave(const label communicator = worldComm)
|
||||
{
|
||||
return nProcs(communicator) - 1;
|
||||
|
||||
@ -290,7 +290,7 @@ Foam::globalIndex::bin
|
||||
if (!globalIds.empty())
|
||||
{
|
||||
labelList& binOffsets = bins.offsets();
|
||||
binOffsets.resize(offsets.size(), Zero);
|
||||
binOffsets.resize(offsets.size(), Foam::zero{});
|
||||
|
||||
labelList& binValues = bins.values();
|
||||
binValues = UIndirectList<label>(globalIds, order);
|
||||
@ -372,7 +372,7 @@ void Foam::globalIndex::reset
|
||||
// TBD: check for (proci >= 0) ?
|
||||
const auto proci = UPstream::myProcNo(comm);
|
||||
|
||||
counts.resize(len, Zero);
|
||||
counts.resize(len, Foam::zero{});
|
||||
counts[proci] = localSize;
|
||||
}
|
||||
|
||||
|
||||
@ -83,6 +83,14 @@ class globalIndex
|
||||
DynamicList<label>& validBins
|
||||
);
|
||||
|
||||
// Cannot use non-blocking for non-contiguous data.
|
||||
// template<class Type>
|
||||
// inline static UPstream::commsTypes getCommsType
|
||||
// (
|
||||
// const UPstream::commsTypes preferred
|
||||
// = UPstream::commsTypes::nonBlocking
|
||||
// );
|
||||
|
||||
//- Report overflow at specified (non-negative) index
|
||||
static void reportOverflowAndExit
|
||||
(
|
||||
@ -187,7 +195,7 @@ public:
|
||||
inline label length() const noexcept;
|
||||
|
||||
//- Global sum of localSizes. Same as totalSize()
|
||||
FOAM_DEPRECATED_STRICT(2022-10, "totalSize() - less ambiguous")
|
||||
FOAM_DEPRECATED_STRICT(2022-10, "totalSize() - unambiguous")
|
||||
inline label size() const;
|
||||
|
||||
//- The span size covered by the offsets, zero if empty
|
||||
@ -722,10 +730,11 @@ public:
|
||||
//- Inplace collect data in processor order on master
|
||||
//- (in serial: a no-op).
|
||||
// Communication with default/specified communicator, message tag.
|
||||
// After the gather, the field is zero-sized on the slaves.
|
||||
// After the gather, the field is zero-sized on non-master.
|
||||
template<class Type>
|
||||
void gatherInplace
|
||||
(
|
||||
//! [in,out]
|
||||
List<Type>& fld,
|
||||
const int tag = UPstream::msgType(),
|
||||
const UPstream::commsTypes = UPstream::commsTypes::nonBlocking,
|
||||
@ -737,12 +746,11 @@ public:
|
||||
// Communication with default/specified communicator.
|
||||
// \attention The nProcs for globalIndex and communicator
|
||||
// must match!!
|
||||
//
|
||||
// The allData is output (master), zero-sized on non-master
|
||||
template<class Type, class OutputContainer = List<Type>>
|
||||
void mpiGather
|
||||
(
|
||||
const UList<Type>& sendData,
|
||||
//! [out] output on master, zero-sized on non-master
|
||||
OutputContainer& allData,
|
||||
const label comm = UPstream::worldComm, //!< communicator
|
||||
|
||||
@ -780,6 +788,7 @@ public:
|
||||
template<class Type>
|
||||
void mpiGatherInplace
|
||||
(
|
||||
//! [in,out]
|
||||
List<Type>& fld,
|
||||
const label comm = UPstream::worldComm, //!< communicator
|
||||
|
||||
@ -833,6 +842,7 @@ public:
|
||||
template<class Type>
|
||||
static void mpiGatherInplaceOp
|
||||
(
|
||||
//! [in,out]
|
||||
List<Type>& fld,
|
||||
const label comm = UPstream::worldComm, //!< communicator
|
||||
|
||||
@ -844,12 +854,11 @@ public:
|
||||
//- Collect data in processor order on master
|
||||
//- (in serial: performs a simple copy).
|
||||
// Communication with default/specified communicator, message tag.
|
||||
//
|
||||
// The allFld is output (master), zero-sized on non-master
|
||||
template<class Type>
|
||||
static void gatherOp
|
||||
(
|
||||
const UList<Type>& sendData,
|
||||
//! [out] output on master, zero-sized on non-master
|
||||
List<Type>& allData,
|
||||
const int tag = UPstream::msgType(),
|
||||
const UPstream::commsTypes = UPstream::commsTypes::nonBlocking,
|
||||
@ -859,12 +868,11 @@ public:
|
||||
//- Collect data in processor order on master
|
||||
//- (in serial: performs a simple copy).
|
||||
// Communication with default/specified communicator, message tag.
|
||||
//
|
||||
// The allFld is output (master), zero-sized on non-master
|
||||
template<class Type, class Addr>
|
||||
static void gatherOp
|
||||
(
|
||||
const IndirectListBase<Type, Addr>& sendData,
|
||||
//! [out] output on master, zero-sized on non-master
|
||||
List<Type>& allData,
|
||||
const int tag = UPstream::msgType(),
|
||||
const UPstream::commsTypes = UPstream::commsTypes::nonBlocking,
|
||||
@ -903,10 +911,11 @@ public:
|
||||
//- (in serial: a no-op).
|
||||
// Communication with default/specified communicator, message tag.
|
||||
//
|
||||
// After the gather, the field is zero-sized on the slaves.
|
||||
// After the gather, the field is zero-sized on non-master.
|
||||
template<class Type>
|
||||
static void gatherInplaceOp
|
||||
(
|
||||
//! [in,out]
|
||||
List<Type>& fld,
|
||||
const int tag = UPstream::msgType(),
|
||||
const UPstream::commsTypes = UPstream::commsTypes::nonBlocking,
|
||||
|
||||
@ -30,6 +30,25 @@ License
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
// Cannot use non-blocking for non-contiguous data.
|
||||
// template<class Type>
|
||||
// inline Foam::UPstream::commsTypes getCommsType
|
||||
// (
|
||||
// const UPstream::commsTypes preferred
|
||||
// )
|
||||
// {
|
||||
// return
|
||||
// (
|
||||
// (
|
||||
// !is_contiguous<Type>::value
|
||||
// && UPstream::commsTypes::nonBlocking == preferred
|
||||
// )
|
||||
// ? UPstream::commsTypes::scheduled
|
||||
// : preferred
|
||||
// );
|
||||
// }
|
||||
|
||||
|
||||
template<class Addr>
|
||||
Foam::labelList
|
||||
Foam::globalIndex::calcOffsets
|
||||
@ -115,8 +134,7 @@ void Foam::globalIndex::gatherValues
|
||||
{
|
||||
// low-level: no parRun guard
|
||||
|
||||
// Automatically change from nonBlocking to scheduled for
|
||||
// non-contiguous data.
|
||||
// Cannot use non-blocking for non-contiguous data.
|
||||
const UPstream::commsTypes commsType =
|
||||
(
|
||||
(
|
||||
@ -202,8 +220,7 @@ void Foam::globalIndex::gather
|
||||
{
|
||||
// low-level: no parRun guard
|
||||
|
||||
// Automatically change from nonBlocking to scheduled for
|
||||
// non-contiguous data.
|
||||
// Cannot use non-blocking for non-contiguous data.
|
||||
const UPstream::commsTypes commsType =
|
||||
(
|
||||
(
|
||||
@ -322,8 +339,7 @@ void Foam::globalIndex::gather
|
||||
return;
|
||||
}
|
||||
|
||||
// Automatically change from nonBlocking to scheduled for
|
||||
// non-contiguous data.
|
||||
// Cannot use non-blocking for non-contiguous data.
|
||||
const UPstream::commsTypes commsType =
|
||||
(
|
||||
(
|
||||
@ -907,8 +923,7 @@ void Foam::globalIndex::scatter
|
||||
{
|
||||
// low-level: no parRun guard
|
||||
|
||||
// Automatically change from nonBlocking to scheduled for
|
||||
// non-contiguous data.
|
||||
// Cannot use non-blocking for non-contiguous data.
|
||||
const UPstream::commsTypes commsType =
|
||||
(
|
||||
(
|
||||
|
||||
Reference in New Issue
Block a user