triqs::stat::mean_mpi

#include <triqs/stat.hpp>

Synopsis

template<typename V>
auto mean_mpi (communicator c, V const & data)

Calculate the arithmetic mean [REF] of data spread over multiple MPI threads. Reduces the answer to all threads.

Template parameters

  • V Iterable type. Pre-conditions: elements must be addable to each other and must be MPI reducible

Parameters

  • data Container with data

Returns

Mean of data on all threads reduced to all threads; type is deduced from first element of data

Example

#include <triqs/stat/mean_error.hpp>
#include <mpi/mpi.hpp>

using namespace triqs::stat;

int main() {
  mpi::communicator world;
  int rank = world.rank();
  // Define linear data spread over the different mpi threads:
  // thread 0: {1,2,3,4}; thread 1 {5,6,7,8}, etc.
  std::vector<double> data{4. * rank + 1, 4. * rank + 2, 4. * rank + 3, 4. * rank + 4};

  auto ave = mean_mpi(world, data);

  std::cout << "Average: " << ave << std::endl;
  // =  (1.0 + 4.0 * world.size()) / 2.0
}

Output

Average: 2.5