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);
332 void Foam::mapDistributeBase::renumberVisitOrder
350 labelList compactToWalkOrder(origElements.size(), -1);
352 forAll(origElements, walkIndex)
354 const label origIndex = origElements[walkIndex];
355 const label compactIndex = oldToNew[origIndex];
357 if (compactIndex >= origElements.size())
360 <<
"Compact index: " << compactIndex
361 <<
" is not represented in the original (" 362 << origElements.size()
363 <<
") elements - indicates an addressing problem" <<
nl 366 else if (compactIndex >= 0)
368 compactToWalkOrder[compactIndex] = walkIndex;
369 oldToNew[origIndex] = walkIndex;
373 renumberMap(maps, compactToWalkOrder, hasFlip);
379 void Foam::mapDistributeBase::calcCompactDataRequirements
381 const bitSet& allowedLocalElems,
382 const bitSet& allowedRemoteElems,
383 List<bitSet>& sendMasks,
384 List<bitSet>& recvMasks,
410 unionCombineMasks(sendMasks, recvMasks, tag, comm_);
414 void Foam::mapDistributeBase::calcCompactLocalDataRequirements
416 const bitSet& allowedLocalElems,
417 List<bitSet>& sendMasks,
418 List<bitSet>& recvMasks,
437 exchangeMasks(sendMasks, recvMasks, tag, comm_);
441 void Foam::mapDistributeBase::calcCompactRemoteDataRequirements
443 const bitSet& allowedRemoteElems,
444 List<bitSet>& sendMasks,
445 List<bitSet>& recvMasks,
464 exchangeMasks(recvMasks, sendMasks, tag, comm_);
470 void Foam::mapDistributeBase::compactData
472 const UList<bitSet>& sendMasks,
473 const UList<bitSet>& recvMasks,
476 const label localSize
480 const auto unflippedSendIndex =
483 ? [](label idx) -> label {
return mag(idx)-1; }
484 : [](label idx) -> label {
return idx; }
488 const auto unflippedRecvIndex =
491 ? [](label idx) -> label {
return mag(idx)-1; }
492 : [](label idx) -> label {
return idx; }
503 label subMapSize(localSize);
506 subMapSize = getMappedSize(subMap_, subHasFlip_);
509 oldToNewSub.resize_nocopy(subMapSize);
513 indexUsed.resize(subMapSize);
517 const bitSet& mask = sendMasks[proci];
518 const auto& map = subMap_[proci];
520 for (
const label i : mask)
522 const label index = unflippedSendIndex(map[i]);
524 indexUsed.set(index);
529 for (
const label i : indexUsed)
531 oldToNewSub[i] = nCompact++;
537 if (
notNull(oldToNewConstruct))
539 oldToNewConstruct.resize_nocopy(constructSize_);
540 oldToNewConstruct = -1;
543 indexUsed.resize(constructSize_);
547 const bitSet& mask = recvMasks[proci];
548 const auto& map = constructMap_[proci];
550 for (
const label i : mask)
552 const label index = unflippedRecvIndex(map[i]);
554 indexUsed.set(index);
559 for (
const label i : indexUsed)
561 oldToNewConstruct[i] = nCompact++;
569 const bitSet& mask = sendMasks[proci];
574 for (
const label i : mask)
579 map[nCompact++] = map[i];
588 label maxRemoteIndex = -1;
592 const bitSet& mask = recvMasks[proci];
597 for (
const label i : mask)
599 const label index = unflippedRecvIndex(map[i]);
600 maxRemoteIndex =
max(maxRemoteIndex, index);
602 map[nCompact++] = map[i];
605 map.resize(nCompact);
608 constructSize_ = maxRemoteIndex+1;
615 renumberMap(subMap_, oldToNewSub, subHasFlip_);
618 if (
notNull(oldToNewConstruct))
621 renumberMap(constructMap_, oldToNewConstruct, constructHasFlip_);
625 schedulePtr_.reset(
nullptr);
629 void Foam::mapDistributeBase::compactData
635 const label localSize,
642 calcCompactDataRequirements
686 const label localSize,
693 calcCompactLocalDataRequirements
728 const label localSize,
735 calcCompactRemoteDataRequirements
765 void Foam::mapDistributeBase::compactDataImpl
767 const UList<bitSet>& sendMasks,
768 const UList<bitSet>& recvMasks,
769 const bool doRenumber
803 const bitSet& allowedLocalElems,
805 const bool doRenumber
808 List<bitSet> sendMasks;
809 List<bitSet> recvMasks;
811 calcCompactLocalDataRequirements
819 compactDataImpl(sendMasks, recvMasks, doRenumber);
825 const bitSet& allowedRemoteElems,
827 const bool doRenumber
833 calcCompactRemoteDataRequirements
841 compactDataImpl(sendMasks, recvMasks, doRenumber);
847 const bitSet& allowedLocalElems,
850 const label localSize,
857 calcCompactLocalDataRequirements
878 const bitSet& allowedRemoteElems,
881 const label localSize,
888 calcCompactRemoteDataRequirements
916 compactRemoteData(
bitSet(remoteElemUsed), tag);
923 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.
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.
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...
static const List< label > & null()
Return a null List.
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...
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)
void reset()
Clear all bits but do not adjust the addressable size.
List< label > labelList
A List of labels.
bool notNull(const T *ptr)
True if ptr is not a pointer (of type T) to the nullObject.
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...