v0.13.1
Loading...
Searching...
No Matches
speed_test.cpp
Go to the documentation of this file.
1/* Tests the difference that loop fusion makes. */
2
3const int N = 60000;
4
5void fused(const double metric[6][N], double inverse[6][N])
6{
7 for(int i = 0; i < N; ++i)
8 {
9 double det = metric[0][i] * metric[3][i] * metric[5][i]
10 + metric[1][i] * metric[4][i] * metric[2][i]
11 + metric[2][i] * metric[1][i] * metric[4][i]
12 - metric[0][i] * metric[4][i] * metric[4][i]
13 - metric[1][i] * metric[1][i] * metric[5][i]
14 - metric[2][i] * metric[3][i] * metric[2][i];
15 inverse[0][i]
16 = (metric[3][i] * metric[5][i] - metric[4][i] * metric[4][i]) / det;
17 inverse[1][i]
18 = (metric[2][i] * metric[4][i] - metric[1][i] * metric[5][i]) / det;
19 inverse[2][i]
20 = (metric[1][i] * metric[4][i] - metric[2][i] * metric[3][i]) / det;
21 inverse[3][i]
22 = (metric[0][i] * metric[5][i] - metric[2][i] * metric[2][i]) / det;
23 inverse[4][i]
24 = (metric[2][i] * metric[1][i] - metric[0][i] * metric[4][i]) / det;
25 inverse[5][i]
26 = (metric[3][i] * metric[0][i] - metric[1][i] * metric[1][i]) / det;
27 }
28}
29
30void fused_big(const double metric[6][N], double inverse[6][N])
31{
32 double det[N];
33 for(int i = 0; i < N; ++i)
34 {
35 det[i] = metric[0][i] * metric[3][i] * metric[5][i]
36 + metric[1][i] * metric[4][i] * metric[2][i]
37 + metric[2][i] * metric[1][i] * metric[4][i]
38 - metric[0][i] * metric[4][i] * metric[4][i]
39 - metric[1][i] * metric[1][i] * metric[5][i]
40 - metric[2][i] * metric[3][i] * metric[2][i];
41 }
42 for(int i = 0; i < N; ++i)
43 {
44 inverse[0][i]
45 = (metric[3][i] * metric[5][i] - metric[4][i] * metric[4][i]) / det[i];
46 }
47 for(int i = 0; i < N; ++i)
48 {
49 inverse[1][i]
50 = (metric[2][i] * metric[4][i] - metric[1][i] * metric[5][i]) / det[i];
51 }
52 for(int i = 0; i < N; ++i)
53 {
54 inverse[2][i]
55 = (metric[1][i] * metric[4][i] - metric[2][i] * metric[3][i]) / det[i];
56 }
57 for(int i = 0; i < N; ++i)
58 {
59 inverse[3][i]
60 = (metric[0][i] * metric[5][i] - metric[2][i] * metric[2][i]) / det[i];
61 }
62 for(int i = 0; i < N; ++i)
63 {
64 inverse[4][i]
65 = (metric[2][i] * metric[1][i] - metric[0][i] * metric[4][i]) / det[i];
66 }
67 for(int i = 0; i < N; ++i)
68 {
69 inverse[5][i]
70 = (metric[3][i] * metric[0][i] - metric[1][i] * metric[1][i]) / det[i];
71 }
72}
73
74void unfused(const double metric[6][N], double inverse[6][N])
75{
76 double det[N];
77
78 for(int i = 0; i < N; ++i)
79 det[i] = metric[0][i] * metric[3][i] * metric[5][i]
80 + metric[1][i] * metric[4][i] * metric[2][i]
81 + metric[2][i] * metric[1][i] * metric[4][i]
82 - metric[0][i] * metric[4][i] * metric[4][i]
83 - metric[1][i] * metric[1][i] * metric[5][i]
84 - metric[2][i] * metric[3][i] * metric[2][i];
85 for(int i = 0; i < N; ++i)
86 inverse[0][i]
87 = (metric[3][i] * metric[5][i] - metric[4][i] * metric[4][i]) / det[i];
88 for(int i = 0; i < N; ++i)
89 inverse[1][i]
90 = (metric[2][i] * metric[4][i] - metric[1][i] * metric[5][i]) / det[i];
91 for(int i = 0; i < N; ++i)
92 inverse[2][i]
93 = (metric[1][i] * metric[4][i] - metric[2][i] * metric[3][i]) / det[i];
94 for(int i = 0; i < N; ++i)
95 inverse[3][i]
96 = (metric[0][i] * metric[5][i] - metric[2][i] * metric[2][i]) / det[i];
97 for(int i = 0; i < N; ++i)
98 inverse[4][i]
99 = (metric[2][i] * metric[1][i] - metric[0][i] * metric[4][i]) / det[i];
100 for(int i = 0; i < N; ++i)
101 inverse[5][i]
102 = (metric[3][i] * metric[0][i] - metric[1][i] * metric[1][i]) / det[i];
103}
104
105#include <ctime>
106#include <iostream>
107
108using namespace std;
109int main()
110{
111 double metric[6][N], inverse[6][N];
112
113 for(int j = 0; j < 6; ++j)
114 for(int i = 0; i < N; ++i)
115 metric[j][i] = 1 + i + j;
116
117 const int iterations = 30;
118
119 for(int i = 0; i < iterations; ++i)
120 {
121 // fused_big(metric,inverse);
122 // fused(metric,inverse);
123 // unfused(metric,inverse);
124 }
125}
FTensor::Index< 'i', SPACE_DIM > i
FTensor::Index< 'j', 3 > j
Definition: enable_if.hpp:6
void fused_big(const double metric[6][N], double inverse[6][N])
Definition: speed_test.cpp:30
void unfused(const double metric[6][N], double inverse[6][N])
Definition: speed_test.cpp:74
void fused(const double metric[6][N], double inverse[6][N])
Definition: speed_test.cpp:5
const int N
Definition: speed_test.cpp:3
int main()
Definition: speed_test.cpp:109