-
Notifications
You must be signed in to change notification settings - Fork 28
/
input.cpp
566 lines (518 loc) · 24.2 KB
/
input.cpp
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
/*
* Copyright (c) 2011-2019, Triad National Security, LLC.
* All rights Reserved.
*
* CLAMR -- LA-CC-11-094
*
* Copyright 2011-2019. Triad National Security, LLC. This software was produced
* under U.S. Government contract 89233218CNA000001 for Los Alamos National
* Laboratory (LANL), which is operated by Triad National Security, LLC
* for the U.S. Department of Energy. The U.S. Government has rights to use,
* reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR
* TRIAD NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR
* ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified
* to produce derivative works, such modified software should be clearly marked,
* so as not to confuse it with the version available from LANL.
*
* Additionally, redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Triad National Security, LLC, Los Alamos
* National Laboratory, LANL, the U.S. Government, nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE TRIAD NATIONAL SECURITY, LLC AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL TRIAD NATIONAL
* SECURITY, LLC OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* CLAMR -- LA-CC-11-094
* This research code is being developed as part of the
* 2011 X Division Summer Workshop for the express purpose
* of a collaborative code for development of ideas in
* the implementation of AMR codes for Exascale platforms
*
* AMR implementation of the Wave code previously developed
* as a demonstration code for regular grids on Exascale platforms
* as part of the Supercomputing Challenge and Los Alamos
* National Laboratory
*
* Authors: Bob Robey XCP-2 [email protected]
* Neal Davis [email protected], [email protected]
* David Nicholaeff [email protected], [email protected]
* Dennis Trujillo [email protected], [email protected]
*
*
* This file and the associated header is based on a file from the capablanca
* project available under the MIT open-source license. As author of that code,
* I, Neal Davis, permit repurposing and redistribution for CLAMR under the New
* BSD License used above.
* http://code.google.com/p/capablanca/
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "state.h"
#include "mesh/partition.h"
#include "mesh/mesh.h"
#include "hash/hash.h"
#include "crux/crux.h"
#include "graphics/display.h"
#include "graphics/graphics.h"
#include <fstream>
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sys/stat.h>
#include <limits.h>
#define OUTPUT_INTERVAL 100
#define COARSE_GRID_RES 128
#define MAX_TIME_STEP 3000
using namespace std;
// Global variables.
char progName[12]; // Program name.
char progVers[8]; // Program version.
// External global variables.
extern bool verbose,
localStencil,
outline,
face_based,
dynamic_load_balance_on,
h5_spoutput,
restart,
phantom_debug;
extern int outputInterval,
crux_type,
enhanced_precision_sum,
tmax,
levmx,
nx,
ny,
niter,
measure_type,
ndigits,
nbits,
do_quo_setup,
calc_neighbor_type,
choose_amr_method,
choose_hash_method,
initial_order,
graphic_outputInterval,
graphics_type,
checkpoint_outputInterval,
neighbor_remap,
num_of_rollback_states,
output_cuts,
cycle_reorder;
extern float
mem_opt_factor;
extern double
upper_mass_diff_percentage;
extern char* restart_file;
void outputHelp()
{ cout << "CLAMR is an experimental adaptive mesh refinement code for the GPU." << endl
<< "Version is " << PACKAGE_VERSION << endl << endl
<< "Usage: " << progName << " [options]..." << endl
<< " -A <T> AMR type (default cell);" << endl
<< " \"cell\"" << endl
<< " \"cell-in-place\"" << endl
<< " \"face\"" << endl
<< " \"face-in-place\"" << endl
<< " \"regular-grid\"" << endl
<< " \"regular-grid-by-faces\"" << endl
<< " -b <B> Number of rollback images, disk or in memory (default 2);" << endl
<< " -B bits to truncate;" << endl
<< " -c <C> Checkpoint to disk at interval specified;" << endl
<< " -C <C> Checkpoint to memory at interval specified;" << endl
<< " -D digits to truncate;" << endl
<< " -e <E> force hash_method, ie linear, quadratic..." <<endl
<< " \"perfect\"" << endl
<< " \"linear\"" << endl
<< " \"quadratic\"" << endl
<< " \"prime_jump\"" << endl
<< " -f face-based finite difference;" << endl
<< " -g <g> specify I step between saving graphics information for post processing;" << endl
<< " -G <G> specify graphics file type for post processing;" << endl
<< " \"bmp\"" << endl
<< " \"gif\"" << endl
<< " \"jpeg\"" << endl
<< " \"mpeg\"" << endl
<< " \"pdf\"" << endl
<< " \"png\"" << endl
<< " \"svg\"" << endl
<< " \"data\"" << endl
<< " \"rdata\"" << endl
<< " \"hash\"" << endl
<< " -h display this help message;" << endl
<< " -i <I> specify I steps between output to files;" << endl
<< " -l <l> max number of levels;" << endl
<< " -M <M> memory optimization factor 1.0 <= M <=100.0 (default 1.0 -- represents 1/20 perfect hash);" << endl
<< " -m <m> specify partition measure type;" << endl
<< " \"with_duplicates\"" << endl
<< " \"without_duplicates\"" << endl
<< " -N <n> specify calc neighbor type;" << endl
<< " \"hash_table\"" << endl
<< " \"kdtree\"" << endl
<< " -n <N> specify coarse grid resolution of NxN;" << endl
<< " -o turn off outlines;" << endl
<< " -P <P> specify initial order P;" << endl
<< " \"original_order\"" << endl
<< " \"hilbert_sort\"" << endl
<< " \"hilbert_partition\"" << endl
<< " \"z_order\"" << endl
<< " -p <p> specify ordering P every cycle;" << endl
<< " \"original_order\"" << endl
<< " \"hilbert_sort\"" << endl
<< " \"hilbert_partition\"" << endl
<< " \"local_hilbert\"" << endl
<< " \"local_fixed\"" << endl
<< " \"z_order\"" << endl
<< " -q turn on quo;" << endl
<< " -r regular sum instead of enhanced precision sum (Kahan sum);" << endl
<< " -R restart simulation from the backup file specified;" << endl
<< " -s <s> specify space-filling curve method S;" << endl
<< " -S write out double precision data as single precision;" << endl
<< " -T execute with TVD;" << endl
<< " -t <t> specify T time steps to run;" << endl
<< " -u allowed percentage of difference between total mass between iterations." << endl
<< " the default value for this parameter is 2.6e-13;" << endl
<< " -V use verbose output;" << endl
<< " -v display version information." << endl
<< " -x turn on phantom AMR regular debug" << endl
<< " -z force recalculation of neighbors." << endl
<< " -Z <Z> Include cuts along y-axis (y vs. H) with output files." << endl
<< " \"yaxis\"" << endl
<< " \"xaxis\"" << endl
<< " \"45deg\"" << endl
<< " \"all\"" << endl;}
void outputVersion()
{ cout << progName << " " << progVers << endl; }
/* parseInput(const int argc, char** argv)
*
* Interpret the command line input.
*/
void parseInput(const int argc, char** argv)
{ strcpy(progName, "clamr");
strcpy(progVers, PACKAGE_VERSION);
// Reconstruct command line argument as a string.
char progCL[256]; // Complete program command line.
strcpy(progCL, argv[0]);
for (int i = 1; i < argc; i++)
{ strcat(progCL, " ");
strcat(progCL, argv[i]); }
// Set variables to defaults, which may be overridden by CLI.
verbose = false;
localStencil = true;
outline = true;
output_cuts = CUT_NONE;
#ifdef HAVE_QUO
do_quo_setup = 0;
#endif
dynamic_load_balance_on = false;
crux_type = CRUX_NONE;
face_based = false;
restart = false;
restart_file = NULL;
outputInterval = OUTPUT_INTERVAL;
nx = COARSE_GRID_RES;
ny = COARSE_GRID_RES;
niter = MAX_TIME_STEP;
neighbor_remap = true;
//measure_type = CSTARVALUE;
measure_type = NO_PARTITION_MEASURE;
ndigits = -1;
nbits = -1;
calc_neighbor_type = HASH_TABLE;
choose_amr_method = CELL_AMR;
choose_hash_method = METHOD_UNSET;
initial_order = HILBERT_SORT;
cycle_reorder = ORIGINAL_ORDER;
graphic_outputInterval = INT_MAX;
graphics_type = GRAPHICS_NONE;
checkpoint_outputInterval = INT_MAX;
num_of_rollback_states = 2;
levmx = 1;
mem_opt_factor = 1.0;
upper_mass_diff_percentage = -1.0;
enhanced_precision_sum = SUM_KAHAN;
char *val;
if (argc > 1)
{ int i = 1;
val = strtok(argv[i++], " ,.-");
while (val != NULL){
switch (val[0]){
case 'A': // AMR method specified.
val = strtok(argv[i++], " ,");
if (! strcmp(val,"cell") ) {
choose_amr_method = CELL_AMR;
} else if (! strcmp(val,"cell-in-place") ) {
choose_amr_method = CELL_IN_PLACE_AMR;
} else if (! strcmp(val,"face") ) {
choose_amr_method = FACE_AMR;
} else if (! strcmp(val,"face-in-place") ) {
choose_amr_method = FACE_IN_PLACE_AMR;
} else if (! strcmp(val,"regular-grid") ) {
choose_amr_method = REGULAR_GRID_AMR;
} else if (! strcmp(val,"regular-grid-by-faces") ) {
choose_amr_method = REGULAR_GRID_BY_FACES_AMR;
} else {
printf("AMR method must be either \"cell\", \"cell-in-place\", \"face\", \"face-in-place\", \"regular-grid\" or \"regular-grid-by-faces\"\n");
}
break;
case 'b': // Number of rollback images, disk or in memory (default 2)
sprintf(val,"0");
if (i < argc) val = strtok(argv[i++], " ,");
if(atoi(val) < 1){
printf("backup number must be at least 1, setting to default value 2\n");
}
else{
num_of_rollback_states = atoi(val);
}
break;
case 'B': // number of bits to truncate at end of burst loop
val = strtok(argv[i++], " ,.-");
nbits = atoi(val);
break;
case 'c': // Checkpoint to disk at interval specified
val = strtok(argv[i++], " ,.-");
checkpoint_outputInterval = atoi(val);
crux_type = CRUX_DISK;
break;
case 'C': // Checkpoint to memory at interval specified
val = strtok(argv[i++], " ,.-");
checkpoint_outputInterval = atoi(val);
crux_type = CRUX_IN_MEMORY;
break;
case 'D': // number of digits to truncate at end of burst loop
val = strtok(argv[i++], " ,.-");
ndigits = atoi(val);
break;
case 'e': // hash method specified.
val = strtok(argv[i++], " ,");
if (! strcmp(val,"perfect") ) {
choose_hash_method = PERFECT_HASH;
} else if (! strcmp(val,"linear") ) {
choose_hash_method = LINEAR;
} else if (! strcmp(val,"quadratic") ) {
choose_hash_method = QUADRATIC;
} else if (! strcmp(val,"prime_jump") ) {
choose_hash_method = PRIME_JUMP;
}
break;
case 'f': // Use face-based finite difference
face_based = true;
break;
case 'g': // Save graphics data to files during simulation.
val = strtok(argv[i++], " ,.-");
graphic_outputInterval = atoi(val);
if (graphics_type == GRAPHICS_NONE) graphics_type = GRAPHICS_DATA;
break;
case 'G': // Graphics data file type.
val = strtok(argv[i++], " ,.-");
if (! strcmp(val,"none") ) {
graphics_type = GRAPHICS_NONE;
graphic_outputInterval = INT_MAX;
} else if (! strcmp(val,"data") ) {
graphics_type = GRAPHICS_DATA;
} else if (! strcmp(val,"rdata") ) {
graphics_type = GRAPHICS_REAL_DATA;
} else if (! strcmp(val,"hash") ) {
graphics_type = GRAPHICS_HASH;
#ifdef HAVE_MAGICKWAND
} else if (! strcmp(val,"bmp") ) {
graphics_type = GRAPHICS_BMP;
} else if (! strcmp(val,"gif") ) {
graphics_type = GRAPHICS_GIF;
} else if (! strcmp(val,"jpeg") ) {
graphics_type = GRAPHICS_JPEG;
} else if (! strcmp(val,"mpeg") ) {
graphics_type = GRAPHICS_MPEG;
} else if (! strcmp(val,"pdf") ) {
graphics_type = GRAPHICS_PDF;
} else if (! strcmp(val,"png") ) {
graphics_type = GRAPHICS_PNG;
} else if (! strcmp(val,"svg") ) {
graphics_type = GRAPHICS_SVG;
#endif
} else {
printf("Unrecognized option for graphics file type %s\n",val);
exit(-1);
}
break;
case 'h': // Output help.
outputHelp();
cout.flush();
exit(EXIT_SUCCESS);
break;
case 'i': // Output interval specified.
val = strtok(argv[i++], " ,.-");
outputInterval = atoi(val);
break;
case 'l': // max level specified.
val = strtok(argv[i++], " ,");
levmx = atoi(val);
break;
case 'M': // memory optimization factor
val = strtok(argv[i++], " ,");
mem_opt_factor = atof(val);
break;
case 'm': // partition measure specified.
val = strtok(argv[i++], " ,");
if (! strcmp(val,"no_partition_measure") ) {
measure_type = NO_PARTITION_MEASURE;
} else if (! strcmp(val,"with_duplicates") ) {
measure_type = WITH_DUPLICATES;
} else if (! strcmp(val,"without_duplicates") ) {
measure_type = WITHOUT_DUPLICATES;
} else if (! strcmp(val,"cvalue") ) {
measure_type = CVALUE;
} else if (! strcmp(val,"cstarvalue") ) {
measure_type = CSTARVALUE;
}
break;
case 'N': // calc neighbor type specified.
val = strtok(argv[i++], " ,");
if (! strcmp(val,"hash_table") ) {
calc_neighbor_type = HASH_TABLE;
} else if (! strcmp(val,"kdtree") ) {
calc_neighbor_type = KDTREE;
}
break;
case 'n': // Domain grid resolution specified.
val = strtok(argv[i++], " ,");
nx = atoi(val);
ny = nx;
break;
case 'o': // Turn off outlines on mesh drawing.
outline = false;
break;
case 'P': // Initial order specified.
val = strtok(argv[i++], " ,");
if (! strcmp(val,"original_order") ) {
initial_order = ORIGINAL_ORDER;
} else if (! strcmp(val,"hilbert_sort") ) {
initial_order = HILBERT_SORT;
} else if (! strcmp(val,"hilbert_partition") ) {
initial_order = HILBERT_PARTITION;
} else if (! strcmp(val,"z_order") ) {
initial_order = ZORDER;
}
break;
case 'p': // Initial order specified.
val = strtok(argv[i++], " ,");
if (! strcmp(val,"original_order") ) {
cycle_reorder = ORIGINAL_ORDER;
localStencil = false;
} else if (! strcmp(val,"hilbert_sort") ) {
cycle_reorder = HILBERT_SORT;
localStencil = false;
} else if (! strcmp(val,"hilbert_partition") ) {
cycle_reorder = HILBERT_PARTITION;
localStencil = false;
} else if (! strcmp(val,"local_hilbert") ) {
cycle_reorder = ORIGINAL_ORDER;
localStencil = true;
} else if (! strcmp(val,"local_fixed") ) {
cycle_reorder = ORIGINAL_ORDER;
localStencil = false;
} else if (! strcmp(val,"z_order") ) {
cycle_reorder = ZORDER;
localStencil = false;
}
break;
case 'q': // turn on quo package.
#ifdef HAVE_QUO
do_quo_setup = 1;
#endif
break;
case 'r': // Regular sum instead of enhanced precision sum.
val = strtok(argv[i++], " ,");
if (! strcmp(val,"regular_sum") ) {
enhanced_precision_sum = SUM_REGULAR;
} else if (! strcmp(val,"kahan_sum") ) {
enhanced_precision_sum = SUM_KAHAN;
} else {
printf("Error with sum argument %s\n",val);
exit(0);
}
break;
case 'R': // Restart application from last checkpoint
restart = true;
restart_file = strtok(argv[i++], " ,");
struct stat stat_descriptor;
if (stat(restart_file,&stat_descriptor) == -1){
printf("Error -- restart file %s does not exist\n",restart_file);
exit(0);
}
break;
case 's': // Space-filling curve method specified (default HILBERT_SORT).
// Add different problem setups such as sloped wave in x, y and diagonal directions to help check algorithm
// HILBERT_SORT
break;
case 'T': // TVD inclusion specified.
break;
case 't': // Number of time steps specified.
val = strtok(argv[i++], " ,.-");
niter = atoi(val);
break;
case 'u': // Allowed percentage of difference in mass per iteration
val = strtok(argv[i++], " ,");
upper_mass_diff_percentage = atof(val);
break;
case 'V': // Verbose output desired.
verbose = true;
break;
case 'v': // Version.
outputVersion();
cout.flush();
exit(EXIT_SUCCESS);
break;
case 'x': // Phantom debug, -x sets to true
phantom_debug = true;
break;
case 'z': // Neighbor remap -- default is true, -z sets to false
neighbor_remap = false;
break;
case 'Z': // Output cuts -- default is none, -Z <Z> sets to type of cut
val = strtok(argv[i++], " ,");
if (! strcmp(val,"xaxis") ) {
output_cuts = CUT_XAXIS;
} else if (! strcmp(val,"yaxis") ) {
output_cuts = CUT_YAXIS;
} else if (! strcmp(val,"45deg") ) {
output_cuts = CUT_45DEG;
} else if (! strcmp(val,"all") ) {
output_cuts = CUT_ALL;
} else {
printf("Error with output cut type\n");
}
break;
default: // Unknown parameter encountered.
cout << "⚠ Unknown input parameter " << val << endl;
outputHelp();
cout.flush();
exit(EXIT_FAILURE);
break; }
val = strtok(argv[i++], " ,.-");
}
}
/*
if(upper_mass_diff_percentage < 0){
upper_mass_diff_percentage = 1.0e-12;
}
*/
}