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

Let the code in mpifunctions.hh only see the communicator object, not the grid view

[[Imported from SVN: r9920]]
parent 155da3eb
No related branches found
No related tags found
No related merge requests found
......@@ -38,10 +38,10 @@ class MatrixCommunicator {
}
// Get number of matrix entries on each process
std::vector<int> localMatrixEntriesSizes(MPIFunctions::shareSizes(guIndex1_.getGridView(), localMatrixEntries.size()));
std::vector<int> localMatrixEntriesSizes(MPIFunctions::shareSizes(guIndex1_.getGridView().comm(), localMatrixEntries.size()));
// Get matrix entries from every process
globalMatrixEntries = MPIFunctions::gatherv(guIndex1_.getGridView(), localMatrixEntries, localMatrixEntriesSizes, root_rank);
globalMatrixEntries = MPIFunctions::gatherv(guIndex1_.getGridView().comm(), localMatrixEntries, localMatrixEntriesSizes, root_rank);
}
public:
......
......@@ -14,52 +14,52 @@ struct MPIFunctions {
return offsets;
}
template<typename GridView>
static std::vector<int> shareSizes(const GridView& gridview, const int& shareRef) {
std::vector<int> sizesVector(gridview.comm().size());
template<typename Communicator>
static std::vector<int> shareSizes(const Communicator& communicator, const int& shareRef) {
std::vector<int> sizesVector(communicator.size());
int share = shareRef;
gridview.comm().template allgather<int>(&share, 1, sizesVector.data());
communicator.template allgather<int>(&share, 1, sizesVector.data());
return sizesVector;
}
template<typename GridView, typename T>
static void scatterv(const GridView& gridview, std::vector<T>& localVec, std::vector<T>& globalVec, std::vector<int>& sizes, int root_rank) {
template<typename Communicator, typename T>
static void scatterv(const Communicator& communicator, std::vector<T>& localVec, std::vector<T>& globalVec, std::vector<int>& sizes, int root_rank) {
int mysize = localVec.size();
std::vector<int> offsets(offsetsFromSizes(sizes));
gridview.comm().template scatterv(globalVec.data(), sizes.data(), offsets.data(), localVec.data(), mysize, root_rank);
communicator.template scatterv(globalVec.data(), sizes.data(), offsets.data(), localVec.data(), mysize, root_rank);
}
template<typename GridView, typename T>
static std::vector<T> gatherv(const GridView& gridview, std::vector<T>& localVec, std::vector<int>& sizes, int root_rank) {
template<typename Communicator, typename T>
static std::vector<T> gatherv(const Communicator& communicator, std::vector<T>& localVec, std::vector<int>& sizes, int root_rank) {
int mysize = localVec.size();
std::vector<T> globalVec;
if (gridview.comm().rank() == root_rank)
if (communicator.rank() == root_rank)
globalVec.resize(std::accumulate(sizes.begin(), sizes.end(), 0));
std::vector<int> offsets(offsetsFromSizes(sizes));
gridview.comm().template gatherv(localVec.data(), mysize, globalVec.data(), sizes.data(), offsets.data(), root_rank);
communicator.template gatherv(localVec.data(), mysize, globalVec.data(), sizes.data(), offsets.data(), root_rank);
return globalVec;
}
template<typename GridView, typename T>
static std::vector<T> allgatherv(const GridView& gridview, std::vector<T>& localVec, std::vector<int>& sizes) {
template<typename Communicator, typename T>
static std::vector<T> allgatherv(const Communicator& communicator, std::vector<T>& localVec, std::vector<int>& sizes) {
int mysize = localVec.size();
std::vector<T> globalVec(std::accumulate(sizes.begin(), sizes.end(), 0));
std::vector<int> offsets(offsetsFromSizes(sizes));
gridview.comm().template allgatherv(localVec.data(), mysize, globalVec.data(), sizes.data(), offsets.data());
communicator.template allgatherv(localVec.data(), mysize, globalVec.data(), sizes.data(), offsets.data());
return globalVec;
......
......@@ -32,10 +32,10 @@ private:
localVectorEntries.push_back(TransferVectorTuple(guIndex.index(k), localVector[k]));
// Get number of vector entries on each process
localVectorEntriesSizes = MPIFunctions::shareSizes(guIndex.getGridView(), localVectorEntries.size());
localVectorEntriesSizes = MPIFunctions::shareSizes(guIndex.getGridView().comm(), localVectorEntries.size());
// Get vector entries from every process
globalVectorEntries = MPIFunctions::gatherv(guIndex.getGridView(), localVectorEntries, localVectorEntriesSizes, root_rank);
globalVectorEntries = MPIFunctions::gatherv(guIndex.getGridView().comm(), localVectorEntries, localVectorEntriesSizes, root_rank);
}
public:
......@@ -43,7 +43,7 @@ public:
: guIndex(gi), root_rank(root)
{
// Get number of vector entries on each process
localVectorEntriesSizes = MPIFunctions::shareSizes(guIndex.getGridView(), guIndex.nOwnedLocalEntity());
localVectorEntriesSizes = MPIFunctions::shareSizes(guIndex.getGridView().comm(), guIndex.nOwnedLocalEntity());
}
VectorType reduceAdd(const VectorType& localVector)
......@@ -81,7 +81,7 @@ public:
// Create vector for transfer data
std::vector<TransferVectorTuple> localVectorEntries(localSize);
MPIFunctions::scatterv(guIndex.getGridView(), localVectorEntries, globalVectorEntries, localVectorEntriesSizes, root_rank);
MPIFunctions::scatterv(guIndex.getGridView().comm(), localVectorEntries, globalVectorEntries, localVectorEntriesSizes, root_rank);
// Create vector for local solution
VectorType x(localSize);
......
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