Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
bridge_setup.cpp
Go to the documentation of this file.
1 
14 #include "bridge_setup.h"
17 #include "Tools/timer.h"
18 #include "bridge_init_factory.h"
19 
20 #ifdef USE_GROUP_SU3
21 #define Nc 3
22 #else
23 #ifdef USE_GROUP_SU2
24 #define Nc 2
25 #else
26 #ifdef USE_GROUP_SU_N
27 #define Nc 3
28 #endif
29 #endif
30 #endif
31 
32 int bridge_initialize(int *pargc, char ***pargv)
33 {
34  // initialize communicator
35  Communicator::init(pargc, pargv);
36 
37  // initialize thread manager
38  //-
39 
40  // setup factory
41 #if defined(USE_FACTORY) && !defined(USE_FACTORY_AUTOREGISTER)
42  bridge_init_factory();
43 #endif
44 
45 #if defined(DEBUG) && defined(USE_FACTORY)
46  // bridge_report_factory();
47 #endif
48 
49  // show banner
50  vout.general("Bridge++ %s\n\n", BRIDGE_VERSION);
51 
53 
54  return EXIT_SUCCESS;
55 }
56 
57 
58 int bridge_initialize(int *pargc, char ***pargv,
59  const Parameters& params
60  )
61 {
62  bridge_initialize(pargc, pargv);
63 
64  bridge_setup(params);
65 
66  return EXIT_SUCCESS;
67 }
68 
69 
70 int bridge_initialize(int *pargc, char ***pargv,
71  const std::vector<int>& lattice_size,
72  const std::vector<int>& grid_size,
73  const int number_of_threads,
74  const int number_of_colors,
75  const std::string& logfile,
76  const std::string& ildg_logfile,
77  const std::string& verbose_level
78  )
79 {
80  bridge_initialize(pargc, pargv);
81 
82  bridge_setup(lattice_size,
83  grid_size,
84  number_of_threads,
85  number_of_colors,
86  logfile,
87  ildg_logfile,
88  verbose_level);
89 
90  return EXIT_SUCCESS;
91 }
92 
93 
95 {
97 
99 
101 
102  return EXIT_SUCCESS;
103 }
104 
105 
106 void bridge_setup(const Parameters& params)
107 {
108  std::vector<int> lattice_size;
109  std::vector<int> grid_size = std::vector<int>(); // will be auto-shaped.
110  int number_of_threads = 0; // will be auto-adjusted.
111  int number_of_colors = Nc;
112  std::string logfile = "stdout";
113  std::string ildg_logfile = "stdout";
114  std::string verbose_level = "General";
115 
116  int ret = 0;
117 
118  ret += params.fetch_int_vector("lattice_size", lattice_size);
119  ret += params.fetch_int_vector("grid_size", grid_size);
120  ret += params.fetch_int("number_of_thread", number_of_threads);
121  ret += params.fetch_int("number_of_color", number_of_colors);
122  ret += params.fetch_string("log_filename", logfile);
123  ret += params.fetch_string("ildg_log_filename", ildg_logfile);
124  ret += params.fetch_string("verbose_level", verbose_level);
125 
126  bridge_setup(lattice_size,
127  grid_size,
128  number_of_threads,
129  number_of_colors,
130  logfile,
131  ildg_logfile,
132  verbose_level
133  );
134 }
135 
136 
138  const std::vector<int>& lattice_size,
139  const std::vector<int>& grid_size_hint,
140  const int number_of_threads,
141  const int number_of_colors,
142  const std::string& logfile,
143  const std::string& ildg_logfile,
144  const std::string& verbose_level
145  )
146 {
147  // report
148  vout.general("Main: input parameters\n");
149  vout.general(" lattice_size = %s\n", Parameters::to_string(lattice_size).c_str());
150  vout.general(" grid_size = %s\n", Parameters::to_string(grid_size_hint).c_str());
151  vout.general(" number of thread = %d\n", number_of_threads);
152  vout.general(" number of color = %d\n", number_of_colors);
153  vout.general(" logfile = %s\n", logfile.c_str());
154  vout.general(" ildg_logfile = %s\n", ildg_logfile.c_str());
155  vout.general(" vlevel = %s\n", verbose_level.c_str());
156 
157 
158  // setup communicator
159  // grid may be auto-shaped.
160 
161  std::vector<int> grid_size(grid_size_hint);
162 
163  Communicator::setup(lattice_size, grid_size);
164 
165  // store to global parameters
166  CommonParameters::init(lattice_size, grid_size, number_of_colors);
167 
168  // setup thread mananger
169  ThreadManager_OpenMP::init(number_of_threads);
170 
171  // set log parameters
174 
175  if ((logfile.size() > 0) && (logfile != "stdout")) {
176  vout.init(logfile);
177  }
178 
179  if ((ildg_logfile.size() > 0) && (ildg_logfile != "stdout")) {
180  vout.ildg_init(ildg_logfile);
181  }
182 }
183 
184 
185 #ifdef Nc
186 #undef Nc
187 #endif
BridgeIO vout
Definition: bridgeIO.cpp:503
#define BRIDGE_VERSION
Definition: configure.h:17
static int init(int *pargc, char ***pargv)
initialize communicator
void general(const char *format,...)
Definition: bridgeIO.cpp:197
void ildg_init(const std::ostream &os)
Definition: bridgeIO.cpp:434
void init(const std::string &filename)
Definition: bridgeIO.cpp:51
Class for parameters.
Definition: parameters.h:46
void bridge_setup(const Parameters &params)
static void init_Vlevel(Bridge::VerboseLevel vlevel)
initialization for default verbose level.
int fetch_string(const string &key, string &value) const
Definition: parameters.cpp:378
int bridge_finalize()
static int finalize()
finalize communicator
static void init(int Nthread)
setup: called in main only once.
int fetch_int(const string &key, int &value) const
Definition: parameters.cpp:346
static void finalize()
finalization.
static int setup(int ninstance=1)
setup communicator
Bridge::VerboseLevel vl
VerboseLevel
Definition: bridgeIO.h:42
static void timestamp()
Definition: timer.cpp:19
int fetch_int_vector(const string &key, vector< int > &value) const
Definition: parameters.cpp:429
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:131
int bridge_initialize(int *pargc, char ***pargv)
static void init(const std::vector< int > &lattice_size, const std::vector< int > &grid_size)
initialization (Nc=3 is assumed).
static string to_string(const vector< T > &v)
Definition: parameters.h:145