-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathmain.cc
114 lines (92 loc) · 2.59 KB
/
main.cc
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
#ifdef USE_MPI
#include "mpi.h"
#endif
#include "Spatter/Configuration.hh"
#include "Spatter/Input.hh"
#define xstr(s) str(s)
#define str(s) #s
void print_build_info(Spatter::ClArgs &cl) {
std::cout << std::endl;
std::cout << "Running Spatter version 1.1" << std::endl;
std::cout << "Compiler: " << xstr(SPAT_CXX_NAME) << " ver. "
<< xstr(SPAT_CXX_VER) << std::endl;
std::cout << "Backend: ";
if (cl.backend.compare("serial") == 0)
std::cout << "Serial" << std::endl;
else if (cl.backend.compare("openmp") == 0)
std::cout << "OpenMP" << std::endl;
else if (cl.backend.compare("cuda") == 0)
std::cout << "CUDA" << std::endl;
std::cout << "Aggregate Results? ";
if (cl.aggregate == true)
std::cout << "YES" << std::endl;
else
std::cout << "NO" << std::endl;
#ifdef USE_CUDA
int gpu_id = 0;
if (cl.backend.compare("cuda") == 0) {
int num_devices = 0;
checkCudaErrors(cudaGetDeviceCount(&num_devices));
struct cudaDeviceProp prop;
checkCudaErrors(cudaGetDeviceProperties(&prop, gpu_id));
std::cout << "Number of Devices: " << num_devices << std::endl;
std::cout << "Device Name: " << prop.name << std::endl;
std::cout << "Memory Clock Rage (KHz): " << prop.memoryClockRate
<< std::endl;
std::cout << "Memory Bus Width (bits): " << prop.memoryBusWidth
<< std::endl;
std::cout << "Peak Memory Bandwidth (GB/s): "
<< 2.0 * prop.memoryClockRate * (prop.memoryBusWidth / 8) / 1.0e6
<< std::endl;
}
#endif
std::cout << std::endl;
}
int main(int argc, char **argv) {
#ifdef USE_MPI
MPI_Init(&argc, &argv);
int rank;
int size;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
#endif
const unsigned long warmup_runs = 10;
bool timed = 0;
Spatter::ClArgs cl;
if (Spatter::parse_input(argc, argv, cl) != 0)
return -1;
#ifdef USE_MPI
if (rank == 0) {
#endif
if (cl.verbosity >= 1)
print_build_info(cl);
if (cl.verbosity >= 2)
std::cout << cl;
cl.report_header();
#ifdef USE_MPI
}
#endif
for (std::unique_ptr<Spatter::ConfigurationBase> const &config : cl.configs) {
for (unsigned long run = 0; run < (config->nruns + warmup_runs); ++run) {
unsigned long run_id = 0;
if (run >= warmup_runs) {
timed = 1;
run_id = run - warmup_runs;
} else {
timed = 0;
}
if (config->run(timed, run_id) != 0)
return -1;
}
#ifdef USE_MPI
if (rank == 0) {
#endif
config->report();
#ifdef USE_MPI
}
#endif
}
#ifdef USE_MPI
MPI_Finalize();
#endif
}