Hi! This might be a silly question, but what the "correct" way of using MPI::all_reduce
, when I want to reduce a std::vector
? Apart from resorting to boost.MPI.
Let's say I want to sum all values of a vector, I can do this in old MPI calls, but I can't see how I can do this with Fenics calls.
Can you help me?
Thanks!
std::vector<int> w(10), e(10);
for (int i = 1; i <= 10; i++)
{
w[i - 1] = (i * MPI::rank(MPI_COMM_WORLD));
}
MPI_Allreduce(w.data(), e.data(), 10, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
//???? ----> MPI::all_reduce(MPI_COMM_WORLD, w, MPI_SUM); <----
for (int i = 1; i <= 10; i++)
std::cout << "RANK " << MPI::rank(MPI_COMM_WORLD) << " REDUCE " << i - 1 << " = " << e[i - 1] << " LOCAL = " << w[i - 1] << std::endl;