-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathtest_driver.cc
2145 lines (1941 loc) · 77 KB
/
test_driver.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
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
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "mpi.h"
#include <cmath>
#include <cstring>
#include <exception>
#include <getopt.h>
#include <malloc.h>
#include <sstream>
#include <stdio.h> // for getCurrentRSS and getPeakRSS
#include <string>
#include <sys/stat.h> //for mkdir
#include <unistd.h> //for getopt, access
// XLF signal handler function to emit a stack trace.
#if defined(__ibmxl__)
#include "signal.h"
extern "C" void xl__trce(int, siginfo_t *, void *);
#endif
#include <signal.h>
#if defined(__linux__)
#include <fenv.h>
#endif
#if defined(TETON_ENABLE_OPENMP)
#include "omp.h"
#endif
#if defined(TETON_ENABLE_UMPIRE)
#include "umpire/Umpire.hpp"
#include "umpire/strategy/QuickPool.hpp"
#include "umpire/strategy/ThreadSafeAllocator.hpp"
#endif
#if defined(TETON_ENABLE_CUDA)
#include "cuda_runtime_api.h"
#endif
#if defined(TETON_ENABLE_HIP)
#include "hip/hip_runtime_api.h"
#endif
#include "TetonConduitInterface.hh"
#include "TetonInterface.hh"
#include "conduit/conduit.hpp"
#include "conduit/conduit_blueprint.hpp"
#include "conduit/conduit_blueprint_mesh_utils.hpp"
#include "conduit/conduit_blueprint_mpi_mesh_utils.hpp"
#include "conduit/conduit_relay.hpp"
#include "conduit/conduit_relay_mpi_io_blueprint.hpp"
#if defined(TETON_ENABLE_MFEM)
#include "mfem.hpp"
#endif
#if defined(TETON_ENABLE_CALIPER)
#include "adiak.hpp"
#include "caliper/cali-manager.h"
#include "caliper/cali-mpi.h"
#include "caliper/cali.h"
#else
#define CALI_MARK_BEGIN(label)
#define CALI_MARK_END(label)
#define CALI_CXX_MARK_SCOPE(label)
#endif
// Determine whether Conduit has the tiled function.
#if CONDUIT_VERSION_MAJOR >= 0 && CONDUIT_VERSION_MINOR >= 8 && CONDUIT_VERSION_PATCH >= 9
#define TETON_CONDUIT_HAS_TILED_FUNCTION
#endif
// Utility function, check if string ends with another string.
bool endsWith(std::string const &fullString, std::string const &ending)
{
if (fullString.length() >= ending.length())
{
return (0 == fullString.compare(fullString.length() - ending.length(), ending.length(), ending));
}
else
{
return false;
}
}
int print_bytes_as_gb(const char *label, size_t bytes)
{
double gbmem = ((double) bytes / (1024.0 * 1024.0 * 1024.0));
fprintf(stdout, "%s: %7.4f GB\n", label, gbmem);
return (0);
}
#if defined(TETON_ENABLE_CUDA)
#define GPU_MEMGETINFO(free, total) cudaMemGetInfo(free, total)
#define GPU_SUCCESS cudaSuccess
#elif defined(TETON_ENABLE_HIP)
#define GPU_MEMGETINFO(free, total) hipMemGetInfo(free, total)
#define GPU_SUCCESS hipSuccess
#else
#define GPU_MEMGETINFO(free, total) 1
#define GPU_SUCCESS 1
#endif
void print_gpu_mem(const char *label)
{
size_t free = 0;
size_t total = 0;
double gbtotal, gbfree, gbused;
if (GPU_MEMGETINFO(&free, &total) != GPU_SUCCESS)
{
printf("MemGetInfo failed for GPU 0");
}
gbtotal = ((double) total) / (1024.0 * 1024.0 * 1024.0);
gbfree = ((double) free) / (1024.0 * 1024.0 * 1024.0);
gbused = ((double) total - free) / (1024.0 * 1024.0 * 1024.0);
fprintf(stdout, "%s: total %7.4f GB; free %7.3f GB; used %7.3f GB\n", label, gbtotal, gbfree, gbused);
fflush(stdout);
}
// Returns the current resident set size (physical memory use) measured in kbytes, or zero if the value cannot be determined on this OS.
size_t getCurrentRSS()
{
long rss = 0L;
FILE *fp = NULL;
if ((fp = fopen("/proc/self/statm", "r")) == NULL)
return (size_t) 0L; /* Can't open? */
if (fscanf(fp, "%*s%ld", &rss) != 1)
{
fclose(fp);
return (size_t) 0L; /* Can't read? */
}
fclose(fp);
return (size_t) rss * (size_t) sysconf(_SC_PAGESIZE);
}
//---------------------------------------------------------------------------
/**
@brief This Conduit error handler is invoked when Conduit would otherwise
throw an exception. The error handler blocks forever, on purpose.
This makes it easier to see the call stack that lead to the Conduit
exception so we can more easily track down the offending code in a
debugger.
*/
void conduit_debug_err_handler(const std::string &s1, const std::string &s2, int i1)
{
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
std::cout << rank << ": s1=" << s1 << ", s2=" << s2 << ", i1=" << i1 << std::endl;
// This is on purpose.
while (1)
;
}
//---------------------------------------------------------------------------
/**
@brief The TetonDriver class contains the driver state, sets up a problem, and
runs Teton via the Conduit interface.
*/
class TetonDriver
{
public:
TetonDriver() = default;
~TetonDriver();
void initialize();
int processArguments(int argc, char *argv[]);
int execute();
void finalize();
private:
void printUsage(const std::string &argv0) const;
void startCaliper(const std::string &label);
void initThreads();
void initGPU();
void writeStartSummary(unsigned int ndims,
unsigned long local_num_corners,
unsigned long num_corners,
unsigned long &num_unknowns,
unsigned long &local_num_unknowns) const;
int readMeshMFEM();
void initializeBlueprintFields(int nelem, int numPolar, int numAzimuthal, int numGroups);
void initializeBoundaryConditionsMFEM();
void updateBoundaryConnectivityMFEM();
void readConduitInputs();
void setOptions();
void verifyMesh();
void cycleLoop(double &dtrad, double &timerad, unsigned long num_unknowns);
void buildBlueprintTiledMesh();
void writeEndSummary(double end_time,
double start_time,
unsigned long num_unknowns,
unsigned long local_num_unknowns);
void release();
private:
int return_status{0};
int myRank{0};
int mySize{0};
unsigned int cycles{0};
int numPhaseAngleSets{0};
int useUmpire{2};
int numOmpMaxThreads{-1}; // Max number of CPU threads to use If -1, use value from omp_get_max_threads()
double fixedDT{0.0};
bool dumpViz{false};
double energy_check_tolerance{1.0e-9};
int input_sanitizer_level{1};
unsigned int benchmarkProblem{0};
int numPolarUser{-1};
int numAzimuthalUser{-1};
int numGroupsUser{0};
#if defined(TETON_ENABLE_MFEM)
int numSerialRefinementFactor{2};
int numParallelRefinementFactor{2};
int numSerialRefinementLevels{0};
int numParallelRefinementLevels{0};
mfem::Mesh *mesh{nullptr};
mfem::ParMesh *pmesh{nullptr};
mfem::ConduitDataCollection *conduit_data_collec{nullptr};
#endif
// MPI
MPI_Comm comm{MPI_COMM_WORLD};
int verbose{1};
bool useGPU{false};
bool useCUDASweep{false};
int gta_kernel{1};
int sweep_kernel{-1};
std::string scattering_kernel{};
::Teton::Teton myTetonObject{};
std::string inputPath{"."};
std::string outputPath{"."};
std::string label{};
std::string colorFile{};
std::string caliper_config
{
#if defined(TETON_ENABLE_CUDA)
"runtime-report,nvprof"
#else
"runtime-report"
#endif
};
std::string meshOrdering{"kdtree"};
#if defined(TETON_ENABLE_CALIPER)
cali::ConfigManager mgr{};
#endif
int blueprintMesh{0};
int dims[3]{10, 10, 10}; //!< Number of cells in blueprint mesh.
};
//---------------------------------------------------------------------------
TetonDriver::~TetonDriver()
{
release();
}
//---------------------------------------------------------------------------
void TetonDriver::initialize()
{
#if defined(TETON_ENABLE_CALIPER)
cali_mpi_init();
mgr.set_default_parameter("aggregate_across_ranks", "true");
mgr.set_default_parameter("calc.inclusive", "true");
mgr.set_default_parameter("main_thread_only", "true");
#endif
#ifdef SIGSEGV
signal(SIGSEGV, SIG_DFL);
#endif
#ifdef SIGILL
signal(SIGILL, SIG_DFL);
#endif
#ifdef SIGFPE
signal(SIGFPE, SIG_DFL);
#endif
#ifdef SIGINT
signal(SIGINT, SIG_DFL);
#endif
#ifdef SIGABRT
signal(SIGABRT, SIG_DFL);
#endif
#ifdef SIGTERM
signal(SIGTERM, SIG_DFL);
#endif
#ifdef SIGQUIT
signal(SIGQUIT, SIG_DFL);
#endif
#if defined(__linux__)
// This is in here for supporting Linux's floating point exceptions.
feenableexcept(FE_DIVBYZERO);
feenableexcept(FE_INVALID);
feenableexcept(FE_OVERFLOW);
#endif
#if defined(TETON_ENABLE_CALIPER)
adiak::init((void *) &comm);
adiak::user();
adiak::launchdate();
adiak::launchday();
adiak::executable();
adiak::clustername();
adiak::jobsize();
adiak::hostlist();
adiak::walltime();
adiak::systime();
adiak::cputime();
adiak::value("Version", teton_get_version(), adiak_general, "TetonBuildInfo");
adiak::value("SHA1", teton_get_git_sha1(), adiak_general, "TetonBuildInfo");
adiak::value("CxxCompiler", teton_get_cxx_compiler(), adiak_general, "TetonBuildInfo");
adiak::value("FortranCompiler", teton_get_fortran_compiler(), adiak_general, "TetonBuildInfo");
#endif
MPI_Comm_rank(comm, &myRank);
MPI_Comm_size(comm, &mySize);
if (myRank == 0)
{
std::cout << "Teton driver: number of MPI ranks: " << mySize << std::endl;
}
//==========================================================
// Set up signal handler
// If compiling with IBM XL, use XLF's trce function to emit a code stack trace if a TRAP signal is caught. This can be used to
// catch errors in any OpenMP kernels by setting'XLSMPOPTS=MSG_TRAP' in your environment.
//==========================================================
#if defined(__ibmxl__)
struct sigaction sa;
sa.sa_flags = SA_SIGINFO | SA_RESTART;
sa.sa_sigaction = xl__trce;
sigemptyset(&sa.sa_mask);
sigaction(SIGTRAP, &sa, NULL);
sigaction(SIGFPE, &sa, NULL);
#endif
}
//---------------------------------------------------------------------------
int TetonDriver::processArguments(int argc, char *argv[])
{
//==========================================================
// Get command line arguments
//==========================================================
while (1)
{
static struct option long_options[] = {
{"apply_label", no_argument, 0, 'l'},
{"benchmark_problem", required_argument, 0, 'b'},
{"blueprint", required_argument, 0, 'B'},
{"dims", required_argument, 0, 'd'},
{"caliper", required_argument, 0, 'p'},
{"input_sanitizer_level", required_argument, 0, 'y'},
{"handler", no_argument, 0, 'H'},
{"help", no_argument, 0, 'h'},
{"input_path", required_argument, 0, 'i'},
{"num_cycles", required_argument, 0, 'c'},
{"dt", required_argument, 0, 'D'},
{"num_phase_space_sets", required_argument, 0, 's'},
{"num_threads", required_argument, 0, 't'},
{"output_path", required_argument, 0, 'o'},
{"umpire_mode", required_argument, 0, 'u'},
{"mesh_ordering", required_argument, 0, 'M'},
{"use_device_aware_mpi", no_argument, 0, 'm'},
{"use_cuda_sweep", no_argument, 0, 'e'},
{"use_gpu_kernels", no_argument, 0, 'g'},
{"gta_kernel", required_argument, 0, 'n'},
{"scattering_kernel", required_argument, 0, 'k'},
{"sweep_kernel", required_argument, 0, 'S'},
{"verbose", required_argument, 0, 'v'},
{"write_viz_file", no_argument, 0, 'V'},
#if defined(TETON_ENABLE_MFEM)
{"serial_refinement_levels", required_argument, 0, 'r'},
{"parallel_refinement_levels", required_argument, 0, 'z'},
{"serial_refinement_factor", required_argument, 0, 'R'},
{"parallel_refinement_factor", required_argument, 0, 'Z'},
{"color_file", required_argument, 0, 'C'},
#endif
{"num_Polar", required_argument, 0, 'P'},
{"num_Azimuthal", required_argument, 0, 'A'},
{"num_Groups", required_argument, 0, 'G'},
{0, 0, 0, 0}
};
/* getopt_long stores the option index here. */
int option_index = 0;
#if defined(TETON_ENABLE_MFEM)
auto optString = "A:B:b:c:D:d:eG:gHhi:k:l:M:mn:o:P:p:s:S:t:u:Vv:y:" // Base options
"C:R:r:z:Z:"; // MFEM-only options
#else
auto optString = "A:B:b:c:D:d:eG:gHhi:k:l:M:mn:o:P:p:s:S:t:u:Vv:y:"; // Base options
#endif
int opt = getopt_long(argc, argv, optString, long_options, &option_index);
/* Detect the end of the options. */
if (opt == EOF)
{
break;
}
switch (opt)
{
case 'B':
if (strcmp(optarg, "local") == 0)
blueprintMesh = 1;
else if (strcmp(optarg, "global") == 0)
blueprintMesh = 2;
else
blueprintMesh = 0;
break;
case 'b':
benchmarkProblem = atoi(optarg);
if (myRank == 0)
{
std::cout << "Teton driver: Running predefined benchmark problem UMT SP#" << benchmarkProblem
<< std::endl;
}
break;
case 'c':
cycles = atoi(optarg);
if (myRank == 0)
{
std::cout << "Teton driver: cycles to execute: " << cycles << std::endl;
}
break;
case 'D':
fixedDT = atof(optarg);
if (myRank == 0)
{
std::cout << "Teton driver: fixed dt selected: " << fixedDT << std::endl;
}
break;
case 'd':
{
int d[3] = {1, 1, 1};
if (sscanf(optarg, "%d,%d,%d", &d[0], &d[1], &d[2]) == 3)
{
dims[0] = std::max(d[0], 1);
dims[1] = std::max(d[1], 1);
dims[2] = std::max(d[2], 0); // Allow 0 for 2D
}
else
{
throw std::runtime_error("Invalid dimensions " + std::string(optarg));
}
}
break;
case 'e':
useCUDASweep = true;
if (myRank == 0)
{
std::cout << "Using experimental streaming CUDA sweep." << std::endl;
}
break;
case 'g':
useGPU = true;
break;
case 'H':
// Install an alternate Conduit error handler for debugging.
conduit::utils::set_error_handler(conduit_debug_err_handler);
break;
case 'h':
if (myRank == 0)
{
printUsage(argv[0]);
}
throw std::runtime_error("");
case 'i':
inputPath = std::string(optarg);
break;
case 'k':
scattering_kernel = std::string(optarg);
if (myRank == 0)
{
std::cout << "Teton driver: using scattering kernel " << scattering_kernel << "." << std::endl;
}
break;
case 'l':
label = std::string(optarg);
if (myRank == 0)
{
std::cout << "Teton driver: this run will be identified as '" << label
<< "' in any caliper spot reports." << std::endl;
}
break;
case 'M':
meshOrdering = std::string(optarg);
if (meshOrdering != "normal" && meshOrdering != "kdtree" && meshOrdering != "hilbert")
{
throw std::runtime_error("Unsupported mesh ordering " + meshOrdering);
}
break;
case 'n':
gta_kernel = atoi(optarg);
if (myRank == 0)
{
std::cout << "Teton driver: using gta solver version " << gta_kernel << "." << std::endl;
}
break;
case 'S':
sweep_kernel = atoi(optarg);
if (myRank == 0)
{
std::cout << "Teton driver: using sweep kernel version " << sweep_kernel
<< ". (0=zone sweep, 1=corner sweep)" << std::endl;
}
break;
case 'o':
outputPath = std::string(optarg);
break;
#if defined(TETON_ENABLE_CALIPER)
case 'p':
caliper_config = std::string(optarg);
if (myRank == 0)
{
std::cout << "Teton driver: using caliper configuration: " << caliper_config << std::endl;
}
if (caliper_config == "help")
{
if (myRank == 0)
{
std::cout << std::endl << "--- AVAILABLE CALIPER KEYWORDS ---" << std::endl;
auto configs = mgr.available_config_specs();
for (auto str : configs)
{
std::cout << mgr.get_documentation_for_spec(str.c_str()) << std::endl;
}
std::cout << std::endl;
std::cout << std::endl << "----------------------------------" << std::endl;
}
throw std::runtime_error(""); // Early return
}
break;
#endif
case 's':
numPhaseAngleSets = atoi(optarg);
if (myRank == 0)
{
std::cout << "Teton driver: number of phase-angle sets to create: " << numPhaseAngleSets << std::endl;
}
break;
#if defined(TETON_ENABLE_MFEM)
case 'r':
numSerialRefinementLevels = atoi(optarg);
if (myRank == 0)
{
std::cout << "Teton driver: number of serial refinement levels: " << numSerialRefinementLevels
<< std::endl;
}
break;
case 'z':
numParallelRefinementLevels = atoi(optarg);
if (myRank == 0)
{
std::cout << "Teton driver: number of parallel refinement levels: " << numParallelRefinementLevels
<< std::endl;
}
break;
case 'R':
numSerialRefinementFactor = atoi(optarg);
if (myRank == 0)
{
std::cout << "Teton driver: serial refinement factor: " << numSerialRefinementFactor << std::endl;
}
break;
case 'Z':
numParallelRefinementFactor = atoi(optarg);
if (myRank == 0)
{
std::cout << "Teton driver: parallel refinement factor: " << numParallelRefinementFactor << std::endl;
}
break;
case 'C':
colorFile = std::string(optarg);
if (myRank == 0)
{
std::cout << "Teton driver: Using color file for decomposition: " << colorFile << std::endl;
}
break;
#endif
case 'A':
#if defined(TETON_ENABLE_MFEM) || defined(TETON_CONDUIT_HAS_TILED_FUNCTION)
numAzimuthalUser = atoi(optarg);
if (myRank == 0)
{
std::cout << "Teton driver: number of azimuthal angles: " << numAzimuthalUser << std::endl;
}
#endif
break;
case 'P':
#if defined(TETON_ENABLE_MFEM) || defined(TETON_CONDUIT_HAS_TILED_FUNCTION)
numPolarUser = atoi(optarg);
if (myRank == 0)
{
std::cout << "Teton driver: number of polar angles: " << numPolarUser << std::endl;
}
#endif
break;
case 'G':
#if defined(TETON_ENABLE_MFEM) || defined(TETON_CONDUIT_HAS_TILED_FUNCTION)
numGroupsUser = atoi(optarg);
if (myRank == 0)
{
std::cout << "Teton driver: number of energy groups: " << numGroupsUser << std::endl;
}
#endif
break;
case 't':
numOmpMaxThreads = atoi(optarg);
if (myRank == 0)
{
std::cout << "Teton driver: setting max # cpu threads to " << numOmpMaxThreads << std::endl;
}
break;
case 'u':
useUmpire = atoi(optarg);
if (myRank == 0)
{
std::cout << "Teton driver: setting useUmpire to " << useUmpire << std::endl;
}
break;
case 'V':
dumpViz = true;
if (myRank == 0)
{
std::cout << "Teton driver: output mesh blueprint visualization file each cycle." << std::endl;
}
break;
case 'v':
verbose = atoi(optarg);
if (myRank == 0)
{
std::cout << "Teton driver: setting verbosity to " << verbose << std::endl;
}
break;
case 'y':
input_sanitizer_level = atoi(optarg);
if (myRank == 0)
{
std::cout << "Teton driver: setting input_sanitizer_level to " << input_sanitizer_level << std::endl;
}
break;
case '?':
if (myRank == 0)
{
std::cout << "Incorrect arguments, try -h to see help." << std::endl;
}
break;
}
}
return 0;
}
//---------------------------------------------------------------------------
void TetonDriver::printUsage(const std::string &argv0) const
{
std::cout << "Usage: " << argv0 << "[OPTIONS]" << std::endl;
std::cout
<< " -b, --benchmark_problem <0,1,2> Run predefined UMT benchmark problem. 0 = user specified # angles and # groups."
<< std::endl;
std::cout << " -c, --num_cycles <cycles> Number of cycles to execute." << std::endl;
std::cout << " -D, --dt float Set a fixed DT per cycle." << std::endl;
std::cout
<< " -e, --use_cuda_sweep Use experimental CUDA sweep. Do not specify this option and -g at the same time."
<< std::endl;
std::cout << " -g, --use_gpu_kernels Run solvers on GPU and enable associated sub-options, where supported."
<< std::endl;
std::cout << " -H, --handler Install an alternate Conduit error handler for debugging."
<< std::endl;
std::cout << " -h, --help Print this help and exit." << std::endl;
std::cout << " -i, --input_path <path> Path to input files." << std::endl;
#if !defined(TETON_ENABLE_MINIAPP_BUILD)
std::cout
<< " -k, --scattering_kernel <none, fp, bc> Select compton scattering kernel. none=no scattering, fp=fokker planck, bc=boltzmann"
<< std::endl;
#endif
std::cout
<< " -l, --apply_label Label this run. This label will be used to identify this run in any caliper reports."
<< std::endl;
std::cout << " -m, --use_device_aware_mpi Use device-aware MPI for GPU runs." << std::endl;
std::cout << " -n, --gta_kernel <0,1,2> Select GTA solver kernel version. 0=use default" << std::endl;
std::cout
<< " -S, --sweep_kernel <0,1> Select sweep kernel version. 0=zone, 1=corner. Note: corner sweep only available as a GPU kernel, on 3D meshes."
<< std::endl;
std::cout << " -o, --output_path <path> Path to generate output files. If not set, will disable output files."
<< std::endl;
#if defined(TETON_ENABLE_CALIPER)
std::cout << " -p, --caliper <string> Caliper configuration profile. Set <string> to 'help'"
<< " to get supported keywords. 'None' disabled caliper. Default is 'runtime-report'." << std::endl;
#endif
std::cout << " -s, --num_phase_space_sets <num_sets> Number of phase-angle sets to construct." << std::endl;
std::cout << " -t, --num_threads <threads> Max number of threads for cpu OpenMP parallel regions." << std::endl;
std::cout << " -u, --umpire_mode <0,1,2> 0 - Disable umpire. 1 - Use Umpire for CPU allocations."
<< " 2 - Use Umpire for CPU and GPU allocations." << std::endl;
std::cout << " -V, --write_viz_file Output blueprint mesh vizualization file each cycle" << std::endl;
std::cout << " -v, --verbose [0,1,2] 0 - quite 1 - informational(default) 2 - really chatty and dump files"
<< std::endl;
std::cout
<< " -y, --input_sanitizer_level 0 - don't check inputs\n 1 - print one message for each bad input category\n 2 - print one message for each bad value of each bad category"
<< std::endl;
#if defined(TETON_ENABLE_MFEM)
std::cout << " -r, --serial_refinement_levels <int> Number of times to halve each edge the MFEM mesh before "
<< "doing parallel decomposition. Applied after the refinement_factor. (factor of 2^((r*dim) new zones)"
<< std::endl;
std::cout << " -z, --parallel_refinement_levels <int> Number of times to halve each edge the MFEM mesh after "
<< "doing parallel decomposition. Applied after the refinement_factor. (factor of 2^(z*dim) new zones)"
<< std::endl;
std::cout << " -R, --serial_refinement_factor <int> Number of subdivisions for each edge in the original MFEM "
<< "mesh before doing parallel decomposition. (factor of (R+1)^dim new zones)" << std::endl;
std::cout << " -Z, --parallel_refinement_factor <int> Number of subdivisions for each edge in the original MFEM "
<< "mesh after doing parallel decomposition. (factor of (Z+1)^dim new zones)" << std::endl;
std::cout << " -C, --color_file <string> color file for manual decomposition" << std::endl;
#endif
#if defined(TETON_ENABLE_MFEM) || defined(TETON_CONDUIT_HAS_TILED_FUNCTION)
std::cout << " -A, --num_Azimuthal <int> Number azimuthal angles in an octant" << std::endl;
std::cout << " -P, --num_Polar <int> Number polar angles in an octant" << std::endl;
std::cout << " -G, --num_Groups <int> Number energy groups" << std::endl;
#endif
#if defined(TETON_CONDUIT_HAS_TILED_FUNCTION)
std::cout << " -B, --blueprint local|global Generate Blueprint tiled mesh in memory using the specified scheme."
<< " The \"local\" scheme creates the same sized mesh on each MPI rank, allowing for weak scaling. The "
<< "\"global\" scheme creates the specified mesh size globally and decomposes that size over the available"
<< "MPI ranks, allowing for strong scaling." << std::endl;
std::cout
<< " -d, --dims i,j,k The size of the Blueprint mesh in tiles in i,j,k. k=0 builds a 2D mesh."
<< std::endl;
std::cout << " -M, --mesh_ordering order The name of the mesh ordering to use (normal or kdtree)." << std::endl;
#endif
}
//---------------------------------------------------------------------------
int TetonDriver::execute()
{
{
conduit::Node &options = myTetonObject.getOptions();
conduit::Node &meshBlueprint = myTetonObject.getMeshBlueprint();
//==========================================================
// If benchmark problem specified, set the parameters.
// UMT SP #1
// 3 x 3 product quadrature
// 128 groups
//
// UMT SP #2
// 2 x 2 product quadrature
// 16 groups
//
// ! Iteration control defaults.
//==========================================================
if (benchmarkProblem > 0)
{
options["iteration/relativeTolerance"] = energy_check_tolerance / 10.0;
// If running UMT, only the sweep kernel is active. Increase the number of
// allowed inner flux iterations to enable it to converge on its own.
#if defined(TETON_ENABLE_MINIAPP_BUILD)
options["iteration/incidentFluxMaxIt"] = 99;
#endif
fixedDT = 1e-3;
if (cycles == 0)
{
cycles = 5;
}
if (benchmarkProblem == 1)
{
numPolarUser = 3;
numAzimuthalUser = 3;
numGroupsUser = 128;
label = "UMTSPP1";
}
else if (benchmarkProblem == 2)
{
numPolarUser = 2;
numAzimuthalUser = 2;
numGroupsUser = 16;
label = "UMTSPP2";
}
else
{
std::cerr << "Teton driver: Custom benchmark problem #" << benchmarkProblem << std::endl;
label = "CustomBenchmark" + std::to_string(benchmarkProblem);
}
if (useGPU)
{
label += "_GPU";
}
}
// More initialization
startCaliper(label);
initThreads();
initGPU();
//==========================================================
// Read in conduit nodes or mfem mesh with problem input
//==========================================================
//==========================================================
// Read in mesh from an mfem mesh file. We set up a uniform
// temperature problem with simple source boundary conditions.
//
// TODO - All this hard-coding can be moved into an input file that lives
// alongside the mfem mesh file.
// TODO - All this code for converting a mfem mesh and input to a blueprint
// mesh should be moved to another function in another source file, so the
// driver doesn't have all this here. -- black27
//==========================================================
//==========================================================
if (blueprintMesh > 0)
{
buildBlueprintTiledMesh();
}
else if (endsWith(inputPath, ".mesh"))
{
CALI_CXX_MARK_SCOPE("Teton_Read_Mfem_Input");
if (access(inputPath.c_str(), F_OK) != -1)
{
#if defined(TETON_ENABLE_MFEM)
int nelem = readMeshMFEM();
{ // new scope
CALI_CXX_MARK_SCOPE("Teton_Init_BP_Fields");
initializeBlueprintFields(nelem, numPolarUser, numAzimuthalUser, numGroupsUser);
initializeBoundaryConditionsMFEM();
updateBoundaryConnectivityMFEM();
// Needs to be re-done when blueprint interface for specifying profiles is updated.
options["sources/profile1/Values"] = 0.3;
options["sources/profile1/NumTimes"] = 1;
options["sources/profile1/NumValues"] = 1;
options["sources/profile1/Multiplier"] = 1.0;
// Disable updating the mesh vertices each cycle. This is unnecessary, as this test problem has fixed
// vertex positions.
options["mesh_motion"] = 0;
}
#else
throw std::runtime_error(
"Unable to open mfem mesh, test driver was not configured with CMake's '-DENABLE_MFEM=ON'.");
#endif
}
else
{
throw std::runtime_error("Couldn't find mfem mesh at " + inputPath);
}
}
// Assume this is an input directory with a set of conduit blueprint mesh files and problem parameter files.
// Note: The parameter files currently have all the input duplicated for each rank. Look into making a
// single 'global' parameter file for global input.
else
{
readConduitInputs();
}
//==========================================================
// Set problem options passed in via command line
//==========================================================
setOptions();
// Verify the mesh.
verifyMesh();
// Initialize Teton
myTetonObject.initialize(comm);
// Calculate size of PSI to provide the number of unknowns solved for benchmarking, throughput calculations, etc.
// This is # corners * # angles * # energy group bins
// Put code here that calculates the # unknowns being solved.
// TODO:
// Some of this code ( especially the code that calculates the # angles ) can go in a helper function later, as
// opposed to bloating up the test driver code.
// -- black27
// Get total number of corners in problem.
const conduit::Node &corner_topology = meshBlueprint.fetch_existing("topologies/main_corner");
unsigned long local_num_corners = conduit::blueprint::mesh::utils::topology::length(corner_topology);
unsigned long num_corners;
// int MPI_Reduce(_In_ void *sendbuf, _Out_opt_ void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm);
int error_code = MPI_Reduce(&local_num_corners, &num_corners, 1, MPI_UNSIGNED_LONG, MPI_SUM, 0, comm);
if (error_code != MPI_SUCCESS)
{
//TODO - error out
}
unsigned long num_unknowns = 0, local_num_unknowns = 0;
unsigned int ndims = conduit::blueprint::mesh::utils::topology::dims(corner_topology);
writeStartSummary(ndims, local_num_corners, num_corners, num_unknowns, local_num_unknowns);
// If a dtrad wasn't provided in the input file, the Teton initialize()
// call will populate it with a default value.
double dtrad = options.fetch_existing("iteration/dtrad").value();
double timerad = 0.0;
if (options.has_path("iteration/timerad"))
{
timerad = options.fetch_existing("iteration/timerad").value();
}
meshBlueprint["state/cycle"] = 0;
double start_time = MPI_Wtime();
cycleLoop(dtrad, timerad, num_unknowns);
double end_time = MPI_Wtime();
myTetonObject.dumpTallyToJson();
writeEndSummary(end_time, start_time, num_unknowns, local_num_unknowns);
}
return return_status;
}
//---------------------------------------------------------------------------
void TetonDriver::startCaliper(const std::string &label)
{
//==========================================================
// Start caliper
//==========================================================
#if defined(TETON_ENABLE_CALIPER)
if (caliper_config != "none")
{
mgr.add(caliper_config.c_str());
if (mgr.error())
{
if (myRank == 0)
{
std::cout << "Teton driver: Caliper config error: " << mgr.error_msg() << std::endl;
}
}
mgr.start();
}
if (!label.empty())
{
adiak::value("ProblemName", label, adiak_general);
}
#endif
}
//---------------------------------------------------------------------------
void TetonDriver::initThreads()
{
#if defined(TETON_ENABLE_OPENMP)
if (numOmpMaxThreads == -1)
{
numOmpMaxThreads = omp_get_max_threads();
}
if (myRank == 0)
{
std::cout << "Teton driver: Threading enabled, max number of threads is " << numOmpMaxThreads << std::endl;
}
#endif
}
//---------------------------------------------------------------------------
void TetonDriver::initGPU()
{
//==========================================================
// Initialize environment on GPU
//==========================================================
#if defined(TETON_ENABLE_OPENMP_OFFLOAD)
if (myRank == 0)
print_gpu_mem("Teton driver: Before hello world gpu kernel run.");
// It's necessary to run a small GPU kernel to initialize the GPU state so our timers get accurate benchmarks later.
#pragma omp target
{
printf("Teton driver: Hello World! GPU is now initialized.\n");
}
if (myRank == 0)
print_gpu_mem("Teton driver: After hello world gpu kernel run.");
#endif
}
//---------------------------------------------------------------------------
int TetonDriver::readMeshMFEM()
{
int nelem = 0;
#if defined(TETON_ENABLE_MFEM)
conduit::Node &options = myTetonObject.getOptions();
conduit::Node &meshBlueprint = myTetonObject.getMeshBlueprint();
if (myRank == 0)
{
std::cout << "Teton driver: reading mfem mesh: " << inputPath << std::endl;
}
{ // new scope
CALI_CXX_MARK_SCOPE("Teton_Refine_Serial_Mesh");
mesh = new mfem::Mesh(inputPath.c_str(), 1, 1);