HILA
Loading...
Searching...
No Matches
test_conjReduce.cpp
1#include "test.h"
2#include <string>
3#include "plumbing/input.h"
4
5/////////////////////
6/// test_case 1
7/// Coverage:
8/// - reduction + onsites env.
9/// - EVEN + ODD accessors / neighbor access
10/// - Field with matrix elements
11/// - NOTE: Assumes periodic boundary conditions
12/////////////////////
13
14// TODO: rng definition that works for MPI, GPU and CPU
15
16int main(int argc, char **argv) {
17 seed_mersenne(4l);
18 double dsum = 0;
19 int isum = 0;
20 test_setup(argc, argv);
21
22 // Test input class - should be possible to call before or after setup
23 hila::input a("params.txt");
24 int nx = a.get("nx");
25 std::string out = a.get("output");
26
28 Field<int> coordinate, nb_coordinate1, nb_coordinate2;
29 Field<SU<4, double>> sufield;
30
31 // check that fieldstruct allocated only after assignment
32 assert(matrices.fs == nullptr);
33
34 // Test that neighbours are gathered correctly
35 foralldir(dir) {
36 onsites(ALL) {
37 element<CoordinateVector> l = X.coordinates();
38 coordinate[X] = l[dir];
39 nb_coordinate1[X] = (l[dir] + 1) % nd[dir];
40 }
41
42 nb_coordinate2[ALL] = coordinate[X + dir];
43
44 onsites(ALL) {
45 element<int> diff = nb_coordinate1[X] - nb_coordinate2[X];
46 isum += diff * diff;
47 }
48 assert(isum == 0 && "Value gathered from neighbour is correct");
49 }
50
51// If MPI is defined, check that gathers are counted correctly
52#ifdef MPI
53 coordinate[ALL] = 1;
54 lattices[0]->n_gather_done = 0;
55 lattices[0]->n_gather_avoided = 0;
56
57 nb_coordinate2[ALL] = coordinate[X - e_x];
58 assert(lattices[0]->n_gather_done == 1);
59 assert(lattices[0]->n_gather_avoided == 0);
60 nb_coordinate2[ALL] = coordinate[X - e_x];
61 assert(lattices[0]->n_gather_done == 1);
62 assert(lattices[0]->n_gather_avoided == 1);
63#endif
64
65 // Test matrix multiplication and neighbour gathers
66 // Calculates M(X) * M.congugate(X+dir)
67 onsites(ALL) {
68 element<Matrix<2, 2, double>> a;
69 element<double> theta =
70 2.0 * M_PI * hila::random(); // make a random rotation matrix at each even site
71 a.c[0][0] = cos(theta);
72 a.c[0][1] = -sin(theta);
73 a.c[1][0] = sin(theta);
74 a.c[1][1] = cos(theta);
75 matrices[X] = a;
76 }
77 assert(matrices.fs != nullptr);
78
79 matrices[ODD] =
80 matrices[X - e_x].conjugate(); // odd matrices are the conjugate of the previous
81 // even site in the X Direction
82
83 onsites(EVEN) {
84 matrices[X] *=
85 matrices[X + e_x]; // multiply the even sites with the matrices stored in the
86 // neighboring odd site in X Direction
87 }
88 onsites(ODD) {
89 matrices[X] *= matrices[X].conjugate(); // multiply odd sites by their conjugate
90 }
91
92 // now all sites should be unit matrices
93
94 dsum = 0;
95 onsites(ALL) { dsum += matrices[X].trace(); }
96
97 assert(((int)dsum) == lattice.volume() * 2 && "Matrix conjugate multiplication");
98
100}
Array< n, m, T > cos(Array< n, m, T > a)
Cosine.
Definition array.h:1089
Array< n, m, T > sin(Array< n, m, T > a)
Sine.
Definition array.h:1079
The field class implements the standard methods for accessing Fields. Hilapp replaces the parity acce...
Definition field.h:61
field_struct *__restrict__ fs
Field::fs holds all of the field content in Field::field_struct.
Definition field.h:243
hila::input - Class for parsing runtime parameter files.
Definition input.h:52
constexpr Parity EVEN
bit pattern: 001
#define foralldir(d)
Macro to loop over (all) Direction(s)
Definition coordinates.h:78
constexpr Parity ODD
bit pattern: 010
constexpr Parity ALL
bit pattern: 011
double random()
Real valued uniform random number generator.
Definition hila_gpu.cpp:121
std::ostream out
this is our default output file stream
void finishrun()
Normal, controlled exit - all nodes must call this. Prints timing information and information about c...