TRIQS/triqs_ctint 4.0.0
A TRIQS application
Loading...
Searching...
No Matches
histogram.cpp
1// Copyright (c) 2018--present, The Simons Foundation
2// This file is part of TRIQS/ctint and is licensed under the terms of GPLv3 or later.
3// SPDX-License-Identifier: GPL-3.0-or-later
4// See LICENSE in the root of this distribution for details.
5
6#include "./histogram.hpp"
7
8namespace triqs_ctint::measures {
9
10 histogram::histogram(params_t const &, qmc_config_t const &qmc_config_, container_set *results)
11 : qmc_config(qmc_config_), histogram_(results->histogram) {
12 results->histogram = std::vector<double>(4);
13 }
14
15 void histogram::accumulate(mc_weight_t) {
16 int k = qmc_config.perturbation_order();
17 while (k >= histogram_->size()) histogram_->resize(2 * histogram_->size());
18 histogram_.value()[k] += 1.;
19 ++N;
20 }
21
22 void histogram::collect_results(mpi::communicator const &comm) {
23 N = mpi::all_reduce(N, comm);
24
25 // Make sure that all mpi threads have an equally sized histogram
26 auto max_size = mpi::all_reduce(histogram_->size(), comm, MPI_MAX);
27 histogram_->resize(max_size, 0.0);
28
29 // Reduce histogram over all mpi threads
30 histogram_ = mpi::all_reduce(histogram_.value(), comm);
31 for (auto &h_k : histogram_.value()) h_k = h_k / N;
32 }
33} // namespace triqs_ctint::measures