9bool hila::about_to_finish =
false;
10bool hila::is_initialized =
false;
11bool hila::check_input =
false;
12int hila::check_with_nodes;
13const char *hila::input_file;
17void vector_type_info();
22int get_onoff(std::string flag)
25 if (hila::cmdline.flag_set(flag.c_str()))
27 std::string opt = hila::cmdline.get_string(flag.c_str());
28 if (opt.compare(
"on") == 0)
30 else if (opt.compare(
"off") == 0)
34 hila::out0 <<
"Command line argument " << flag <<
" requires value on/off\n";
47#if (defined(__GNUC__) && !defined(DARWIN))
57void setup_partitions();
68#if (defined(__GNUC__) && !defined(DARWIN) && !defined(_MAC_OSX_))
74 mallopt( M_MMAP_MAX, 0 );
76 mallopt(M_TRIM_THRESHOLD, -1);
79 feenableexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW);
84 initialize_communications(argc, &argv);
87 hila::is_initialized =
true;
102 hila::cmdline.add_flag(
"-t",
"cpu time limit");
103 hila::cmdline.add_flag(
"-o",
"output filename (default: stdout)");
104 hila::cmdline.add_flag(
"-i",
"input filename (overrides the 1st hila::input() name)\nuse '-i -' for standard input");
105 hila::cmdline.add_flag(
"-device",
"in GPU runs using only 1 GPU, choose this GPU number (default 0)");
106 hila::cmdline.add_flag(
"-check",
"check input & layout with <nodes>-nodes & exit\nonly with 1 real MPI node (don't use mpirun)");
107 hila::cmdline.add_flag(
"-n",
"number of nodes used in layout check, only relevant with -check");
108 hila::cmdline.add_flag(
"-partitions",
"number of partitioned lattice streams");
109 hila::cmdline.add_flag(
"-sync",
"synchronize partition runs (on/off) (default = off)");
114 hila::cmdline.initialise_args(argc, argv);
119 if (lattice.nodes.number == 1) {
121 if (hila::cmdline.flag_present(
"-check")) {
123 if (hila::cmdline.flag_present(
"-n")) {
124 nodes = hila::cmdline.get_int(
"-n");
129 hila::check_input =
true;
132 hila::check_with_nodes = nodes;
133 hila::out <<
"****** INPUT AND LAYOUT CHECK ******" << std::endl;
136 lattice.mynode.rank = 0;
137 lattice.nodes.number = hila::check_with_nodes;
141#if defined(CUDA) || defined(HIP)
142 if (!hila::check_input) {
144 if (hila::cmdline.flag_set(
"-device"))
145 device = hila::cmdline.get_int(
"-device");
148 hila::out0 <<
"Chose device " << device <<
"\n";
150 initialize_gpu(lattice.mynode.rank, device);
157 if (hila::partitions.number() == 1) {
160 if (hila::cmdline.flag_present(
"-o")) {
163 if (hila::cmdline.flag_set(
"-o"))
164 name = hila::cmdline.get_string(
"-o");
167 hila::out0 <<
"The name of the output file must be provided after flag '-o'!\n";
171 if (!hila::check_input) {
174 hila::out <<
"Cannot open output file " << name <<
'\n';
177 hila::out0 <<
"Output is now directed to the file '"
195 print_dashed_line(
"HILA lattice framework");
196 hila::out0 <<
"Running program " << argv[0] <<
"\n";
197 hila::out0 <<
"with command line arguments '";
198 for (
int i = 1; i < argc; i++)
202#if defined(GIT_SHA_VALUE)
203#define xstr(s) makestr(s)
205 hila::out0 <<
"git SHA " << xstr(GIT_SHA_VALUE) <<
'\n';
207 hila::out0 <<
"no git information available\n";
209 hila::out0 <<
"Compiled " << __DATE__ <<
" at " << __TIME__ <<
'\n';
211 hila::out0 <<
"with options: EVEN_SITES_FIRST";
212#ifndef EVEN_SITES_FIRST
215#ifdef SPECIAL_BOUNDARY_CONDITIONS
220 hila::timestamp(
"Starting");
224 if (hila::cmdline.flag_present(
"-t")) {
226 long cputime = hila::cmdline.get_int(
"-t");
228 hila::out0 <<
"CPU time limit " << cputime <<
" seconds\n";
229 hila::setup_timelimit(cputime);
237 hila::input_file =
nullptr;
238 if (hila::cmdline.flag_present(
"-i"))
242 static const std::string input_string = hila::cmdline.get_string(
"-i");
243 hila::input_file = input_string.c_str();
244 hila::out0 <<
"Input file from command line: " << hila::input_file <<
"\n";
249 hila::out0 <<
"Using option OPENMP - with " << omp_get_max_threads() <<
" threads\n";
253#if defined(CUDA) || defined(HIP)
254 hila::out0 <<
"Using thread blocks of size " << N_threads <<
" threads\n";
256#if defined(GPU_AWARE_MPI)
262#if !defined(GPU_VECTOR_REDUCTION_THREAD_BLOCKS) || GPU_VECTOR_REDUCTION_THREAD_BLOCKS <= 0
263 hila::out0 <<
"ReductionVector with atomic operations (GPU_VECTOR_REDUCTION_THREAD_BLOCKS=0)\n";
265 hila::out0 <<
"ReductionVector with " << GPU_VECTOR_REDUCTION_THREAD_BLOCKS
266 <<
" thread blocks\n";
269 if (!hila::check_input)
279#if defined(CUDA) && !defined(PIZDAINT)
283#if (defined(__GNUC__) && !defined(DARWIN))
284 hila::out0 <<
"GNU c-library performance: not returning allocated memory\n";
294 hila::timestamp(
"Terminate");
296 hila::about_to_finish =
true;
297 if (is_comm_initialized()) {
298 finish_communications();
307void hila::error(
const char *msg) {
312void hila::error(
const std::string &msg) {
313 hila::error(msg.c_str());
326 int64_t gathers = latp->n_gather_done;
327 int64_t avoided = latp->n_gather_avoided;
329 if (gathers + avoided > 0) {
330 hila::out0 <<
" COMMS from node 0: " << gathers <<
" done, " << avoided <<
"("
331 << 100.0 * avoided / (avoided + gathers) <<
"%) optimized away\n";
333 hila::out0 <<
" No communications done from node 0\n";
338#if defined(CUDA) || defined(HIP)
342 if (hila::partitions.number() > 1) {
343 hila::timestamp(
"Waiting to sync partitions");
350 hila::timestamp(
"Finishing");
352 hila::about_to_finish =
true;
354 finish_communications();
366FILE *open_parameter_file()
368 static char parameter[] =
"parameter";
373 if (n_partitions > 1) {
374 char parameter_name[50];
376 sprintf(parameter_name,
"%s%d",parameter,this_partition);
377 fil = fopen(parameter_name,
"r");
380 fprintf(outf,
" READING PARAMETERS FROM %s\n",parameter_name);
385 fil = fopen(parameter,
"r");
387 halt(
" ** No parameter file?");
405void setup_partitions() {
408 if (hila::cmdline.flag_present(
"-partitions")) {
410 long lnum = hila::cmdline.get_int(
"-partitions");
412 hila::out0 <<
"partitions=<number> command line argument value must be positive "
413 "integer (or argument omitted)\n";
417 hila::partitions._number = lnum;
420 hila::partitions._number = 1;
422 if (hila::partitions.number() == 1)
425 hila::out0 <<
" Dividing nodes into " << hila::partitions.number() <<
" partitions\n";
429 << hila::partitions.number() <<
" partitions\n";
433#if defined(BLUEGENE_LAYOUT)
434 hila::partitions._mylattice = bg_layout_partitions(hila::partitions.number());
436 hila::partitions._mylattice =
439 if (!hila::check_input)
440 split_into_partitions(hila::partitions.mylattice());
443 if (hila::cmdline.flag_present(
"-o"))
445 std::string opt = hila::cmdline.get_string(
"-o");
446 fname = opt + std::to_string(hila::partitions.mylattice());
460 std::cout <<
"Cannot open output file " << fname <<
'\n';
471 if (!hila::check_input) {
479 << hila::partitions.number() <<
" partitions, this " << hila::partitions.mylattice()
484 if (hila::cmdline.flag_present(
"-sync"))
486 std::string onoffopt = hila::cmdline.get_string(
"-sync");
487 if (get_onoff(onoffopt) == 1)
489 hila::partitions._sync =
true;
490 hila::out0 <<
"Synchronising partition trajectories\n";
495 hila::partitions._sync =
false;
496 hila::out0 <<
"Not synchronising the partition trajectories\n"
497 <<
"Use '-sync on' command line argument to override\n";
504void vector_type_info() {
506 hila::out0 <<
"Using VCL vector class with instruction set level INSTRSET=" << INSTRSET
543 hila::out0 <<
" (You probably should use options '-mavx2 -fmad' in compilation)\n";
549void print_dashed_line(
const std::string &text) {
550 static constexpr int linelength = 60;
554 if (text.size() == 0) {
555 for (
int i = 0; i < linelength; i++)
561 for (
int i = 7 + text.size(); i < linelength; i++)
Define the logger class here.
logger_class log
Now declare the logger.
int myrank()
rank of this node
int number_of_nodes()
how many nodes there are
void synchronize()
synchronize mpi
std::ostream out
this is our default output file stream
std::ostream out0
This writes output only from main process (node 0)
std::ofstream output_file
this is just a hook to store output file, if it is in use
void initialize(int argc, char **argv)
Read in command line arguments. Initialise default stream and MPI communication.
T broadcast(T &var, int rank=0)
Broadcast the value of var to all MPI ranks from rank (default=0).
void finishrun()
Normal, controlled exit - all nodes must call this. Prints timing information and information about c...
void terminate(int status)
#define DEFAULT_OUTPUT_NAME
Default output file name.