Skip to content
Snippets Groups Projects
Commit fb96a4b1 authored by Oliver Sander's avatar Oliver Sander Committed by sander
Browse files

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]]
parent 76b268c7
No related branches found
No related tags found
No related merge requests found
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
template<typename GUIndex, typename VectorType> template<typename GUIndex, typename VectorType>
class VectorCommunicator { class VectorCommunicator {
public:
struct TransferVectorTuple { struct TransferVectorTuple {
typedef typename VectorType::value_type EntryType; typedef typename VectorType::value_type EntryType;
...@@ -20,15 +20,7 @@ public: ...@@ -20,15 +20,7 @@ public:
TransferVectorTuple(const size_t& r, const EntryType& e) : row(r), entry(e) {} TransferVectorTuple(const size_t& r, const EntryType& e) : row(r), entry(e) {}
}; };
public: private:
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());
}
void transferVector(const VectorType& localVector) { void transferVector(const VectorType& localVector) {
// Create vector for transfer data // Create vector for transfer data
std::vector<TransferVectorTuple> localVectorEntries; std::vector<TransferVectorTuple> localVectorEntries;
...@@ -51,7 +43,6 @@ public: ...@@ -51,7 +43,6 @@ public:
for (size_t k = 0; k < globalVectorEntries.size(); ++k) for (size_t k = 0; k < globalVectorEntries.size(); ++k)
globalVector[globalVectorEntries[k].row] += globalVectorEntries[k].entry; globalVector[globalVectorEntries[k].row] += globalVectorEntries[k].entry;
return globalVector; return globalVector;
} }
...@@ -64,6 +55,25 @@ public: ...@@ -64,6 +55,25 @@ public:
return globalVector; 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) { void fillEntriesFromVector(const VectorType& x_global) {
for (size_t k = 0; k < globalVectorEntries.size(); ++k) for (size_t k = 0; k < globalVectorEntries.size(); ++k)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment