Skip to content
Snippets Groups Projects
Commit 2981f4fd authored by Dmitri Naumov's avatar Dmitri Naumov
Browse files

[BL/MPI] allgather version for vectors

parent c2cead6f
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,8 @@
#pragma once
#include <algorithm>
#include "Error.h"
#ifdef USE_PETSC
......@@ -86,6 +88,21 @@ static std::vector<T> allgather(T const& value, Mpi const& mpi)
return result;
}
template <typename T>
static std::vector<T> allgather(std::vector<T> const& vector, Mpi const& mpi)
{
std::size_t const size = vector.size();
// Flat in memory over all ranks;
std::vector<T> result(mpi.size * size);
std::copy_n(vector.begin(), size, &result[mpi.rank * size]);
MPI_Allgather(&result[mpi.rank * size], size, mpiType<T>(), result.data(),
size, mpiType<T>(), mpi.communicator);
return result;
}
template <typename T>
static T allreduce(T const& value, MPI_Op const& mpi_op, Mpi const& mpi)
{
......
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