52 masks[proci].
resize(maps[proci].size());
67 const bitSet& allowedElems,
74 const auto unflippedIndex =
77 ? [](label idx) -> label {
return mag(idx)-1; }
78 : [](label idx) -> label {
return idx; }
92 bitSet& mask = masks[proci];
101 const label index = unflippedIndex(map[i]);
103 if (allowedElems.
test(index))
106 maxIndex =
max(maxIndex, index);
131 if (sendMasks.
size() != recvMasks.
size())
134 <<
"Mismatched mask sizes: " 135 << sendMasks.
size() <<
" != " 148 <<
"Mask sizes (" << sendMasks.
size()
149 <<
") are larger than number of procs:" 159 if (proci != myRank && recvMasks[proci].size())
165 recvMasks[proci].data_bytes(),
166 recvMasks[proci].size_bytes(),
175 if (proci != myRank && sendMasks[proci].size())
181 sendMasks[proci].cdata_bytes(),
182 sendMasks[proci].size_bytes(),
194 recvMasks[myRank] = sendMasks[myRank];
210 if (sendMasks.
size() != recvMasks.
size())
213 <<
"Mismatched mask sizes: " 214 << sendMasks.
size() <<
" != " 222 List<bitSet> scratch(recvMasks.
size());
227 scratch[proci].resize(recvMasks[proci].size());
231 exchangeMasks(sendMasks, scratch, tag, comm);
236 recvMasks[proci] &= scratch[proci];
242 scratch[proci].resize(sendMasks[proci].size());
246 exchangeMasks(recvMasks, scratch, tag, comm);
251 sendMasks[proci] &= scratch[proci];
259 recvMasks[myRank] &= sendMasks[myRank];
260 sendMasks[myRank] = recvMasks[myRank];
266 for (
auto& mask : sendMasks)
271 for (
auto& mask : recvMasks)
294 for (label& val : map)
297 const label index = oldToNew[
mag(val)-1];
301 maxIndex =
max(maxIndex, index);
304 val = (val < 0 ? (-index-1) : (index+1));
313 for (label& val : map)
317 const label index = oldToNew[val];
321 maxIndex =
max(maxIndex, index);
335 const label localSize,
337 const Map<label>& cMap,
346 for (label& val : map)
349 const label index =
mag(val)-1;
350 if (index < localSize)
367 val = -cMap[index]-1;
374 maxIndex =
max(maxIndex,
mag(val)-1);
379 for (label& val : map)
390 maxIndex =
max(maxIndex, val);
401 const label localSize,
403 const Map<label>& cMap,
430 void Foam::mapDistributeBase::renumberVisitOrder
448 labelList compactToWalkOrder(origElements.size(), -1);
450 forAll(origElements, walkIndex)
452 const label origIndex = origElements[walkIndex];
453 const label compactIndex = oldToNew[origIndex];
455 if (compactIndex >= origElements.size())
458 <<
"Compact index: " << compactIndex
459 <<
" is not represented in the original (" 460 << origElements.size()
461 <<
") elements - indicates an addressing problem" <<
nl 464 else if (compactIndex >= 0)
466 compactToWalkOrder[compactIndex] = walkIndex;
467 oldToNew[origIndex] = walkIndex;
471 renumberMap(maps, compactToWalkOrder, hasFlip);
477 void Foam::mapDistributeBase::calcCompactDataRequirements
479 const bitSet& allowedLocalElems,
480 const bitSet& allowedRemoteElems,
481 List<bitSet>& sendMasks,
482 List<bitSet>& recvMasks,
508 unionCombineMasks(sendMasks, recvMasks, tag, comm_);
512 void Foam::mapDistributeBase::calcCompactLocalDataRequirements
514 const bitSet& allowedLocalElems,
515 List<bitSet>& sendMasks,
516 List<bitSet>& recvMasks,
535 exchangeMasks(sendMasks, recvMasks, tag, comm_);
539 void Foam::mapDistributeBase::calcCompactRemoteDataRequirements
541 const bitSet& allowedRemoteElems,
542 List<bitSet>& sendMasks,
543 List<bitSet>& recvMasks,
562 exchangeMasks(recvMasks, sendMasks, tag, comm_);
568 void Foam::mapDistributeBase::compactData
570 const UList<bitSet>& sendMasks,
571 const UList<bitSet>& recvMasks,
574 const label localSize
578 const auto unflippedSendIndex =
581 ? [](label idx) -> label {
return mag(idx)-1; }
582 : [](label idx) -> label {
return idx; }
586 const auto unflippedRecvIndex =
589 ? [](label idx) -> label {
return mag(idx)-1; }
590 : [](label idx) -> label {
return idx; }
601 label subMapSize(localSize);
604 subMapSize = getMappedSize(subMap_, subHasFlip_);
607 oldToNewSub.resize_nocopy(subMapSize);
611 indexUsed.resize(subMapSize);
615 const bitSet& mask = sendMasks[proci];
616 const auto& map = subMap_[proci];
618 for (
const label i : mask)
620 const label index = unflippedSendIndex(map[i]);
622 indexUsed.set(index);
627 for (
const label i : indexUsed)
629 oldToNewSub[i] = nCompact++;
635 if (
notNull(oldToNewConstruct))
637 oldToNewConstruct.resize_nocopy(constructSize_);
638 oldToNewConstruct = -1;
641 indexUsed.resize(constructSize_);
645 const bitSet& mask = recvMasks[proci];
646 const auto& map = constructMap_[proci];
648 for (
const label i : mask)
650 const label index = unflippedRecvIndex(map[i]);
652 indexUsed.set(index);
657 for (
const label i : indexUsed)
659 oldToNewConstruct[i] = nCompact++;
667 const bitSet& mask = sendMasks[proci];
672 for (
const label i : mask)
677 map[nCompact++] = map[i];
686 label maxRemoteIndex = -1;
690 const bitSet& mask = recvMasks[proci];
695 for (
const label i : mask)
697 const label index = unflippedRecvIndex(map[i]);
698 maxRemoteIndex =
max(maxRemoteIndex, index);
700 map[nCompact++] = map[i];
703 map.resize(nCompact);
706 constructSize_ = maxRemoteIndex+1;
713 renumberMap(subMap_, oldToNewSub, subHasFlip_);
716 if (
notNull(oldToNewConstruct))
719 renumberMap(constructMap_, oldToNewConstruct, constructHasFlip_);
723 schedulePtr_.reset(
nullptr);
727 void Foam::mapDistributeBase::compactData
733 const label localSize,
740 calcCompactDataRequirements
784 const label localSize,
791 calcCompactLocalDataRequirements
826 const label localSize,
833 calcCompactRemoteDataRequirements
863 void Foam::mapDistributeBase::compactDataImpl
865 const UList<bitSet>& sendMasks,
866 const UList<bitSet>& recvMasks,
867 const bool doRenumber
901 const bitSet& allowedLocalElems,
903 const bool doRenumber
906 List<bitSet> sendMasks;
907 List<bitSet> recvMasks;
909 calcCompactLocalDataRequirements
917 compactDataImpl(sendMasks, recvMasks, doRenumber);
923 const bitSet& allowedRemoteElems,
925 const bool doRenumber
931 calcCompactRemoteDataRequirements
939 compactDataImpl(sendMasks, recvMasks, doRenumber);
945 const bitSet& allowedLocalElems,
948 const label localSize,
955 calcCompactLocalDataRequirements
976 const bitSet& allowedRemoteElems,
979 const label localSize,
986 calcCompactRemoteDataRequirements
1014 compactRemoteData(
bitSet(remoteElemUsed), tag);
1021 const label localSize,
void size(const label n)
Older name for setAddressableSize.
void compactLocalData(const bitSet &allowedLocalElems, const int tag=UPstream::msgType(), const bool doRenumber=false)
Compact send/receive maps based on selection of originating local (send) elements.
void set(const bitSet &bitset)
Set specified bits from another bitset.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
void resize(const label len)
Adjust allocated size of list.
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...
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
static label nRequests() noexcept
Number of outstanding requests (on the internal list of requests)
constexpr char nl
The newline '\n' character (0x0a)
bool empty() const noexcept
True if List is empty (ie, size() is zero)
static bool & parRun() noexcept
Test if this a parallel run.
label comm() const noexcept
The communicator used.
void compactRemoteData(const bitSet &allowedRemoteElems, const int tag=UPstream::msgType(), const bool doRenumber=false)
Compact send/receive maps based on selection of remote (receive) elements.
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.
static void waitRequests()
Wait for all requests to finish.
UList< label > labelUList
A UList of labels.
void resize(const label numElem, const unsigned int val=0u)
Reset addressable list size, does not shrink the allocated size.
Various functions to operate on Lists.
#define forAll(list, i)
Loop across all elements in list.
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run. ...
static void exchangeMasks(const UList< bitSet > &sendMasks, UList< bitSet > &recvMasks, const int tag, const label comm)
Synchronize send/recv mask buffers as a 'copy' operation.
void compact(const boolList &remoteElemUsed, const int tag=UPstream::msgType())
OpenFOAM-v2112 and earlier naming for compactRemoteData() using boolList.
static label calcElementMasks(const bitSet &allowedElems, List< bitSet > &masks, const labelListList &maps, const bool hasFlip)
errorManip< error > abort(error &err)
static void blankElementMasks(List< bitSet > &masks, const labelListList &maps)
bool test(const label pos) const
Test for True value at specified position, never auto-vivify entries.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
static void unionCombineMasks(UList< bitSet > &sendMasks, UList< bitSet > &recvMasks, const int tag, const label comm)
Bi-direction sync of send/recv buffers using bitwise '&=' combine operation.
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
bool notNull(const T *ptr) noexcept
True if ptr is not a pointer (of type T) to the nullObject.
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" (immediate) : (MPI_Isend, MPI_Irecv)
void reset()
Clear all bits but do not adjust the addressable size.
List< label > labelList
A List of labels.
static const List< label > & null() noexcept
Return a null List (reference to a nullObject). Behaves like an empty List.
static label renumberMap(labelListList &mapElements, const labelUList &oldToNew, const bool hasFlip)
Helper for renumbering the (compacted) map elements using the supplied old-to-new mapping...
static std::streamsize 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.