forked from LLNL/LULESH
-
Notifications
You must be signed in to change notification settings - Fork 1
/
lulesh-util.cc
230 lines (211 loc) · 7.63 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
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdio.h>
#include <iostream>
#include <iomanip>
#if USE_MPI
#include <mpi.h>
#endif
#include "lulesh.h"
/* Helper function for converting strings to ints, with error checking */
template<typename IntT>
int StrToInt(const char *token, IntT *retVal)
{
const char *c ;
char *endptr ;
const int decimal_base = 10 ;
if (token == NULL)
return 0 ;
c = token ;
*retVal = 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(" -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_t 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++;
}
/* -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.
// Cast to 64-bit integer to avoid overflows.
Int8_t nx8 = nx;
Real_t grindTime1 = ((elapsed_time*1e6)/locDom.cycle())/(nx8*nx8*nx8);
Real_t grindTime2 = ((elapsed_time*1e6)/locDom.cycle())/(nx8*nx8*nx8*numRanks);
Index_t ElemId = 0;
std::cout << "Run completed:\n";
std::cout << " Problem size = " << nx << "\n";
std::cout << " MPI tasks = " << numRanks << "\n";
std::cout << " Iteration count = " << locDom.cycle() << "\n";
std::cout << " Final Origin Energy = ";
std::cout << std::scientific << std::setprecision(6);
std::cout << std::setw(12) << locDom.e(ElemId) << "\n";
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
std::cout << " Testing Plane 0 of Energy Array on rank 0:\n";
std::cout << " MaxAbsDiff = " << std::setw(12) << MaxAbsDiff << "\n";
std::cout << " TotalAbsDiff = " << std::setw(12) << TotalAbsDiff << "\n";
std::cout << " MaxRelDiff = " << std::setw(12) << MaxRelDiff << "\n";
// Timing information
std::cout.unsetf(std::ios_base::floatfield);
std::cout << std::setprecision(2);
std::cout << "\nElapsed time = " << std::setw(10) << elapsed_time << " (s)\n";
std::cout << std::setprecision(8);
std::cout << "Grind time (us/z/c) = " << std::setw(10) << grindTime1 << " (per dom) ("
<< std::setw(10) << elapsed_time << " overall)\n";
std::cout << "FOM = " << std::setw(10) << 1000.0/grindTime2 << " (z/s)\n\n";
return ;
}