source: CIVL/examples/omp/nas-dc/sys/setparams.c@ 1aaefd4

main test-branch
Last change on this file since 1aaefd4 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 31.6 KB
Line 
1/*
2 * This utility configures a NPB to be built for a specific class.
3 * It creates a file "npbparams.h"
4 * in the source directory. This file keeps state information about
5 * which size of benchmark is currently being built (so that nothing
6 * if unnecessarily rebuilt) and defines (through PARAMETER statements)
7 * the number of nodes and class for which a benchmark is being built.
8
9 * The utility takes 3 arguments:
10 * setparams benchmark-name class
11 * benchmark-name is "sp", "bt", etc
12 * class is the size of the benchmark
13 * These parameters are checked for the current benchmark. If they
14 * are invalid, this program prints a message and aborts.
15 * If the parameters are ok, the current npbsize.h (actually just
16 * the first line) is read in. If the new parameters are the same as
17 * the old, nothing is done, but an exit code is returned to force the
18 * user to specify (otherwise the make procedure succeeds but builds a
19 * binary of the wrong name). Otherwise the file is rewritten.
20 * Errors write a message (to stdout) and abort.
21 *
22 * This program makes use of two extra benchmark "classes"
23 * class "X" means an invalid specification. It is returned if
24 * there is an error parsing the config file.
25 * class "U" is an external specification meaning "unknown class"
26 *
27 * Unfortunately everything has to be case sensitive. This is
28 * because we can always convert lower to upper or v.v. but
29 * can't feed this information back to the makefile, so typing
30 * make CLASS=a and make CLASS=A will produce different binaries.
31 *
32 *
33 */
34
35#include <sys/types.h>
36#include <stdlib.h>
37#include <stdio.h>
38#include <ctype.h>
39#include <string.h>
40#include <time.h>
41
42/*
43 * This is the master version number for this set of
44 * NPB benchmarks. It is in an obscure place so people
45 * won't accidentally change it.
46 */
47
48#define VERSION "3.3.1"
49
50/* controls verbose output from setparams */
51/* #define VERBOSE */
52
53#define FILENAME "npbparams.h"
54#define DESC_LINE "c CLASS = %c\n"
55#define DEF_CLASS_LINE "#define CLASS '%c'\n"
56#define FINDENT " "
57#define CONTINUE " > "
58
59void get_info(char *argv[], int *typep, char *classp);
60void check_info(int type, char class);
61void read_info(int type, char *classp);
62void write_info(int type, char class);
63void write_sp_info(FILE *fp, char class);
64void write_bt_info(FILE *fp, char class);
65void write_dc_info(FILE *fp, char class);
66void write_lu_info(FILE *fp, char class);
67void write_mg_info(FILE *fp, char class);
68void write_cg_info(FILE *fp, char class);
69void write_ft_info(FILE *fp, char class);
70void write_ep_info(FILE *fp, char class);
71void write_is_info(FILE *fp, char class);
72void write_ua_info(FILE *fp, char class);
73void write_compiler_info(int type, FILE *fp);
74void write_convertdouble_info(int type, FILE *fp);
75void check_line(char *line, char *label, char *val);
76int check_include_line(char *line, char *filename);
77void put_string(FILE *fp, char *name, char *val);
78void put_def_string(FILE *fp, char *name, char *val);
79void put_def_variable(FILE *fp, char *name, char *val);
80int ilog2(int i);
81double power(double base, int i);
82
83enum benchmark_types {SP, BT, LU, MG, FT, IS, EP, CG, UA, DC};
84
85int main(int argc, char *argv[])
86{
87 int type;
88 char class, class_old;
89
90 if (argc != 3) {
91 printf("Usage: %s benchmark-name class\n", argv[0]);
92 exit(1);
93 }
94
95 /* Get command line arguments. Make sure they're ok. */
96 get_info(argv, &type, &class);
97 if (class != 'U') {
98#ifdef VERBOSE
99 printf("setparams: For benchmark %s: class = %c\n",
100 argv[1], class);
101#endif
102 check_info(type, class);
103 }
104
105 /* Get old information. */
106 read_info(type, &class_old);
107 if (class != 'U') {
108 if (class_old != 'X') {
109#ifdef VERBOSE
110 printf("setparams: old settings: class = %c\n",
111 class_old);
112#endif
113 }
114 } else {
115 printf("setparams:\n\
116 *********************************************************************\n\
117 * You must specify CLASS to build this benchmark *\n\
118 * For example, to build a class A benchmark, type *\n\
119 * make {benchmark-name} CLASS=A *\n\
120 *********************************************************************\n\n");
121
122 if (class_old != 'X') {
123#ifdef VERBOSE
124 printf("setparams: Previous settings were CLASS=%c \n", class_old);
125#endif
126 }
127 exit(1); /* exit on class==U */
128 }
129
130 /* Write out new information if it's different. */
131 if (class != class_old) {
132#ifdef VERBOSE
133 printf("setparams: Writing %s\n", FILENAME);
134#endif
135 write_info(type, class);
136 } else {
137#ifdef VERBOSE
138 printf("setparams: Settings unchanged. %s unmodified\n", FILENAME);
139#endif
140 }
141
142 return 0;
143}
144
145
146/*
147 * get_info(): Get parameters from command line
148 */
149
150void get_info(char *argv[], int *typep, char *classp)
151{
152
153 *classp = *argv[2];
154
155 if (!strcmp(argv[1], "sp") || !strcmp(argv[1], "SP")) *typep = SP;
156 else if (!strcmp(argv[1], "bt") || !strcmp(argv[1], "BT")) *typep = BT;
157 else if (!strcmp(argv[1], "ft") || !strcmp(argv[1], "FT")) *typep = FT;
158 else if (!strcmp(argv[1], "lu") || !strcmp(argv[1], "LU")) *typep = LU;
159 else if (!strcmp(argv[1], "mg") || !strcmp(argv[1], "MG")) *typep = MG;
160 else if (!strcmp(argv[1], "is") || !strcmp(argv[1], "IS")) *typep = IS;
161 else if (!strcmp(argv[1], "ep") || !strcmp(argv[1], "EP")) *typep = EP;
162 else if (!strcmp(argv[1], "cg") || !strcmp(argv[1], "CG")) *typep = CG;
163 else if (!strcmp(argv[1], "ua") || !strcmp(argv[1], "UA")) *typep = UA;
164 else if (!strcmp(argv[1], "dc") || !strcmp(argv[1], "DC")) *typep = DC;
165 else {
166 printf("setparams: Error: unknown benchmark type %s\n", argv[1]);
167 exit(1);
168 }
169}
170
171/*
172 * check_info(): Make sure command line data is ok for this benchmark
173 */
174
175void check_info(int type, char class)
176{
177
178 /* check class */
179 if (class != 'S' &&
180 class != 'W' &&
181 class != 'A' &&
182 class != 'B' &&
183 class != 'C' &&
184 class != 'D' &&
185 class != 'E') {
186 printf("setparams: Unknown benchmark class %c\n", class);
187 printf("setparams: Allowed classes are \"S\", \"W\", and \"A\" through \"E\"\n");
188 exit(1);
189 }
190
191 if (class == 'E' && (type == IS || type == UA || type == DC)) {
192 printf("setparams: Benchmark class %c not defined for IS, UA, or DC\n", class);
193 exit(1);
194 }
195 if ((class == 'C' || class == 'D') && type == DC) {
196 printf("setparams: Benchmark class %c not defined for DC\n", class);
197 exit(1);
198 }
199}
200
201
202/*
203 * read_info(): Read previous information from file.
204 * Not an error if file doesn't exist, because this
205 * may be the first time we're running.
206 * Assumes the first line of the file is in a special
207 * format that we understand (since we wrote it).
208 */
209
210void read_info(int type, char *classp)
211{
212 int nread;
213 FILE *fp;
214 fp = fopen(FILENAME, "r");
215 if (fp == NULL) {
216#ifdef VERBOSE
217 printf("setparams: INFO: configuration file %s does not exist (yet)\n", FILENAME);
218#endif
219 goto abort;
220 }
221
222 /* first line of file contains info (fortran), first two lines (C) */
223
224 switch(type) {
225 case SP:
226 case BT:
227 case FT:
228 case MG:
229 case LU:
230 case EP:
231 case CG:
232 case UA:
233 nread = fscanf(fp, DESC_LINE, classp);
234 if (nread != 1) {
235 printf("setparams: Error parsing config file %s. Ignoring previous settings\n", FILENAME);
236 goto abort;
237 }
238 break;
239 case IS:
240 case DC:
241 nread = fscanf(fp, DEF_CLASS_LINE, classp);
242 if (nread != 1) {
243 printf("setparams: Error parsing config file %s. Ignoring previous settings\n", FILENAME);
244 goto abort;
245 }
246 break;
247 default:
248 /* never should have gotten this far with a bad name */
249 printf("setparams: (Internal Error) Benchmark type %d unknown to this program\n", type);
250 exit(1);
251 }
252
253 fclose(fp);
254
255
256 return;
257
258 abort:
259 *classp = 'X';
260 return;
261}
262
263
264/*
265 * write_info(): Write new information to config file.
266 * First line is in a special format so we can read
267 * it in again. Then comes a warning. The rest is all
268 * specific to a particular benchmark.
269 */
270
271void write_info(int type, char class)
272{
273 FILE *fp;
274 fp = fopen(FILENAME, "w");
275 if (fp == NULL) {
276 printf("setparams: Can't open file %s for writing\n", FILENAME);
277 exit(1);
278 }
279
280 switch(type) {
281 case SP:
282 case BT:
283 case FT:
284 case MG:
285 case LU:
286 case EP:
287 case CG:
288 case UA:
289 /* Write out the header */
290 fprintf(fp, DESC_LINE, class);
291 /* Print out a warning so bozos don't mess with the file */
292 fprintf(fp, "\
293c \n\
294c \n\
295c This file is generated automatically by the setparams utility.\n\
296c It sets the number of processors and the class of the NPB\n\
297c in this directory. Do not modify it by hand.\n\
298c \n");
299
300 break;
301 case IS:
302 fprintf(fp, DEF_CLASS_LINE, class);
303 fprintf(fp, "\
304/*\n\
305 This file is generated automatically by the setparams utility.\n\
306 It sets the number of processors and the class of the NPB\n\
307 in this directory. Do not modify it by hand. */\n\
308 \n");
309 break;
310 case DC:
311 fprintf(fp, DEF_CLASS_LINE, class);
312 fprintf(fp, "\
313/*\n\
314 This file is generated automatically by the setparams utility.\n\
315 It sets the number of processors and the class of the NPB\n\
316 in this directory. Do not modify it by hand.\n\
317 This file provided for backward compatibility.\n\
318 It is not used in DC benchmark. */\n\
319 \n");
320 break;
321 default:
322 printf("setparams: (Internal error): Unknown benchmark type %d\n",
323 type);
324 exit(1);
325 }
326
327 /* Now do benchmark-specific stuff */
328 switch(type) {
329 case SP:
330 write_sp_info(fp, class);
331 break;
332 case BT:
333 write_bt_info(fp, class);
334 break;
335 case DC:
336 write_dc_info(fp, class);
337 break;
338 case LU:
339 write_lu_info(fp, class);
340 break;
341 case MG:
342 write_mg_info(fp, class);
343 break;
344 case IS:
345 write_is_info(fp, class);
346 break;
347 case FT:
348 write_ft_info(fp, class);
349 break;
350 case EP:
351 write_ep_info(fp, class);
352 break;
353 case CG:
354 write_cg_info(fp, class);
355 break;
356 case UA:
357 write_ua_info(fp, class);
358 break;
359 default:
360 printf("setparams: (Internal error): Unknown benchmark type %d\n", type);
361 exit(1);
362 }
363 write_convertdouble_info(type, fp);
364 write_compiler_info(type, fp);
365 fclose(fp);
366 return;
367}
368
369
370/*
371 * write_sp_info(): Write SP specific info to config file
372 */
373
374void write_sp_info(FILE *fp, char class)
375{
376 int problem_size, niter;
377 char *dt;
378 if (class == 'S') { problem_size = 12; dt = "0.015d0"; niter = 100; }
379 else if (class == 'W') { problem_size = 36; dt = "0.0015d0"; niter = 400; }
380 else if (class == 'A') { problem_size = 64; dt = "0.0015d0"; niter = 400; }
381 else if (class == 'B') { problem_size = 102; dt = "0.001d0"; niter = 400; }
382 else if (class == 'C') { problem_size = 162; dt = "0.00067d0"; niter = 400; }
383 else if (class == 'D') { problem_size = 408; dt = "0.00030d0"; niter = 500; }
384 else if (class == 'E') { problem_size = 1020; dt = "0.0001d0"; niter = 500; }
385 else {
386 printf("setparams: Internal error: invalid class %c\n", class);
387 exit(1);
388 }
389 fprintf(fp, "%sinteger problem_size, niter_default\n", FINDENT);
390 fprintf(fp, "%sparameter (problem_size=%d, niter_default=%d)\n",
391 FINDENT, problem_size, niter);
392 fprintf(fp, "%sdouble precision dt_default\n", FINDENT);
393 fprintf(fp, "%sparameter (dt_default = %s)\n", FINDENT, dt);
394}
395
396/*
397 * write_bt_info(): Write BT specific info to config file
398 */
399
400void write_bt_info(FILE *fp, char class)
401{
402 int problem_size, niter;
403 char *dt;
404 if (class == 'S') { problem_size = 12; dt = "0.010d0"; niter = 60; }
405 else if (class == 'W') { problem_size = 24; dt = "0.0008d0"; niter = 200; }
406 else if (class == 'A') { problem_size = 64; dt = "0.0008d0"; niter = 200; }
407 else if (class == 'B') { problem_size = 102; dt = "0.0003d0"; niter = 200; }
408 else if (class == 'C') { problem_size = 162; dt = "0.0001d0"; niter = 200; }
409 else if (class == 'D') { problem_size = 408; dt = "0.00002d0"; niter = 250; }
410 else if (class == 'E') { problem_size = 1020; dt = "0.4d-5"; niter = 250; }
411 else {
412 printf("setparams: Internal error: invalid class %c\n", class);
413 exit(1);
414 }
415 fprintf(fp, "%sinteger problem_size, niter_default\n", FINDENT);
416 fprintf(fp, "%sparameter (problem_size=%d, niter_default=%d)\n",
417 FINDENT, problem_size, niter);
418 fprintf(fp, "%sdouble precision dt_default\n", FINDENT);
419 fprintf(fp, "%sparameter (dt_default = %s)\n", FINDENT, dt);
420}
421
422/*
423 * write_dc_info(): Write DC specific info to config file
424 */
425
426
427void write_dc_info(FILE *fp, char class)
428{
429 long int input_tuples, attrnum;
430 if (class == 'S') { input_tuples = 1000; attrnum = 5; }
431 else if (class == 'W') { input_tuples = 100000; attrnum = 10; }
432 else if (class == 'A') { input_tuples = 1000000; attrnum = 15; }
433 else if (class == 'B') { input_tuples = 10000000; attrnum = 20; }
434 else {
435 printf("setparams: Internal error: invalid class %c\n", class);
436 exit(1);
437 }
438 fprintf(fp, "long long int input_tuples=%ld, attrnum=%ld;\n",
439 input_tuples, attrnum);
440}
441
442
443/*
444 * write_lu_info(): Write LU specific info to config file
445 */
446
447void write_lu_info(FILE *fp, char class)
448{
449 int isiz1, isiz2, itmax, inorm, problem_size;
450 char *dt_default;
451
452 if (class == 'S') { problem_size = 12; dt_default = "0.5d0"; itmax = 50; }
453 else if (class == 'W') { problem_size = 33; dt_default = "1.5d-3"; itmax = 300; }
454 else if (class == 'A') { problem_size = 64; dt_default = "2.0d0"; itmax = 250; }
455 else if (class == 'B') { problem_size = 102; dt_default = "2.0d0"; itmax = 250; }
456 else if (class == 'C') { problem_size = 162; dt_default = "2.0d0"; itmax = 250; }
457 else if (class == 'D') { problem_size = 408; dt_default = "1.0d0"; itmax = 300; }
458 else if (class == 'E') { problem_size = 1020; dt_default = "0.5d0"; itmax = 300; }
459 else {
460 printf("setparams: Internal error: invalid class %c\n", class);
461 exit(1);
462 }
463 inorm = itmax;
464 isiz1 = problem_size;
465 isiz2 = problem_size;
466
467
468 fprintf(fp, "\nc full problem size\n");
469 fprintf(fp, "%sinteger isiz1, isiz2, isiz3\n", FINDENT);
470 fprintf(fp, "%sparameter (isiz1=%d, isiz2=%d, isiz3=%d)\n",
471 FINDENT, isiz1, isiz2, problem_size );
472
473 fprintf(fp, "\nc number of iterations and how often to print the norm\n");
474 fprintf(fp, "%sinteger itmax_default, inorm_default\n", FINDENT);
475 fprintf(fp, "%sparameter (itmax_default=%d, inorm_default=%d)\n",
476 FINDENT, itmax, inorm);
477
478 fprintf(fp, "%sdouble precision dt_default\n", FINDENT);
479 fprintf(fp, "%sparameter (dt_default = %s)\n", FINDENT, dt_default);
480
481}
482
483/*
484 * write_mg_info(): Write MG specific info to config file
485 */
486
487void write_mg_info(FILE *fp, char class)
488{
489 int problem_size, nit, log2_size, lt_default, lm;
490 int ndim1, ndim2, ndim3;
491 if (class == 'S') { problem_size = 32; nit = 4; }
492/* else if (class == 'W') { problem_size = 64; nit = 40; }*/
493 else if (class == 'W') { problem_size = 128; nit = 4; }
494 else if (class == 'A') { problem_size = 256; nit = 4; }
495 else if (class == 'B') { problem_size = 256; nit = 20; }
496 else if (class == 'C') { problem_size = 512; nit = 20; }
497 else if (class == 'D') { problem_size = 1024; nit = 50; }
498 else if (class == 'E') { problem_size = 2048; nit = 50; }
499 else {
500 printf("setparams: Internal error: invalid class type %c\n", class);
501 exit(1);
502 }
503 log2_size = ilog2(problem_size);
504 /* lt is log of largest total dimension */
505 lt_default = log2_size;
506 /* log of log of maximum dimension on a node */
507 lm = log2_size;
508 ndim1 = lm;
509 ndim3 = log2_size;
510 ndim2 = log2_size;
511
512 fprintf(fp, "%sinteger nx_default, ny_default, nz_default\n", FINDENT);
513 fprintf(fp, "%sparameter (nx_default=%d, ny_default=%d, nz_default=%d)\n",
514 FINDENT, problem_size, problem_size, problem_size);
515 fprintf(fp, "%sinteger nit_default, lm, lt_default\n", FINDENT);
516 fprintf(fp, "%sparameter (nit_default=%d, lm = %d, lt_default=%d)\n",
517 FINDENT, nit, lm, lt_default);
518 fprintf(fp, "%sinteger debug_default\n", FINDENT);
519 fprintf(fp, "%sparameter (debug_default=%d)\n", FINDENT, 0);
520 fprintf(fp, "%sinteger ndim1, ndim2, ndim3\n", FINDENT);
521 fprintf(fp, "%sparameter (ndim1 = %d, ndim2 = %d, ndim3 = %d)\n",
522 FINDENT, ndim1, ndim2, ndim3);
523 fprintf(fp, "%sinteger%s one, nr, nv, ir\n",
524 FINDENT, (problem_size > 1024)? "*8" : "");
525 fprintf(fp, "%sparameter (one=1)\n", FINDENT);
526}
527
528
529/*
530 * write_is_info(): Write IS specific info to config file
531 */
532
533void write_is_info(FILE *fp, char class)
534{
535 if( class != 'S' &&
536 class != 'W' &&
537 class != 'A' &&
538 class != 'B' &&
539 class != 'C' &&
540 class != 'D')
541 {
542 printf("setparams: Internal error: invalid class type %c\n", class);
543 exit(1);
544 }
545}
546
547
548/*
549 * write_cg_info(): Write CG specific info to config file
550 */
551
552void write_cg_info(FILE *fp, char class)
553{
554 int na,nonzer,niter;
555 char *shift,*rcond="1.0d-1";
556 char *shiftS="10.",
557 *shiftW="12.",
558 *shiftA="20.",
559 *shiftB="60.",
560 *shiftC="110.",
561 *shiftD="500.",
562 *shiftE="1.5d3";
563
564
565 if( class == 'S' )
566 { na=1400; nonzer=7; niter=15; shift=shiftS; }
567 else if( class == 'W' )
568 { na=7000; nonzer=8; niter=15; shift=shiftW; }
569 else if( class == 'A' )
570 { na=14000; nonzer=11; niter=15; shift=shiftA; }
571 else if( class == 'B' )
572 { na=75000; nonzer=13; niter=75; shift=shiftB; }
573 else if( class == 'C' )
574 { na=150000; nonzer=15; niter=75; shift=shiftC; }
575 else if( class == 'D' )
576 { na=1500000; nonzer=21; niter=100; shift=shiftD; }
577 else if( class == 'E' )
578 { na=9000000; nonzer=26; niter=100; shift=shiftE; }
579 else
580 {
581 printf("setparams: Internal error: invalid class type %c\n", class);
582 exit(1);
583 }
584 fprintf( fp, "%sinteger na, nonzer, niter\n", FINDENT );
585 fprintf( fp, "%sdouble precision shift, rcond\n", FINDENT );
586 fprintf( fp, "%sparameter( na=%d,\n", FINDENT, na );
587 fprintf( fp, "%s nonzer=%d,\n", CONTINUE, nonzer );
588 fprintf( fp, "%s niter=%d,\n", CONTINUE, niter );
589 fprintf( fp, "%s shift=%s,\n", CONTINUE, shift );
590 fprintf( fp, "%s rcond=%s )\n", CONTINUE, rcond );
591
592}
593
594
595
596/*
597 * write_ua_info(): Write UA specific info to config file
598 */
599
600void write_ua_info(FILE *fp, char class)
601{
602 int lelt, lmor,refine_max, niter, nmxh, fre;
603 char *alpha;
604
605 fre = 5;
606 if( class == 'S' )
607 { lelt=250;lmor=11600; refine_max=4; niter=50; nmxh=10; alpha="0.040d0"; }
608 else if( class == 'W' )
609 { lelt=700;lmor=26700; refine_max=5; niter=100; nmxh=10; alpha="0.060d0"; }
610 else if( class == 'A' )
611 { lelt=2400;lmor=92700; refine_max=6; niter=200; nmxh=10; alpha="0.076d0"; }
612 else if( class == 'B' )
613 { lelt=8800; lmor=334600; refine_max=7; niter=200; nmxh=10; alpha="0.076d0"; }
614 else if( class == 'C' )
615 { lelt=33500; lmor=1262100; refine_max=8; niter=200; nmxh=10; alpha="0.067d0"; }
616 else if( class == 'D' )
617 { lelt=515000;lmor=19500000; refine_max=10; niter=250; nmxh=10; alpha="0.046d0"; }
618 else
619 {
620 printf("setparams: Internal error: invalid class type %c\n", class);
621 exit(1);
622 }
623
624 fprintf( fp, "%sinteger lelt, lmor, refine_max, fre_default\n", FINDENT );
625 fprintf( fp, "%sinteger niter_default, nmxh_default\n", FINDENT );
626 fprintf( fp, "%scharacter class_default\n", FINDENT );
627 fprintf( fp, "%sdouble precision alpha_default\n", FINDENT );
628 fprintf( fp, "%sparameter( lelt=%d,\n", FINDENT, lelt );
629 fprintf( fp, "%s lmor=%d,\n", CONTINUE, lmor );
630 fprintf( fp, "%s refine_max=%d,\n", CONTINUE, refine_max );
631 fprintf( fp, "%s fre_default=%d,\n", CONTINUE, fre );
632 fprintf( fp, "%s niter_default=%d,\n", CONTINUE, niter );
633 fprintf( fp, "%s nmxh_default=%d,\n", CONTINUE, nmxh );
634 fprintf( fp, "%s class_default=\"%c\",\n", CONTINUE, class );
635 fprintf( fp, "%s alpha_default=%s )\n", CONTINUE, alpha );
636
637}
638
639
640/*
641 * write_ft_info(): Write FT specific info to config file
642 */
643
644void write_ft_info(FILE *fp, char class)
645{
646 /* easiest way (given the way the benchmark is written)
647 * is to specify log of number of grid points in each
648 * direction m1, m2, m3. nt is the number of iterations
649 */
650 int nx, ny, nz, maxdim, niter;
651 if (class == 'S') { nx = 64; ny = 64; nz = 64; niter = 6;}
652 else if (class == 'W') { nx = 128; ny = 128; nz = 32; niter = 6;}
653 else if (class == 'A') { nx = 256; ny = 256; nz = 128; niter = 6;}
654 else if (class == 'B') { nx = 512; ny = 256; nz = 256; niter =20;}
655 else if (class == 'C') { nx = 512; ny = 512; nz = 512; niter =20;}
656 else if (class == 'D') { nx = 2048; ny = 1024; nz = 1024; niter =25;}
657 else if (class == 'E') { nx = 4096; ny = 2048; nz = 2048; niter =25;}
658 else {
659 printf("setparams: Internal error: invalid class type %c\n", class);
660 exit(1);
661 }
662 maxdim = nx;
663 if (ny > maxdim) maxdim = ny;
664 if (nz > maxdim) maxdim = nz;
665 fprintf(fp, "%sinteger nx, ny, nz, maxdim, niter_default\n", FINDENT);
666 fprintf(fp, "%sinteger%s ntotal, nxp, nyp, ntotalp\n", FINDENT,
667 (nx > 1024)? "*8" : "");
668 fprintf(fp, "%sparameter (nx=%d, ny=%d, nz=%d, maxdim=%d)\n",
669 FINDENT, nx, ny, nz, maxdim);
670 fprintf(fp, "%sparameter (niter_default=%d)\n", FINDENT, niter);
671 fprintf(fp, "%sparameter (nxp=nx+1, nyp=ny)\n", FINDENT);
672 fprintf(fp, "%sparameter (ntotal=nx*nyp*nz)\n", FINDENT);
673 fprintf(fp, "%sparameter (ntotalp=nxp*nyp*nz)\n", FINDENT);
674
675}
676
677/*
678 * write_ep_info(): Write EP specific info to config file
679 */
680
681void write_ep_info(FILE *fp, char class)
682{
683 /* easiest way (given the way the benchmark is written)
684 * is to specify log of number of grid points in each
685 * direction m1, m2, m3. nt is the number of iterations
686 */
687 int m;
688 if (class == 'S') { m = 24; }
689 else if (class == 'W') { m = 25; }
690 else if (class == 'A') { m = 28; }
691 else if (class == 'B') { m = 30; }
692 else if (class == 'C') { m = 32; }
693 else if (class == 'D') { m = 36; }
694 else if (class == 'E') { m = 40; }
695 else {
696 printf("setparams: Internal error: invalid class type %c\n", class);
697 exit(1);
698 }
699
700 fprintf(fp, "%scharacter class\n",FINDENT);
701 fprintf(fp, "%sparameter (class =\'%c\')\n",
702 FINDENT, class);
703 fprintf(fp, "%sinteger m\n", FINDENT);
704 fprintf(fp, "%sparameter (m=%d)\n", FINDENT, m);
705}
706
707
708/*
709 * This is a gross hack to allow the benchmarks to
710 * print out how they were compiled. Various other ways
711 * of doing this have been tried and they all fail on
712 * some machine - due to a broken "make" program, or
713 * F77 limitations, of whatever. Hopefully this will
714 * always work because it uses very portable C. Unfortunately
715 * it relies on parsing the make.def file - YUK.
716 * If your machine doesn't have <string.h> or <ctype.h>, happy hacking!
717 *
718 */
719
720#define VERBOSE
721#define LL 400
722#define DEFFILE "../config/make.def"
723#define DEFAULT_MESSAGE "(none)"
724FILE *deffile;
725void write_compiler_info(int type, FILE *fp)
726{
727 char line[LL];
728 char f77[LL], flink[LL], f_lib[LL], f_inc[LL], fflags[LL], flinkflags[LL];
729 char compiletime[LL], randfile[LL];
730 char cc[LL], cflags[LL], clink[LL], clinkflags[LL],
731 c_lib[LL], c_inc[LL];
732 struct tm *tmp;
733 time_t t;
734 deffile = fopen(DEFFILE, "r");
735 if (deffile == NULL) {
736 printf("\n\
737setparams: File %s doesn't exist. To build the NAS benchmarks\n\
738 you need to create is according to the instructions\n\
739 in the README in the main directory and comments in \n\
740 the file config/make.def.template\n", DEFFILE);
741 exit(1);
742 }
743 strcpy(f77, DEFAULT_MESSAGE);
744 strcpy(flink, DEFAULT_MESSAGE);
745 strcpy(f_lib, DEFAULT_MESSAGE);
746 strcpy(f_inc, DEFAULT_MESSAGE);
747 strcpy(fflags, DEFAULT_MESSAGE);
748 strcpy(flinkflags, DEFAULT_MESSAGE);
749 strcpy(randfile, DEFAULT_MESSAGE);
750 strcpy(cc, DEFAULT_MESSAGE);
751 strcpy(cflags, DEFAULT_MESSAGE);
752 strcpy(clink, DEFAULT_MESSAGE);
753 strcpy(clinkflags, DEFAULT_MESSAGE);
754 strcpy(c_lib, DEFAULT_MESSAGE);
755 strcpy(c_inc, DEFAULT_MESSAGE);
756
757 while (fgets(line, LL, deffile) != NULL) {
758 if (*line == '#') continue;
759 /* yes, this is inefficient. but it's simple! */
760 check_line(line, "F77", f77);
761 check_line(line, "FLINK", flink);
762 check_line(line, "F_LIB", f_lib);
763 check_line(line, "F_INC", f_inc);
764 check_line(line, "FFLAGS", fflags);
765 check_line(line, "FLINKFLAGS", flinkflags);
766 check_line(line, "RAND", randfile);
767 check_line(line, "CC", cc);
768 check_line(line, "CFLAGS", cflags);
769 check_line(line, "CLINK", clink);
770 check_line(line, "CLINKFLAGS", clinkflags);
771 check_line(line, "C_LIB", c_lib);
772 check_line(line, "C_INC", c_inc);
773 }
774
775
776 (void) time(&t);
777 tmp = localtime(&t);
778 (void) strftime(compiletime, (size_t)LL, "%d %b %Y", tmp);
779
780
781 switch(type) {
782 case FT:
783 case SP:
784 case BT:
785 case MG:
786 case LU:
787 case EP:
788 case CG:
789 case UA:
790 put_string(fp, "compiletime", compiletime);
791 put_string(fp, "npbversion", VERSION);
792 put_string(fp, "cs1", f77);
793 put_string(fp, "cs2", flink);
794 put_string(fp, "cs3", f_lib);
795 put_string(fp, "cs4", f_inc);
796 put_string(fp, "cs5", fflags);
797 put_string(fp, "cs6", flinkflags);
798 put_string(fp, "cs7", randfile);
799 break;
800 case IS:
801 case DC:
802 put_def_string(fp, "COMPILETIME", compiletime);
803 put_def_string(fp, "NPBVERSION", VERSION);
804 put_def_string(fp, "CC", cc);
805 put_def_string(fp, "CFLAGS", cflags);
806 put_def_string(fp, "CLINK", clink);
807 put_def_string(fp, "CLINKFLAGS", clinkflags);
808 put_def_string(fp, "C_LIB", c_lib);
809 put_def_string(fp, "C_INC", c_inc);
810 break;
811 default:
812 printf("setparams: (Internal error): Unknown benchmark type %d\n",
813 type);
814 exit(1);
815 }
816
817}
818
819void check_line(char *line, char *label, char *val)
820{
821 char *original_line;
822 int n;
823 original_line = line;
824 /* compare beginning of line and label */
825 while (*label != '\0' && *line == *label) {
826 line++; label++;
827 }
828 /* if *label is not EOS, we must have had a mismatch */
829 if (*label != '\0') return;
830 /* if *line is not a space, actual label is longer than test label */
831 if (!isspace(*line) && *line != '=') return ;
832 /* skip over white space */
833 while (isspace(*line)) line++;
834 /* next char should be '=' */
835 if (*line != '=') return;
836 /* skip over white space */
837 while (isspace(*++line));
838 /* if EOS, nothing was specified */
839 if (*line == '\0') return;
840 /* finally we've come to the value */
841 strcpy(val, line);
842 /* chop off the newline at the end */
843 n = strlen(val)-1;
844 if (n >= 0 && val[n] == '\n')
845 val[n--] = '\0';
846 if (n >= 0 && val[n] == '\r')
847 val[n--] = '\0';
848 /* treat continuation */
849 while (val[n] == '\\' && fgets(original_line, LL, deffile)) {
850 line = original_line;
851 while (isspace(*line)) line++;
852 if (isspace(*original_line)) val[n++] = ' ';
853 while (*line && *line != '\n' && *line != '\r' && n < LL-1)
854 val[n++] = *line++;
855 val[n] = '\0';
856 n--;
857 }
858/* if (val[n] == '\\') {
859 printf("\n\
860setparams: Error in file make.def. Because of the way in which\n\
861 command line arguments are incorporated into the\n\
862 executable benchmark, you can't have any continued\n\
863 lines in the file make.def, that is, lines ending\n\
864 with the character \"\\\". Although it may be ugly, \n\
865 you should be able to reformat without continuation\n\
866 lines. The offending line is\n\
867 %s\n", original_line);
868 exit(1);
869 } */
870}
871
872int check_include_line(char *line, char *filename)
873{
874 char *include_string = "include";
875 /* compare beginning of line and "include" */
876 while (*include_string != '\0' && *line == *include_string) {
877 line++; include_string++;
878 }
879 /* if *include_string is not EOS, we must have had a mismatch */
880 if (*include_string != '\0') return(0);
881 /* if *line is not a space, first word is not "include" */
882 if (!isspace(*line)) return(0);
883 /* skip over white space */
884 while (isspace(*++line));
885 /* if EOS, nothing was specified */
886 if (*line == '\0') return(0);
887 /* next keyword should be name of include file in *filename */
888 while (*filename != '\0' && *line == *filename) {
889 line++; filename++;
890 }
891 if (*filename != '\0' ||
892 (*line != ' ' && *line != '\0' && *line !='\n')) return(0);
893 else return(1);
894}
895
896
897#define MAXL 46
898void put_string(FILE *fp, char *name, char *val)
899{
900 int len;
901 len = strlen(val);
902 if (len > MAXL) {
903 val[MAXL] = '\0';
904 val[MAXL-1] = '.';
905 val[MAXL-2] = '.';
906 val[MAXL-3] = '.';
907 len = MAXL;
908 }
909 fprintf(fp, "%scharacter %s*%d\n", FINDENT, name, len);
910 fprintf(fp, "%sparameter (%s=\'%s\')\n", FINDENT, name, val);
911}
912
913/* need to escape quote (") in val */
914int fix_string_quote(char *val, char *newval, int maxl)
915{
916 int len;
917 int i, j;
918 len = strlen(val);
919 i = j = 0;
920 while (i < len && j < maxl) {
921 if (val[i] == '"')
922 newval[j++] = '\\';
923 if (j < maxl)
924 newval[j++] = val[i++];
925 }
926 newval[j] = '\0';
927 return j;
928}
929
930/* NOTE: is the ... stuff necessary in C? */
931void put_def_string(FILE *fp, char *name, char *val0)
932{
933 int len;
934 char val[MAXL+3];
935 len = fix_string_quote(val0, val, MAXL+2);
936 if (len > MAXL) {
937 val[MAXL] = '\0';
938 val[MAXL-1] = '.';
939 val[MAXL-2] = '.';
940 val[MAXL-3] = '.';
941 len = MAXL;
942 }
943 fprintf(fp, "#define %s \"%s\"\n", name, val);
944}
945
946void put_def_variable(FILE *fp, char *name, char *val)
947{
948 int len;
949 len = strlen(val);
950 if (len > MAXL) {
951 val[MAXL] = '\0';
952 val[MAXL-1] = '.';
953 val[MAXL-2] = '.';
954 val[MAXL-3] = '.';
955 len = MAXL;
956 }
957 fprintf(fp, "#define %s %s\n", name, val);
958}
959
960
961
962#if 0
963
964/* this version allows arbitrarily long lines but
965 * some compilers don't like that and they're rarely
966 * useful
967 */
968
969#define LINELEN 65
970void put_string(FILE *fp, char *name, char *val)
971{
972 int len, nlines, pos, i;
973 char line[100];
974 len = strlen(val);
975 nlines = len/LINELEN;
976 if (nlines*LINELEN < len) nlines++;
977 fprintf(fp, "%scharacter*%d %s\n", FINDENT, nlines*LINELEN, name);
978 fprintf(fp, "%sparameter (%s = \n", FINDENT, name);
979 for (i = 0; i < nlines; i++) {
980 pos = i*LINELEN;
981 if (i == 0) fprintf(fp, "%s\'", CONTINUE);
982 else fprintf(fp, "%s", CONTINUE);
983 /* number should be same as LINELEN */
984 fprintf(fp, "%.65s", val+pos);
985 if (i == nlines-1) fprintf(fp, "\')\n");
986 else fprintf(fp, "\n");
987 }
988}
989
990#endif
991
992
993/* integer log base two. Return error is argument isn't
994 * a power of two or is less than or equal to zero
995 */
996
997int ilog2(int i)
998{
999 int log2;
1000 int exp2 = 1;
1001 if (i <= 0) return(-1);
1002
1003 for (log2 = 0; log2 < 30; log2++) {
1004 if (exp2 == i) return(log2);
1005 if (exp2 > i) break;
1006 exp2 *= 2;
1007 }
1008 return(-1);
1009}
1010
1011
1012/* Power function. We could use pow from the math library, but then
1013 * we would have to insist on always linking with the math library, just
1014 * for this function. Since we only need pow with integer exponents,
1015 * we'll code it ourselves here.
1016 */
1017
1018double power(double base, int i)
1019{
1020 double x;
1021
1022 if (i==0) return (1.0);
1023 else if (i<0) {
1024 base = 1.0/base;
1025 i = -i;
1026 }
1027 x = 1.0;
1028 while (i>0) {
1029 x *=base;
1030 i--;
1031 }
1032 return (x);
1033}
1034
1035
1036void write_convertdouble_info(int type, FILE *fp)
1037{
1038 switch(type) {
1039 case SP:
1040 case BT:
1041 case LU:
1042 case FT:
1043 case MG:
1044 case EP:
1045 case CG:
1046 case UA:
1047 fprintf(fp, "%slogical convertdouble\n", FINDENT);
1048#ifdef CONVERTDOUBLE
1049 fprintf(fp, "%sparameter (convertdouble = .true.)\n", FINDENT);
1050#else
1051 fprintf(fp, "%sparameter (convertdouble = .false.)\n", FINDENT);
1052#endif
1053 break;
1054 }
1055}
Note: See TracBrowser for help on using the repository browser.