TRIQS/triqs_cthyb 4.0.0
A TRIQS application
Loading...
Searching...
No Matches
average_sign.hpp
1/*******************************************************************************
2 *
3 * TRIQS: a Toolbox for Research in Interacting Quantum Systems
4 *
5 * Copyright (C) 2014, P. Seth, I. Krivenko, M. Ferrero and O. Parcollet
6 *
7 * TRIQS is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later
10 * version.
11 *
12 * TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
15 * details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * TRIQS. If not, see <http://www.gnu.org/licenses/>.
19 *
20 ******************************************************************************/
21#pragma once
22#include "../qmc_data.hpp"
23
24namespace triqs_cthyb {
25
26 struct measure_average_sign {
27
28 qmc_data const &data;
29 mc_weight_t &average_sign;
30 mc_weight_t sign, z;
31
32 measure_average_sign(qmc_data const &_data, mc_weight_t &_average_sign) : data(_data), average_sign(_average_sign) {
33 average_sign = 1.0;
34 z = 0;
35 sign = 0;
36 }
37 // --------------------
38
39 void accumulate(mc_weight_t s) {
40
41 sign += s * data.atomic_reweighting;
42 z += std::abs(data.atomic_reweighting);
43 }
44 // ---------------------------------------------
45
46 void collect_results(mpi::communicator const &c) {
47
48 z = mpi::all_reduce(z, c);
49 sign = mpi::all_reduce(sign, c);
50 average_sign = sign / z;
51 }
52 };
53} // namespace triqs_cthyb