-
Notifications
You must be signed in to change notification settings - Fork 1
/
time_uniform.cpp
143 lines (104 loc) · 3.51 KB
/
time_uniform.cpp
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
const double MLFMM_ALPHA(1.0);
#include "General.hpp"
#include "MLFMM_Env.hpp"
#include "Direct.hpp"
double printResults(const vector<complex>& mlfmm,
const vector<complex>& exact)
{
double TotRelError = 0;
double TotErrorSq = 0;
double TotNormSq = 0;
double MaxRelErr = 0;
int N = exact.size();
for( int k = 0; k < N; ++k ) {
//cerr << mlfmm[k] << "\t\t" << exact[k] << "\t\t" << mlfmm[k]-exact[k] << endl;
// Individual Relative
TotRelError += abs(mlfmm[k] - exact[k]) / abs(exact[k]);
// Total Relative
TotErrorSq += norm(mlfmm[k] - exact[k]);
TotNormSq += norm(exact[k]);
// Max Absolute
MaxRelErr = max(abs(mlfmm[k] - exact[k]) / abs(exact[k]), MaxRelErr);
}
// Relative Error
double RelError = sqrt(TotErrorSq/TotNormSq);
cout << "Tot Rel Error: " << RelError << endl;
// Average Relative Error
double AveRelError = TotRelError/N;
cout << "Ave Rel Error: " << AveRelError << endl;
// Max Relative Error
cout << "Max Rel Error: " << MaxRelErr << endl;
return AveRelError;
}
struct HelmKernel
{
double kappa;
inline complex operator()(double r) {
return exp(CI * kappa * r) / r;
}
};
// Big Run - Many tests keeping points/wavelength constant
int main(int argc, char** argv)
{
(void) argc; (void) argv;
double a0 = 1;
int Nnum = 14;
int Nlist[14] = {1000, 2000, 4000, 8000, 16000,
32000, 64000, 128000, 256000, 512000,
1024000, 2048000, 4096000, 8192000};
fstream myFile("time_uniform.dat", ios::out);
myFile << "N\ta0kappa\tDIRtime\tFMMtime2\tFMMtime3\tFMMtime4\tFMMtime5\tFMMtime6\tFMMtime7" << endl;
for( int Nindex = 0; Nindex < Nnum; ++Nindex )
{
int N = Nlist[Nindex];
srand48(0);
vector<Vec3> p(N);
vector<complex> psi(N);
for( int k = 0; k < N; ++k ) {
p[k] = Vec3(getRandom(0,a0), getRandom(0,a0), getRandom(0,a0));
psi[k] = 1;
}
HelmKernel K;
K.kappa = (100/a0) * pow(N/8192000.0, 1.0/3.0);
myFile << N << "\t" << a0*K.kappa << "\t";
vector<complex> exact(N,0);
if( N <= 100000 ) {
cout << "Computing Direct " << N << endl;
StopWatch timer;
timer.start();
Direct( K, p, psi, exact );
double DIRtime = timer.stop();
myFile << DIRtime << "\t";
} else {
myFile << "NaN\t";
}
for( int levels = 2; levels <= 6; ++levels ) {
if( N > 500000 && levels <= 2 ) { myFile << "NaN\t"; continue; }
if( N > 1000000 && levels <= 3 ) { myFile << "NaN\t"; continue; }
if( N > 2000000 && levels <= 4 ) { myFile << "NaN\t"; continue; }
if( N > 8000000 && levels <= 5 ) { myFile << "NaN\t"; continue; }
// 24G Memory overload
if( N > 4000000 && levels >= 7 ) { myFile << "NaN\t"; continue; }
cout << "\nStarting " << N << "\t" << K.kappa << "\t" << levels << endl;
const static int DIM = 3;
MLFMM_Env<HelmKernel,DIM> env( K, p, levels, 1e-4 );
vector<complex> mlfmm(N,0);
StopWatch timer;
timer.start();
env.execute( psi, mlfmm );
env.execute( psi, mlfmm );
env.execute( psi, mlfmm );
env.execute( psi, mlfmm );
double MLFMMtime = timer.stop()/4;
double aveErr = 0;
if( exact[0] != complex(0) || exact[1] != complex(0) )
aveErr = printResults(mlfmm, exact);
cout << "N\ta0kappa\tlevels\tFMMtime\tAveErr" << endl;
cout << N << "\t" << a0*K.kappa << "\t" << levels << "\t" << MLFMMtime << "\t" << "\t" << aveErr << endl;
myFile << MLFMMtime << "\t";
}
myFile << endl;
}
myFile.close();
return 0;
}