Commit 5c517879 authored by mattijs's avatar mattijs
Browse files

ENH: globalIndex: inplace gather

parent ceb4f3a6
......@@ -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
(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment