-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathhybmain.cpp
More file actions
123 lines (110 loc) · 4.38 KB
/
hybmain.cpp
File metadata and controls
123 lines (110 loc) · 4.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/****************************************************************************
*
* ALPS DMFT Project
*
* Copyright (C) 2012 by Emanuel Gull <gull@pks.mpg.de>,
* Hartmut Hafermann <hafermann@cpht.polytechnique.fr>
*
* based on an earlier version by Philipp Werner and Emanuel Gull
*
*
* This software is part of the ALPS Applications, published under the ALPS
* Application License; you can use, redistribute it and/or modify it under
* the terms of the license, either version 1 or (at your option) any later
* version.
*
* You should have received a copy of the ALPS Application License along with
* the ALPS Applications; see the file LICENSE.txt. If not, the license is also
* available from http://alps.comp-phys.org/.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*****************************************************************************/
#include <ctime>
#include "hyb.hpp"
#include "hybevaluate.hpp"
#include <boost/bind.hpp>
#ifdef ALPS_HAVE_MPI
#include <alps/mc/mpiadapter.hpp>
typedef alps::mcmpiadapter<hybridization> sim_type;
#else
typedef hybridization sim_type;
#endif
//stops the simulation if time > end_time or if signals received.
bool stop_callback(const time_t end_time) {
static alps::signal signal;
return !signal.empty() || time(0) > end_time;
}
void master_final_tasks(const alps::results_type<hybridization>::type &results, const alps::parameters_type<hybridization>::type ¶meters, const std::string &output_name);
int global_mpi_rank;
int main(int argc, char* argv[]){
#ifdef ALPS_HAVE_MPI
//boot up MPI environment
MPI_Init(&argc, &argv);
#endif
//read in command line options
alps::parameters_type<hybridization>::type parameters(argc, (const char**)argv, "/parameters");
sim_type::define_parameters(parameters);
if (parameters.help_requested(std::cout)) {
exit(0);
}
try {
unsigned long max_time=parameters["MAX_TIME"];
#ifndef ALPS_HAVE_MPI
global_mpi_rank=0;
sim_type s(parameters,global_mpi_rank);
#else
alps::mpi::communicator c;
c.barrier();
global_mpi_rank=c.rank();
if (!global_mpi_rank) std::cout << "Parameters : " << std::endl << parameters << std::endl;
sim_type s(parameters, c);
#endif
//run the simulation
s.run(boost::bind(&stop_callback, time(0)+max_time));
//on the master: collect MC results and store them in file, then postprocess
if (global_mpi_rank==0){
alps::results_type<hybridization>::type results = collect_results(s);
std::string output_path = parameters["cthyb.BASEPATH"].as<std::string>()+std::string("/simulation/results");
alps::save_results(results, parameters, "sim.h5", output_path); //"/simulation/results");
master_final_tasks(results, parameters, "sim.h5");
#ifdef ALPS_HAVE_MPI
} else{ //on any slave: send back results to master.
collect_results(s);
}
c.barrier();
MPI_Finalize();
#else
}
#endif
}
catch(std::exception& exc){
std::cerr<<exc.what()<<std::endl;
return -1;
}
catch(...){
std::cerr << "Fatal Error: Unknown Exception!\n";
return -2;
}
}
void master_final_tasks(const alps::results_type<hybridization>::type &results,
const alps::parameters_type<hybridization>::type ¶meters,
const std::string &output_name){
//do some post processing: collect Green functions and write
//them into hdf5 files; calls compute vertex at the very end
alps::hdf5::archive solver_output(output_name, "a");
evaluate_basics(results,parameters,solver_output);
evaluate_gtau(results,parameters,solver_output);
evaluate_freq(results,parameters,solver_output);
evaluate_legendre(results,parameters,solver_output);
evaluate_nnt(results,parameters,solver_output);
evaluate_nnw(results,parameters,solver_output);
evaluate_sector_statistics(results,parameters,solver_output);
evaluate_2p(results, parameters, solver_output);
}