HILA
Loading...
Searching...
No Matches
defs.h
Go to the documentation of this file.
1#ifndef DEFS_H_
2#define 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// The compiler is hilapp
39#define __device__
40#define __host__
41#define __global__
42#endif
43
44// #include "plumbing/mersenne.h"
45#include "plumbing/memalloc.h" // memory allocator
46#include "plumbing/timing.h"
47
48
49/// Define __restrict__? It is non-standard but supported by most (all?) compilers.
50/// ADD HERE GUARD FOR THOSE WHICH DO not HAVE IT
51#define RESTRICT __restrict__
52// #ifndef CUDA
53// #define RESTRICT __restrict__
54// #else
55// #define RESTRICT // disabled here
56// #endif
57
58
59// This below declares "out_only" -qualifier. It is empty on purpose. Do not remove!
60#define out_only
61// out_only indicates that the function does not use the original value of the argument:
62// double func( out_only double & p, ..) { ... }
63// func(a);
64// This helps hilapp to optimize memory access. It is not a bug to leave out out_only,
65// but it is a bug to "lie", i.e. use the original value of the variable if out_only is
66// used.
67//
68// out_only for class methods tells hilapp that the base variable original value is not
69// needed:
70// class C {
71// int set() out_only { .. }
72// };
73// indicates that a.set(); does not need original value of a. e qualifier.
74
75// Defined empty on purpose, same as above!
76#define const_function
77// const_function does not change the base variable, but can return a (non-const)
78// reference. Needed typically for access operators for loop extern variables:
79// class v {
80// double c[N];
81// double & e(const int i) const_function { return c[i]; }
82// };
83//
84// v vv;
85// Field<v> f;
86// onsites(ALL) { f[X].e(0) += vv.e(0); }
87// This would not work without const_function, because vv.e(0) might modify loop
88// extern variable vv, which is not allowed. If method is marked "const",
89// then the assignment would not work.
90//
91// const_function is weaker than const.
92
93
94// text output section -- defines also hila::out0, which writes from node 0 only
95
96namespace hila {
97
98/// this is our default output file stream
99extern std::ostream out;
100
101/// This writes output only from main process (node 0)
102extern std::ostream out0;
103
104/// this is just a hook to store output file, if it is in use
105extern std::ofstream output_file;
106
107// about_to_finish becomes true at the end. Signals that
108// better not rely on MPI or existence of objects any more.
109extern bool about_to_finish;
110
111// is the machine initialized? This is set in hila::setup
112// does not tell if lattice is initialized
113extern bool is_initialized;
114
115// check_input is used to notify that we're just checking the
116// input values and will exit before fields are allocated.
117extern bool check_input;
118extern int check_with_nodes;
119
120// optional input filename
121extern const char *input_file;
122
123enum sort { unsorted, ascending, descending };
124
125void initialize(int argc, char **argv);
126void finishrun();
127void terminate(int status);
128void error(const std::string &msg);
129void error(const char *msg);
130
131
132/// rank of this node
133int myrank();
134/// how many nodes there are
135int number_of_nodes();
136/// synchronize mpi
137void synchronize();
138
139
140} // namespace hila
141
142// The logger uses hila::myrank, so it cannot be included on top
143#include "plumbing/logger.h"
144namespace hila {
145/// Now declare the logger
146extern logger_class log;
147} // namespace hila
148
149/// define a class for FFT direction
150enum class fft_direction { forward, back };
151
152/// Define convenience function sqr(), returning square of argument
153template <typename T>
154constexpr inline T sqr(const T &arg) {
155 return arg * arg;
156}
157
158namespace hila {
159
160// define hila::swap(), because std::swap cannot be used in gpu code
161template <typename T>
162constexpr inline void swap(T &a, T &b) {
163 T c = a;
164 a = b;
165 b = c;
166}
167} // namespace hila
168
169
170// Backend defs-headers
171
172#if defined(CUDA) || defined(HIP)
173#include "plumbing/backend_gpu/defs.h"
174#elif defined(AVX)
175#include "plumbing/backend_vector/defs.h"
176#else
177#include "plumbing/backend_cpu/defs.h"
178#endif
179
180// this include has to be after the backend defs, because those define hila::random()
181#include "plumbing/random.h"
182
183// This contains useful template tools
184#include "plumbing/type_tools.h"
185
186#include "plumbing/has_unary_minus.h"
187
188#if defined(CUDA) || defined(HIP)
189#include "plumbing/backend_gpu/gpu_templated_ops.h"
190#endif
191
192// Include some basic functions for real (non-class) vars,
193// to help with generic code
194#include "plumbing/real_var_ops.h"
195
196// MPI Related functions and definitions
197#define MAX_GATHERS 1000
198
199
200void initialize_communications(int &argc, char ***argv);
201void split_into_partitions(int rank);
202bool is_comm_initialized(void);
203void finish_communications();
204void abort_communications(int status);
205
206// and print a dashed line
207void print_dashed_line(const std::string &txt = {});
208
209
210#endif
Define the logger class here.
Definition logger.h:8
T arg(const Complex< T > &a)
Return argument of Complex number.
Definition cmplx.h:1199
fft_direction
define a class for FFT direction
Definition defs.h:150
constexpr T sqr(const T &arg)
Define convenience function sqr(), returning square of argument.
Definition defs.h:154
Implement hila::swap for gauge fields.
Definition array.h:981
logger_class log
Now declare the logger.
int myrank()
rank of this node
Definition com_mpi.cpp:234
int number_of_nodes()
how many nodes there are
Definition com_mpi.cpp:245
void synchronize()
synchronize mpi
Definition com_mpi.cpp:254
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)
Read in command line arguments. Initialise default stream and MPI communication.
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.