TRIQS/triqs_cthyb 4.0.0
A TRIQS application
Loading...
Searching...
No Matches
average_order.hpp
1/*******************************************************************************
2 *
3 * TRIQS: a Toolbox for Research in Interacting Quantum Systems
4 *
5 * Copyright (C) 2021, Simons Foundation
6 * author: N. Wentzell
7 *
8 * TRIQS is free software: you can redistribute it and/or modify it under the
9 * terms of the GNU General Public License as published by the Free Software
10 * Foundation, either version 3 of the License, or (at your option) any later
11 * version.
12 *
13 * TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY
14 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 * details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * TRIQS. If not, see <http://www.gnu.org/licenses/>.
20 *
21 ******************************************************************************/
22#pragma once
23#include "../qmc_data.hpp"
24
25namespace triqs_cthyb {
26
28 struct measure_average_order {
29
30 measure_average_order(qmc_data const &_data, double &_average_order) : data(_data), average_order(_average_order) { average_order = 0.0; }
31
32 void accumulate(mc_weight_t) {
33 average_order += data.config.size() / 2;
34 ++N;
35 }
36
37 void collect_results(mpi::communicator const &comm) {
38 N = mpi::all_reduce(N, comm);
39
40 // Reduce and normalize
41 average_order = mpi::all_reduce(average_order, comm);
42 average_order = average_order / N;
43 }
44
45 private:
46 // The Monte-Carlo configuration
47 qmc_data const &data;
48
49 // Reference to double for accumulation
50 double &average_order;
51
52 // Accumulation counter
53 long long N = 0;
54 };
55
56} // namespace triqs_cthyb