48 for (
const label val : map)
70 for (
const label val : map)
99 for (label index : map)
103 index =
mag(index)-1;
106 maxIndex =
max(maxIndex, index);
121 if (elements.empty())
128 bitSet unvisited(elements);
129 label nUnmapped = unvisited.count();
135 for (label index : map)
137 index =
mag(index)-1;
139 if (unvisited.unset(index))
142 if (!nUnmapped)
break;
151 for (label index : map)
153 if (unvisited.unset(index))
156 if (!nUnmapped)
break;
169 const label expectedSize,
170 const label receivedSize
173 if (receivedSize != expectedSize)
176 <<
"From processor " << proci
177 <<
" : expected " << expectedSize
178 <<
" but received " << receivedSize <<
" elements" <<
nl 198 List<labelPair> allComms;
208 if (subMap[proci].size())
211 commsSet.insert(
labelPair(myRank, proci));
213 if (constructMap[proci].size())
216 commsSet.insert(
labelPair(proci, myRank));
220 allComms = commsSet.toc();
230 List<labelPair> nbrData;
233 for (
const labelPair& connection : nbrData)
235 allComms.push_uniq(connection);
257 ).procSchedule()[myRank]
278 return *schedulePtr_;
304 forAll(constructMap_, proci)
306 const labelList& construct = constructMap_[proci];
307 if (constructHasFlip_)
311 label index =
mag(construct[i])-1;
312 minIndex[proci] =
min(minIndex[proci], index);
313 maxIndex[proci] =
max(maxIndex[proci], index);
320 label index = construct[i];
321 minIndex[proci] =
min(minIndex[proci], index);
322 maxIndex[proci] =
max(maxIndex[proci], index);
331 localSize = maxIndex[myRank]+1;
334 os <<
"Layout: (constructSize:" << constructSize_
335 <<
" subHasFlip:" << subHasFlip_
336 <<
" constructHasFlip:" << constructHasFlip_
338 <<
"local (processor " << myRank <<
"):" <<
nl 339 <<
" start : 0" <<
nl 340 <<
" size : " << localSize <<
endl;
342 label offset = localSize;
345 if (proci != myRank && !constructMap_[proci].empty())
351 size = maxIndex[proci]-minIndex[proci]+1;
352 if (minIndex[proci] != offset)
355 <<
"offset:" << offset
356 <<
" proci:" << proci
357 <<
" minIndex:" << minIndex[proci]
362 os <<
"processor " << proci <<
':' <<
nl 363 <<
" start : " << offset <<
nl 364 <<
" size : " << size <<
endl;
374 const globalIndex& globalNumbering,
376 List<Map<label>>& compactMap
385 for (
const label globalIdx : elements)
387 if (globalIdx != -1 && !globalNumbering.isLocal(myRank, globalIdx))
389 label proci = globalNumbering.whichProcID(myRank, globalIdx);
394 compactMap.resize_nocopy(nProcs);
398 compactMap[proci].clear();
401 compactMap[proci].reserve(nNonLocal[proci]);
407 for (
const label globalIdx : elements)
409 if (globalIdx != -1 && !globalNumbering.isLocal(myRank, globalIdx))
411 label proci = globalNumbering.whichProcID(myRank, globalIdx);
412 label index = globalNumbering.toLocal(proci, globalIdx);
413 compactMap[proci].insert(index, compactMap[proci].size());
421 const globalIndex& globalNumbering,
423 List<Map<label>>& compactMap
432 for (
const labelList& cCells : cellCells)
434 for (
const label globalIdx : cCells)
436 if (globalIdx != -1 && !globalNumbering.isLocal(myRank, globalIdx))
438 label proci = globalNumbering.whichProcID(myRank, globalIdx);
444 compactMap.resize_nocopy(nProcs);
448 compactMap[proci].clear();
451 compactMap[proci].reserve(nNonLocal[proci]);
457 for (
const labelList& cCells : cellCells)
459 for (
const label globalIdx : cCells)
461 if (globalIdx != -1 && !globalNumbering.isLocal(myRank, globalIdx))
463 label proci = globalNumbering.whichProcID(myRank, globalIdx);
464 label index = globalNumbering.toLocal(proci, globalIdx);
465 compactMap[proci].insert(index, compactMap[proci].size());
475 const globalIndex& globalNumbering,
477 List<Map<label>>& compactMap,
488 compactStart.setSize(nProcs);
489 compactStart[myRank] = 0;
490 constructSize_ = globalNumbering.localSize(myRank);
491 forAll(compactStart, proci)
495 compactStart[proci] = constructSize_;
496 constructSize_ += compactMap[proci].size();
506 constructMap_.setSize(nProcs);
512 label nLocal = globalNumbering.localSize(myRank);
513 wantedRemoteElements[proci] =
identity(nLocal);
514 constructMap_[proci] =
identity(nLocal);
519 labelList& remoteElem = wantedRemoteElements[proci];
520 labelList& localElem = constructMap_[proci];
521 remoteElem.
setSize(compactMap[proci].size());
522 localElem.setSize(compactMap[proci].size());
526 const label compactI = compactStart[proci] + iter.val();
527 remoteElem[i] = iter.key();
528 localElem[i] = compactI;
529 iter.val() = compactI;
535 subMap_.setSize(nProcs);
536 Pstream::exchange<labelList, label>
538 wantedRemoteElements,
545 for (label& elem : elements)
547 elem =
renumber(globalNumbering, comm_, compactMap, elem);
555 const globalIndex& globalNumbering,
557 List<Map<label>>& compactMap,
568 compactStart.setSize(nProcs);
569 compactStart[myRank] = 0;
570 constructSize_ = globalNumbering.localSize(myRank);
571 forAll(compactStart, proci)
575 compactStart[proci] = constructSize_;
576 constructSize_ += compactMap[proci].size();
586 constructMap_.setSize(nProcs);
592 label nLocal = globalNumbering.localSize(myRank);
593 wantedRemoteElements[proci] =
identity(nLocal);
594 constructMap_[proci] =
identity(nLocal);
599 labelList& remoteElem = wantedRemoteElements[proci];
600 labelList& localElem = constructMap_[proci];
601 remoteElem.
setSize(compactMap[proci].size());
602 localElem.setSize(compactMap[proci].size());
606 const label compactI = compactStart[proci] + iter.val();
607 remoteElem[i] = iter.key();
608 localElem[i] = compactI;
609 iter.val() = compactI;
615 subMap_.setSize(nProcs);
616 Pstream::exchange<labelList, label>
618 wantedRemoteElements,
627 for (label& celli : cCells)
629 celli =
renumber(globalNumbering, comm_, compactMap, celli);
649 constructHasFlip_(
false),
651 schedulePtr_(
nullptr)
657 constructSize_(map.constructSize_),
658 subMap_(map.subMap_),
659 constructMap_(map.constructMap_),
660 subHasFlip_(map.subHasFlip_),
661 constructHasFlip_(map.constructHasFlip_),
663 schedulePtr_(nullptr)
677 const label constructSize,
680 const bool subHasFlip,
681 const bool constructHasFlip,
685 constructSize_(constructSize),
686 subMap_(
std::move(subMap)),
687 constructMap_(
std::move(constructMap)),
688 subHasFlip_(subHasFlip),
689 constructHasFlip_(constructHasFlip),
691 schedulePtr_(nullptr)
706 constructHasFlip_(false),
708 schedulePtr_(nullptr)
713 if (sendProcs.
size() != recvProcs.
size())
716 <<
"The send and receive data is not the same length. sendProcs:" 717 << sendProcs.
size() <<
" recvProcs:" << recvProcs.
size()
725 forAll(sendProcs, sampleI)
727 const label sendProc = sendProcs[sampleI];
728 const label recvProc = recvProcs[sampleI];
733 if (myRank == sendProc)
738 if (myRank == recvProc)
745 subMap_.setSize(nProcs);
749 subMap_[proci].setSize(nSend[proci]);
750 constructMap_[proci].
setSize(nRecv[proci]);
756 label maxRecvIndex = -1;
758 forAll(sendProcs, sampleI)
760 const label sendProc = sendProcs[sampleI];
761 const label recvProc = recvProcs[sampleI];
763 if (myRank == sendProc)
766 subMap_[recvProc][nSend[recvProc]++] = sampleI;
768 if (myRank == recvProc)
771 constructMap_[sendProc][nRecv[sendProc]++] = sampleI;
772 maxRecvIndex = sampleI;
776 constructSize_ = maxRecvIndex+1;
782 const globalIndex& globalNumbering,
784 List<Map<label>>& compactMap,
793 constructHasFlip_(false),
795 schedulePtr_(nullptr)
845 const globalIndex& globalNumbering,
847 List<Map<label>>& compactMap,
856 constructHasFlip_(false),
858 schedulePtr_(nullptr)
908 const layoutTypes constructLayout,
910 const bool subHasFlip,
911 const bool constructHasFlip,
916 subMap_(
std::move(subMap)),
918 subHasFlip_(subHasFlip),
919 constructHasFlip_(constructHasFlip),
921 schedulePtr_(nullptr)
931 constructMap_.
resize(nProcs);
937 forAll(constructMap_, proci)
939 const label len = recvSizes[proci];
941 constructMap_[proci] =
identity(len, constructSize_);
942 constructSize_ += len;
951 const label len = recvSizes[myRank];
953 constructMap_[myRank] =
identity(len, constructSize_);
954 constructSize_ += len;
958 forAll(constructMap_, proci)
962 const label len = recvSizes[proci];
964 constructMap_[proci] =
identity(len, constructSize_);
965 constructSize_ += len;
975 const bool subHasFlip,
976 const bool constructHasFlip,
982 layoutTypes::localFirst,
1003 constructHasFlip_(false),
1005 schedulePtr_(nullptr)
1013 subHasFlip_ = maps[0].subHasFlip();
1014 constructHasFlip_ = maps[0].constructHasFlip();
1016 const label nNewRanks = newToOldRanks.
size();
1025 if (localRanks.
size() != maps.
size())
1028 <<
"Number of maps:" << maps.
size()
1029 <<
" number of localRanks:" << localRanks.
size()
1034 const auto& map0 = maps[0];
1037 const auto& map = maps[mapi];
1041 (map.comm() != map0.comm())
1042 || (map.subHasFlip() != map0.subHasFlip())
1043 || (map.constructHasFlip() != map0.constructHasFlip())
1047 <<
"Maps should all be the same form" 1049 <<
" has comm:" << map.comm()
1050 <<
" subHasFlip:" << map.subHasFlip()
1051 <<
" constructHasFlip:" << map.constructHasFlip()
1052 <<
" which is different from map 0" 1056 const label localRank = localRanks[mapi];
1057 const auto& constructOwn = maps[mapi].constructMap()[localRank];
1060 if (constructOwn[i] != i)
1063 <<
"Maps constructMap not identity." 1065 <<
" constructMap:" <<
flatOutput(constructOwn)
1073 subMap_.resize_nocopy(nNewRanks);
1078 compactMaps.resize_nocopy(maps.
size());
1080 label constructi = 0;
1083 startOfLocal[mapi] = constructi;
1084 const label localRank = localRanks[mapi];
1085 const auto& map = maps[mapi].constructMap()[localRank];
1088 const label nRemote = maps[mapi].constructSize()-map.
size();
1089 compactMaps[mapi].resize(2*nRemote);
1091 constructi += map.size();
1093 startOfLocal.
last() = constructi;
1101 const label nOldProcs = maps[mapi].constructMap().
size();
1102 labelList& starts = startOfRemote[mapi];
1107 const labelList& map = maps[mapi].constructMap()[oldProci];
1116 starts[oldProci] =
min(starts[oldProci], index);
1138 labelList& myConstruct = constructMap_[myNewRank];
1143 const label localRank = localRanks[mapi];
1144 const auto& map = maps[mapi].constructMap()[localRank];
1145 const label offset = startOfLocal[mapi];
1149 if (constructHasFlip_)
1155 myConstruct[constructi++] = map[i]-offset;
1159 myConstruct[constructi++] = map[i]+offset;
1165 myConstruct[constructi++] = map[i]+offset;
1176 const auto& oldProcs = newToOldRanks[myNewRank];
1180 for (
const label oldProci : oldProcs)
1182 if (oldProci != localRanks[mapi])
1184 const auto& map = maps[mapi].constructMap()[oldProci];
1194 const label sourceMapi = localRanks.
find(oldProci);
1196 maps[sourceMapi].subMap()[localRanks[mapi]];
1208 <<
"oldProci:" << oldProci
1210 <<
" constructMap:" << map.size()
1211 <<
" sourceMapi:" << sourceMapi
1216 const label offset = startOfLocal[sourceMapi];
1218 const label nMapLocal = startOfRemote[mapi][oldProci];
1220 auto& cptMap = compactMaps[mapi];
1230 const label newIndex =
subMap[index-nMapLocal]+offset;
1236 !cptMap.insert(index, newIndex)
1237 && cptMap[index] != newIndex
1241 <<
"From oldProc:" << oldProci
1242 <<
" on map:" << mapi
1243 <<
" at index:" << i
1244 <<
" have construct slot:" << index
1245 <<
" new index:" << newIndex
1246 <<
" but already have entry:" << cptMap[index]
1247 <<
" on for that slot" 1263 forAll(newToOldRanks, newProci)
1265 if (newProci != myNewRank)
1267 const auto& oldProcs = newToOldRanks[newProci];
1272 for (
const label oldProci : oldProcs)
1274 allSize += maps[mapi].constructMap()[oldProci].
size();
1278 labelList& myConstruct = constructMap_[newProci];
1284 for (
const label oldProci : oldProcs)
1286 const auto& map = maps[mapi].constructMap()[oldProci];
1288 const label nMapLocal = startOfRemote[mapi][oldProci];
1289 SubList<label> slice(myConstruct, map.size(), allSize);
1291 if (constructHasFlip_)
1297 slice[i] = map[i]+nMapLocal-constructi;
1301 slice[i] = map[i]-nMapLocal+constructi;
1305 auto& cptMap = compactMaps[mapi];
1308 cptMap.insert(
mag(map[i])-1,
mag(slice[i])-1);
1315 slice[i] = map[i]-nMapLocal+constructi;
1316 compactMaps[mapi].insert(map[i], slice[i]);
1319 allSize += map.size();
1320 constructi += map.size();
1342 const label localRank = localRanks[mapi];
1343 allSize += maps[mapi].subMap()[localRank].
size();
1351 const label localRank = localRanks[mapi];
1352 const auto& map = maps[mapi].subMap()[localRank];
1353 SubList<label> slice(mySub, map.size(), allSize);
1361 slice[i] = map[i]-startOfLocal[mapi];
1365 slice[i] = map[i]+startOfLocal[mapi];
1373 slice[i] = map[i]+startOfLocal[mapi];
1376 allSize += map.
size();
1380 forAll(newToOldRanks, newProci)
1382 if (newProci != myNewRank)
1384 const auto& oldProcs = newToOldRanks[newProci];
1389 for (
const label oldProci : oldProcs)
1391 allSize += maps[mapi].subMap()[oldProci].
size();
1399 for (
const label oldProci : oldProcs)
1403 const auto& map = maps[mapi].subMap()[oldProci];
1404 SubList<label> slice(mySub, map.size(), allSize);
1411 slice[i] = map[i]-startOfLocal[mapi];
1415 slice[i] = map[i]+startOfLocal[mapi];
1423 slice[i] = map[i]+startOfLocal[mapi];
1426 allSize += map.
size();
1433 constructSize_ = constructi;
1444 sizes[i] = subMap_[i].size();
1455 sizes[i] = constructMap_[i].size();
1464 for (
const auto& list : subMap_)
1466 total += list.size();
1475 for (
const auto& list : constructMap_)
1477 total += list.size();
1487 constructMap_.clear();
1488 subHasFlip_ =
false;
1489 constructHasFlip_ =
false;
1491 schedulePtr_.reset(
nullptr);
1503 constructSize_ = rhs.constructSize_;
1504 subMap_.transfer(rhs.subMap_);
1505 constructMap_.transfer(rhs.constructMap_);
1506 subHasFlip_ = rhs.subHasFlip_;
1507 constructHasFlip_ = rhs.constructHasFlip_;
1509 schedulePtr_.reset(
nullptr);
1511 rhs.constructSize_ = 0;
1512 rhs.subHasFlip_ =
false;
1513 rhs.constructHasFlip_ =
false;
1531 if (globalNumbering.
isLocal(myRank, globalI))
1533 return globalNumbering.
toLocal(myRank, globalI);
1537 label proci = globalNumbering.
whichProcID(myRank, globalI);
1538 label index = globalNumbering.
toLocal(proci, globalI);
1539 return compactMap[proci][index];
1553 constructSize_ = rhs.constructSize_;
1554 subMap_ = rhs.subMap_;
1555 constructMap_ = rhs.constructMap_;
1556 subHasFlip_ = rhs.subHasFlip_;
1557 constructHasFlip_ = rhs.constructHasFlip_;
1559 schedulePtr_.reset(
nullptr);
label toLocal(const label proci, const label i) const
From global to local on proci.
void calcCompactAddressing(const globalIndex &globalNumbering, const labelUList &elements, List< Map< label >> &compactMap) const
Construct per processor compact addressing of the global elements.
void size(const label n)
Older name for setAddressableSize.
static label countUnmapped(const labelUList &elements, const labelListList &maps, const bool hasFlip)
Count the number of unmapped elements.
errorManipArg< error, int > exit(error &err, const int errNo=1)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
void resize(const label len)
Adjust allocated size of list.
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...
const List< labelPair > & schedule() const
Return a schedule. Demand driven. See above.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
IntListType renumber(const labelUList &oldToNew, const IntListType &input)
Renumber the values within a list.
constexpr char nl
The newline '\n' character (0x0a)
label whichProcID(const label proci, const label i) const
Which processor does global id come from? Checks proci first (assumed to occur reasonably frequently)...
Ostream & endl(Ostream &os)
Add newline and flush stream.
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 & msgType() noexcept
Message tag of standard messages.
static int myProcNo(const label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Can be negative if the process i...
List< labelList > labelListList
List of labelList.
UList< label > labelUList
A UList of labels.
static void broadcast(Type &value, const label comm=UPstream::worldComm)
Broadcast content (contiguous or non-contiguous) to all communicator ranks. Does nothing in non-paral...
Various functions to operate on Lists.
#define forAll(list, i)
Loop across all elements in list.
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run. ...
static void recv(Type &value, const int fromProcNo, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm, IOstreamOption::streamFormat fmt=IOstreamOption::BINARY)
Receive and deserialize a value. Uses operator>> for de-serialization.
void setSize(const label n)
Alias for resize()
const List< labelPair > & whichSchedule(const UPstream::commsTypes commsType) const
Return real or dummy schedule depending on the communication type.
"scheduled" (MPI standard) : (MPI_Send, MPI_Recv)
static bool hasFlipAddressing(const labelUList &map)
Test for flip addressing, where flips are encoded as negative indices and non-flips are encoded as po...
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i), works like std::iota() but returning a...
static constexpr int masterNo() noexcept
Relative rank for the master process - is always 0.
void printLayout(Ostream &os) const
Debug: print layout. Can only be used on maps with sorted.
label size() const noexcept
The number of entries in the list.
#define forAllIters(container, iter)
Iterate across all elements in the container object.
bool isLocal(const label proci, const label i) const
Is on processor proci.
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
void transfer(mapDistributeBase &rhs)
Transfer the contents of the argument and annul the argument.
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
errorManip< error > abort(error &err)
A HashTable to objects of type <T> with a labelPair key. The hashing is based on labelPair (FixedList...
label find(const T &val) const
Find index of the first occurrence of the value.
void operator=(const mapDistributeBase &rhs)
Copy assignment.
Class containing processor-to-processor mapping information.
int debug
Static debugging option.
Pair< label > labelPair
A pair of labels.
OBJstream os(runTime.globalPath()/outputName)
defineTypeNameAndDebug(combustionModel, 0)
label subMapTotalSize() const noexcept
The sum of the subMap list sizes.
T & last()
Access last element of the list, position [size()-1].
const labelListList & constructMap() const noexcept
From subsetted data to new reconstructed data.
static label renumber(const globalIndex &, const label comm, const List< Map< label >> &compactMap, const label globalElement)
Helper for construct from globalIndex. Renumbers element.
bool empty() const noexcept
True if the list is empty (ie, size() is zero)
void exchangeAddressing(const int tag, const globalIndex &globalNumbering, labelList &elements, List< Map< label >> &compactMap, labelList &compactStart)
labelList subMapSizes() const
The sizes of the subMap lists.
void clear()
Reset to zero size, only retaining communicator.
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
static void exchangeSizes(const labelUList &sendProcs, const labelUList &recvProcs, const Container &sendBufs, labelList &sizes, const label tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Helper: exchange sizes of sendBufs for specified send/recv ranks.
static void checkReceivedSize(const label proci, const label expectedSize, const label receivedSize)
Fatal if expected != received size.
static label getMappedSize(const labelListList &maps, const bool hasFlip)
Scan the maps for the max addressed index.
label constructMapTotalSize() const noexcept
The sum of the constructMap list sizes.
static rangeType subProcs(const label communicator=worldComm)
Range of process indices for sub-processes.
List< label > labelList
A List of labels.
mapDistributeBase() noexcept
Default construct (uses worldComm)
const labelListList & subMap() const noexcept
From subsetted data back to original data.
HashSet< labelPair, Foam::Hash< labelPair > > labelPairHashSet
A HashSet for a labelPair. The hashing is based on labelPair (FixedList) and is thus non-commutative...
bool send()
Send buffer contents now and not in destructor [advanced usage]. Returns true on success.
labelList constructMapSizes() const
The sizes of the constructMap lists.
static const List< T > & null() noexcept
Return a null List (reference to a nullObject). Behaves like an empty List.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
Inter-processor communications stream.
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
static constexpr const zero Zero
Global zero (0)