-
Notifications
You must be signed in to change notification settings - Fork 3
/
mplex-nt.cxx
161 lines (126 loc) · 3.48 KB
/
mplex-nt.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// HOST / AVX
// icc -O3 -mavx -I. -o mult66 mult66.cc -vec-report=3
// ./mult66
// MIC
// icc -O3 -mmic -I. -o mult66-mic mult66.cc -vec-report=3
// scp mult66-mic root@mic0:
// ssh root@mic0 ./mult66-mic
#include "MatriplexNT.h"
#include "mplex-common.h"
typedef Matriplex<float, M, M> MPlexMM;
int main(int arg, char *argv[])
{
SMatrixMM *res = new_sth<SMatrixMM>(Ns);
SMatrixMM *mul = new_sth<SMatrixMM>(Ns);
SMatrixMM *muz = new_sth<SMatrixMM>(Ns);
#ifdef SYMM
SMatrixSS *muls = new_sth<SMatrixSS>(Ns);
SMatrixSS *muzs = new_sth<SMatrixSS>(Ns);
#else
SMatrixSS *muls = 0;
SMatrixSS *muzs = 0;
#endif
MPlexMM mpl(N);
MPlexMM mpz(N);
MPlexMM mpres(N);
init_mulmuz(mul, muz, muls, muzs);
// Multiplex arrays
for (int i = 0; i < N; ++i)
{
mpl.Assign(i, mul[i].Array());
mpz.Assign(i, muz[i].Array());
}
double t0, tmp, tsm;
// ================================================================
if (NN_MULT)
{
t0 = dtime();
for (int i = 0; i < NN_MULT; ++i)
{
//#pragma omp simd collapse(8)
#pragma ivdep
for (int m = 0; m < N; ++m)
{
res[m] = mul[m] * muz[m];
}
}
tsm = dtime() - t0;
std::cout << "SMatrix multiply time = " << tsm << " s\n";
// ----------------------------------------------------------------
t0 = dtime();
for (int i = 0; i < NN_MULT; ++i)
{
Multiply(mpl, mpz, mpres);
}
tmp = dtime() - t0;
std::cout << "Matriplex multiply time = " << tmp << " s\n";
std::cout << "SMatrix / Matriplex = " << tsm/tmp << "";
{
double x = 0, y = 0;
for (int j = 0; j < N; ++j)
{
x += res[j](1,2);
y += mpres(1,2,j);
}
std::cout << "\t\t\tx = " << x << ", y = " << y << "\n";
}
std::cout << "\n";
/*
for (int i = 0; i < N; ++i)
for (int j = 0; j < M; ++j)
for (int k = 0; k < M; ++k)
{
if (res[i](j,k) != mpres.At(j, k, i))
std::cout << i <<" "<< j <<" "<< k <<" "<< res[i](j,k) <<" "<< mpres.At(j, k, i) << "\n";
}
*/
}
// ================================================================
if (NN_INV)
{
t0 = dtime();
for (int i = 0; i < NN_INV; ++i)
{
//#pragma omp simd collapse(8)
#pragma ivdep
for (int m = 0; m < N; ++m)
{
//mul[m].InvertFast();
//muz[m].InvertFast();
#ifdef SYMM
bool bl = muls[m].InvertChol();
bool bz = muzs[m].InvertChol();
#else
bool bl = mul[m].InvertChol();
bool bz = muz[m].InvertChol();
#endif
//if ( ! bl || ! bz) printf("Grr %d %d %d\n", m, bl, bz);
}
}
tsm = dtime() - t0;
std::cout << "SMatrix invert time = " << tsm << " s\n";
// ----------------------------------------------------------------
t0 = dtime();
for (int i = 0; i < NN_INV; ++i)
{
// InvertCramer(mpl);
// InvertCramer(mpz);
InvertChol(mpl);
InvertChol(mpz);
}
tmp = dtime() - t0;
std::cout << "Matriplex invert time = " << tmp << " s\n";
std::cout << "SMatrix / Matriplex = " << tsm/tmp << "\n\n";
// ================================================================
if (COMPARE_INVERSES)
{
for (int i = 0; i < M; ++i) { for (int j = 0; j < M; ++j)
printf("%8f ", muls[0](i,j)); printf("\n");
} printf("\n");
for (int i = 0; i < M; ++i) { for (int j = 0; j < M; ++j)
printf("%8f ", mpl.At(i,j,0)); printf("\n");
} printf("\n");
}
}
return 0;
}