| [788bdd2] | 1 | #include "XSbench_header.h"
|
|---|
| 2 |
|
|---|
| 3 | #ifdef MPI
|
|---|
| 4 | #include<mpi.h>
|
|---|
| 5 | #endif
|
|---|
| 6 |
|
|---|
| 7 | // Prints program logo
|
|---|
| 8 | void logo(int version)
|
|---|
| 9 | {
|
|---|
| 10 | border_print();
|
|---|
| 11 | printf(
|
|---|
| 12 | " __ __ ___________ _ \n"
|
|---|
| 13 | " \\ \\ / // ___| ___ \\ | | \n"
|
|---|
| 14 | " \\ V / \\ `--.| |_/ / ___ _ __ ___| |__ \n"
|
|---|
| 15 | " / \\ `--. \\ ___ \\/ _ \\ '_ \\ / __| '_ \\ \n"
|
|---|
| 16 | " / /^\\ \\/\\__/ / |_/ / __/ | | | (__| | | | \n"
|
|---|
| 17 | " \\/ \\/\\____/\\____/ \\___|_| |_|\\___|_| |_| \n\n"
|
|---|
| 18 | );
|
|---|
| 19 | border_print();
|
|---|
| 20 | center_print("Developed at Argonne National Laboratory", 79);
|
|---|
| 21 | char v[100];
|
|---|
| 22 | sprintf(v, "Version: %d", version);
|
|---|
| 23 | center_print(v, 79);
|
|---|
| 24 | border_print();
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | // Prints Section titles in center of 80 char terminal
|
|---|
| 28 | void center_print(const char *s, int width)
|
|---|
| 29 | {
|
|---|
| 30 | int length = strlen(s);
|
|---|
| 31 | int i;
|
|---|
| 32 | for (i=0; i<=(width-length)/2; i++) {
|
|---|
| 33 | fputs(" ", stdout);
|
|---|
| 34 | }
|
|---|
| 35 | fputs(s, stdout);
|
|---|
| 36 | fputs("\n", stdout);
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | void print_results( Inputs in, int mype, double runtime, int nprocs,
|
|---|
| 40 | unsigned long long vhash )
|
|---|
| 41 | {
|
|---|
| 42 | // Calculate Lookups per sec
|
|---|
| 43 | int lookups_per_sec = (int) ((double) in.lookups / runtime);
|
|---|
| 44 |
|
|---|
| 45 | // If running in MPI, reduce timing statistics and calculate average
|
|---|
| 46 | #ifdef MPI
|
|---|
| 47 | int total_lookups = 0;
|
|---|
| 48 | MPI_Barrier(MPI_COMM_WORLD);
|
|---|
| 49 | MPI_Reduce(&lookups_per_sec, &total_lookups, 1, MPI_INT,
|
|---|
| 50 | MPI_SUM, 0, MPI_COMM_WORLD);
|
|---|
| 51 | #endif
|
|---|
| 52 |
|
|---|
| 53 | // Print output
|
|---|
| 54 | if( mype == 0 )
|
|---|
| 55 | {
|
|---|
| 56 | border_print();
|
|---|
| 57 | center_print("RESULTS", 79);
|
|---|
| 58 | border_print();
|
|---|
| 59 |
|
|---|
| 60 | // Print the results
|
|---|
| 61 | printf("Threads: %d\n", in.nthreads);
|
|---|
| 62 | #ifdef MPI
|
|---|
| 63 | printf("MPI ranks: %d\n", nprocs);
|
|---|
| 64 | #endif
|
|---|
| 65 | #ifdef MPI
|
|---|
| 66 | printf("Total Lookups/s: ");
|
|---|
| 67 | fancy_int(total_lookups);
|
|---|
| 68 | printf("Avg Lookups/s per MPI rank: ");
|
|---|
| 69 | fancy_int(total_lookups / nprocs);
|
|---|
| 70 | #else
|
|---|
| 71 | printf("Runtime: %.3lf seconds\n", runtime);
|
|---|
| 72 | printf("Lookups: "); fancy_int(in.lookups);
|
|---|
| 73 | printf("Lookups/s: ");
|
|---|
| 74 | fancy_int(lookups_per_sec);
|
|---|
| 75 | #endif
|
|---|
| 76 | #ifdef VERIFICATION
|
|---|
| 77 | printf("Verification checksum: %llu\n", vhash);
|
|---|
| 78 | #endif
|
|---|
| 79 | border_print();
|
|---|
| 80 |
|
|---|
| 81 | // For bechmarking, output lookup/s data to file
|
|---|
| 82 | if( SAVE )
|
|---|
| 83 | {
|
|---|
| 84 | FILE * out = fopen( "results.txt", "a" );
|
|---|
| 85 | fprintf(out, "%d\t%d\n", in.nthreads, lookups_per_sec);
|
|---|
| 86 | fclose(out);
|
|---|
| 87 | }
|
|---|
| 88 | }
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | void print_inputs(Inputs in, int nprocs, int version )
|
|---|
| 92 | {
|
|---|
| 93 | // Calculate Estimate of Memory Usage
|
|---|
| 94 | int mem_tot = estimate_mem_usage( in );
|
|---|
| 95 | logo(version);
|
|---|
| 96 | center_print("INPUT SUMMARY", 79);
|
|---|
| 97 | border_print();
|
|---|
| 98 | #ifdef VERIFICATION
|
|---|
| 99 | printf("Verification Mode: on\n");
|
|---|
| 100 | #endif
|
|---|
| 101 | printf("Materials: %d\n", 12);
|
|---|
| 102 | printf("H-M Benchmark Size: %s\n", in.HM);
|
|---|
| 103 | printf("Total Nuclides: %ld\n", in.n_isotopes);
|
|---|
| 104 | printf("Gridpoints (per Nuclide): ");
|
|---|
| 105 | fancy_int(in.n_gridpoints);
|
|---|
| 106 | printf("Unionized Energy Gridpoints: ");
|
|---|
| 107 | fancy_int(in.n_isotopes*in.n_gridpoints);
|
|---|
| 108 | printf("XS Lookups: "); fancy_int(in.lookups);
|
|---|
| 109 | #ifdef MPI
|
|---|
| 110 | printf("MPI Ranks: %d\n", nprocs);
|
|---|
| 111 | printf("OMP Threads per MPI Rank: %d\n", in.nthreads);
|
|---|
| 112 | printf("Mem Usage per MPI Rank (MB): "); fancy_int(mem_tot);
|
|---|
| 113 | #else
|
|---|
| 114 | printf("Threads: %d\n", in.nthreads);
|
|---|
| 115 | printf("Est. Memory Usage (MB): "); fancy_int(mem_tot);
|
|---|
| 116 | #endif
|
|---|
| 117 | border_print();
|
|---|
| 118 | center_print("INITIALIZATION", 79);
|
|---|
| 119 | border_print();
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | void border_print(void)
|
|---|
| 123 | {
|
|---|
| 124 | printf(
|
|---|
| 125 | "==================================================================="
|
|---|
| 126 | "=============\n");
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | // Prints comma separated integers - for ease of reading
|
|---|
| 130 | void fancy_int( long a )
|
|---|
| 131 | {
|
|---|
| 132 | if( a < 1000 )
|
|---|
| 133 | printf("%ld\n",a);
|
|---|
| 134 |
|
|---|
| 135 | else if( a >= 1000 && a < 1000000 )
|
|---|
| 136 | printf("%ld,%03ld\n", a / 1000, a % 1000);
|
|---|
| 137 |
|
|---|
| 138 | else if( a >= 1000000 && a < 1000000000 )
|
|---|
| 139 | printf("%ld,%03ld,%03ld\n",a / 1000000,(a % 1000000) / 1000,a % 1000 );
|
|---|
| 140 |
|
|---|
| 141 | else if( a >= 1000000000 )
|
|---|
| 142 | printf("%ld,%03ld,%03ld,%03ld\n",
|
|---|
| 143 | a / 1000000000,
|
|---|
| 144 | (a % 1000000000) / 1000000,
|
|---|
| 145 | (a % 1000000) / 1000,
|
|---|
| 146 | a % 1000 );
|
|---|
| 147 | else
|
|---|
| 148 | printf("%ld\n",a);
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | void print_CLI_error(void)
|
|---|
| 152 | {
|
|---|
| 153 | printf("Usage: ./XSBench <options>\n");
|
|---|
| 154 | printf("Options include:\n");
|
|---|
| 155 | printf(" -t <threads> Number of OpenMP threads to run\n");
|
|---|
| 156 | printf(" -s <size> Size of H-M Benchmark to run (small, large, XL, XXL)\n");
|
|---|
| 157 | printf(" -g <gridpoints> Number of gridpoints per nuclide (overrides -s defaults)\n");
|
|---|
| 158 | printf(" -l <lookups> Number of Cross-section (XS) lookups\n");
|
|---|
| 159 | printf("Default is equivalent to: -s large -l 15000000\n");
|
|---|
| 160 | printf("See readme for full description of default run values\n");
|
|---|
| 161 | exit(4);
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| 164 | Inputs read_CLI( int argc, char * argv[] )
|
|---|
| 165 | {
|
|---|
| 166 | Inputs input;
|
|---|
| 167 |
|
|---|
| 168 | // defaults to max threads on the system
|
|---|
| 169 | input.nthreads = omp_get_num_procs();
|
|---|
| 170 |
|
|---|
| 171 | // defaults to 355 (corresponding to H-M Large benchmark)
|
|---|
| 172 | input.n_isotopes = 355;
|
|---|
| 173 |
|
|---|
| 174 | // defaults to 11303 (corresponding to H-M Large benchmark)
|
|---|
| 175 | input.n_gridpoints = 11303;
|
|---|
| 176 |
|
|---|
| 177 | // defaults to 15,000,000
|
|---|
| 178 | input.lookups = 15000000;
|
|---|
| 179 |
|
|---|
| 180 | // defaults to H-M Large benchmark
|
|---|
| 181 | input.HM = (char *) malloc( 6 * sizeof(char) );
|
|---|
| 182 | input.HM[0] = 'l' ;
|
|---|
| 183 | input.HM[1] = 'a' ;
|
|---|
| 184 | input.HM[2] = 'r' ;
|
|---|
| 185 | input.HM[3] = 'g' ;
|
|---|
| 186 | input.HM[4] = 'e' ;
|
|---|
| 187 | input.HM[5] = '\0';
|
|---|
| 188 |
|
|---|
| 189 | // Check if user sets these
|
|---|
| 190 | int user_g = 0;
|
|---|
| 191 |
|
|---|
| 192 | // Collect Raw Input
|
|---|
| 193 | for( int i = 1; i < argc; i++ )
|
|---|
| 194 | {
|
|---|
| 195 | char * arg = argv[i];
|
|---|
| 196 |
|
|---|
| 197 | // nthreads (-t)
|
|---|
| 198 | if( strcmp(arg, "-t") == 0 )
|
|---|
| 199 | {
|
|---|
| 200 | if( ++i < argc )
|
|---|
| 201 | input.nthreads = atoi(argv[i]);
|
|---|
| 202 | else
|
|---|
| 203 | print_CLI_error();
|
|---|
| 204 | }
|
|---|
| 205 | // n_gridpoints (-g)
|
|---|
| 206 | else if( strcmp(arg, "-g") == 0 )
|
|---|
| 207 | {
|
|---|
| 208 | if( ++i < argc )
|
|---|
| 209 | {
|
|---|
| 210 | user_g = 1;
|
|---|
| 211 | input.n_gridpoints = atol(argv[i]);
|
|---|
| 212 | }
|
|---|
| 213 | else
|
|---|
| 214 | print_CLI_error();
|
|---|
| 215 | }
|
|---|
| 216 | // lookups (-l)
|
|---|
| 217 | else if( strcmp(arg, "-l") == 0 )
|
|---|
| 218 | {
|
|---|
| 219 | if( ++i < argc )
|
|---|
| 220 | input.lookups = atoi(argv[i]);
|
|---|
| 221 | else
|
|---|
| 222 | print_CLI_error();
|
|---|
| 223 | }
|
|---|
| 224 | // HM (-s)
|
|---|
| 225 | else if( strcmp(arg, "-s") == 0 )
|
|---|
| 226 | {
|
|---|
| 227 | if( ++i < argc )
|
|---|
| 228 | input.HM = argv[i];
|
|---|
| 229 | else
|
|---|
| 230 | print_CLI_error();
|
|---|
| 231 | }
|
|---|
| 232 | else
|
|---|
| 233 | print_CLI_error();
|
|---|
| 234 | }
|
|---|
| 235 |
|
|---|
| 236 | // Validate Input
|
|---|
| 237 |
|
|---|
| 238 | // Validate nthreads
|
|---|
| 239 | if( input.nthreads < 1 )
|
|---|
| 240 | print_CLI_error();
|
|---|
| 241 |
|
|---|
| 242 | // Validate n_isotopes
|
|---|
| 243 | if( input.n_isotopes < 1 )
|
|---|
| 244 | print_CLI_error();
|
|---|
| 245 |
|
|---|
| 246 | // Validate n_gridpoints
|
|---|
| 247 | if( input.n_gridpoints < 1 )
|
|---|
| 248 | print_CLI_error();
|
|---|
| 249 |
|
|---|
| 250 | // Validate lookups
|
|---|
| 251 | if( input.lookups < 1 )
|
|---|
| 252 | print_CLI_error();
|
|---|
| 253 |
|
|---|
| 254 | // Validate HM size
|
|---|
| 255 | if( strcasecmp(input.HM, "small") != 0 &&
|
|---|
| 256 | strcasecmp(input.HM, "large") != 0 &&
|
|---|
| 257 | strcasecmp(input.HM, "XL") != 0 &&
|
|---|
| 258 | strcasecmp(input.HM, "XXL") != 0 )
|
|---|
| 259 | print_CLI_error();
|
|---|
| 260 |
|
|---|
| 261 | // Set HM size specific parameters
|
|---|
| 262 | // (defaults to large)
|
|---|
| 263 | if( strcasecmp(input.HM, "small") == 0 )
|
|---|
| 264 | input.n_isotopes = 68;
|
|---|
| 265 | else if( strcasecmp(input.HM, "XL") == 0 && user_g == 0 )
|
|---|
| 266 | input.n_gridpoints = 238847; // sized to make 120 GB XS data
|
|---|
| 267 | else if( strcasecmp(input.HM, "XXL") == 0 && user_g == 0 )
|
|---|
| 268 | input.n_gridpoints = 238847 * 2.1; // 252 GB XS data
|
|---|
| 269 |
|
|---|
| 270 | // Return input struct
|
|---|
| 271 | return input;
|
|---|
| 272 | }
|
|---|