
Hello, how can I use the mpi::all_reduce with std::accumulate? I would reduce the values of each process with a sum function Thanks Phil

Hi Phillip,
On Thu, Dec 2, 2010 at 7:08 PM, Kraus Philipp
how can I use the mpi::all_reduce with std::accumulate? I would reduce the values of each process with a sum function
You can use mpi::all_reduce like this:: int local_value = ...; // local computation int global_value = 0; mpi::all_reduce(comm_, local_value, global_value, std::plus<int>()); // now `global_value` holds the sum of `local_value` of all MPI ranks where `comm_` is an instance of mpi::communicator; other binary operations are available besides std::plus (or you can define your own). Best regards, Riccardo

On 2010-12-02 23:37:34 +0100, Riccardo Murri said:
Hi Phillip,
On Thu, Dec 2, 2010 at 7:08 PM, Kraus Philipp
wrote: how can I use the mpi::all_reduce with std::accumulate? I would reduce the values of each process with a sum function
You can use mpi::all_reduce like this::
int local_value = ...; // local computation int global_value = 0; mpi::all_reduce(comm_, local_value, global_value, std::plus<int>()); // now `global_value` holds the sum of `local_value` of all MPI ranks
where `comm_` is an instance of mpi::communicator; other binary operations are available besides std::plus (or you can define your own).
Thank's Phil
participants (3)
-
Kraus Philipp
-
Philipp Kraus
-
Riccardo Murri