33 template<
class T,
class CombineOp,
class negateOp>
40 const negateOp& negOp,
50 label index = map[i]-1;
51 cop(lhs[index], rhs[i]);
55 label index = -map[i]-1;
56 cop(lhs[index], negOp(rhs[i]));
61 <<
"At index " << i <<
" out of " << map.
size()
62 <<
" have illegal index " << map[i]
63 <<
" for field " << rhs.
size() <<
" with flipMap" 72 cop(lhs[map[i]], rhs[i]);
78 template<
class T,
class negateOp>
96 t = negOp(fld[-index-1]);
101 <<
"Illegal index " << index
102 <<
" into field of size " << fld.
size()
103 <<
" with face-flipping" 117 template<
class T,
class negateOp>
122 const label constructSize,
124 const bool subHasFlip,
126 const bool constructHasFlip,
128 const negateOp& negOp,
132 if (!Pstream::parRun())
136 const labelList& mySubMap = subMap[Pstream::myProcNo()];
141 subField[i] = accessAndFlip(field, mySubMap[i], subHasFlip, negOp);
145 const labelList& map = constructMap[Pstream::myProcNo()];
162 if (commsType == Pstream::blocking)
168 for (
label domain = 0; domain < Pstream::nProcs(); domain++)
172 if (domain != Pstream::myProcNo() && map.
size())
174 OPstream toNbr(Pstream::blocking, domain, 0, tag);
179 subField[i] = accessAndFlip
192 const labelList& mySubMap = subMap[Pstream::myProcNo()];
197 subField[i] = accessAndFlip(field, mySubMap[i], subHasFlip, negOp);
201 const labelList& map = constructMap[Pstream::myProcNo()];
216 for (
label domain = 0; domain < Pstream::nProcs(); domain++)
218 const labelList& map = constructMap[domain];
220 if (domain != Pstream::myProcNo() && map.
size())
222 IPstream fromNbr(Pstream::blocking, domain, 0, tag);
225 checkReceivedSize(domain, map.
size(), subField.
size());
239 else if (commsType == Pstream::scheduled)
244 List<T> newField(constructSize);
248 const labelList& mySubMap = subMap[Pstream::myProcNo()];
253 subField[i] = accessAndFlip
265 constructMap[Pstream::myProcNo()],
281 label sendProc = twoProcs[0];
282 label recvProc = twoProcs[1];
284 if (Pstream::myProcNo() == sendProc)
288 OPstream toNbr(Pstream::scheduled, recvProc, 0, tag);
294 subField[i] = accessAndFlip
305 IPstream fromNbr(Pstream::scheduled, recvProc, 0, tag);
308 const labelList& map = constructMap[recvProc];
310 checkReceivedSize(recvProc, map.
size(), subField.
size());
327 IPstream fromNbr(Pstream::scheduled, sendProc, 0, tag);
330 const labelList& map = constructMap[sendProc];
332 checkReceivedSize(sendProc, map.
size(), subField.
size());
345 OPstream toNbr(Pstream::scheduled, sendProc, 0, tag);
351 subField[i] = accessAndFlip
365 else if (commsType == Pstream::nonBlocking)
367 label nOutstanding = Pstream::nRequests();
369 if (!contiguous<T>())
374 for (
label domain = 0; domain < Pstream::nProcs(); domain++)
378 if (domain != Pstream::myProcNo() && map.
size())
386 subField[i] = accessAndFlip
394 toDomain << subField;
403 const labelList& mySub = subMap[Pstream::myProcNo()];
407 mySubField[i] = accessAndFlip
419 const labelList& map = constructMap[Pstream::myProcNo()];
434 Pstream::waitRequests(nOutstanding);
437 for (
label domain = 0; domain < Pstream::nProcs(); domain++)
439 const labelList& map = constructMap[domain];
441 if (domain != Pstream::myProcNo() && map.
size())
446 checkReceivedSize(domain, map.
size(), recvField.
size());
466 for (
label domain = 0; domain < Pstream::nProcs(); domain++)
470 if (domain != Pstream::myProcNo() && map.
size())
472 List<T>& subField = sendFields[domain];
476 subField[i] = accessAndFlip
487 Pstream::nonBlocking,
489 reinterpret_cast<const char*>(subField.
begin()),
500 for (
label domain = 0; domain < Pstream::nProcs(); domain++)
502 const labelList& map = constructMap[domain];
504 if (domain != Pstream::myProcNo() && map.
size())
509 Pstream::nonBlocking,
511 reinterpret_cast<char*>(recvFields[domain].begin()),
512 recvFields[domain].byteSize(),
522 const labelList& map = subMap[Pstream::myProcNo()];
524 List<T>& subField = sendFields[Pstream::myProcNo()];
528 subField[i] = accessAndFlip
546 const labelList& map = constructMap[Pstream::myProcNo()];
547 const List<T>& subField = sendFields[Pstream::myProcNo()];
563 Pstream::waitRequests(nOutstanding);
568 for (
label domain = 0; domain < Pstream::nProcs(); domain++)
570 const labelList& map = constructMap[domain];
572 if (domain != Pstream::myProcNo() && map.
size())
574 const List<T>& subField = recvFields[domain];
576 checkReceivedSize(domain, map.
size(), subField.
size());
594 <<
"Unknown communication schedule " << commsType
601 template<
class T,
class CombineOp,
class negateOp>
606 const label constructSize,
608 const bool subHasFlip,
610 const bool constructHasFlip,
612 const CombineOp& cop,
613 const negateOp& negOp,
618 if (!Pstream::parRun())
622 const labelList& mySubMap = subMap[Pstream::myProcNo()];
627 subField[i] = accessAndFlip(field, mySubMap[i], subHasFlip, negOp);
631 const labelList& map = constructMap[Pstream::myProcNo()];
636 flipAndCombine(map, constructHasFlip, subField, cop, negOp, field);
641 if (commsType == Pstream::blocking)
647 for (
label domain = 0; domain < Pstream::nProcs(); domain++)
651 if (domain != Pstream::myProcNo() && map.
size())
653 OPstream toNbr(Pstream::blocking, domain, 0, tag);
657 subField[i] = accessAndFlip
670 const labelList& mySubMap = subMap[Pstream::myProcNo()];
675 subField[i] = accessAndFlip(field, mySubMap[i], subHasFlip, negOp);
679 const labelList& map = constructMap[Pstream::myProcNo()];
684 flipAndCombine(map, constructHasFlip, subField, cop, negOp, field);
687 for (
label domain = 0; domain < Pstream::nProcs(); domain++)
689 const labelList& map = constructMap[domain];
691 if (domain != Pstream::myProcNo() && map.
size())
693 IPstream fromNbr(Pstream::blocking, domain, 0, tag);
696 checkReceivedSize(domain, map.
size(), subField.
size());
710 else if (commsType == Pstream::scheduled)
715 List<T> newField(constructSize, nullValue);
718 const labelList& mySubMap = subMap[Pstream::myProcNo()];
724 subField[i] = accessAndFlip
734 const labelList& map = constructMap[Pstream::myProcNo()];
755 label sendProc = twoProcs[0];
756 label recvProc = twoProcs[1];
758 if (Pstream::myProcNo() == sendProc)
762 OPstream toNbr(Pstream::scheduled, recvProc, 0, tag);
769 subField[i] = accessAndFlip
780 IPstream fromNbr(Pstream::scheduled, recvProc, 0, tag);
782 const labelList& map = constructMap[recvProc];
784 checkReceivedSize(recvProc, map.
size(), subField.
size());
801 IPstream fromNbr(Pstream::scheduled, sendProc, 0, tag);
803 const labelList& map = constructMap[sendProc];
805 checkReceivedSize(sendProc, map.
size(), subField.
size());
818 OPstream toNbr(Pstream::scheduled, sendProc, 0, tag);
825 subField[i] = accessAndFlip
839 else if (commsType == Pstream::nonBlocking)
841 label nOutstanding = Pstream::nRequests();
843 if (!contiguous<T>())
848 for (
label domain = 0; domain < Pstream::nProcs(); domain++)
852 if (domain != Pstream::myProcNo() && map.
size())
860 subField[i] = accessAndFlip
868 toDomain << subField;
877 const labelList& myMap = subMap[Pstream::myProcNo()];
882 mySubField[i] = accessAndFlip
896 const labelList& map = constructMap[Pstream::myProcNo()];
911 Pstream::waitRequests(nOutstanding);
914 for (
label domain = 0; domain < Pstream::nProcs(); domain++)
916 const labelList& map = constructMap[domain];
918 if (domain != Pstream::myProcNo() && map.
size())
923 checkReceivedSize(domain, map.
size(), recvField.
size());
943 for (
label domain = 0; domain < Pstream::nProcs(); domain++)
947 if (domain != Pstream::myProcNo() && map.
size())
949 List<T>& subField = sendFields[domain];
953 subField[i] = accessAndFlip
964 Pstream::nonBlocking,
966 reinterpret_cast<const char*>(subField.
begin()),
967 subField.
size()*
sizeof(
T),
977 for (
label domain = 0; domain < Pstream::nProcs(); domain++)
979 const labelList& map = constructMap[domain];
981 if (domain != Pstream::myProcNo() && map.
size())
986 Pstream::nonBlocking,
988 reinterpret_cast<char*>(recvFields[domain].begin()),
989 recvFields[domain].size()*
sizeof(
T),
998 const labelList& map = subMap[Pstream::myProcNo()];
1000 List<T>& subField = sendFields[Pstream::myProcNo()];
1004 subField[i] = accessAndFlip
1022 const labelList& map = constructMap[Pstream::myProcNo()];
1023 const List<T>& subField = sendFields[Pstream::myProcNo()];
1039 Pstream::waitRequests(nOutstanding);
1044 for (
label domain = 0; domain < Pstream::nProcs(); domain++)
1046 const labelList& map = constructMap[domain];
1048 if (domain != Pstream::myProcNo() && map.
size())
1050 const List<T>& subField = recvFields[domain];
1052 checkReceivedSize(domain, map.
size(), subField.
size());
1070 <<
"Unknown communication schedule " << commsType
1101 toDomain << subField;
1126 if (recvField.
size() != map.
size())
1129 <<
"Expected from processor " << domain
1130 <<
" " << map.
size() <<
" but received " 1131 << recvField.
size() <<
" elements." 1150 template<
class T,
class negateOp>
1154 const negateOp& negOp,
1243 const label constructSize,
1305 const label constructSize,
Class containing functor to negate primitives. Dummy for all other types.
#define forAll(list, i)
Loop across all elements in list.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
void finishedSends(const bool block=true)
Mark all sends as having been done. This will start receives.
errorManipArg< error, int > exit(error &err, const int errNo=1)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
commsTypes
Types of communications.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
void size(const label)
Override size to be inconsistent with allocated storage.
labelListList subMap_
Maps from subsetted data back to original data.
Combination-Reduction operation for a parallel run. The information from all nodes is collected on th...
label constructSize_
Size of reconstructed data.
Input inter-processor communications stream.
Input inter-processor communications stream operating on external buffer.
std::streamsize byteSize() const
Return the binary size in number of characters of the UList.
bool read(const char *, int32_t &)
An ordered pair of two objects of type <T> with first() and second() elements.
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().x()<< ' ';}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().y()<< ' ';}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().z()<< ' ';}gmvFile<< nl;forAll(lagrangianScalarNames, i){const word &name=lagrangianScalarNames[i];IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
static T accessAndFlip(const UList< T > &fld, const label index, const bool hasFlip, const negateOp &negOp)
void setCapacity(const label)
Alter the size of the underlying storage.
iterator begin()
Return an iterator to begin traversing the UList.
static void distribute(const Pstream::commsTypes commsType, const List< labelPair > &schedule, const label constructSize, const labelListList &subMap, const bool subHasFlip, const labelListList &constructMap, const bool constructHasFlip, List< T > &, const negateOp &negOp, const int tag=UPstream::msgType())
Distribute data. Note:schedule only used for Pstream::scheduled.
errorManip< error > abort(error &err)
labelListList constructMap_
Maps from subsetted data to new reconstructed data.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Output inter-processor communications stream operating on external buffer.
DynamicList< T, SizeInc, SizeMult, SizeDiv > & shrink()
Shrink the allocated space to the number of elements used.
const List< labelPair > & schedule() const
Return a schedule. Demand driven. See above.
Output inter-processor communications stream.
Buffers for inter-processor communications streams (UOPstream, UIPstream).
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
bool subHasFlip_
Whether subMap includes flip or not.
label size() const
Return the number of elements in the UList.
static commsTypes defaultCommsType
Default commsType.
void setSize(const label)
Reset size of List.
static label nProcs(const label communicator=0)
Number of processes in parallel run.
bool constructHasFlip_
Whether constructMap includes flip or not.
void send(PstreamBuffers &, const List< T > &) const
Do all sends using PstreamBuffers.
void reverseDistribute(const label constructSize, List< T > &, const int tag=UPstream::msgType()) const
Reverse distribute data using default commsType.
void receive(PstreamBuffers &, List< T > &) const
Do all receives using PstreamBuffers.
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
static void flipAndCombine(const UList< label > &map, const bool hasFlip, const UList< T > &rhs, const CombineOp &cop, const negateOp &negOp, List< T > &lhs)