HILA
Loading...
Searching...
No Matches
hila_example.cpp
1#include "hila.h"
2#include "fft.h"
3
4// define an alias for a 3x3 complex matrix
6
7int main(int argc, char **argv) {
8
9 // hila::initialize should be called as early as possible
10 hila::initialize(argc, argv);
11
12
13 // hila provides an input class hila::input, which is
14 // a convenient way to read in parameters from input files.
15 // parameters are presented as key - value pairs, as an example
16 // " lattice size 64, 64, 64 "
17 // is read below.
18 //
19 // Values are broadcast to all MPI nodes.
20 //
21 // .get() -method can read many different input types,
22 // see file "input.h" for documentation
23
24 hila::input par("parameters");
25 CoordinateVector lsize;
26 lsize = par.get("lattice size"); // reads NDIM numbers
27 int loops = par.get("smear loops");
28 double smear_coeff = par.get("smear coefficient");
29 int taylor_order = par.get("expansion order");
30 long seed = par.get("random seed");
31
32 par.close(); // file is closed also when par goes out of scope
33
34 // setting up the lattice is convenient to do after reading
35 // the parameter
36 lattice.setup(lsize);
37
38 // We need random number here
40
41 // 2 matrix fields
42 Field<Mtype> f, g;
43
44 // set g to gaussian rnd matrix
45 onsites(ALL) g[X].gaussian_random();
46
47 hila::out0 << "Smearing a Gaussian random " << Mtype::rows() << "x" << Mtype::columns()
48 << " complex matrix field " << loops << " times\n";
49
50
51 double c1 = 1 - 6 * smear_coeff;
52
53 // Use a timer to time periodic events
54 // Automatically reported at the end
55 // Good idea to define these static
56 static hila::timer smear_timer("Smear");
57
58 for (int l = 0; l < loops; l++) {
59 smear_timer.start();
60 onsites(ALL) {
61 f[X] = g[X + e_x] + g[X - e_x] + g[X + e_y] + g[X - e_y] + g[X + e_z] + g[X - e_z];
62 }
63 g[ALL] = c1 * g[X] + smear_coeff * f[X];
64 smear_timer.stop();
65 }
66
67 hila::out0 << "field g at (0,0,0) after smearing:\n";
68 hila::out0 << g[{0, 0, 0}] << '\n';
69
70
71 hila::out0 << "Calculating exp(g) using Taylor expansin to order " << taylor_order << '\n';
72
73 // another way to time, using gettime
74 double t = hila::gettime();
75
76 onsites(ALL) {
77 Mtype product;
78 product = 1;
79 f[X] = 1;
80 int64_t fac = 1;
81 for (int i = 1; i <= taylor_order; i++) {
82 product *= g[X];
83 fac *= i;
84 f[X] += product / fac;
85 }
86 }
87
88 hila::out0 << "Taylor expansion, time " << hila::gettime() - t << " seconds\n";
89
90 hila::out0 << "Result at (0,0,0):\n";
91 hila::out0 << f[{0, 0, 0}] << '\n';
92
93
94 t = hila::gettime();
95
96 FFT_field(f, g);
97
98 hila::out0 << "FFT time " << hila::gettime() - t << '\n';
99
100 Array<2, 2, double> A(1.0);
102 B = {1, 1, 1, 1};
103 hila::out0 << B << std::endl;
104
106}
Array type
Definition array.h:43
The field class implements the standard methods for accessing Fields. Hilapp replaces the parity acce...
Definition field.h:61
static constexpr int rows()
Define constant methods rows(), columns() - may be useful in template code.
Definition matrix.h:220
static constexpr int columns()
Returns column length.
Definition matrix.h:228
Matrix class which defines matrix operations.
Definition matrix.h:1679
hila::input - Class for parsing runtime parameter files.
Definition input.h:52
void setup(const CoordinateVector &siz)
General lattice setup.
Definition lattice.cpp:33
constexpr Parity ALL
bit pattern: 011
void FFT_field(const Field< T > &input, Field< T > &result, const CoordinateVector &directions, fft_direction fftdir=fft_direction::forward)
Definition fft.h:376
std::ostream out0
This writes output only from main process (node 0)
void initialize(int argc, char **argv)
Read in command line arguments. Initialise default stream and MPI communication.
void seed_random(uint64_t seed, bool device_rng=true)
Seed random generators with 64-bit unsigned value. On MPI shuffles the seed so that different MPI ran...
Definition random.cpp:86
double gettime()
Definition timing.cpp:163
void finishrun()
Normal, controlled exit - all nodes must call this. Prints timing information and information about c...