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