ENH: support alternative construct map layout mapDistributeBase

- when constructing from a sendMap, can now also specify a linear
  receive layout instead of a localFirst layout

  This will make it easier to reduce some code (#2932)

- add missing interface for simple distribute of List/DynamicList
  with a specified commsType. Was previously restricted to
  defaultCommsType only.

ENH: mapDistribute distribute/reverseDistribute with specified commsType

STYLE: prefer UPstream vs Pstream within mapDistribute
This commit is contained in:
Mark Olesen
2023-07-03 11:16:02 +02:00
parent 728527a345
commit 0d456a4c66
7 changed files with 506 additions and 139 deletions

View File

@ -222,7 +222,7 @@ Foam::mapDistribute::mapDistribute
:
mapDistributeBase(comm)
{
const label myRank = Pstream::myProcNo(comm);
const label myRank = UPstream::myProcNo(comm);
// Construct per processor compact addressing of the global elements
// needed. The ones from the local processor are not included since
@ -330,7 +330,7 @@ Foam::mapDistribute::mapDistribute
:
mapDistributeBase(comm)
{
const label myRank = Pstream::myProcNo(comm);
const label myRank = UPstream::myProcNo(comm);
// Construct per processor compact addressing of the global elements
// needed. The ones from the local processor are not included since

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015-2022 OpenCFD Ltd.
Copyright (C) 2015-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -409,7 +409,7 @@ public:
// Access
//- For every globalIndexAndTransform::transformPermutations
// gives the elements that need to be transformed
//- gives the elements that need to be transformed
const labelListList& transformElements() const noexcept
{
return transformElements_;
@ -433,7 +433,8 @@ public:
//- Transfer the contents of the argument and annul the argument.
void transfer(mapDistribute& map);
//- Distribute data using default commsType.
//- Distribute List data using default commsType,
//- default flip/negate operator
template<class T>
void distribute
(
@ -442,7 +443,40 @@ public:
const int tag = UPstream::msgType()
) const;
//- Distribute data using default commsType.
//- Distribute DynamicList data using default commsType,
//- default flip/negate operator
template<class T>
void distribute
(
DynamicList<T>& fld,
const bool dummyTransform = true,
const int tag = UPstream::msgType()
) const;
//- Distribute List data using specified commsType,
//- default flip/negate operator
template<class T>
void distribute
(
const UPstream::commsTypes commsType,
List<T>& fld,
const bool dummyTransform = true,
const int tag = UPstream::msgType()
) const;
//- Distribute DynamicList data using specified commsType,
//- default flip/negate operator
template<class T>
void distribute
(
const UPstream::commsTypes commsType,
DynamicList<T>& fld,
const bool dummyTransform = true,
const int tag = UPstream::msgType()
) const;
//- Distribute List data using default commsType
//- and the specified negate operator (for flips).
template<class T, class NegateOp>
void distribute
(
@ -452,11 +486,14 @@ public:
const int tag = UPstream::msgType()
) const;
//- Distribute data using default commsType.
template<class T>
//- Distribute List data using specified commsType
//- and the specified negate operator (for flips).
template<class T, class NegateOp>
void distribute
(
DynamicList<T>& fld,
const UPstream::commsTypes commsType,
List<T>& fld,
const NegateOp& negOp,
const bool dummyTransform = true,
const int tag = UPstream::msgType()
) const;
@ -471,6 +508,17 @@ public:
const int tag = UPstream::msgType()
) const;
//- Reverse distribute data using specified commsType.
template<class T>
void reverseDistribute
(
const UPstream::commsTypes commsType,
const label constructSize,
List<T>& fld,
const bool dummyTransform = true,
const int tag = UPstream::msgType()
) const;
//- Reverse distribute data using default commsType.
// Since constructSize might be larger than supplied size supply
// a nullValue
@ -484,6 +532,20 @@ public:
const int tag = UPstream::msgType()
) const;
//- Reverse distribute data using specified commsType.
// Since constructSize might be larger than supplied size supply
// a nullValue
template<class T>
void reverseDistribute
(
const UPstream::commsTypes commsType,
const label constructSize,
const T& nullValue,
List<T>& fld,
const bool dummyTransform = true,
const int tag = UPstream::msgType()
) const;
//- Distribute with transforms
template<class T, class TransformOp>
void distribute
@ -494,6 +556,18 @@ public:
const int tag = UPstream::msgType()
) const;
//- Distribute with transforms
template<class T, class TransformOp>
void distribute
(
const UPstream::commsTypes commsType,
const globalIndexAndTransform&,
List<T>& fld,
const TransformOp& top,
const int tag = UPstream::msgType()
) const;
//- Reverse distribute with transforms
template<class T, class TransformOp>
void reverseDistribute
@ -509,6 +583,31 @@ public:
template<class T, class TransformOp>
void reverseDistribute
(
const UPstream::commsTypes commsType,
const globalIndexAndTransform&,
const label constructSize,
List<T>& fld,
const TransformOp& top,
const int tag = UPstream::msgType()
) const;
//- Reverse distribute with transforms
template<class T, class TransformOp>
void reverseDistribute
(
const globalIndexAndTransform&,
const label constructSize,
const T& nullValue,
List<T>& fld,
const TransformOp& top,
const int tag = UPstream::msgType()
) const;
//- Reverse distribute with transforms
template<class T, class TransformOp>
void reverseDistribute
(
const UPstream::commsTypes commsType,
const globalIndexAndTransform&,
const label constructSize,
const T& nullValue,

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015-2017 OpenFOAM Foundation
Copyright (C) 2015-2022 OpenCFD Ltd.
Copyright (C) 2015-2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -191,8 +191,8 @@ Foam::List<Foam::labelPair> Foam::mapDistributeBase::schedule
const label comm
)
{
const label myRank = Pstream::myProcNo(comm);
const label nProcs = Pstream::nProcs(comm);
const label myRank = UPstream::myProcNo(comm);
const label nProcs = UPstream::nProcs(comm);
// Communications: send and receive processor
List<labelPair> allComms;
@ -222,14 +222,14 @@ Foam::List<Foam::labelPair> Foam::mapDistributeBase::schedule
// Gather/reduce
if (Pstream::master(comm))
if (UPstream::master(comm))
{
// Receive and merge
for (const int proci : Pstream::subProcs(comm))
for (const int proci : UPstream::subProcs(comm))
{
IPstream fromProc
(
Pstream::commsTypes::scheduled,
UPstream::commsTypes::scheduled,
proci,
0,
tag,
@ -245,12 +245,12 @@ Foam::List<Foam::labelPair> Foam::mapDistributeBase::schedule
}
else
{
if (Pstream::parRun())
if (UPstream::parRun())
{
OPstream toMaster
(
Pstream::commsTypes::scheduled,
Pstream::masterNo(),
UPstream::commsTypes::scheduled,
UPstream::masterNo(),
0,
tag,
comm
@ -310,8 +310,8 @@ const Foam::List<Foam::labelPair>& Foam::mapDistributeBase::whichSchedule
void Foam::mapDistributeBase::printLayout(Ostream& os) const
{
const label myRank = Pstream::myProcNo(comm_);
const label nProcs = Pstream::nProcs(comm_);
const label myRank = UPstream::myProcNo(comm_);
const label nProcs = UPstream::nProcs(comm_);
// Determine offsets of remote data.
labelList minIndex(nProcs, labelMax);
@ -391,8 +391,8 @@ void Foam::mapDistributeBase::calcCompactAddressing
List<Map<label>>& compactMap
) const
{
const label myRank = Pstream::myProcNo(comm_);
const label nProcs = Pstream::nProcs(comm_);
const label myRank = UPstream::myProcNo(comm_);
const label nProcs = UPstream::nProcs(comm_);
// Count all (non-local) elements needed. Just for presizing map.
labelList nNonLocal(nProcs, Zero);
@ -439,8 +439,8 @@ void Foam::mapDistributeBase::calcCompactAddressing
List<Map<label>>& compactMap
) const
{
const label myRank = Pstream::myProcNo(comm_);
const label nProcs = Pstream::nProcs(comm_);
const label myRank = UPstream::myProcNo(comm_);
const label nProcs = UPstream::nProcs(comm_);
// Count all (non-local) elements needed. Just for presizing map.
labelList nNonLocal(nProcs, Zero);
@ -495,8 +495,8 @@ void Foam::mapDistributeBase::exchangeAddressing
labelList& compactStart
)
{
const label myRank = Pstream::myProcNo(comm_);
const label nProcs = Pstream::nProcs(comm_);
const label myRank = UPstream::myProcNo(comm_);
const label nProcs = UPstream::nProcs(comm_);
// The overall compact addressing is
// - myProcNo data first (uncompacted)
@ -575,8 +575,8 @@ void Foam::mapDistributeBase::exchangeAddressing
labelList& compactStart
)
{
const label myRank = Pstream::myProcNo(comm_);
const label nProcs = Pstream::nProcs(comm_);
const label myRank = UPstream::myProcNo(comm_);
const label nProcs = UPstream::nProcs(comm_);
// The overall compact addressing is
// - myProcNo data first (uncompacted)
@ -724,8 +724,8 @@ Foam::mapDistributeBase::mapDistributeBase
comm_(comm),
schedulePtr_(nullptr)
{
const label myRank = Pstream::myProcNo(comm_);
const label nProcs = Pstream::nProcs(comm_);
const label myRank = UPstream::myProcNo(comm_);
const label nProcs = UPstream::nProcs(comm_);
if (sendProcs.size() != recvProcs.size())
{
@ -922,6 +922,7 @@ Foam::mapDistributeBase::mapDistributeBase
Foam::mapDistributeBase::mapDistributeBase
(
const layoutTypes constructLayout,
labelListList&& subMap,
const bool subHasFlip,
const bool constructHasFlip,
@ -936,17 +937,31 @@ Foam::mapDistributeBase::mapDistributeBase
comm_(comm),
schedulePtr_(nullptr)
{
const label myRank = Pstream::myProcNo(comm_);
const label nProcs = Pstream::nProcs(comm_);
const label myRank = UPstream::myProcNo(comm_);
const label nProcs = UPstream::nProcs(comm_);
// Send over how many i need to receive.
labelList recvSizes;
Pstream::exchangeSizes(subMap_, recvSizes, comm_);
// Determine order of receiving
constructSize_ = 0;
constructMap_.resize(nProcs);
// The order of receiving:
if (constructLayout == layoutTypes::linear)
{
forAll(constructMap_, proci)
{
const label len = recvSizes[proci];
constructMap_[proci] = identity(len, constructSize_);
constructSize_ += len;
}
}
else
{
// layoutTypes::localFirst
// My data first
{
@ -967,9 +982,29 @@ Foam::mapDistributeBase::mapDistributeBase
constructSize_ += len;
}
}
}
}
Foam::mapDistributeBase::mapDistributeBase
(
labelListList&& subMap,
const bool subHasFlip,
const bool constructHasFlip,
const label comm
)
:
mapDistributeBase
(
layoutTypes::localFirst,
std::move(subMap),
subHasFlip,
constructHasFlip,
comm
)
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
Foam::labelList Foam::mapDistributeBase::subMapSizes() const

View File

@ -107,6 +107,18 @@ Ostream& operator<<(Ostream&, const InfoProxy<mapDistributeBase>&);
class mapDistributeBase
{
public:
//- The map layout (eg, of the constructMap)
enum class layoutTypes : char
{
linear, //!< In processor-order
localFirst //!< Local processor first, others in linear order
};
private:
// Private Data
//- Size of reconstructed data
@ -432,6 +444,17 @@ public:
const label comm = UPstream::worldComm
);
//- Construct from my elements to send, targetting the specified
//- constructMap layout
explicit mapDistributeBase
(
const layoutTypes constructLayout,
labelListList&& subMap,
const bool subHasFlip = false,
const bool constructHasFlip = false,
const label comm = UPstream::worldComm
);
//- Construct from my elements to send.
// Assumes layout is my elements first followed by elements
// from all other processors in consecutive order.
@ -792,7 +815,7 @@ public:
template<class T, class NegateOp>
static void distribute
(
const Pstream::commsTypes commsType,
const UPstream::commsTypes commsType,
const List<labelPair>& schedule,
const label constructSize,
const labelListList& subMap,
@ -812,7 +835,7 @@ public:
template<class T, class CombineOp, class NegateOp>
static void distribute
(
const Pstream::commsTypes commsType,
const UPstream::commsTypes commsType,
const List<labelPair>& schedule,
const label constructSize,
const labelListList& subMap,
@ -828,7 +851,9 @@ public:
);
//- Distribute data using default commsType
// Distribute (simpler interface)
//- Distribute List data using default commsType
//- and the default flip/negate operator.
template<class T>
void distribute
@ -837,7 +862,7 @@ public:
const int tag = UPstream::msgType()
) const;
//- Distribute data using default commsType
//- Distribute DynamicList data using default commsType
//- and the default flip/negate operator.
template<class T>
void distribute
@ -846,6 +871,26 @@ public:
const int tag = UPstream::msgType()
) const;
//- Distribute List data using specified commsType
//- and the default flip/negate operator.
template<class T>
void distribute
(
const UPstream::commsTypes commsType,
List<T>& values,
const int tag = UPstream::msgType()
) const;
//- Distribute DynamicList data using specified commsType
//- and the default flip/negate operator.
template<class T>
void distribute
(
const UPstream::commsTypes commsType,
DynamicList<T>& values,
const int tag = UPstream::msgType()
) const;
//- Distribute data using default commsType
//- and the specified negate operator (for flips).
template<class T, class NegateOp>
@ -864,7 +909,7 @@ public:
template<class T, class NegateOp>
void distribute
(
const Pstream::commsTypes commsType,
const UPstream::commsTypes commsType,
List<T>& values,
const NegateOp& negOp,
const int tag = UPstream::msgType()
@ -878,7 +923,7 @@ public:
template<class T, class NegateOp>
void distribute
(
const Pstream::commsTypes commsType,
const UPstream::commsTypes commsType,
const T& nullValue,
List<T>& values,
const NegateOp& negOp,
@ -886,6 +931,8 @@ public:
) const;
// Reverse Distribute (simpler interface)
//- Reverse distribute data using default commsType
//- and the default flip/negate operator
template<class T>
@ -914,7 +961,7 @@ public:
template<class T>
void reverseDistribute
(
const Pstream::commsTypes commsType,
const UPstream::commsTypes commsType,
const label constructSize,
List<T>& values,
const int tag = UPstream::msgType()
@ -925,7 +972,7 @@ public:
template<class T, class NegateOp>
void reverseDistribute
(
const Pstream::commsTypes commsType,
const UPstream::commsTypes commsType,
const label constructSize,
List<T>& values,
const NegateOp& negOp,
@ -939,7 +986,7 @@ public:
template<class T>
void reverseDistribute
(
const Pstream::commsTypes commsType,
const UPstream::commsTypes commsType,
const label constructSize,
const T& nullValue,
List<T>& values,
@ -947,6 +994,8 @@ public:
) const;
// Send/Receive
//- Do all sends using PstreamBuffers
template<class T>
void send(PstreamBuffers& pBufs, const List<T>& field) const;

View File

@ -216,7 +216,7 @@ void Foam::mapDistributeBase::unionCombineMasks
<< Foam::abort(FatalError);
}
if (Pstream::parRun())
if (UPstream::parRun())
{
// Scratch buffers for union operations
List<bitSet> scratch(recvMasks.size());
@ -254,7 +254,7 @@ void Foam::mapDistributeBase::unionCombineMasks
else
{
// Non-parallel: 'synchronize' myself
const label myRank = Pstream::myProcNo(comm);
const label myRank = UPstream::myProcNo(comm);
recvMasks[myRank] &= sendMasks[myRank];
sendMasks[myRank] = recvMasks[myRank];

View File

@ -417,7 +417,7 @@ void Foam::mapDistributeBase::receive
template<class T, class NegateOp>
void Foam::mapDistributeBase::distribute
(
const Pstream::commsTypes commsType,
const UPstream::commsTypes commsType,
const List<labelPair>& schedule,
const label constructSize,
const labelListList& subMap,
@ -430,10 +430,10 @@ void Foam::mapDistributeBase::distribute
const label comm
)
{
const label myRank = Pstream::myProcNo(comm);
const label nProcs = Pstream::nProcs(comm);
const label myRank = UPstream::myProcNo(comm);
const label nProcs = UPstream::nProcs(comm);
if (!Pstream::parRun())
if (!UPstream::parRun())
{
// Do only me to me.
@ -460,13 +460,13 @@ void Foam::mapDistributeBase::distribute
return;
}
if (commsType == Pstream::commsTypes::blocking)
if (commsType == UPstream::commsTypes::blocking)
{
// Since buffered sending can reuse the field to collect the
// received data.
// Send sub field to neighbour
for (const int domain : Pstream::allProcs(comm))
for (const int domain : UPstream::allProcs(comm))
{
const labelList& map = subMap[domain];
@ -474,7 +474,7 @@ void Foam::mapDistributeBase::distribute
{
OPstream toNbr
(
Pstream::commsTypes::blocking,
UPstream::commsTypes::blocking,
domain,
0,
tag,
@ -514,7 +514,7 @@ void Foam::mapDistributeBase::distribute
}
// Receive sub field from neighbour
for (const int domain : Pstream::allProcs(comm))
for (const int domain : UPstream::allProcs(comm))
{
const labelList& map = constructMap[domain];
@ -522,7 +522,7 @@ void Foam::mapDistributeBase::distribute
{
IPstream fromNbr
(
Pstream::commsTypes::blocking,
UPstream::commsTypes::blocking,
domain,
0,
tag,
@ -544,7 +544,7 @@ void Foam::mapDistributeBase::distribute
}
}
}
else if (commsType == Pstream::commsTypes::scheduled)
else if (commsType == UPstream::commsTypes::scheduled)
{
// Need to make sure I don't overwrite field with received data
// since the data might need to be sent to another processor. So
@ -587,7 +587,7 @@ void Foam::mapDistributeBase::distribute
{
OPstream toNbr
(
Pstream::commsTypes::scheduled,
UPstream::commsTypes::scheduled,
recvProc,
0,
tag,
@ -605,7 +605,7 @@ void Foam::mapDistributeBase::distribute
{
IPstream fromNbr
(
Pstream::commsTypes::scheduled,
UPstream::commsTypes::scheduled,
recvProc,
0,
tag,
@ -634,7 +634,7 @@ void Foam::mapDistributeBase::distribute
{
IPstream fromNbr
(
Pstream::commsTypes::scheduled,
UPstream::commsTypes::scheduled,
sendProc,
0,
tag,
@ -659,7 +659,7 @@ void Foam::mapDistributeBase::distribute
{
OPstream toNbr
(
Pstream::commsTypes::scheduled,
UPstream::commsTypes::scheduled,
sendProc,
0,
tag,
@ -678,16 +678,16 @@ void Foam::mapDistributeBase::distribute
}
field.transfer(newField);
}
else if (commsType == Pstream::commsTypes::nonBlocking)
else if (commsType == UPstream::commsTypes::nonBlocking)
{
const label nOutstanding = Pstream::nRequests();
const label nOutstanding = UPstream::nRequests();
if (!is_contiguous<T>::value)
{
PstreamBuffers pBufs(Pstream::commsTypes::nonBlocking, tag, comm);
PstreamBuffers pBufs(UPstream::commsTypes::nonBlocking, tag, comm);
// Stream data into buffer
for (const int domain : Pstream::allProcs(comm))
for (const int domain : UPstream::allProcs(comm))
{
const labelList& map = subMap[domain];
@ -733,10 +733,10 @@ void Foam::mapDistributeBase::distribute
}
// Block ourselves, waiting only for the current comms
Pstream::waitRequests(nOutstanding);
UPstream::waitRequests(nOutstanding);
// Consume
for (const int domain : Pstream::allProcs(comm))
for (const int domain : UPstream::allProcs(comm))
{
const labelList& map = constructMap[domain];
@ -765,7 +765,7 @@ void Foam::mapDistributeBase::distribute
List<List<T>> sendFields(nProcs);
for (const int domain : Pstream::allProcs(comm))
for (const int domain : UPstream::allProcs(comm))
{
const labelList& map = subMap[domain];
@ -776,7 +776,7 @@ void Foam::mapDistributeBase::distribute
UOPstream::write
(
Pstream::commsTypes::nonBlocking,
UPstream::commsTypes::nonBlocking,
domain,
sendFields[domain].cdata_bytes(),
sendFields[domain].size_bytes(),
@ -790,7 +790,7 @@ void Foam::mapDistributeBase::distribute
List<List<T>> recvFields(nProcs);
for (const int domain : Pstream::allProcs(comm))
for (const int domain : UPstream::allProcs(comm))
{
const labelList& map = constructMap[domain];
@ -799,7 +799,7 @@ void Foam::mapDistributeBase::distribute
recvFields[domain].resize(map.size());
UIPstream::read
(
Pstream::commsTypes::nonBlocking,
UPstream::commsTypes::nonBlocking,
domain,
recvFields[domain].data_bytes(),
recvFields[domain].size_bytes(),
@ -839,12 +839,12 @@ void Foam::mapDistributeBase::distribute
// Wait for outstanding requests
Pstream::waitRequests(nOutstanding);
UPstream::waitRequests(nOutstanding);
// Collect neighbour fields
for (const int domain : Pstream::allProcs(comm))
for (const int domain : UPstream::allProcs(comm))
{
const labelList& map = constructMap[domain];
@ -879,7 +879,7 @@ void Foam::mapDistributeBase::distribute
template<class T, class CombineOp, class NegateOp>
void Foam::mapDistributeBase::distribute
(
const Pstream::commsTypes commsType,
const UPstream::commsTypes commsType,
const List<labelPair>& schedule,
const label constructSize,
const labelListList& subMap,
@ -894,10 +894,10 @@ void Foam::mapDistributeBase::distribute
const label comm
)
{
const label myRank = Pstream::myProcNo(comm);
const label nProcs = Pstream::nProcs(comm);
const label myRank = UPstream::myProcNo(comm);
const label nProcs = UPstream::nProcs(comm);
if (!Pstream::parRun())
if (!UPstream::parRun())
{
// Do only me to me.
@ -917,13 +917,13 @@ void Foam::mapDistributeBase::distribute
return;
}
if (commsType == Pstream::commsTypes::blocking)
if (commsType == UPstream::commsTypes::blocking)
{
// Since buffered sending can reuse the field to collect the
// received data.
// Send sub field to neighbour
for (const int domain : Pstream::allProcs(comm))
for (const int domain : UPstream::allProcs(comm))
{
const labelList& map = subMap[domain];
@ -931,7 +931,7 @@ void Foam::mapDistributeBase::distribute
{
OPstream toNbr
(
Pstream::commsTypes::blocking,
UPstream::commsTypes::blocking,
domain,
0,
tag,
@ -971,7 +971,7 @@ void Foam::mapDistributeBase::distribute
}
// Receive sub field from neighbour
for (const int domain : Pstream::allProcs(comm))
for (const int domain : UPstream::allProcs(comm))
{
const labelList& map = constructMap[domain];
@ -979,7 +979,7 @@ void Foam::mapDistributeBase::distribute
{
IPstream fromNbr
(
Pstream::commsTypes::blocking,
UPstream::commsTypes::blocking,
domain,
0,
tag,
@ -1001,7 +1001,7 @@ void Foam::mapDistributeBase::distribute
}
}
}
else if (commsType == Pstream::commsTypes::scheduled)
else if (commsType == UPstream::commsTypes::scheduled)
{
// Need to make sure I don't overwrite field with received data
// since the data might need to be sent to another processor. So
@ -1045,7 +1045,7 @@ void Foam::mapDistributeBase::distribute
{
OPstream toNbr
(
Pstream::commsTypes::scheduled,
UPstream::commsTypes::scheduled,
recvProc,
0,
tag,
@ -1064,7 +1064,7 @@ void Foam::mapDistributeBase::distribute
{
IPstream fromNbr
(
Pstream::commsTypes::scheduled,
UPstream::commsTypes::scheduled,
recvProc,
0,
tag,
@ -1092,7 +1092,7 @@ void Foam::mapDistributeBase::distribute
{
IPstream fromNbr
(
Pstream::commsTypes::scheduled,
UPstream::commsTypes::scheduled,
sendProc,
0,
tag,
@ -1116,7 +1116,7 @@ void Foam::mapDistributeBase::distribute
{
OPstream toNbr
(
Pstream::commsTypes::scheduled,
UPstream::commsTypes::scheduled,
sendProc,
0,
tag,
@ -1136,16 +1136,16 @@ void Foam::mapDistributeBase::distribute
}
field.transfer(newField);
}
else if (commsType == Pstream::commsTypes::nonBlocking)
else if (commsType == UPstream::commsTypes::nonBlocking)
{
const label nOutstanding = Pstream::nRequests();
const label nOutstanding = UPstream::nRequests();
if (!is_contiguous<T>::value)
{
PstreamBuffers pBufs(Pstream::commsTypes::nonBlocking, tag, comm);
PstreamBuffers pBufs(UPstream::commsTypes::nonBlocking, tag, comm);
// Stream data into buffer
for (const int domain : Pstream::allProcs(comm))
for (const int domain : UPstream::allProcs(comm))
{
const labelList& map = subMap[domain];
@ -1192,10 +1192,10 @@ void Foam::mapDistributeBase::distribute
}
// Block ourselves, waiting only for the current comms
Pstream::waitRequests(nOutstanding);
UPstream::waitRequests(nOutstanding);
// Consume
for (const int domain : Pstream::allProcs(comm))
for (const int domain : UPstream::allProcs(comm))
{
const labelList& map = constructMap[domain];
@ -1224,7 +1224,7 @@ void Foam::mapDistributeBase::distribute
List<List<T>> sendFields(nProcs);
for (const int domain : Pstream::allProcs(comm))
for (const int domain : UPstream::allProcs(comm))
{
const labelList& map = subMap[domain];
@ -1235,7 +1235,7 @@ void Foam::mapDistributeBase::distribute
UOPstream::write
(
Pstream::commsTypes::nonBlocking,
UPstream::commsTypes::nonBlocking,
domain,
sendFields[domain].cdata_bytes(),
sendFields[domain].size_bytes(),
@ -1249,7 +1249,7 @@ void Foam::mapDistributeBase::distribute
List<List<T>> recvFields(nProcs);
for (const int domain : Pstream::allProcs(comm))
for (const int domain : UPstream::allProcs(comm))
{
const labelList& map = constructMap[domain];
@ -1258,7 +1258,7 @@ void Foam::mapDistributeBase::distribute
recvFields[domain].resize(map.size());
UIPstream::read
(
Pstream::commsTypes::nonBlocking,
UPstream::commsTypes::nonBlocking,
domain,
recvFields[domain].data_bytes(),
recvFields[domain].size_bytes(),
@ -1298,12 +1298,12 @@ void Foam::mapDistributeBase::distribute
// Wait for outstanding requests
Pstream::waitRequests(nOutstanding);
UPstream::waitRequests(nOutstanding);
// Collect neighbour fields
for (const int domain : Pstream::allProcs(comm))
for (const int domain : UPstream::allProcs(comm))
{
const labelList& map = constructMap[domain];
@ -1340,7 +1340,7 @@ void Foam::mapDistributeBase::send(PstreamBuffers& pBufs, const List<T>& field)
const
{
// Stream data into buffer
for (const int domain : Pstream::allProcs(comm_))
for (const int domain : UPstream::allProcs(comm_))
{
const labelList& map = subMap_[domain];
@ -1370,7 +1370,7 @@ const
// Consume
field.resize_nocopy(constructSize_);
for (const int domain : Pstream::allProcs(comm_))
for (const int domain : UPstream::allProcs(comm_))
{
const labelList& map = constructMap_[domain];
@ -1405,7 +1405,7 @@ const
template<class T, class NegateOp>
void Foam::mapDistributeBase::distribute
(
const Pstream::commsTypes commsType,
const UPstream::commsTypes commsType,
List<T>& values,
const NegateOp& negOp,
const int tag
@ -1431,7 +1431,7 @@ void Foam::mapDistributeBase::distribute
template<class T, class NegateOp>
void Foam::mapDistributeBase::distribute
(
const Pstream::commsTypes commsType,
const UPstream::commsTypes commsType,
const T& nullValue,
List<T>& values,
const NegateOp& negOp,
@ -1475,11 +1475,41 @@ void Foam::mapDistributeBase::distribute
template<class T>
void Foam::mapDistributeBase::distribute
(
const UPstream::commsTypes commsType,
List<T>& values,
const int tag
) const
{
distribute(values, flipOp(), tag);
distribute(commsType, values, flipOp(), tag);
}
template<class T>
void Foam::mapDistributeBase::distribute
(
const UPstream::commsTypes commsType,
DynamicList<T>& values,
const int tag
) const
{
values.shrink();
List<T>& list = static_cast<List<T>&>(values);
distribute(commsType, list, tag);
values.setCapacity(list.size());
}
template<class T>
void Foam::mapDistributeBase::distribute
(
List<T>& values,
const int tag
) const
{
distribute(UPstream::defaultCommsType, values, tag);
}
@ -1490,20 +1520,14 @@ void Foam::mapDistributeBase::distribute
const int tag
) const
{
values.shrink();
List<T>& list = static_cast<List<T>&>(values);
distribute(list, tag);
values.setCapacity(list.size());
distribute(UPstream::defaultCommsType, values, tag);
}
template<class T>
void Foam::mapDistributeBase::reverseDistribute
(
const Pstream::commsTypes commsType,
const UPstream::commsTypes commsType,
const label constructSize,
List<T>& values,
const int tag
@ -1523,7 +1547,7 @@ void Foam::mapDistributeBase::reverseDistribute
template<class T, class NegateOp>
void Foam::mapDistributeBase::reverseDistribute
(
const Pstream::commsTypes commsType,
const UPstream::commsTypes commsType,
const label constructSize,
List<T>& values,
const NegateOp& negOp,
@ -1550,7 +1574,7 @@ void Foam::mapDistributeBase::reverseDistribute
template<class T>
void Foam::mapDistributeBase::reverseDistribute
(
const Pstream::commsTypes commsType,
const UPstream::commsTypes commsType,
const label constructSize,
const T& nullValue,
List<T>& values,

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -39,7 +40,6 @@ void Foam::mapDistribute::applyDummyTransforms(List<T>& field) const
forAll(transformElements_, trafoI)
{
const labelList& elems = transformElements_[trafoI];
label n = transformStart_[trafoI];
forAll(elems, i)
@ -129,13 +129,14 @@ void Foam::mapDistribute::applyInverseTransforms
template<class T, class NegateOp>
void Foam::mapDistribute::distribute
(
const UPstream::commsTypes commsType,
List<T>& fld,
const NegateOp& negOp,
const bool dummyTransform,
const int tag
) const
{
mapDistributeBase::distribute(fld, negOp, tag);
mapDistributeBase::distribute(commsType, fld, negOp, tag);
//- Fill in transformed slots with copies
if (dummyTransform)
@ -145,6 +146,32 @@ void Foam::mapDistribute::distribute
}
template<class T, class NegateOp>
void Foam::mapDistribute::distribute
(
List<T>& fld,
const NegateOp& negOp,
const bool dummyTransform,
const int tag
) const
{
distribute(UPstream::defaultCommsType, fld, negOp, dummyTransform, tag);
}
template<class T>
void Foam::mapDistribute::distribute
(
const UPstream::commsTypes commsType,
List<T>& fld,
const bool dummyTransform,
const int tag
) const
{
distribute(commsType, fld, flipOp(), dummyTransform, tag);
}
template<class T>
void Foam::mapDistribute::distribute
(
@ -153,7 +180,26 @@ void Foam::mapDistribute::distribute
const int tag
) const
{
distribute(fld, flipOp(), dummyTransform, tag);
distribute(UPstream::defaultCommsType, fld, dummyTransform, tag);
}
template<class T>
void Foam::mapDistribute::distribute
(
const UPstream::commsTypes commsType,
DynamicList<T>& fld,
const bool dummyTransform,
const int tag
) const
{
fld.shrink();
List<T>& list = static_cast<List<T>&>(fld);
distribute(commsType, list, dummyTransform, tag);
fld.setCapacity(list.size());
}
@ -165,13 +211,26 @@ void Foam::mapDistribute::distribute
const int tag
) const
{
fld.shrink();
distribute(UPstream::defaultCommsType, fld, dummyTransform, tag);
}
List<T>& list = static_cast<List<T>&>(fld);
distribute(list, dummyTransform, tag);
template<class T>
void Foam::mapDistribute::reverseDistribute
(
const UPstream::commsTypes commsType,
const label constructSize,
List<T>& fld,
const bool dummyTransform,
const int tag
) const
{
if (dummyTransform)
{
applyDummyInverseTransforms(fld);
}
fld.setCapacity(list.size());
mapDistributeBase::reverseDistribute(commsType, constructSize, fld, tag);
}
@ -183,13 +242,42 @@ void Foam::mapDistribute::reverseDistribute
const bool dummyTransform,
const int tag
) const
{
reverseDistribute
(
UPstream::defaultCommsType,
constructSize,
fld,
dummyTransform,
tag
);
}
template<class T>
void Foam::mapDistribute::reverseDistribute
(
const UPstream::commsTypes commsType,
const label constructSize,
const T& nullValue,
List<T>& fld,
const bool dummyTransform,
const int tag
) const
{
if (dummyTransform)
{
applyDummyInverseTransforms(fld);
}
mapDistributeBase::reverseDistribute(constructSize, fld, tag);
mapDistributeBase::reverseDistribute
(
commsType,
constructSize,
nullValue,
fld,
tag
);
}
@ -203,12 +291,33 @@ void Foam::mapDistribute::reverseDistribute
const int tag
) const
{
if (dummyTransform)
{
applyDummyInverseTransforms(fld);
}
reverseDistribute
(
UPstream::defaultCommsType,
constructSize,
nullValue,
fld,
dummyTransform,
tag
);
}
mapDistributeBase::reverseDistribute(constructSize, nullValue, fld, tag);
template<class T, class TransformOp>
void Foam::mapDistribute::distribute
(
const UPstream::commsTypes commsType,
const globalIndexAndTransform& git,
List<T>& fld,
const TransformOp& top,
const int tag
) const
{
// Distribute. Leave out dummy transforms since we're doing them ourselves
distribute(commsType, fld, false, tag);
// Do transforms
applyTransforms(git, fld, top);
}
@ -222,10 +331,28 @@ void Foam::mapDistribute::distribute
) const
{
// Distribute. Leave out dummy transforms since we're doing them ourselves
distribute(fld, false, tag);
distribute(UPstream::defaultCommsType, git, fld, top, tag);
}
// Do transforms
applyTransforms(git, fld, top);
template<class T, class TransformOp>
void Foam::mapDistribute::reverseDistribute
(
const UPstream::commsTypes commsType,
const globalIndexAndTransform& git,
const label constructSize,
List<T>& fld,
const TransformOp& top,
const int tag
) const
{
// Fill slots with reverse-transformed data. Note that it also copies
// back into the non-remote part of fld even though these values are not
// used.
applyInverseTransforms(git, fld, top);
// And send back (the remote slots). Disable dummy transformations.
reverseDistribute(commsType, constructSize, fld, false, tag);
}
@ -252,6 +379,7 @@ void Foam::mapDistribute::reverseDistribute
template<class T, class TransformOp>
void Foam::mapDistribute::reverseDistribute
(
const UPstream::commsTypes commsType,
const globalIndexAndTransform& git,
const label constructSize,
const T& nullValue,
@ -266,7 +394,39 @@ void Foam::mapDistribute::reverseDistribute
applyInverseTransforms(git, fld, top); //, eqOp<T>());
// And send back (the remote slots) Disable dummy transformations.
reverseDistribute(constructSize, nullValue, fld, false, tag);
reverseDistribute
(
commsType,
constructSize,
nullValue,
fld,
false,
tag
);
}
template<class T, class TransformOp>
void Foam::mapDistribute::reverseDistribute
(
const globalIndexAndTransform& git,
const label constructSize,
const T& nullValue,
List<T>& fld,
const TransformOp& top,
const int tag
) const
{
reverseDistribute
(
UPstream::defaultCommsType,
git,
constructSize,
nullValue,
fld,
top,
tag
);
}