Commit 98614912 authored by Sebastian Aland's avatar Sebastian Aland

added synchMultiVector function to get correct sync after coarsening operations

parent f7b6e563
......@@ -282,6 +282,74 @@ namespace AMDiS { namespace Parallel {
synchVector(vec);
}
/** \brief
* Synchronize \p vec using indicator vector \p additionalVecs, e.g. let
* additionalVecs[0] be 1 on all dofs the value should be taken from
my rank
* and 0 elsewhere.
*/
// op(std::vector<T>& out, std::vector<T> const& in)
template<typename T, typename Operator>
void synchMultiVector(DOFVector<T> &vec, std::vector<DOFVector<T>*> additionalVecs, Operator op)
{
// get FE space and check equal FE space
const FiniteElemSpace *fe = vec.getFeSpace();
MultiLevelDofComm& dofComm = dofComms[fe->getMesh()];
typedef typename std::vector<DOFVector<T>*>::iterator Iterator;
int nLevels = levelData.getNumberOfLevels();
for (int level = nLevels - 1; level >= 0; level--)
{
StdMpi < std::vector<std::vector<T> > >
stdMpi(levelData.getMpiComm(level));
for (DofComm::Iterator it(dofComm[level].getRecvDofs(), fe);
!it.end(); it.nextRank())
{
std::vector<std::vector<T> > dofs;
dofs.reserve(it.getDofs().size());
for (; !it.endDofIter(); it.nextDof())
{
std::vector<T> values;
values.reserve(additionalVecs.size() + 1);
values.push_back( vec[it.getDofIndex()] );
for (Iterator vecIt = additionalVecs.begin(); vecIt !=
additionalVecs.end(); ++vecIt )
values.push_back( (**vecIt)[it.getDofIndex()] );
dofs.push_back( values );
}
stdMpi.send(it.getRank(), dofs);
}
for (DofComm::Iterator it(dofComm[level].getSendDofs(), fe);
!it.end(); it.nextRank())
stdMpi.recv(it.getRank());
stdMpi.startCommunication();
for (DofComm::Iterator it(dofComm[level].getSendDofs(), fe);
!it.end(); it.nextRank()) {
for (; !it.endDofIter(); it.nextDof()) {
std::vector<T> values;
values.reserve(additionalVecs.size() + 1);
values.push_back( vec[it.getDofIndex()] );
for (Iterator vecIt = additionalVecs.begin(); vecIt !=
additionalVecs.end(); ++vecIt )
values.push_back( (**vecIt)[it.getDofIndex()] );
op(values, stdMpi.getRecvData(it.getRank())[it.getDofCounter()]);
}
}
}
synchVector(vec);
}
/** \brief
* This function must be used if the values of a set of DOFVectors must be
* synchronized over all ranks. That means, that each rank sends the
......
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