-
Notifications
You must be signed in to change notification settings - Fork 8
/
test_driver.cc
1582 lines (1430 loc) · 61.2 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 <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
#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_relay.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)
#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);
}
int print_gpu_mem(const char *label)
{
#if defined(TETON_ENABLE_CUDA)
size_t free_on_gpu = 0;
size_t total_on_gpu = 0;
double gbtotal, gbfree, gbused;
if (cudaMemGetInfo(&free_on_gpu, &total_on_gpu) != cudaSuccess)
{
printf("cudeMemGetInfo failed for GPU 0");
return (1);
}
gbtotal = ((double) total_on_gpu) / (1024.0 * 1024.0 * 1024.0);
gbfree = ((double) free_on_gpu) / (1024.0 * 1024.0 * 1024.0);
gbused = ((double) total_on_gpu - free_on_gpu) / (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);
#else
(void) label;
#endif
return (0);
}
// 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);
}
//==========================================================
// run syntax:
//
// ./test_driver -c <# cycles> -i <input path> -o <output path>
// Note: to use the new blueprint format, ./test_driver -b ...
//==========================================================
int main(int argc, char *argv[])
{
int return_status = 0;
int myRank = 0;
int mySize = 0;
int opt;
unsigned int cycles = 0;
int numPhaseAngleSets = 0;
int useUmpire = 1;
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;
#if defined(TETON_ENABLE_MFEM)
int numSerialRefinementFactor = 2;
int numParallelRefinementFactor = 2;
int numSerialRefinementLevels = 0;
int numParallelRefinementLevels = 0;
int numPolar = -1;
int numAzimuthal = -1;
int numGroups = -1;
int benchmarkProblem = 0;
mfem::ParMesh *pmesh = nullptr;
mfem::ConduitDataCollection *conduit_data_collec = nullptr;
#endif
// MPI
MPI_Comm comm = MPI_COMM_WORLD;
int provided = 0;
int claimed = 0;
int request = MPI_THREAD_SINGLE;
int verbose = 1;
bool useGPU = false;
bool useCUDASweep = false;
bool useNewGTASolver = false;
bool useDeviceAwareMPI = false; // Pass device addresses to MPI ( device-aware MPI ).
std::string inputPath(".");
std::string outputPath(".");
std::string label("");
std::string colorFile("");
std::string caliper_config("runtime-report");
#if defined(TETON_ENABLE_CUDA)
caliper_config += ",nvprof";
#endif
//==========================================================
// Initialize MPI and MPI thread support.
//==========================================================
#if defined(TETON_ENABLE_OPENMP)
request = MPI_THREAD_MULTIPLE;
#endif
#if defined(TETON_ENABLE_CALIPER)
cali_mpi_init();
cali::ConfigManager mgr;
mgr.set_default_parameter("aggregate_across_ranks", "true");
mgr.set_default_parameter("calc.inclusive", "true");
mgr.set_default_parameter("main_thread_only", "true");
auto configs = mgr.available_config_specs();
#endif
CALI_MARK_BEGIN("Teton_Test_Driver");
if (MPI_Init_thread(&argc, &argv, request, &provided) != MPI_SUCCESS)
{
std::cerr << "Error calling MPI_Init_thread. " << std::endl;
exit(1);
}
MPI_Query_thread(&claimed);
if (provided < request)
{
std::cerr << "Teton driver: MPI_Init_thread was only able to provided thread level support " << provided
<< ". Teton requested level " << request << std::endl;
exit(1);
}
if (claimed < request)
{
std::cerr << "Teton driver: MPI_Init_thread was only able to provided thread level support " << claimed
<< ". Teton requested level " << request << std::endl;
exit(1);
}
#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;
}
//==========================================================
// Get command line arguments
//==========================================================
while (1)
{
static struct option long_options[] = {
{"apply_label", no_argument, 0, 'l'},
{"benchmark_problem", required_argument, 0, 'b'},
{"caliper", required_argument, 0, 'p'},
{"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'},
{"use_device_aware_mpi", no_argument, 0, 'm'},
{"use_cuda_sweep", no_argument, 0, 'e'},
{"use_gpu_kernels", no_argument, 0, 'g'},
{"use_new_gta", no_argument, 0, 'n'},
{"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'},
{"num_Polar", required_argument, 0, 'P'},
{"num_Azimuthal", required_argument, 0, 'A'},
{"num_Groups", required_argument, 0, 'G'},
{"color_file", required_argument, 0, 'C'},
#endif
{0, 0, 0, 0}
};
/* getopt_long stores the option index here. */
int option_index = 0;
#if defined(TETON_ENABLE_MFEM)
auto optString = "A:b:G:P:C:c:D:eghi:l:mno:p:r:R:s:t:u:Vv:z:Z:";
#else
auto optString = "c:D:eghi:l:mno:p:s:t:u:Vv:";
#endif
opt = getopt_long(argc, argv, optString, long_options, &option_index);
/* Detect the end of the options. */
if (opt == EOF)
{
break;
}
switch (opt)
{
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 'e':
useCUDASweep = true;
if (myRank == 0)
{
std::cout << "Using experimental streaming CUDA sweep." << std::endl;
}
break;
case 'g':
useGPU = true;
break;
case 'h':
if (myRank == 0)
{
std::cout << "Usage: " << argv[0] << "[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
<< " -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 Run solvers on GPU and enable associated sub-options, where supported."
<< 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;
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 --use_new_gta Use newer GTA solver." << 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, --verbose [0,1,2] 0 - quite 1 - informational(default) 2 - really chatty and dump files"
<< 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 << " -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;
std::cout << " -C, --color_file <string> color file for manual decomposition" << std::endl;
#endif
std::cout << " -V, --write-viz-file Output blueprint mesh vizualization file each cycle"
<< std::endl;
}
return (0);
case 'i':
inputPath = std::string(optarg);
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':
useDeviceAwareMPI = true;
break;
case 'n':
useNewGTASolver = true;
if (myRank == 0)
{
std::cout << "Teton driver: using new gta solver." << 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;
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;
}
return (0);
}
#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 'A':
numAzimuthal = atoi(optarg);
if (myRank == 0)
{
std::cout << "Teton driver: number of azimuthal angles: " << numAzimuthal << std::endl;
}
break;
case 'P':
numPolar = atoi(optarg);
if (myRank == 0)
{
std::cout << "Teton driver: number of polar angles: " << numPolar << std::endl;
}
break;
case 'G':
numGroups = atoi(optarg);
if (myRank == 0)
{
std::cout << "Teton driver: number of energy groups: " << numGroups << 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 '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 '?':
if (myRank == 0)
{
std::cout << "Incorrect arguments, try -h to see help." << std::endl;
}
break;
}
}
//==========================================================
// 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
{
::Teton::Teton myTetonObject;
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
//
// This still supports overriding each value with individual
// command line arguments for angles and # groups.
//==========================================================
double energy_check_tolerance;
if (benchmarkProblem > 0)
{
options["iteration/relativeTolerance"] = 1e-10;
if (benchmarkProblem == 1)
{
fixedDT = 1e-3;
cycles = 5;
numPolar = 3;
numAzimuthal = 3;
numGroups = 128;
energy_check_tolerance = 1.0e-11;
}
else if (benchmarkProblem == 2)
{
fixedDT = 1e-3;
cycles = 5;
numPolar = 2;
numAzimuthal = 2;
numGroups = 16;
energy_check_tolerance = 1.0e-11;
}
else
{
std::cerr << "Teton driver: Unknown benchmark problem #" << benchmarkProblem << std::endl;
}
if (label.empty())
{
label = "UMTSPP" + std::to_string(benchmarkProblem);
if (useGPU)
{
label += "_GPU";
}
}
}
//==========================================================
// 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
#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
//==========================================================
// 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
//==========================================================
// 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 (endsWith(inputPath, ".mesh"))
{
CALI_MARK_BEGIN("Teton_Read_Mfem_Input");
if (access(inputPath.c_str(), F_OK) != -1)
{
#if defined(TETON_ENABLE_MFEM)
if (myRank == 0)
{
std::cout << "Teton driver: reading mfem mesh: " << inputPath << std::endl;
}
mfem::Mesh mesh(inputPath.c_str(), 1, 1);
CALI_MARK_BEGIN("Teton_Refine_Serial_Mesh");
for (int l = 0; l < numSerialRefinementLevels; ++l)
{
if (myRank == 0)
{
std::cout << "Teton driver: Uniformly refining serial mesh, iteration " << l + 1
<< ", factor = " << numSerialRefinementFactor << std::endl;
}
if (numSerialRefinementFactor == 2)
{
mesh.UniformRefinement();
}
else
{
int ref_type = mfem::BasisType::ClosedUniform;
mesh = mfem::Mesh::MakeRefined(mesh, numSerialRefinementFactor, ref_type);
}
}
CALI_MARK_END("Teton_Refine_Serial_Mesh");
if (benchmarkProblem > -1 && (numSerialRefinementLevels > 0))
{
// Save refined mesh to file, if running benchmark problems ( for later use ).
std::ofstream mesh_ofs("refined_mesh.mesh");
mesh_ofs.precision(16);
mesh.Print(mesh_ofs);
mesh_ofs.close();
}
CALI_MARK_BEGIN("Teton_Create_Par_Mesh");
// MFEM does not support parallel refinement on NURBs meshes.
// Convert to high order mesh to enable basic refinement capability.
// Also add a grid function if we didn't have one before.
mesh.SetCurvature(1);
if (myRank == 0)
{
std::cout << "Teton driver: decomposing serial mesh into parallel" << std::endl;
}
if (colorFile.size() > 0)
{
if (access(colorFile.c_str(), F_OK) != -1)
{
int nelem = mesh.GetNE();
std::vector<int> colorData;
colorData.reserve(nelem);
int e = 0;
std::ifstream colorFileStream(colorFile.c_str());
while (!colorFileStream.eof() or e == nelem)
{
int c = 0;
colorFileStream >> c;
colorData.push_back(c);
++e;
}
if (e < nelem)
{
std::cerr << "Not enough colors in " << colorFile << std::endl;
return (1);
}
colorFileStream.close();
pmesh = new mfem::ParMesh(comm, mesh, colorData.data());
}
else
{
std::cerr << "could not open color file: " << colorFile << std::endl;
return (1);
}
}
else
{
// Only re-order without the color file, otherwise we won't know
// order the elements are.
// Sort the grid for better locality
mfem::Array<int> ordering;
mesh.GetHilbertElementOrdering(ordering);
mesh.ReorderElements(ordering);
// TODO Make optional. This will use the space-filling curve for
// partitioning. It's both nicer and more horrific than Metis,
// if that was even possible.
// mesh.EnsureNCMesh();
pmesh = new mfem::ParMesh(comm, mesh);
if (int wrong = pmesh->CheckElementOrientation(true) > 0)
{
std::cout << "There were " << wrong
<< " 3D mesh elements with the wrong orientation after reordering.\n";
}
if (int wrong = pmesh->CheckBdrElementOrientation(true) > 0)
{
std::cout << "There were " << wrong
<< " 3D mesh boundary elements with the wrong orientation after reordering.\n";
}
}
CALI_MARK_END("Teton_Create_Par_Mesh");
CALI_MARK_BEGIN("Teton_Refine_Par_Mesh");
for (int l = 0; l < numParallelRefinementLevels; ++l)
{
if (myRank == 0)
{
std::cout << "Teton driver: Uniformly refining parallel mesh, iteration " << l + 1
<< ", factor = " << numParallelRefinementFactor << std::endl;
}
if (numParallelRefinementFactor == 2)
{
mesh.UniformRefinement();
}
else
{
int ref_type = mfem::BasisType::ClosedUniform;
*pmesh = mfem::ParMesh::MakeRefined(*pmesh, numParallelRefinementFactor, ref_type);
}
}
CALI_MARK_END("Teton_Refine_Par_Mesh");
if (myRank == 0)
{
std::cout << "Teton driver: Final parallel mesh characteristics are:" << std::endl;
}
pmesh->PrintInfo();
// This is local number of elements.
int nelem = pmesh->GetNE();
CALI_MARK_BEGIN("Teton_Create_BP_Mesh");
// Create a blueprint node from the mfem mesh
conduit_data_collec = new mfem::ConduitDataCollection("mfem_conduit_data_collection", pmesh);
// Note - the mesh blueprint node contains pointers back into the mfem
// mesh for some of the data. For example, the coordinates.
// ***************************
// DO NOT DELETE the mfem mesh objects until this blueprint node is no
// longer needed.
// ***************************
conduit_data_collec->MeshToBlueprintMesh(pmesh, meshBlueprint);
CALI_MARK_END("Teton_Create_BP_Mesh");
CALI_MARK_BEGIN("Teton_Init_BP_Fields");
// Delete extra fields we don't need. Some of these are not yet supported
// by VisIt (https://wci.llnl.gov/simulation/computer-codes/visit)
if (meshBlueprint.has_path("topologies/main/grid_function"))
{
meshBlueprint.remove("topologies/main/grid_function");
}
if (meshBlueprint.has_path("topologies/main/boundary_topology"))
{
meshBlueprint.remove("topologies/main/boundary_topology");
}
if (meshBlueprint.has_path("fields/mesh_nodes"))
{
meshBlueprint.remove("fields/mesh_nodes");
}
if (numGroups < 1)
{
std::cerr
<< "Teton driver: Must specify number of energy groups angles via '-G#' or by specifying a benchmark problem via '-b#'."
<< std::endl;
exit(1);
}
std::vector<double> gr_bounds(numGroups + 1);
const double lowerBound = 1.0e-6;
const double upperBound = 1.0e2;
const double upperBoundLog = std::log(upperBound);
const double lowerBoundLog = std::log(lowerBound);
const double deltaLog = (upperBoundLog - lowerBoundLog) / numGroups;
for (int g = 0; g <= numGroups; ++g)
{
gr_bounds[g] = std::exp(lowerBoundLog + g * deltaLog);
}
gr_bounds[numGroups] = upperBound;
//Energy groups and SN quadrature info
int qtype = 2;
int qorder = 10;
if (numPolar < 1)
{
std::cerr
<< "Teton driver: Must specify number of polar angles via '-P#' or by specifying a benchmark problem via '-b#'."
<< std::endl;
exit(1);
}
if (numAzimuthal < 1)
{
std::cerr
<< "Teton driver: Must specify number of azimuthal angles via '-A#' or by specifying a benchmark problem via '-b#'."
<< std::endl;
exit(1);
}
int paxis = 1;
options["quadrature/gnu"].set(gr_bounds.data(), gr_bounds.size());
options["quadrature/qtype"] = qtype;
options["quadrature/qorder"] = qorder;
options["quadrature/npolar"] = numPolar;
options["quadrature/nazimu"] = numAzimuthal;
options["quadrature/paxis"] = paxis;
options["quadrature/num_groups"] = numGroups;
options["quadrature/gtaorder"] = 2;
options["quadrature/nSetsMaster"] = -1;
options["quadrature/nSets"] = 1;
// TODO: Make MFEM Grid functions for ConduitDataCollection to handle
// instead.
//Material dependent fields
std::vector<double> thermo_density(nelem);
std::vector<double> electron_specific_heat(nelem);
std::vector<double> radiation_temperature(nelem);
std::vector<double> electron_temperature(nelem);
std::vector<double> absorption_opacity(numGroups * nelem);
std::vector<double> scattering_opacity(numGroups * nelem, 0.0);
std::vector<double> electron_number_density(nelem, 4.16100608392217e+24);
// Field value to initialize each material to.
// Material # -> field -> value.
std::map<int, std::map<std::string, double>> material_field_vals;
//NOTE: some of these fields need to have the initial values updated.
//These values are based on the old field meanings, before they were
//renamed for the current mesh blueprint interface. Need to consult
//with haut3. -- black27
// We only support one material on an MFEM mesh
material_field_vals[1]["thermo_density"] = 1.31;
material_field_vals[1]["electron_specific_heat"] = 0.501;
material_field_vals[1]["radiation_temperature"] = 0.05;
material_field_vals[1]["electron_temperature"] = 0.5;
material_field_vals[1]["absorption_opacity"] = 10.0;
for (int i = 0; i < nelem; ++i)
{
// Ignore, we only support one.
//int attr_no = pmesh->GetAttribute(i);
int attr_no = 1;
thermo_density[i] = material_field_vals[attr_no]["thermo_density"];
electron_specific_heat[i] = material_field_vals[attr_no]["electron_specific_heat"];
radiation_temperature[i] = material_field_vals[attr_no]["radiation_temperature"];
electron_temperature[i] = material_field_vals[attr_no]["electron_temperature"];
double abs_opacity = material_field_vals[attr_no]["absorption_opacity"];
for (int g = 0; g < numGroups; ++g)
{
absorption_opacity[i * numGroups + g] = abs_opacity;
}
}
// Store the various fields (density, material temperature, etc.)
meshBlueprint["fields/thermo_density/association"] = "element";
meshBlueprint["fields/thermo_density/topology"] = "main";
meshBlueprint["fields/thermo_density/values"].set(thermo_density.data(), thermo_density.size());
meshBlueprint["fields/electron_specific_heat/association"] = "element";
meshBlueprint["fields/electron_specific_heat/topology"] = "main";
meshBlueprint["fields/electron_specific_heat/values"].set(electron_specific_heat.data(),
electron_specific_heat.size());
meshBlueprint["fields/electron_temperature/association"] = "element";
meshBlueprint["fields/electron_temperature/topology"] = "main";
meshBlueprint["fields/electron_temperature/values"].set(electron_temperature.data(),
electron_temperature.size());
meshBlueprint["fields/radiation_temperature/association"] = "element";
meshBlueprint["fields/radiation_temperature/topology"] = "main";
meshBlueprint["fields/radiation_temperature/values"].set(radiation_temperature.data(),
radiation_temperature.size());
meshBlueprint["fields/absorption_opacity/association"] = "element";
meshBlueprint["fields/absorption_opacity/topology"] = "main";
meshBlueprint["fields/absorption_opacity/values"].set(absorption_opacity.data(), absorption_opacity.size());
meshBlueprint["fields/scattering_opacity/association"] = "element";
meshBlueprint["fields/scattering_opacity/topology"] = "main";
meshBlueprint["fields/scattering_opacity/values"].set(scattering_opacity.data(), scattering_opacity.size());
meshBlueprint["fields/electron_number_density/association"] = "element";
meshBlueprint["fields/electron_number_density/topology"] = "main";
meshBlueprint["fields/electron_number_density/values"].set(electron_number_density.data(),
electron_number_density.size());
// Make all boundaries vacuum
std::map<int, int> boundary_id_to_type;