HILA
Loading...
Searching...
No Matches
hila_simple_example.cpp
Go to the documentation of this file.
1/**
2 * @file hila_simple_example.cpp
3 * @author Aaron Haarti
4 * @brief Simple HILA example application which computes laplacian of Gaussian random complex
5 * field
6 *
7 * @details The application generates a \f$ 32^2 \f$ size field \f$ f \f$ of random Complex numbers.
8 * We proceed to compute the summed absolute value of the Laplacian of said field:
9 *
10 * \f{align}{g(X) &= |\nabla^2 f(X)| \\
11 * &= \sum_{d \in \hat{e}} |f(X + d) - 2f(X) + f(X-d)|, \f}
12 *
13 * where \f$\hat{e} = \{e_x,e_y,e_z\}\f$ is the set of unit vectors. Afterwards this quantity is
14 * printed out.
15 *
16 */
17
18#include "hila.h"
19static_assert(NDIM == 3, "NDIM must be 3");
20
21/**
22 * @brief Main function for application which implements the method
23 *
24 * @param argc
25 * @param argv
26 * @return int
27 */
28int main(int argc, char *argv[]) {
29
30 hila::initialize(argc, argv);
31
32 // set up 32^3 lattice
33 lattice.setup({32, 32, 32});
34
35 // Random numbers are used here
36 hila::seed_random(32345);
37
39 Field<double> g = 0;
40
41 // make f Gaussian random distributed
42 onsites(ALL) f[X].gaussian_random();
43
44 // calculate sum of 2nd derivatives of f in to g
45 foralldir(d) {
46 g[ALL] += abs(f[X + d] - 2 * f[X] + f[X - d]);
47 }
48
49 // get average of g
50 double average = 0;
51 onsites(ALL) {
52 average += g[X];
53 }
54
55 average = average / lattice.volume();
56 hila::out0 << "Average of g is " << average << '\n';
57
58 // make a clean exit
60}
The field class implements the standard methods for accessing Fields. Hilapp replaces the parity acce...
Definition field.h:61
void setup(const CoordinateVector &siz)
General lattice setup.
Definition lattice.cpp:33
T abs(const Complex< T > &a)
Return absolute value of Complex number.
Definition cmplx.h:1187
#define foralldir(d)
Macro to loop over (all) Direction(s)
Definition coordinates.h:78
constexpr Parity ALL
bit pattern: 011
int main(int argc, char *argv[])
Main function for application which implements the method.
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
void finishrun()
Normal, controlled exit - all nodes must call this. Prints timing information and information about c...