-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
92 lines (87 loc) · 2.95 KB
/
main.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
#include "main.h"
#include <omp.h>
using namespace std;
// TODO: optimisation by eliminating deque
/*deque<deque<State>> gen_grid(const Parameters &p, State &s_init) {
deque<deque<State>> ans(1, deque<State>(1, s_init));
while (ans.size() <= p.depth) {
cout << "at depth: " << ans.size() << endl;
// preallocated
deque<State> new_states(ans.back().size() * p.us.size(), s_init);
//#pragma omp parallel for
for (int i = 0; i < ans.back().size(); i++) {
const auto &s = ans.back()[i];
int u_count = 0;
for (const auto &u: p.us) {
auto new_state = s.gen_next_state(u, ans.size() * p.dt);
new_states[i * p.us.size() + u_count] = new_state;
u_count++;
}
}
ans.push_back(new_states);
}
return ans;
}*/
deque<deque<State>> gen_grid(const Parameters &p, State &s_init) {
deque<deque<State>> ans(1, deque<State>(1, s_init));
while (ans.size() <= p.depth) {
//cout << "at depth: " << ans.size() << endl;
// preallocated
deque<State> new_states;//(ans.back().size() * p.us.size(), s_init);
for (int i = 0; i < ans.back().size(); i++) {
const auto &s = ans.back()[i];
int u_count = 0;
for (const auto &u: p.us) {
auto new_state = s.gen_next_state(u, ans.size() * p.dt);
if (abs(new_state.a.psi_i) < M_PI)
new_states.push_back(new_state);
u_count++;
}
}
ans.push_back(new_states);
}
return ans;
}
void run_main(int argc, char *argv[]) {
CmdLineOptions o(argc, argv);
int max_threads = omp_get_max_threads();
std::cout << "Maximum number of threads available for OpenMP: " << max_threads << std::endl;
cout << "one instance of State takes " << sizeof(State) << endl;
system("rm *png *gpt");
Parameters p(o.V, o.dt, o.depth, o.us);
Attributes a(o.psi_init, 1e-20, 1e-20, 0, 0);
State s(a, &p);
auto grid = gen_grid(p, s);
// add points
Visualizer v(0, "red");
for (const auto step: grid)
for (const auto s: step)
v.add_state(s);
v.save();
// render plots
system("parallel -j 24 gnuplot {} \">\" {.}.png ::: *.gpt");
}
void run_tests(int argc, char *argv[]) {
CmdLineOptions o(argc, argv);
int max_threads = omp_get_max_threads();
// loop between 0 and max
int max_timesteps = 70;
for (int i = 1; i < max_timesteps; i++) {
//cout << i << ",";
o.depth = i;
Parameters p(o.V, o.dt, o.depth, o.us);
Attributes a(o.psi_init, 1e-20, 1e-20, 0, 0);
State s(a, &p);
auto grid = gen_grid(p, s);
int count=0;
for (const auto step: grid)
for (const auto s: step)
count++;
cout<<count<<endl;
}
}
int main(int argc, char *argv[]) {
//run_main(argc,argv);
run_tests(argc,argv);
return 0;
}