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 <<
"Expected from processor " << proci
177 <<
" " << expectedSize <<
" but received "
178 << receivedSize <<
" elements."
208 if (subMap[proci].size())
213 if (constructMap[proci].size())
220 allComms = commsSet.
toc();
240 for (
const labelPair& connection : nbrData)
258 toMaster << allComms;
272 ).procSchedule()[myRank]
293 return *schedulePtr_;
319 forAll(constructMap_, proci)
321 const labelList& construct = constructMap_[proci];
322 if (constructHasFlip_)
326 label index =
mag(construct[i])-1;
327 minIndex[proci] =
min(minIndex[proci], index);
328 maxIndex[proci] =
max(maxIndex[proci], index);
335 label index = construct[i];
336 minIndex[proci] =
min(minIndex[proci], index);
337 maxIndex[proci] =
max(maxIndex[proci], index);
346 localSize = maxIndex[myRank]+1;
349 os <<
"Layout: (constructSize:" << constructSize_
350 <<
" subHasFlip:" << subHasFlip_
351 <<
" constructHasFlip:" << constructHasFlip_
353 <<
"local (processor " << myRank <<
"):" <<
nl
354 <<
" start : 0" <<
nl
355 <<
" size : " << localSize <<
endl;
357 label offset = localSize;
360 if (proci != myRank && !constructMap_[proci].empty())
366 size = maxIndex[proci]-minIndex[proci]+1;
367 if (minIndex[proci] != offset)
370 <<
"offset:" << offset
371 <<
" proci:" << proci
372 <<
" minIndex:" << minIndex[proci]
377 os <<
"processor " << proci <<
':' <<
nl
378 <<
" start : " << offset <<
nl
379 <<
" size : " << size <<
endl;
400 for (
const label globalIdx : elements)
402 if (globalIdx != -1 && !globalNumbering.
isLocal(globalIdx))
404 label proci = globalNumbering.whichProcID(globalIdx);
409 compactMap.resize_nocopy(nProcs);
413 compactMap[proci].clear();
416 compactMap[proci].resize(2*nNonLocal[proci]);
422 for (
const label globalIdx : elements)
424 if (globalIdx != -1 && !globalNumbering.
isLocal(globalIdx))
426 label proci = globalNumbering.whichProcID(globalIdx);
427 label index = globalNumbering.
toLocal(proci, globalIdx);
428 label nCompact = compactMap[proci].size();
429 compactMap[proci].insert(index, nCompact);
448 for (
const labelList& cCells : cellCells)
450 for (
const label globalIdx : cCells)
452 if (globalIdx != -1 && !globalNumbering.
isLocal(globalIdx))
454 label proci = globalNumbering.whichProcID(globalIdx);
464 compactMap[proci].clear();
467 compactMap[proci].resize(2*nNonLocal[proci]);
473 for (
const labelList& cCells : cellCells)
475 for (
const label globalIdx : cCells)
477 if (globalIdx != -1 && !globalNumbering.
isLocal(globalIdx))
479 label proci = globalNumbering.whichProcID(globalIdx);
480 label index = globalNumbering.
toLocal(proci, globalIdx);
481 label nCompact = compactMap[proci].size();
482 compactMap[proci].insert(index, nCompact);
506 compactStart[myRank] = 0;
507 constructSize_ = globalNumbering.
localSize();
508 forAll(compactStart, proci)
512 compactStart[proci] = constructSize_;
513 constructSize_ += compactMap[proci].
size();
523 constructMap_.setSize(nProcs);
529 label nLocal = globalNumbering.
localSize();
530 wantedRemoteElements[proci] =
identity(nLocal);
531 constructMap_[proci] =
identity(nLocal);
536 labelList& remoteElem = wantedRemoteElements[proci];
537 labelList& localElem = constructMap_[proci];
538 remoteElem.
setSize(compactMap[proci].size());
539 localElem.
setSize(compactMap[proci].size());
543 const label compactI = compactStart[proci] + iter.val();
544 remoteElem[i] = iter.key();
545 localElem[i] = compactI;
546 iter.val() = compactI;
553 Pstream::exchange<labelList, label>
555 wantedRemoteElements,
562 for (label& elem : elements)
564 elem =
renumber(globalNumbering, compactMap, elem);
586 compactStart[myRank] = 0;
587 constructSize_ = globalNumbering.
localSize();
588 forAll(compactStart, proci)
592 compactStart[proci] = constructSize_;
593 constructSize_ += compactMap[proci].
size();
603 constructMap_.setSize(nProcs);
609 label nLocal = globalNumbering.
localSize();
610 wantedRemoteElements[proci] =
identity(nLocal);
611 constructMap_[proci] =
identity(nLocal);
616 labelList& remoteElem = wantedRemoteElements[proci];
617 labelList& localElem = constructMap_[proci];
618 remoteElem.
setSize(compactMap[proci].size());
619 localElem.
setSize(compactMap[proci].size());
623 const label compactI = compactStart[proci] + iter.val();
624 remoteElem[i] = iter.key();
625 localElem[i] = compactI;
626 iter.val() = compactI;
633 Pstream::exchange<labelList, label>
635 wantedRemoteElements,
644 for (label& celli : cCells)
646 celli =
renumber(globalNumbering, compactMap, celli);
666 constructHasFlip_(false),
668 schedulePtr_(nullptr)
674 constructSize_(map.constructSize_),
675 subMap_(map.subMap_),
676 constructMap_(map.constructMap_),
677 subHasFlip_(map.subHasFlip_),
678 constructHasFlip_(map.constructHasFlip_),
680 schedulePtr_(nullptr)
694 const label constructSize,
697 const bool subHasFlip,
698 const bool constructHasFlip,
702 constructSize_(constructSize),
703 subMap_(std::move(subMap)),
704 constructMap_(std::move(constructMap)),
705 subHasFlip_(subHasFlip),
706 constructHasFlip_(constructHasFlip),
708 schedulePtr_(nullptr)
723 constructHasFlip_(false),
725 schedulePtr_(nullptr)
730 if (sendProcs.
size() != recvProcs.
size())
733 <<
"The send and receive data is not the same length. sendProcs:"
734 << sendProcs.
size() <<
" recvProcs:" << recvProcs.
size()
742 forAll(sendProcs, sampleI)
744 const label sendProc = sendProcs[sampleI];
745 const label recvProc = recvProcs[sampleI];
750 if (myRank == sendProc)
755 if (myRank == recvProc)
766 subMap_[proci].
setSize(nSend[proci]);
767 constructMap_[proci].
setSize(nRecv[proci]);
773 label maxRecvIndex = -1;
775 forAll(sendProcs, sampleI)
777 const label sendProc = sendProcs[sampleI];
778 const label recvProc = recvProcs[sampleI];
780 if (myRank == sendProc)
783 subMap_[recvProc][nSend[recvProc]++] = sampleI;
785 if (myRank == recvProc)
788 constructMap_[sendProc][nRecv[sendProc]++] = sampleI;
789 maxRecvIndex = sampleI;
793 constructSize_ = maxRecvIndex+1;
810 constructHasFlip_(false),
812 schedulePtr_(nullptr)
873 constructHasFlip_(false),
875 schedulePtr_(nullptr)
926 const bool subHasFlip,
927 const bool constructHasFlip,
932 subMap_(std::move(subMap)),
934 subHasFlip_(subHasFlip),
935 constructHasFlip_(constructHasFlip),
937 schedulePtr_(nullptr)
948 constructMap_.
resize(nProcs);
953 const label len = recvSizes[myRank];
955 constructMap_[myRank] =
identity(len, constructSize_);
956 constructSize_ += len;
960 forAll(constructMap_, proci)
964 const label len = recvSizes[proci];
966 constructMap_[proci] =
identity(len, constructSize_);
967 constructSize_ += len;
980 sizes[i] = subMap_[i].
size();
992 sizes[i] = constructMap_[i].
size();
1003 constructMap_.clear();
1004 subHasFlip_ =
false;
1005 constructHasFlip_ =
false;
1007 schedulePtr_.reset(
nullptr);
1019 constructSize_ = rhs.constructSize_;
1020 subMap_.transfer(rhs.subMap_);
1021 constructMap_.transfer(rhs.constructMap_);
1022 subHasFlip_ = rhs.subHasFlip_;
1023 constructHasFlip_ = rhs.constructHasFlip_;
1025 schedulePtr_.reset(
nullptr);
1027 rhs.constructSize_ = 0;
1028 rhs.subHasFlip_ =
false;
1029 rhs.constructHasFlip_ =
false;
1044 if (globalNumbering.
isLocal(globalI))
1046 return globalNumbering.
toLocal(globalI);
1050 label proci = globalNumbering.whichProcID(globalI);
1051 label index = globalNumbering.
toLocal(proci, globalI);
1052 return compactMap[proci][index];
1066 constructSize_ = rhs.constructSize_;
1067 subMap_ = rhs.subMap_;
1068 constructMap_ = rhs.constructMap_;
1069 subHasFlip_ = rhs.subHasFlip_;
1070 constructHasFlip_ = rhs.constructHasFlip_;
1072 schedulePtr_.reset(
nullptr);
Various functions to operate on Lists.
A HashTable with keys but without contents that is similar to std::unordered_set.
bool insert(const Key &key)
Insert a new entry, not overwriting existing entries.
List< Key > toc() const
The table of contents (the keys) in unsorted order.
Input inter-processor communications stream.
void setSize(const label n)
Alias for resize()
void resize_nocopy(const label len)
Adjust allocated size of list without necessarily.
label appendUniq(const T &val)
Append an element if not already in the list.
void resize(const label len)
Adjust allocated size of list.
static const List< T > & null()
Return a null List.
A HashTable to objects of type <T> with a label key.
Output inter-processor communications stream.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
label nProcs() const noexcept
Number of ranks associated with PstreamBuffers.
UPstream::rangeType subProcs() const noexcept
Range of sub-processes indices associated with PstreamBuffers.
static void exchangeSizes(const labelUList &sendProcs, const labelUList &recvProcs, const Container &sendData, labelList &sizes, const label tag=UPstream::msgType(), const label comm=UPstream::worldComm)
static void broadcast(Type &value, const label comm=UPstream::worldComm)
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
void size(const label n)
Older name for setAddressableSize.
Inter-processor communications stream.
commsTypes
Types of communications.
static int & msgType() noexcept
Message tag of standard messages.
static constexpr int masterNo() noexcept
Process index of the master (always 0)
static bool & parRun() noexcept
Test if this a parallel run.
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
unsigned int count(const bool on=true) const
Count number of bits set.
bitSet & unset(const bitSet &other)
Determines the order in which a set of processors should communicate with one another.
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
label localSize() const
My local size.
label toLocal(const label i) const
From global to local on current processor.
bool isLocal(const label i) const
Is on local processor.
Class containing processor-to-processor mapping information.
void operator=(const mapDistributeBase &rhs)
Copy assignment.
const List< labelPair > & whichSchedule(const UPstream::commsTypes commsType) const
const List< labelPair > & schedule() const
Return a schedule. Demand driven. See above.
mapDistributeBase()
Default construct (uses worldComm)
void printLayout(Ostream &os) const
Debug: print layout. Can only be used on maps with sorted.
void transfer(mapDistributeBase &rhs)
Transfer the contents of the argument and annul the argument.
static label renumber(const globalIndex &, const List< Map< label > > &compactMap, const label globalElement)
Helper for construct from globalIndex. Renumbers element.
void calcCompactAddressing(const globalIndex &globalNumbering, const labelUList &elements, List< Map< label > > &compactMap) const
Construct per processor compact addressing of the global elements.
static void checkReceivedSize(const label proci, const label expectedSize, const label receivedSize)
Fatal if expected and received size are not equal.
labelList constructMapSizes() const
The sizes of the constructMap lists.
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.
static label countUnmapped(const labelUList &elements, const labelListList &maps, const bool hasFlip)
Count the number of unmapped elements.
static label getMappedSize(const labelListList &maps, const bool hasFlip)
Scan the maps for the max addressed index.
void clear()
Reset to zero size, only retaining communicator.
static bool hasFlipAddressing(const labelUList &map)
int myProcNo() const noexcept
Return processor number.
transferModelList & transfer()
Transfer.
splitCell * master() const
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
OBJstream os(runTime.globalPath()/outputName)
A HashTable to objects of type <T> with a labelPair key. The hashing is based on labelPair (FixedList...
Pair< label > labelPair
A pair of labels.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i)
IntListType renumber(const labelUList &oldToNew, const IntListType &input)
Renumber the values (not the indices) of a list.
Ostream & endl(Ostream &os)
Add newline and flush stream.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
errorManip< error > abort(error &err)
static constexpr const zero Zero
Global zero (0)
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
constexpr char nl
The newline '\n' character (0x0a)
#define forAll(list, i)
Loop across all elements in list.
#define forAllIters(container, iter)
Iterate across all elements in the container object.