TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
Loading...
Searching...
No Matches
mc_measure.cpp
Go to the documentation of this file.
1// Copyright (c) 2013-2018 Commissariat à l'énergie atomique et aux énergies alternatives (CEA)
2// Copyright (c) 2013-2018 Centre national de la recherche scientifique (CNRS)
3// Copyright (c) 2018-2022 Simons Foundation
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You may obtain a copy of the License at
16// https://www.gnu.org/licenses/gpl-3.0.txt
17//
18// Authors: Michel Ferrero, Olivier Parcollet, Nils Wentzell
19
24
25#include "./concepts.hpp"
26#include "./mc_measure.hpp"
27
28#include <fmt/format.h>
29#include <mpi/communicator.hpp>
30
31#include <complex>
32#include <string>
33
34namespace triqs::mc_tools {
35
36 template <DoubleOrComplex MCSignType> void measure<MCSignType>::collect_results(mpi::communicator const &c) {
37 if (enable_timer_) timer_.start();
38 ptr_->collect_results(c);
39 if (enable_timer_) timer_.stop();
40 }
41
42 template <DoubleOrComplex MCSignType> std::string measure<MCSignType>::report() const {
43 if (enable_report_) return ptr_->report();
44 return {};
45 }
46
47 template <DoubleOrComplex MCSignType> std::string measure<MCSignType>::get_timings(std::string const &name, std::string const &prefix) const {
48 if (is_measure_set_) {
49 auto str = fmt::format("{}Measure set {}: Duration = {:.4f}\n", prefix, name, duration());
50 return str + ptr_->ms_get_timings(prefix + " ");
51 } else {
52 return fmt::format("{}Measure {}: Duration = {:.4f}\n", prefix, name, duration());
53 }
54 }
55
56 template <DoubleOrComplex MCSignType> std::vector<std::string> measure<MCSignType>::names() const {
57 if (is_measure_set_) return ptr_->ms_names();
58 return {};
59 }
60
61 template <DoubleOrComplex MCSignType> double measure<MCSignType>::duration() const {
62 if (enable_timer_) return static_cast<double>(timer_);
63 return 0.0;
64 }
65
66 // Explicit template instantiations.
67 template class measure<double>;
68 template class measure<std::complex<double>>;
69
70} // namespace triqs::mc_tools
Type erasure class for MC measures.
double duration() const
Get the duration of the cumulative accumulate() and collect_results() calls.
void collect_results(mpi::communicator const &c)
Collect results from multiple MPI processes.
std::string report() const
Report information about the measure.
std::vector< std::string > names() const
Get a vector of all the measure names in a measure set.
std::string get_timings(std::string const &name, std::string const &prefix="") const
Get a formatted string showing the runtime of the accumulate() and collect_results() calls.
Provides type erasure for MC measurements.
Provides concepts for the MC tools.