HILA
Loading...
Searching...
No Matches
defs.h
Go to the documentation of this file.
1#ifndef HILA_DEFS_H_
2#define HILA_DEFS_H_
3/**
4 * @file defs.h
5 * @brief This file defines all includes for HILA
6 *
7 */
8// This gives us math constants, e.g. M_PI etc.
9#define _USE_MATH_DEFINES
10
11// Useful global definitions here -- this file should be included by (almost) all others
12
13#include <cstdint>
14#include <iostream>
15#include <array>
16#include <vector>
17#include <sstream>
18// #include <math.h>
19#include <type_traits>
20#include <cmath>
21#include <iomanip>
22
23
24#ifdef HILAPP
25#include "hilapp_mpi.h"
26#else
27#include <mpi.h>
28#endif
29
30// Read in Makefile tunable parameters first
31// NDEBUG is defined (or not) in params, so assert.h comes after
32#include "params.h"
33
34#include <assert.h>
35
36
37#ifdef HILAPP
38// Define these to nothing in hilapp
39#define __device__
40#define __host__
41#define __global__
42#define __constant__
43#endif
44
45// #include "plumbing/mersenne.h"
46#include "plumbing/memalloc.h" // memory allocator
47#include "plumbing/timing.h"
48
49
50/// Define __restrict__? It is non-standard but supported by most (all?) compilers.
51/// ADD HERE GUARD FOR THOSE WHICH DO not HAVE IT
52#define RESTRICT __restrict__
53// #ifndef CUDA
54// #define RESTRICT __restrict__
55// #else
56// #define RESTRICT // disabled here
57// #endif
58
59
60// This below declares "out_only" -qualifier. It is empty on purpose. Do not remove!
61#define out_only
62// out_only indicates that the function does not use the original value of the argument:
63// double func( out_only double & p, ..) { ... }
64// func(a);
65// This helps hilapp to optimize memory access. It is not a bug to leave out out_only,
66// but it is a bug to "lie", i.e. use the original value of the variable if out_only is
67// used.
68//
69// out_only for class methods tells hilapp that the base variable original value is not
70// needed:
71// class C {
72// int set() out_only { .. }
73// };
74// indicates that a.set(); does not need original value of a. e qualifier.
75
76// Defined empty on purpose, same as above!
77#define const_function
78// const_function does not change the base variable, but can return a (non-const)
79// reference. Needed typically for access operators for loop extern variables:
80// class v {
81// double c[N];
82// double & e(const int i) const_function { return c[i]; }
83// };
84//
85// v vv;
86// Field<v> f;
87// onsites(ALL) { f[X].e(0) += vv.e(0); }
88// This would not work without const_function, because vv.e(0) might modify loop
89// extern variable vv, which is not allowed. If method is marked "const",
90// then the assignment would not work.
91//
92// const_function is weaker than const.
93
94
95// text output section -- defines also hila::out0, which writes from node 0 only
96
97namespace hila {
98
99/// this is our default output file stream
100extern std::ostream out;
101
102/// This writes output only from main process (node 0)
103extern std::ostream out0;
104
105/// this is just a hook to store output file, if it is in use
106extern std::ofstream output_file;
107
108// about_to_finish becomes true at the end. Signals that
109// better not rely on MPI or existence of objects any more.
110extern bool about_to_finish;
111
112// is the machine initialized? This is set in hila::setup
113// does not tell if lattice is initialized
114extern bool is_initialized;
115
116// check_input is used to notify that we're just checking the
117// input values and will exit before fields are allocated.
118extern bool check_input;
119extern int check_with_nodes;
120
121enum sort { unsorted, ascending, descending };
122
123void initialize(int argc, char **argv);
124void finishrun();
125void terminate(int status);
126void error(const std::string &msg);
127void error(const char *msg);
128
129
130/// rank of this node
131int myrank();
132/// how many nodes there are
133int number_of_nodes();
134/// sync MPI
135void barrier();
136/// synchronize mpi + gpu
137void synchronize();
138void synchronize_partitions();
139
140void initialize_communications(int &argc, char ***argv);
141void split_into_partitions(int rank);
142bool is_comm_initialized(void);
143void finish_communications();
144void abort_communications(int status);
145
146// and print a dashed line
147void print_dashed_line(const std::string &txt = {});
148
149} // namespace hila
150
151// The logger uses hila::myrank, so it cannot be included on top
152#include "plumbing/logger.h"
153namespace hila {
154/// Now declare the logger
155extern logger_class log;
156} // namespace hila
157
158/// define a class for FFT direction
159enum class fft_direction { forward, back };
160
161/// Define convenience function sqr(), returning square of argument
162template <typename T>
163constexpr inline T sqr(const T &arg) {
164 return arg * arg;
165}
166
167namespace hila {
168
169// define hila::swap(), because std::swap cannot be used in gpu code
170template <typename T>
171constexpr inline void swap(T &a, T &b) {
172 T c = a;
173 a = b;
174 b = c;
175}
176} // namespace hila
177
178
179// Backend defs-headers
180
181#if defined(CUDA) || defined(HIP)
182#include "plumbing/backend_gpu/defs.h"
183#elif defined(AVX)
184#include "plumbing/backend_vector/defs.h"
185#else
186#include "plumbing/backend_cpu/defs.h"
187#endif
188
189// this include has to be after the backend defs, because those define hila::random()
190#include "plumbing/random.h"
191
192// This contains useful template tools
193#include "plumbing/type_tools.h"
194
195#include "plumbing/has_unary_minus.h"
196
197#if defined(CUDA) || defined(HIP)
198#include "plumbing/backend_gpu/gpu_templated_ops.h"
199#endif
200
201// Include some basic functions for real (non-class) vars,
202// to help with generic code
203#include "plumbing/real_var_ops.h"
204
205// MPI Related functions and definitions
206#define MAX_GATHERS 1000
207
208
209// <filesystem> can be in different locations, check...
210#if __has_include(<filesystem>)
211#include <filesystem>
212namespace filesys_ns = std::filesystem;
213
214#elif __has_include(<experimental/filesystem>)
215#include <experimental/filesystem>
216namespace filesys_ns = std::experimental::filesystem;
217
218#else
219static_assert(0, "Neither <filesystem> nor <experimental/filesystem> found!");
220
221#endif
222
223
224#endif
Define the logger class here.
Definition logger.h:8
T arg(const Complex< T > &a)
Return argument of Complex number.
Definition cmplx.h:1278
fft_direction
define a class for FFT direction
Definition defs.h:159
constexpr T sqr(const T &arg)
Define convenience function sqr(), returning square of argument.
Definition defs.h:163
Implement hila::swap for gauge fields.
Definition array.h:982
logger_class log
Now declare the logger.
void barrier()
sync MPI
Definition com_mpi.cpp:264
int myrank()
rank of this node
Definition com_mpi.cpp:237
int number_of_nodes()
how many nodes there are
Definition com_mpi.cpp:248
void synchronize()
synchronize mpi + gpu
Definition com_mpi.cpp:257
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
Definition initialize.cpp:8
void initialize(int argc, char **argv)
Initial setup routines.
void split_into_partitions(int rank)
Definition com_mpi.cpp:290
void finishrun()
Normal, controlled exit - all nodes must call this. Prints timing information and information about c...
void terminate(int status)
This file contains #defined constants.