HILA
Loading...
Searching...
No Matches
bench_matrix2.cpp
1#include <sstream>
2#include <iostream>
3#include <string>
4#include <math.h>
5#include <assert.h>
6#include <sys/time.h>
7#include <ctime>
8
9#include "plumbing/defs.h"
10#include "datatypes/matrix.h"
11#include "plumbing/field.h"
12
13// Minimum time to run each benchmark
14// in microseconds
15constexpr double mintime = 1000;
16
17// Direct output to stdout
18// std::ostream &hila::out = std::cout;
19
20// Calculate time difference in milliseconds
21static inline double timediff(timeval start, timeval end) {
22 long long t1 = (long long)(start.tv_usec) + 1000000 * (long long)(start).tv_sec;
23 long long t2 = (long long)(end.tv_usec) + 1000000 * (long long)(end).tv_sec;
24 return 1e-3 * (double)(t2 - t1);
25}
26
27#ifndef MSIZE
28#define MSIZE 3
29#endif
30
31#ifndef SEED
32#define SEED 100
33#endif
34
35#define MADD(x) (MSIZE + x)
36
37const CoordinateVector latsize = {32, 32, 32, 32};
38
39
40///////////////////////////////////////
41// benchmark conjugate operations for
42// increasing matrix sizes starting
43// from msize.
44///////////////////////////////////////
45
46using ntype = double;
47
48int main(int argc, char **argv) {
49 int n_runs = 1;
50 double msecs;
51 struct timeval start, end;
52 double timing;
53 double sum;
54
55 hila::initialize(argc, argv);
56
57 lattice.setup(latsize);
58
59 // test matrix indexing operators
61
62 timing = 0;
63 for (n_runs = 1; timing < mintime;) {
64 n_runs *= 2;
65 gettimeofday(&start, NULL);
66 for (int i = 0; i < n_runs; i++) {
67 onsites(ALL) {
68 for (int a = 0; a < 4; a++)
69 for (int b = 0; b < 4; b++)
70 matd[X].e(a, b) = a + b;
71 }
72 }
74 gettimeofday(&end, NULL);
75 timing = timediff(start, end);
76 }
77 timing = timing / (double)n_runs;
78 hila::out0 << "4x4 matrix index .e : " << timing << " ms \n";
79
81
82 hila::timer timer1("Timer1");
83
84 Field<Matrix<MADD(0), MADD(0), Complex<ntype>>> matrix1;
85 Field<Matrix<MADD(1), MADD(1), Complex<ntype>>> matrix2;
86 Field<Matrix<MADD(3), MADD(3), Complex<ntype>>> matrix3;
87 Field<Matrix<MADD(6), MADD(6), Complex<ntype>>> matrix4;
88
89 onsites(ALL) {
90 matrix1[X].random();
91 matrix2[X].random();
92 matrix3[X].random();
93 matrix4[X].random();
94 }
95
96 // Time dagger(matrix) * matrix * dagger(matrix)
97 timing = 0;
98 for (n_runs = 1; timing < mintime;) {
99 n_runs *= 2;
100 gettimeofday(&start, NULL);
101 for (int i = 0; i < n_runs; i++) {
102 matrix1[ALL] = matrix1[X].dagger() * matrix1[X] * matrix1[X].dagger();
103 }
105 gettimeofday(&end, NULL);
106 timing = timediff(start, end);
107 }
108 timing = timing / (double)n_runs;
109 hila::out0 << "matrix size " << (int)MSIZE << "*" << (int)MSIZE << " : " << timing
110 << " ms \n";
111
112 // timer1.start();
113
114 // Time dagger(matrix) * matrix * dagger(matrix)
115 timing = 0;
116 for (n_runs = 1; timing < mintime;) {
117 n_runs *= 2;
118 gettimeofday(&start, NULL);
119 for (int i = 0; i < n_runs; i++) {
120 matrix2[ALL] = matrix2[X].dagger() * matrix2[X] * matrix2[X].dagger();
121 }
123 gettimeofday(&end, NULL);
124 timing = timediff(start, end);
125 }
126 timing = timing / (double)n_runs;
127 hila::out0 << "matrix size " << (int)MSIZE + 1 << "*" << (int)MSIZE + 1 << " : "
128 << timing << " ms \n";
129
130 // timer1.end();
131
132 // Time dagger(matrix) * matrix * dagger(matrix)
133 timing = 0;
134 for (n_runs = 1; timing < mintime;) {
135 n_runs *= 2;
136 gettimeofday(&start, NULL);
137 for (int i = 0; i < n_runs; i++) {
138 matrix3[ALL] = matrix3[X].dagger() * matrix3[X] * matrix3[X].dagger();
139 }
141 gettimeofday(&end, NULL);
142 timing = timediff(start, end);
143 }
144 timing = timing / (double)n_runs;
145 hila::out0 << "matrix size " << (int)MSIZE + 3 << "*" << (int)MSIZE + 3 << " : "
146 << timing << " ms \n";
147
148 timing = 0;
149 for (n_runs = 1; timing < mintime;) {
150 n_runs *= 2;
151 gettimeofday(&start, NULL);
152 for (int i = 0; i < n_runs; i++) {
153 matrix4[ALL] = matrix4[X].dagger() * matrix4[X] * matrix4[X].dagger();
154 }
156 gettimeofday(&end, NULL);
157 timing = timediff(start, end);
158 }
159 timing = timing / (double)n_runs;
160 hila::out0 << "matrix size " << (int)MSIZE + 6 << "*" << (int)MSIZE + 6 << " : "
161 << timing << " ms \n";
162
163 //------------------------------------------------
164
165 // Time dagger(matrix) * matrix * dagger(matrix)
166 timing = 0;
167 for (n_runs = 1; timing < mintime;) {
168 n_runs *= 2;
169 gettimeofday(&start, NULL);
170 for (int i = 0; i < n_runs; i++) {
171 matrix1[ALL] = matrix1[X].adjoint() * matrix1[X] * matrix1[X].adjoint();
172 }
174 gettimeofday(&end, NULL);
175 timing = timediff(start, end);
176 }
177 timing = timing / (double)n_runs;
178 hila::out0 << "matrix size " << (int)MSIZE << "*" << (int)MSIZE << " : " << timing
179 << " ms \n";
180
181 // Time matrix) * .adjoint()atrix * matrix)
182 timing = 0;
183 for (n_runs = 1; timing < mintime;) {
184 n_runs *= 2;
185 gettimeofday(&start, NULL);
186 for (int i = 0; i < n_runs; i++) {
187 matrix2[ALL] = matrix2[X].adjoint() * matrix2[X] * matrix2[X].adjoint();
188 }
190 gettimeofday(&end, NULL);
191 timing = timediff(start, end);
192 }
193 timing = timing / (double)n_runs;
194 hila::out0 << "matrix size " << (int)MSIZE + 1 << "*" << (int)MSIZE + 1 << " : "
195 << timing << " ms \n";
196
197 // Time matrix) * .adjoint()atrix * matrix)
198 timing = 0;
199 for (n_runs = 1; timing < mintime;) {
200 n_runs *= 2;
201 gettimeofday(&start, NULL);
202 for (int i = 0; i < n_runs; i++) {
203 matrix3[ALL] = matrix3[X].adjoint() * matrix3[X] * matrix3[X].adjoint();
204 }
206 gettimeofday(&end, NULL);
207 timing = timediff(start, end);
208 }
209 timing = timing / (double)n_runs;
210 hila::out0 << "matrix size " << (int)MSIZE + 3 << "*" << (int)MSIZE + 3 << " : "
211 << timing << " ms \n";
212
213 timing = 0;
214 for (n_runs = 1; timing < mintime;) {
215 n_runs *= 2;
216 gettimeofday(&start, NULL);
217 for (int i = 0; i < n_runs; i++) {
218 matrix4[ALL] = matrix4[X].adjoint() * matrix4[X] * matrix4[X].adjoint();
219 }
221 gettimeofday(&end, NULL);
222 timing = timediff(start, end);
223 }
224 timing = timing / (double)n_runs;
225 hila::out0 << "matrix size " << (int)MSIZE + 6 << "*" << (int)MSIZE + 6 << " : "
226 << timing << " ms \n";
227
229}
Complex definition.
Definition cmplx.h:56
The field class implements the standard methods for accessing Fields. Hilapp replaces the parity acce...
Definition field.h:61
Matrix class which defines matrix operations.
Definition matrix.h:1620
void setup(const CoordinateVector &siz)
General lattice setup.
Definition lattice.cpp:33
constexpr Parity ALL
bit pattern: 011
This file defines all includes for HILA.
This files containts definitions for the Field class and the classes required to define it such as fi...
Definition of Matrix types.
void synchronize()
synchronize mpi
Definition com_mpi.cpp:255
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...