-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.cpp
More file actions
120 lines (97 loc) · 3.08 KB
/
main.cpp
File metadata and controls
120 lines (97 loc) · 3.08 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <iostream> // std::cout, std::endl
#include <iomanip> // std::setw
#include <sstream> // std::stringstream
#include "gd.h"
#ifdef __APPLE__
#include <OpenCL/opencl.h>
#else
#include <CL/cl.h>
#endif
#include "cllogger.h"
#include "clbuffer.h"
#include "clcontext.h"
#include "clkernel.h"
#include "parameters.h"
#include "asystem.h"
int main(int argc, char * argv[]) {
cl_device_type DeviceType = CL_DEVICE_TYPE_CPU;
bool profiling_enabled = false;
std::string s_profilePath = "";
std::string s_statePath = "";
std::string s_output = "";
int timescheme = 1;
int device = 0;
for (int i = 1; i < argc; i++) {
if (std::string(argv[i]) == "--device" || std::string(argv[i]) == "-dev") {
device = (int)atof(argv[i+1]);
} else if (std::string(argv[i]) == "-profiling") {
profiling_enabled = true;
} else if (std::string(argv[i]) == "-p") {
s_profilePath = (argv[i+1]);
} else if (std::string(argv[i]) == "-b") {
s_statePath = (argv[i+1]);
} else if (std::string(argv[i]) == "-o") {
s_output = (argv[i+1]);
} else if (std::string(argv[i]) == "-rk3") {
timescheme = 0;
} else if (std::string(argv[i]) == "-mis") {
timescheme = 1;
}
}
clcontext *context;
cllogger *logger;
asystem *sys;
logger = new cllogger(1, profiling_enabled, s_output);
context = new clcontext(logger, device, profiling_enabled);
sys = new asystem(context, logger, timescheme);
long long ns;
// context->info();
std::stringstream FileName;
context->used_memory();
if (s_statePath.length() == 0) {
logger->log(0, "No state files given\n");
if (s_profilePath.length() == 0) {
logger->log(0, "No profile provided\n");
sys->init_from_kernel();
} else {
sys->init_from_file(s_profilePath);
// remember to modify k_init if using this!
}
logger->log(0, "Equilibrating...");
sys->equilibrate();
sys->write_state("equil");
} else {
logger->log(0, "Reading state files from %s\n", s_statePath.c_str());
sys->read_state(s_statePath);
}
// sys->write_files(0);
// return 0;
sys->perturb();
logger->start_new_timer();
logger->log(2, "Estimating remaining time...\n");
int iterations = 10000;
for (int i = 0; i < iterations; i++) {
logger->start_new_timer();
sys->mis_step();
long long ns = logger->end_last_timer();
double seconds = double(ns)/1.0E9;
logger->log_estimated_time(seconds, i, iterations);
logger->log(2," - %d/%d",i,iterations);
}
double seconds_taken = double(logger->end_last_timer())/1.0E9;
int hours_taken = int(seconds_taken/3600.0);
seconds_taken = fmod(seconds_taken,3600.0);
int minutes_taken = int(seconds_taken/60.0);
seconds_taken = fmod(seconds_taken,60.0);
logger->log(0, "\ndone after %02dh %02dm %02ds\n",hours_taken,minutes_taken,int(seconds_taken));
if (profiling_enabled) {
context->full_info();
logger->log(0, "\tcl_time: %f\n", context->profiling_time * 1.0e-9);
}
delete sys;
delete context;
delete logger;
return 0;
}