35 template<
class T,
class CombineOp,
class NegateOp>
47 const label len = map.
size();
51 for (label i = 0; i < len; ++i)
53 const label index = map[i];
57 cop(lhs[index-1], rhs[i]);
61 cop(lhs[-index-1], negOp(rhs[i]));
66 <<
"Illegal flip index '0' at " << i <<
'/' << map.
size()
67 <<
" for list:" << rhs.
size() <<
nl 74 for (label i = 0; i < len; ++i)
76 cop(lhs[map[i]], rhs[i]);
82 template<
class T,
class NegateOp>
92 const label len = map.size();
98 for (label i = 0; i < len; ++i)
100 const label index = map[i];
113 <<
"Illegal flip index '0' at " << i <<
'/' << map.size()
114 <<
" for list:" <<
values.size() <<
nl 122 for (label i = 0; i < len; ++i)
130 template<
class T,
class NegateOp>
136 const NegateOp& negOp
139 List<T>
output(map.size());
145 template<
class T,
class negateOp>
149 const bool subHasFlip,
151 const bool constructHasFlip,
160 const negateOp& negOp,
168 <<
"Only contiguous is currently supported" 178 recvRequests.
size() = 0;
180 recvFields.resize(nProcs);
184 const labelList& map = constructMap[proci];
190 else if (map.empty())
193 (void) recvFields.release(proci);
197 List<T>& subField = recvFields.try_emplace(proci);
204 subField.data_bytes(),
205 subField.size_bytes(),
218 sendRequests.
size() = 0;
220 sendFields.resize(nProcs);
229 (void) sendFields.release(proci);
231 else if (map.empty())
234 (void) sendFields.release(proci);
238 List<T>& subField = sendFields.try_emplace(proci);
241 accessAndFlip(subField,
field, map, subHasFlip, negOp);
247 subField.cdata_bytes(),
248 subField.size_bytes(),
266 (void) recvFields.release(myRank);
270 List<T>& subField = recvFields.try_emplace(myRank);
273 accessAndFlip(subField,
field, map, subHasFlip, negOp);
282 const UList<T>&
field,
283 labelRange& sendRequests,
284 PtrList<List<T>>& sendFields,
285 labelRange& recvRequests,
286 PtrList<List<T>>& recvFields,
297 sendRequests, sendFields,
298 recvRequests, recvFields,
306 template<
class T,
class CombineOp,
class negateOp>
309 const label constructSize,
311 const bool constructHasFlip,
315 const CombineOp& cop,
316 const negateOp& negOp,
324 <<
"Only contiguous is currently supported" 334 DynamicList<int> recvProcs(nProcs);
337 const labelList& map = constructMap[proci];
339 if (proci != myRank && map.size())
343 const auto* subFieldPtr = recvFields.get(proci);
346 checkReceivedSize(proci, map.size(), subFieldPtr->size());
351 <<
"From processor " << proci
352 <<
" : unallocated receive field" <<
nl 360 field.resize_nocopy(constructSize);
364 if (recvFields.test(myRank))
366 const labelList& map = constructMap[myRank];
367 const List<T>& subField = recvFields[myRank];
397 for (
const int proci : recvProcs)
399 const labelList& map = constructMap[proci];
400 const List<T>& subField = recvFields[proci];
422 const labelRange& requests,
423 const UPtrList<List<T>>& recvFields,
444 template<
class T,
class CombineOp,
class NegateOp>
449 const label constructSize,
451 const bool subHasFlip,
453 const bool constructHasFlip,
456 const CombineOp& cop,
457 const NegateOp& negOp,
471 accessAndFlip(
field, subMap[myRank], subHasFlip, negOp)
475 const labelList& map = constructMap[myRank];
478 field.resize_nocopy(constructSize);
504 if (proci != myRank && map.size())
516 accessAndFlip(
field, map, subHasFlip, negOp)
527 accessAndFlip(
field, subMap[myRank], subHasFlip, negOp)
531 const labelList& map = constructMap[myRank];
534 field.resize_nocopy(constructSize);
551 const labelList& map = constructMap[proci];
553 if (proci != myRank && map.size())
563 List<T> subField(is);
565 checkReceivedSize(proci, map.size(), subField.size());
585 newField.resize_nocopy(constructSize);
586 newField = nullValue;
593 accessAndFlip(
field, subMap[myRank], subHasFlip, negOp)
597 const labelList& map = constructMap[myRank];
612 for (
const labelPair& twoProcs : schedule)
617 if (twoProcs.first() == myRank)
620 const label nbrProc = twoProcs.second();
636 accessAndFlip(
field, map, subHasFlip, negOp)
650 List<T> subField(is);
651 const labelList& map = constructMap[nbrProc];
653 checkReceivedSize(nbrProc, map.size(), subField.size());
669 const label nbrProc = twoProcs.first();
680 List<T> subField(is);
681 const labelList& map = constructMap[nbrProc];
683 checkReceivedSize(nbrProc, map.size(), subField.size());
709 accessAndFlip(
field, map, subHasFlip, negOp)
716 field.transfer(newField);
722 if (!is_contiguous<T>::value)
731 if (proci != myRank && map.size())
733 UOPstream
os(proci, pBufs);
737 accessAndFlip(
field, map, subHasFlip, negOp)
751 accessAndFlip(
field, subMap[myRank], subHasFlip, negOp)
755 field.resize_nocopy(constructSize);
759 const labelList& map = constructMap[myRank];
778 const labelList& map = constructMap[proci];
780 if (proci != myRank && map.size())
782 UIPstream is(proci, pBufs);
783 List<T> subField(is);
785 checkReceivedSize(proci, map.size(), subField.size());
803 List<List<T>> recvFields(nProcs);
804 DynamicList<int> recvProcs(nProcs);
808 const labelList& map = constructMap[proci];
810 if (proci != myRank && map.size())
813 List<T>& subField = recvFields[proci];
814 subField.resize_nocopy(map.size());
820 subField.data_bytes(),
821 subField.size_bytes(),
831 List<List<T>> sendFields(nProcs);
837 if (proci != myRank && map.size())
839 List<T>& subField = sendFields[proci];
842 accessAndFlip(subField,
field, map, subHasFlip, negOp);
848 subField.cdata_bytes(),
849 subField.size_bytes(),
859 List<T>& subField = recvFields[myRank];
862 accessAndFlip(subField,
field, map, subHasFlip, negOp);
867 field.resize_nocopy(constructSize);
872 const labelList& map = constructMap[myRank];
873 const List<T>& subField = recvFields[myRank];
891 DynamicList<int> indices(recvProcs.size());
902 for (
const int idx : indices)
904 const int proci = recvProcs[idx];
905 const labelList& map = constructMap[proci];
906 const List<T>& subField = recvFields[proci];
930 <<
"Unknown communication schedule " << int(commsType)
936 template<
class T,
class NegateOp>
940 const List<labelPair>& schedule,
941 const label constructSize,
943 const bool subHasFlip,
945 const bool constructHasFlip,
947 const NegateOp& negOp,
961 accessAndFlip(
field, subMap[myRank], subHasFlip, negOp)
965 const labelList& map = constructMap[myRank];
968 field.resize_nocopy(constructSize);
993 if (proci != myRank && map.size())
1006 accessAndFlip(
field, map, subHasFlip, negOp)
1017 accessAndFlip(
field, subMap[myRank], subHasFlip, negOp)
1021 const labelList& map = constructMap[myRank];
1024 field.resize_nocopy(constructSize);
1040 const labelList& map = constructMap[proci];
1042 if (proci != myRank && map.size())
1052 List<T> subField(is);
1054 checkReceivedSize(proci, map.size(), subField.size());
1074 newField.resize_nocopy(constructSize);
1081 accessAndFlip(
field, subMap[myRank], subHasFlip, negOp)
1085 const labelList& map = constructMap[myRank];
1099 for (
const labelPair& twoProcs : schedule)
1104 if (twoProcs.first() == myRank)
1107 const label nbrProc = twoProcs.second();
1122 accessAndFlip(
field, map, subHasFlip, negOp)
1136 List<T> subField(is);
1138 const labelList& map = constructMap[nbrProc];
1140 checkReceivedSize(nbrProc, map.size(), subField.size());
1156 const label nbrProc = twoProcs.first();
1167 List<T> subField(is);
1169 const labelList& map = constructMap[nbrProc];
1171 checkReceivedSize(nbrProc, map.size(), subField.size());
1196 accessAndFlip(
field, map, subHasFlip, negOp)
1203 field.transfer(newField);
1209 if (!is_contiguous<T>::value)
1218 if (proci != myRank && map.size())
1220 UOPstream
os(proci, pBufs);
1224 accessAndFlip(
field, map, subHasFlip, negOp)
1238 accessAndFlip(
field, subMap[myRank], subHasFlip, negOp)
1242 field.resize_nocopy(constructSize);
1245 const labelList& map = constructMap[myRank];
1264 const labelList& map = constructMap[proci];
1266 if (proci != myRank && map.size())
1268 UIPstream is(proci, pBufs);
1269 List<T> subField(is);
1271 checkReceivedSize(proci, map.size(), subField.size());
1289 List<List<T>> recvFields(nProcs);
1290 DynamicList<int> recvProcs(nProcs);
1294 const labelList& map = constructMap[proci];
1296 if (proci != myRank && map.size())
1299 List<T>& subField = recvFields[proci];
1300 subField.resize_nocopy(map.size());
1306 subField.data_bytes(),
1307 subField.size_bytes(),
1317 List<List<T>> sendFields(nProcs);
1323 if (proci != myRank && map.size())
1325 List<T>& subField = sendFields[proci];
1328 accessAndFlip(subField,
field, map, subHasFlip, negOp);
1334 subField.cdata_bytes(),
1335 subField.size_bytes(),
1345 List<T>& subField = recvFields[myRank];
1348 accessAndFlip(subField,
field, map, subHasFlip, negOp);
1353 field.resize_nocopy(constructSize);
1358 const labelList& map = constructMap[myRank];
1359 const List<T>& subField = recvFields[myRank];
1377 DynamicList<int> indices(recvProcs.size());
1388 for (
const int idx : indices)
1390 const int proci = recvProcs[idx];
1391 const labelList& map = constructMap[proci];
1392 const List<T>& subField = recvFields[proci];
1416 <<
"Unknown communication schedule " << int(commsType)
1425 PstreamBuffers& pBufs,
1426 const List<T>&
field 1436 UOPstream
os(proci, pBufs);
1440 accessAndFlip(
field, map, subHasFlip_, flipOp())
1448 pBufs.finishedSends(
false);
1460 field.resize_nocopy(constructSize_);
1464 const labelList& map = constructMap_[proci];
1471 checkReceivedSize(proci, map.
size(), subField.
size());
1487 template<
class T,
class NegateOp>
1492 const NegateOp& negOp,
1499 whichSchedule(commsType),
1513 template<
class T,
class NegateOp>
1519 const NegateOp& negOp,
1526 whichSchedule(commsType),
1542 template<
class T,
class NegateOp>
1546 const NegateOp& negOp,
1581 distribute(commsType, list, tag);
1613 const label constructSize,
1618 reverseDistribute<T, flipOp>
1629 template<
class T,
class NegateOp>
1633 const label constructSize,
1635 const NegateOp& negOp,
1642 whichSchedule(commsType),
1660 const label constructSize,
1669 whichSchedule(commsType),
1690 const label constructSize,
1708 const label constructSize,
void size(const label n)
Older name for setAddressableSize.
"blocking" : (MPI_Bsend, MPI_Recv)
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.
errorManipArg< error, int > exit(error &err, const int errNo=1)
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 void accessAndFlip(List< T > &output, const UList< T > &values, const labelUList &map, const bool hasFlip, const NegateOp &negOp)
Lookup field values at specified map indices and save after any flip negation operations.
void send(PstreamBuffers &pBufs, const List< T > &field) const
Do all sends using PstreamBuffers.
static label nRequests() noexcept
Number of outstanding requests (on the internal list of requests)
static rangeType allProcs(const label communicator=worldComm)
Range of process indices for all processes.
A range or interval of labels defined by a start and a size.
constexpr char nl
The newline '\n' character (0x0a)
static bool & parRun() noexcept
Test if this a parallel run.
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...
void push_back(const T &val)
Append an element at the end of the list.
List< labelList > labelListList
List of labelList.
static void waitRequests()
Wait for all requests to finish.
UList< label > labelUList
A UList of labels.
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
Input inter-processor communications stream using MPI send/recv etc. - operating on external buffer...
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run. ...
"scheduled" : (MPI_Send, MPI_Recv)
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
void finishedSends(const bool wait=true)
Mark the send phase as being finished.
void reverseDistribute(const label constructSize, List< T > &values, const int tag=UPstream::msgType()) const
Reverse distribute data using default commsType and the default flip/negate operator.
IntType start() const noexcept
The (inclusive) lower value of the range.
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
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...
Pair< label > labelPair
A pair of labels.
OBJstream os(runTime.globalPath()/outputName)
Buffers for inter-processor communications streams (UOPstream, UIPstream).
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
void receive(PstreamBuffers &pBufs, List< T > &field) const
Do all receives using PstreamBuffers.
static commsTypes defaultCommsType
Default commsType.
static void flipAndCombine(List< T > &lhs, const UList< T > &rhs, const labelUList &map, const bool hasFlip, const CombineOp &cop, const NegateOp &negOp)
Combine field values (after any flip negation operation) into the specified mapped target locations...
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
A template class to specify that a data type can be considered as being contiguous in memory...
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 Ostream & output(Ostream &os, const IntRange< T > &range)
List< label > labelList
A List of labels.
IntType size() const noexcept
The size of the range.
Functor to negate primitives. Dummy for most other types.
static void distribute(const UPstream::commsTypes commsType, const List< labelPair > &schedule, const label constructSize, const labelListList &subMap, const bool subHasFlip, const labelListList &constructMap, const bool constructHasFlip, List< T > &field, const T &nullValue, const CombineOp &cop, const NegateOp &negOp, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Distribute combine data with specified combine operation and negate operator (for flips)...
static bool waitSomeRequests(const label pos, label len=-1, DynamicList< int > *indices=nullptr)
Wait until some requests (from position onwards) have finished. Corresponds to MPI_Waitsome() ...