#include #include #include #include #if USE_MPI # include #endif #include "lulesh.h" /* Helper function for converting strings to ints, with error checking */ int StrToInt(const char* token, int* retVal) { const char* c; char* endptr; const int decimal_base = 10; if(token == NULL) return 0; c = token; *retVal = (int) strtol(c, &endptr, decimal_base); if((endptr != c) && ((*endptr == ' ') || (*endptr == '\0'))) return 1; else return 0; } static void PrintCommandLineOptions(char* execname, int myRank) { if(myRank == 0) { printf("Usage: %s [opts]\n", execname); printf(" where [opts] is one or more of:\n"); printf(" -q : quiet mode - suppress all stdout\n"); printf(" -i : number of cycles to run\n"); printf(" -s : length of cube mesh along side\n"); printf(" -r : Number of distinct regions (def: 11)\n"); printf(" -b : Load balance between regions of a domain (def: 1)\n"); printf(" -c : Extra cost of more expensive regions (def: 1)\n"); printf(" -f : 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 myRank, struct cmdLineOpts* opts) { if(argc > 1) { int i = 1; while(i < argc) { int ok; /* -i */ 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 */ 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 */ 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 */ 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++; } /* -q */ else if(strcmp(argv[i], "-a") == 0) { opts->do_atomic = 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 Real_t grindTime1 = ((elapsed_time * 1e6) / locDom.cycle()) / (nx * nx * nx); Real_t grindTime2 = ((elapsed_time * 1e6) / locDom.cycle()) / (nx * nx * nx * numRanks); Index_t ElemId = 0; auto h_e = Kokkos::create_mirror_view(locDom.e_view()); Kokkos::deep_copy(h_e, locDom.e_view()); printf("Run completed: \n"); printf(" Problem size = %i \n", nx); printf(" MPI tasks = %i \n", numRanks); printf(" Iteration count = %i \n", locDom.cycle()); printf(" Final Origin Energy = %12.6e \n", h_e(ElemId)); Real_t MaxAbsDiff = Real_t(0.0); Real_t TotalAbsDiff = Real_t(0.0); Real_t MaxRelDiff = Real_t(0.0); for(Index_t j = 0; j < nx; ++j) { for(Index_t k = j + 1; k < nx; ++k) { Real_t AbsDiff = FABS(h_e(j * nx + k) - h_e(k * nx + j)); TotalAbsDiff += AbsDiff; if(MaxAbsDiff < AbsDiff) MaxAbsDiff = AbsDiff; Real_t RelDiff = AbsDiff / h_e(k * nx + j); if(MaxRelDiff < RelDiff) MaxRelDiff = RelDiff; } } // Quick symmetry check printf(" Testing Plane 0 of Energy Array on rank 0:\n"); printf(" MaxAbsDiff = %12.6e\n", MaxAbsDiff); printf(" TotalAbsDiff = %12.6e\n", TotalAbsDiff); printf(" MaxRelDiff = %12.6e\n\n", MaxRelDiff); // Timing information printf("\nElapsed time = %10.2f (s)\n", elapsed_time); printf("Grind time (us/z/c) = %10.8g (per dom) (%10.8g overall)\n", grindTime1, grindTime2); printf("FOM = %10.8g (z/s)\n\n", 1000.0 / grindTime2); // zones per second return; }