-
Notifications
You must be signed in to change notification settings - Fork 1
/
lulesh-util.cc
241 lines (222 loc) · 8.08 KB
/
lulesh-util.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
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
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdio.h>
#if USE_MPI
#include <mpi.h>
#endif
#include "lulesh.h"
/* Helper function for converting strings to ints, with error checking */
int StrToInt(const char *token, int *retVal)
{
const char *c ;
char *endptr ;
const int decimal_base = 10 ;
if (token == NULL)
return 0 ;
c = token ;
*retVal = (int)strtol(c, &endptr, decimal_base) ;
if((endptr != c) && ((*endptr == ' ') || (*endptr == '\0')))
return 1 ;
else
return 0 ;
}
static void PrintCommandLineOptions(char *execname, int myRank)
{
if (myRank == 0) {
printf("Usage: %s [opts]\n", execname);
printf(" where [opts] is one or more of:\n");
printf(" -q : quiet mode - suppress all stdout\n");
printf(" -i <iterations> : number of cycles to run\n");
printf(" -s <size> : length of cube mesh along side\n");
printf(" -r <numregions> : Number of distinct regions (def: 11)\n");
printf(" -b <balance> : Load balance between regions of a domain (def: 1)\n");
printf(" -c <cost> : Extra cost of more expensive regions (def: 1)\n");
printf(" -f <numfiles> : Number of files to split viz dump into (def: (np+10)/9)\n");
printf(" -p : Print out progress\n");
printf(" -v : Output viz file (requires compiling with -DVIZ_MESH\n");
printf(" -repart : enable repartitioning by defining the number of target group\n");
printf(" -repart_cycle : cycle at which repartitioning happens\n");
printf(" -h : This message\n");
printf("\n\n");
}
}
static void ParseError(const char *message, int myRank)
{
if (myRank == 0) {
printf("%s\n", message);
#if USE_MPI
MPI_Abort(MPI_COMM_WORLD, -1);
#else
exit(-1);
#endif
}
}
void ParseCommandLineOptions(int argc, char *argv[],
int myRank, struct cmdLineOpts *opts)
{
if(argc > 1) {
int i = 1;
while(i < argc) {
int ok;
/* -i <iterations> */
if(strcmp(argv[i], "-i") == 0) {
if (i+1 >= argc) {
ParseError("Missing integer argument to -i", myRank);
}
ok = StrToInt(argv[i+1], &(opts->its));
if(!ok) {
ParseError("Parse Error on option -i integer value required after argument\n", myRank);
}
i+=2;
}
/* -s <size, sidelength> */
else if(strcmp(argv[i], "-s") == 0) {
if (i+1 >= argc) {
ParseError("Missing integer argument to -s\n", myRank);
}
ok = StrToInt(argv[i+1], &(opts->nx));
if(!ok) {
ParseError("Parse Error on option -s integer value required after argument\n", myRank);
}
i+=2;
}
/* -r <numregions> */
else if (strcmp(argv[i], "-r") == 0) {
if (i+1 >= argc) {
ParseError("Missing integer argument to -r\n", myRank);
}
ok = StrToInt(argv[i+1], &(opts->numReg));
if (!ok) {
ParseError("Parse Error on option -r integer value required after argument\n", myRank);
}
i+=2;
}
/* -f <numfilepieces> */
else if (strcmp(argv[i], "-f") == 0) {
if (i+1 >= argc) {
ParseError("Missing integer argument to -f\n", myRank);
}
ok = StrToInt(argv[i+1], &(opts->numFiles));
if (!ok) {
ParseError("Parse Error on option -f integer value required after argument\n", myRank);
}
i+=2;
}
/* -p */
else if (strcmp(argv[i], "-p") == 0) {
opts->showProg = 1;
i++;
}
/* -q */
else if (strcmp(argv[i], "-q") == 0) {
opts->quiet = 1;
i++;
}
else if (strcmp(argv[i], "-b") == 0) {
if (i+1 >= argc) {
ParseError("Missing integer argument to -b\n", myRank);
}
ok = StrToInt(argv[i+1], &(opts->balance));
if (!ok) {
ParseError("Parse Error on option -b integer value required after argument\n", myRank);
}
i+=2;
}
else if (strcmp(argv[i], "-c") == 0) {
if (i+1 >= argc) {
ParseError("Missing integer argument to -c\n", myRank);
}
ok = StrToInt(argv[i+1], &(opts->cost));
if (!ok) {
ParseError("Parse Error on option -c integer value required after argument\n", myRank);
}
i+=2;
}
/* -v */
else if (strcmp(argv[i], "-v") == 0) {
#if VIZ_MESH
opts->viz = 1;
#else
ParseError("Use of -v requires compiling with -DVIZ_MESH\n", myRank);
#endif
i++;
}
else if(strcmp(argv[i], "-repart") == 0) {
if (i+1 >= argc) {
ParseError("Missing integer argument to -repart\n", myRank);
}
ok = StrToInt(argv[i+1], &(opts->repart));
if(!ok) {
ParseError("Parse Error on option -repart integer value required after argument\n", myRank);
}
i+=2;
}
else if(strcmp(argv[i], "-repart_cycle") == 0) {
if (i+1 >= argc) {
ParseError("Missing integer argument to -repart_cycle\n", myRank);
}
ok = StrToInt(argv[i+1], &(opts->cycle));
if(!ok) {
ParseError("Parse Error on option -repart_cycle integer value required after argument\n", myRank);
}
i+=2;
}
/* -h */
else if (strcmp(argv[i], "-h") == 0) {
PrintCommandLineOptions(argv[0], myRank);
#if USE_MPI
MPI_Abort(MPI_COMM_WORLD, 0);
#else
exit(0);
#endif
}
else {
char msg[80];
PrintCommandLineOptions(argv[0], myRank);
sprintf(msg, "ERROR: Unknown command line argument: %s\n", argv[i]);
ParseError(msg, myRank);
}
}
}
}
/////////////////////////////////////////////////////////////////////
void VerifyAndWriteFinalOutput(Real_t elapsed_time,
Domain& locDom,
Int_t nx,
Int_t numRanks)
{
// GrindTime1 only takes a single domain into account, and is thus a good way to measure
// processor speed indepdendent of MPI parallelism.
// GrindTime2 takes into account speedups from MPI parallelism
Real_t grindTime1 = ((elapsed_time*1e6)/locDom.cycle())/(nx*nx*nx);
Real_t grindTime2 = ((elapsed_time*1e6)/locDom.cycle())/(nx*nx*nx*numRanks);
Index_t ElemId = 0;
printf("Run completed: \n");
printf(" Problem size = %i \n", nx);
printf(" MPI tasks = %i \n", numRanks);
printf(" Iteration count = %i \n", locDom.cycle());
printf(" Final Origin Energy = %12.6e \n", locDom.e(ElemId));
Real_t MaxAbsDiff = Real_t(0.0);
Real_t TotalAbsDiff = Real_t(0.0);
Real_t MaxRelDiff = Real_t(0.0);
for (Index_t j=0; j<nx; ++j) {
for (Index_t k=j+1; k<nx; ++k) {
Real_t AbsDiff = FABS(locDom.e(j*nx+k)-locDom.e(k*nx+j));
TotalAbsDiff += AbsDiff;
if (MaxAbsDiff <AbsDiff) MaxAbsDiff = AbsDiff;
Real_t RelDiff = AbsDiff / locDom.e(k*nx+j);
if (MaxRelDiff <RelDiff) MaxRelDiff = RelDiff;
}
}
// Quick symmetry check
printf(" Testing Plane 0 of Energy Array on rank 0:\n");
printf(" MaxAbsDiff = %12.6e\n", MaxAbsDiff );
printf(" TotalAbsDiff = %12.6e\n", TotalAbsDiff );
printf(" MaxRelDiff = %12.6e\n\n", MaxRelDiff );
// Timing information
printf("\nElapsed time = %10.2f (s)\n", elapsed_time);
printf("Grind time (us/z/c) = %10.8g (per dom) (%10.8g overall)\n", grindTime1, grindTime2);
printf("FOM = %10.8g (z/s)\n\n", 1000.0/grindTime2); // zones per second
return ;
}