HILA
Loading...
Searching...
No Matches
ising.cpp
1#include "hila.h"
2
3// Define some parameters for the simulation
4double beta = 0.01;
5int n_measurements = 100;
6int n_updates_per_measurement = 10;
7long seed = 123456;
8int NX = 64, NY = 64;
9int VOLUME = NX * NY;
10int log_level = 2;
11
12int main(int argc, char **argv) {
13 // Basic setup
14 const CoordinateVector nd = {NX, NY};
15 hila::initialize(argc, argv);
16 lattice.setup(nd);
17
18 // Set verbosity level
19 hila::log.set_verbosity(log_level);
20
21 // Define a field
22 Field<double> spin;
23
25
26 // Set to 1
27 spin[ALL] = 1;
28
29 // Run update-measure loop
30 for (int i = 0; i < n_measurements; i++) {
32
33 // Run a number of updates, starting with EVEN sites
34 // and alternating between parities
35 Parity p = EVEN;
36 for (int j = 0; j < 2 * n_updates_per_measurement; j++) {
38
39 // A temporary field for the local change in action
40 onsites(p) {
41 double deltaS;
42 deltaS = 2.0 * spin[X] *
43 (spin[X + e_x] + spin[X - e_x] + spin[X + e_y] + spin[X - e_y]);
44
45 if (hila::random() < exp(-beta * deltaS)) {
46 spin[X] = -spin[X];
47 }
48 }
49 p = opp_parity(p);
50 hila::log << "Update " << j << " loop done\n";
52 }
53
54 // Measure magnetisation
55 double M = 0;
56 onsites(ALL) { M += spin[X]; }
58 hila::log << "Magnetisation " << M / VOLUME << "\n";
59 }
60
62 return 0;
63}
Array< n, m, T > exp(Array< n, m, T > a)
Exponential.
Definition array.h:1059
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
void decrease_level()
Definition logger.h:44
void set_verbosity(int level)
Set logging level.
Definition logger.h:36
void increase_level()
Definition logger.h:40
Parity
Parity enum with values EVEN, ODD, ALL; refers to parity of the site. Parity of site (x,...
constexpr Parity EVEN
bit pattern: 001
constexpr Parity ALL
bit pattern: 011
logger_class log
Now declare the logger.
double random()
Real valued uniform random number generator.
Definition hila_gpu.cpp:118
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...