mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: globalIndex: inplace gather
This commit is contained in:
@ -162,6 +162,17 @@ public:
|
||||
const int tag = UPstream::msgType()
|
||||
) const;
|
||||
|
||||
//- Inplace collect data in processor order on master
|
||||
// (== procIDs[0]). Needs offsets only on master.
|
||||
template<class Type>
|
||||
void gather
|
||||
(
|
||||
const label comm,
|
||||
const labelList& procIDs,
|
||||
List<Type>& fld,
|
||||
const int tag = UPstream::msgType()
|
||||
) const;
|
||||
|
||||
//- Distribute data in processor order. Requires fld to be sized!
|
||||
template<class Type>
|
||||
void scatter
|
||||
|
||||
@ -109,6 +109,89 @@ void Foam::globalIndex::gather
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::globalIndex::gather
|
||||
(
|
||||
const label comm,
|
||||
const labelList& procIDs,
|
||||
List<Type>& fld,
|
||||
const int tag
|
||||
) const
|
||||
{
|
||||
if (Pstream::myProcNo(comm) == procIDs[0])
|
||||
{
|
||||
List<Type> allFld(size());
|
||||
|
||||
// Assign my local data
|
||||
SubList<Type>(allFld, fld.size(), 0).assign(fld);
|
||||
|
||||
for (label i = 1; i < procIDs.size(); i++)
|
||||
{
|
||||
SubList<Type> procSlot
|
||||
(
|
||||
allFld,
|
||||
offsets_[i+1]-offsets_[i],
|
||||
offsets_[i]
|
||||
);
|
||||
|
||||
if (contiguous<Type>())
|
||||
{
|
||||
IPstream::read
|
||||
(
|
||||
Pstream::scheduled,
|
||||
procIDs[i],
|
||||
reinterpret_cast<char*>(procSlot.begin()),
|
||||
procSlot.byteSize(),
|
||||
tag,
|
||||
comm
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
IPstream fromSlave
|
||||
(
|
||||
Pstream::scheduled,
|
||||
procIDs[i],
|
||||
0,
|
||||
tag,
|
||||
comm
|
||||
);
|
||||
fromSlave >> procSlot;
|
||||
}
|
||||
}
|
||||
|
||||
fld.transfer(allFld);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (contiguous<Type>())
|
||||
{
|
||||
OPstream::write
|
||||
(
|
||||
Pstream::scheduled,
|
||||
procIDs[0],
|
||||
reinterpret_cast<const char*>(fld.begin()),
|
||||
fld.byteSize(),
|
||||
tag,
|
||||
comm
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
OPstream toMaster
|
||||
(
|
||||
Pstream::scheduled,
|
||||
procIDs[0],
|
||||
0,
|
||||
tag,
|
||||
comm
|
||||
);
|
||||
toMaster << fld;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::globalIndex::scatter
|
||||
(
|
||||
|
||||
Reference in New Issue
Block a user