From fb96a4b108d2797813c28f00cac9508b297cf04b Mon Sep 17 00:00:00 2001 From: Oliver Sander <sander@igpm.rwth-aachen.de> Date: Wed, 14 May 2014 15:26:54 +0000 Subject: [PATCH] Introduce new methods reduceAdd and reduceCopy Those do many-to-one communication with a single method call. Previously, two subsequent calls were needed. There is no reason why the interface has to consist of two calls. A single one is much easier to use. [[Imported from SVN: r9730]] --- dune/gfe/parallel/vectorcommunicator.hh | 32 ++++++++++++++++--------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/dune/gfe/parallel/vectorcommunicator.hh b/dune/gfe/parallel/vectorcommunicator.hh index 8be602c0..7dca7e45 100644 --- a/dune/gfe/parallel/vectorcommunicator.hh +++ b/dune/gfe/parallel/vectorcommunicator.hh @@ -9,7 +9,7 @@ template<typename GUIndex, typename VectorType> class VectorCommunicator { -public: + struct TransferVectorTuple { typedef typename VectorType::value_type EntryType; @@ -20,15 +20,7 @@ public: TransferVectorTuple(const size_t& r, const EntryType& e) : row(r), entry(e) {} }; -public: - VectorCommunicator(const GUIndex& gi, const int& root) - : guIndex(gi), root_rank(root) - { - // Get number of vector entries on each process - localVectorEntriesSizes = MPIFunctions::shareSizes(guIndex.getGridView(), guIndex.nOwnedLocalEntity()); - } - - +private: void transferVector(const VectorType& localVector) { // Create vector for transfer data std::vector<TransferVectorTuple> localVectorEntries; @@ -51,7 +43,6 @@ public: for (size_t k = 0; k < globalVectorEntries.size(); ++k) globalVector[globalVectorEntries[k].row] += globalVectorEntries[k].entry; - return globalVector; } @@ -64,6 +55,25 @@ public: return globalVector; } +public: + VectorCommunicator(const GUIndex& gi, const int& root) + : guIndex(gi), root_rank(root) + { + // Get number of vector entries on each process + localVectorEntriesSizes = MPIFunctions::shareSizes(guIndex.getGridView(), guIndex.nOwnedLocalEntity()); + } + + VectorType reduceAdd(const VectorType& localVector) + { + transferVector(localVector); + return createGlobalVector(); + } + + VectorType reduceCopy(const VectorType& localVector) + { + transferVector(localVector); + return copyIntoGlobalVector(); + } void fillEntriesFromVector(const VectorType& x_global) { for (size_t k = 0; k < globalVectorEntries.size(); ++k) -- GitLab