24#include <boost/mpi/collectives/gather.hpp>
25#include <boost/mpi/communicator.hpp>
26#include <boost/serialization/vector.hpp>
32namespace Observables::detail {
36auto gather(boost::mpi::communicator
const &comm,
37 std::vector<Pos>
const &local_pos) {
38 std::vector<std::vector<Pos>> global_pos{};
39 global_pos.reserve(
static_cast<std::size_t
>(comm.size()));
40 boost::mpi::gather(comm, local_pos, global_pos, 0);
45template <
class Pos,
class Val>
46auto gather(boost::mpi::communicator
const &comm,
47 std::vector<Pos>
const &local_pos,
48 std::vector<Val>
const &local_val) {
49 std::vector<std::vector<Pos>> global_pos{};
50 global_pos.reserve(
static_cast<std::size_t
>(comm.size()));
51 boost::mpi::gather(comm, local_pos, global_pos, 0);
52 std::vector<std::vector<Val>> global_val{};
53 global_val.reserve(
static_cast<std::size_t
>(comm.size()));
54 boost::mpi::gather(comm, local_val, global_val, 0);
55 return std::make_pair(global_pos, global_val);
59template <
class T, std::
size_t N, std::
size_t M,
class U,
class Pos,
class Val>
61 std::vector<std::vector<Pos>>
const &pos,
62 std::vector<std::vector<Val>>
const &val) {
63 for (std::size_t rank = 0u; rank < pos.size(); ++rank) {
64 auto const &pos_vec = pos[rank];
65 auto const &val_vec = val[rank];
66 for (std::size_t i = 0u; i < pos_vec.size(); ++i) {
67 histogram.
update(pos_vec[i], val_vec[i]);
72struct empty_bin_exception {};
75template <
class T, std::
size_t N, std::
size_t M,
class U>
77 bool allow_empty_bins =
true) {
80 for (std::size_t i = 0u; i < hist_data.size(); ++i) {
81 if (tot_count[i] != 0u) {
82 hist_data[i] /=
static_cast<double>(tot_count[i]);
83 }
else if (not allow_empty_bins) {
84 throw empty_bin_exception{};
Histogram in Cartesian coordinates.
std::vector< std::size_t > get_tot_count() const
Get the histogram count data.
std::vector< T > get_histogram() const
Get the histogram data.
void update(std::span< const U > pos)
Add data to the histogram.