-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
268 lines (190 loc) · 4.49 KB
/
Copy pathmain.cpp
File metadata and controls
268 lines (190 loc) · 4.49 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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
double CPU_FREQ;
#include <unistd.h>
#include <memory>
#ifdef IBV
#include <vector>
#include <list>
#endif
#ifdef ISEND
#include <queue>
#endif
#if QQ == 2
#include "gf/gf2.h"
#endif
#if QQ == 16
#include "gf/gf16.h"
#endif
#if QQ == 31
#include "gf/gf31.h"
#endif
#ifdef MPI
#define OMPI_SKIP_MPICXX
#define MPICH_SKIP_MPICXX
#include <mpi.h>
#endif
#ifdef _OPENMP
#include <omp.h>
#endif
double GLOBAL_start_time;
#ifdef OPEN_MPI
unsigned mpi_rank, mpi_size;
#else // #ifdef OPEN_MPI
const unsigned mpi_rank = 0;
const unsigned mpi_size = 1;
#endif // #ifdef OPEN_MPI
#include "params.h"
#include "xl.h"
#ifdef NUMA
#include <numa.h>
#endif
void dump_proc_status()
{
int pid = getpid();
char cmd[100];
sprintf(cmd, "cat /proc/%d/status | grep Vm\n", pid);
#ifdef OPEN_MPI
if(mpi_rank == 0)
#endif
pid = system(cmd);
}
float get_cpu_freq()
{
char buf[1024];
FILE *f = fopen("/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq", "r");
if (f != NULL)
{
if (fgets(buf, 1024, f) == NULL)
{
ECHO("error reading frequency!\n");
fclose(f);
return -1;
}
double freq = atof(buf) / 1000.0;
fclose(f);
return freq;
}
else
{
f = fopen("/proc/cpuinfo", "r");
do
{
if (strncmp("cpu MHz", buf, 7) == 0)
{
uint32_t pos = 0;
while ((pos <= (strlen(buf)-1)) && (buf[pos] != ':'))
pos ++;
pos ++;
double freq = atof(buf + pos);
fclose(f);
return freq;
}
}
while (fgets(buf, 1024, f) != NULL);
fclose(f);
}
return -1;
}
void setup(int argc, char * argv[], Options *options)
{
GLOBAL_start_time = - get_ms_time();
CPU_FREQ = get_cpu_freq();
ECHO("running svn revision $Revision: 4129 $\n");
ECHO("got cpu frequency from \\proc\\cpuinf: %f\n", CPU_FREQ);
#ifdef OPEN_MPI
int size;
int rank;
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &size);
mpi_size = size;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
mpi_rank = rank;
#endif
dump_proc_status();
#ifdef OPEN_MPI
DUMP(mpi_size);
#ifdef BLOCKING
ECHO("MPI is in blocking mode...\n")
#endif
char processor_name[MPI_MAX_PROCESSOR_NAME];
int namelen;
MPI_Get_processor_name(processor_name, &namelen);
for (unsigned rank = 0; rank < mpi_size; rank++)
{
MPI_Status status;
int pid = getpid();
if (rank > 0)
{
if (mpi_rank == 0)
{
MPI_Recv(processor_name, MPI_MAX_PROCESSOR_NAME, MPI_CHAR,
rank, 0, MPI_COMM_WORLD, &status);
MPI_Recv(&pid, 1, MPI_INT, rank, 0, MPI_COMM_WORLD, &status);
}
if (mpi_rank == rank)
{
MPI_Send(processor_name, MPI_MAX_PROCESSOR_NAME, MPI_CHAR,
0, 0, MPI_COMM_WORLD);
MPI_Send(&pid, 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
}
}
ECHO("rank %i is %s (%i)\n", rank, processor_name, pid);
}
ECHO_NL();
MPI_Barrier(MPI_COMM_WORLD);
#ifdef MPI_SIZE
if (mpi_size != MPI_SIZE)
{
if (mpi_rank == 0)
fprintf(stderr,
"%s was compiled for %i nodes!\n"
"Please run 'mpirun ... -n %i ... %s'\n",
argv[0], MPI_SIZE, MPI_SIZE, argv[0]);
ABORT;
}
#endif
#endif // #ifdef OPEN_MPI
options->parse(argc, argv);
#ifdef NUMA
if (options->bind != NULL)
numa_run_on_node(options->bind[mpi_rank]);
#endif // #ifdef NUMA
#ifdef OPEN_MPI
MPI_Bcast(&options->seed, sizeof(options->seed), MPI_BYTE, 0,
MPI_COMM_WORLD);
#endif // #ifdef OPEN_MPI
srand(options->seed);
ECHO("random seed = 0x%x\n", options->seed);
#ifdef _OPENMP
ECHO("max threads: %d\n", omp_get_max_threads());
#endif
}
void teardown(void)
{
#ifdef OPEN_MPI
MPI_Finalize();
#endif // #ifdef OPEN_MPI
dump_proc_status();
}
int main(int argc, char *argv[])
{
Options options;
setup(argc, argv, &options);
XL<MM,NN> xl(&options);
try
{
double comp_time = 0;
comp_time -= get_ms_time();
xl.run();
comp_time += get_ms_time();
ECHO_NL();
ECHO("total time of computation: %.3f ms\n", comp_time);
}
catch (BW_Exception &e)
{
ECHO_NL();
ECHO("BW did not return solution; run all steps up to bw3.\nExiting...\n\n");
}
fflush(stdout);
teardown();
return 0;
}