HILA
Loading...
Searching...
No Matches
bench_fermion.cpp
1#include "bench.h"
3#include "dirac/conjugate_gradient.h"
4
5#define N 3
6
7#ifndef SEED
8#define SEED 100
9#endif
10
11const CoordinateVector latsize = {32, 32, 32, 32};
12
13int main(int argc, char **argv) {
14 int n_runs = 1;
15 double msecs;
16 struct timeval start, end;
17 double timing;
18 double sum;
19 float fsum;
20
21 hila::initialize(argc, argv);
22
23 lattice.setup(latsize);
24
26
27 // Define a gauge matrix
28 Field<SU<N, double>> U[NDIM];
29 Field<SU_vector<N, double>> sunvec1, sunvec2;
30
31 foralldir(d) {
32 onsites(ALL) { U[d][X].random(); }
33 }
34 onsites(ALL) {
35 sunvec1[X].gaussian_random();
36 sunvec2[X].gaussian_random();
37 }
38
39 // Time staggered Dirac operator
40 timing = 0;
41
42 using sunvec = SU_vector<N, double>;
43 using sunmat = SU<N, double>;
44 using dirac_stg = dirac_staggered<sunmat>;
45 dirac_stg D_staggered(0.1, U);
46 D_staggered.apply(sunvec1, sunvec2);
47
48 // synchronize();
49 for (n_runs = 1; timing < mintime;) {
50 n_runs *= 2;
51 gettimeofday(&start, NULL);
52 for (int i = 0; i < n_runs; i++) {
53 sunvec1.mark_changed(ALL); // Ensure communication is included
54 D_staggered.apply(sunvec1, sunvec2);
55 }
56 // synchronize();
57 gettimeofday(&end, NULL);
58 timing = timediff(start, end);
59 hila::broadcast(timing);
60 }
61 timing = timing / (double)n_runs;
62 hila::out0 << "Dirac staggered: " << timing << "ms \n";
63
64 // Conjugate gradient step
65 CG<dirac_stg> stg_inverse(D_staggered, 1e-5, 1);
66 timing = 0;
67 sunvec1[ALL] = 0;
68 stg_inverse.apply(sunvec2, sunvec1);
69 for (n_runs = 1; timing < mintime;) {
70 n_runs *= 2;
71
72 gettimeofday(&start, NULL);
73 for (int i = 0; i < n_runs; i++) {
74 sunvec1[ALL] = 0;
75 stg_inverse.apply(sunvec2, sunvec1);
76 }
77
78 // synchronize();
79 gettimeofday(&end, NULL);
80 timing = timediff(start, end);
81 hila::broadcast(timing);
82 }
83
84 timing = timing / (double)n_runs;
85 hila::out0 << "Staggered CG: " << timing << "ms / iteration\n";
86
88 onsites(ALL) {
89 wvec1[X].gaussian_random();
90 wvec2[X].gaussian_random();
91 }
92 // Time staggered Dirac operator
93 timing = 0;
94 // printf("node %d, dirac_staggered 0\n", hila::myrank());
96 Dirac_Wilson D_wilson(0.05, U);
97 D_wilson.apply(wvec1, wvec2);
98
99 // synchronize();
100 for (n_runs = 1; timing < mintime;) {
101 n_runs *= 2;
102 gettimeofday(&start, NULL);
103 for (int i = 0; i < n_runs; i++) {
104 wvec1.mark_changed(ALL); // Ensure communication is included
105 D_wilson.apply(wvec1, wvec2);
106 }
107 // synchronize();
108 gettimeofday(&end, NULL);
109 timing = timediff(start, end);
110 hila::broadcast(timing);
111 }
112 timing = timing / (double)n_runs;
113 hila::out0 << "Dirac Wilson: " << timing << "ms \n";
114
115 // Conjugate gradient step (set accuracy=1 to run only 1 step)
116 CG<Dirac_Wilson> w_inverse(D_wilson, 1e-12, 5);
117 timing = 0;
118 wvec1[ALL] = 0;
119 w_inverse.apply(wvec2, wvec1);
120 for (n_runs = 1; timing < mintime;) {
121
122 n_runs *= 2;
123
124 gettimeofday(&start, NULL);
125 for (int i = 0; i < n_runs; i++) {
126 wvec1[ALL] = 0;
127 w_inverse.apply(wvec2, wvec1);
128 }
129
130 // synchronize();
131 gettimeofday(&end, NULL);
132 timing = timediff(start, end);
133 hila::broadcast(timing);
134 }
135
136 timing = timing / (double)n_runs;
137 hila::out0 << "Dirac Wilson CG: " << timing << "ms / iteration\n";
138
140}
The conjugate gradient operator. Applies the inverse square of an operator on a vector.
The field class implements the standard methods for accessing Fields. Hilapp replaces the parity acce...
Definition field.h:61
Class for SU(N) matrix.
Definition sun_matrix.h:37
void setup(const CoordinateVector &siz)
General lattice setup.
Definition lattice.cpp:33
This header file defines:
#define foralldir(d)
Macro to loop over (all) Direction(s)
Definition coordinates.h:78
constexpr Parity ALL
bit pattern: 011
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
T broadcast(T &var, int rank=0)
Broadcast the value of var to all MPI ranks from rank (default=0).
Definition com_mpi.h:153
void finishrun()
Normal, controlled exit - all nodes must call this. Prints timing information and information about c...