-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbots_main.cilk~
547 lines (508 loc) · 18.3 KB
/
bots_main.cilk~
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
/**********************************************************************************************/
/* This program is part of the Barcelona OpenMP Tasks Suite */
/* Copyright (C) 2009 Barcelona Supercomputing Center - Centro Nacional de Supercomputacion */
/* Copyright (C) 2009 Universitat Politecnica de Catalunya */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License, or */
/* (at your option) any later version. */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program; if not, write to the Free Software */
/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
/**********************************************************************************************/
/***********************************************************************
* main function & common behaviour of the benchmark.
**********************************************************************/
#include <cilk.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stddef.h>
#include <memory.h>
#include <sys/time.h>
#include <libgen.h>
#include "bots_common.h"
#include "bots_main.h"
#include "bots.h"
#include "app-desc.h"
/***********************************************************************
* BENCHMARK HEADERS
*********************************************************************/
cilk int parallel_uts( Node *root );
void bots_initialize();
void bots_finalize();
void bots_sequential_ini();
long bots_sequential();
void bots_sequential_fini();
int bots_check_result();
void bots_print_usage_specific();
void bots_get_params_specific(int argc, char **argv);
void bots_set_info();
/***********************************************************************
* DEFAULT VALUES
*********************************************************************/
/* common flags */
int bots_sequential_flag = FALSE;
int bots_check_flag = FALSE;
bots_verbose_mode_t bots_verbose_mode = BOTS_VERBOSE_DEFAULT;
int bots_result = BOTS_RESULT_NOT_REQUESTED;
int bots_output_format = 1;
int bots_print_header = FALSE;
/* common variables */
char bots_name[128];
char bots_execname[128];
char bots_parameters[128];
char bots_model[128];
char bots_resources[128];
/* compile and execution information */
char bots_exec_date[128];
char bots_exec_message[128];
char bots_comp_date[128];
char bots_comp_message[128];
char bots_cc[128];
char bots_cflags[128];
char bots_ld[128];
char bots_ldflags[128];
char bots_cutoff[128];
/* time variables */
double bots_time_program = 0.0;
double bots_time_sequential = 0.0;
int bots_number_of_tasks = 0;
/*
* Application dependent info
*/
#ifndef BOTS_APP_NAME
#error "Application name must be defined (#define BOTS_APP_NAME)"
#endif
#ifndef BOTS_APP_PARAMETERS_DESC
#define BOTS_APP_PARAMETERS_DESC ""
#endif
#ifndef BOTS_APP_PARAMETERS_LIST
#define BOTS_APP_PARAMETERS_LIST
#endif
#ifndef BOTS_APP_INIT
#define BOTS_APP_INIT
#endif
#ifndef BOTS_APP_FINI
#define BOTS_APP_FINI
#endif
#ifndef KERNEL_CALL
#error "Initial kernell call must be specified (#define KERNEL_CALL)"
#endif
#ifndef KERNEL_INIT
#define KERNEL_INIT
#endif
#ifndef KERNEL_FINI
#define KERNEL_FINI
#endif
#ifndef KERNEL_SEQ_INIT
#define KERNEL_SEQ_INIT
#endif
#ifndef KERNEL_SEQ_FINI
#define KERNEL_SEQ_FINI
#endif
#ifndef BOTS_MODEL_DESC
#define BOTS_MODEL_DESC "Unknown"
#endif
#ifdef BOTS_APP_USES_ARG_SIZE
#ifndef BOTS_APP_DEF_ARG_SIZE
#error "Default vaule for argument size must be specified (#define BOTS_APP_DEF_ARG_SIZE)"
#endif
#ifndef BOTS_APP_DESC_ARG_SIZE
#error "Help description for argument size must be specified (#define BOTS_APP_DESC_ARG_SIZE)"
#endif
int bots_arg_size = BOTS_APP_DEF_ARG_SIZE;
#endif
#ifdef BOTS_APP_USES_ARG_SIZE_1
#ifndef BOTS_APP_DEF_ARG_SIZE_1
#error "Default vaule for argument size must be specified (#define BOTS_APP_DEF_ARG_SIZE_1)"
#endif
#ifndef BOTS_APP_DESC_ARG_SIZE_1
#error "Help description for argument size must be specified (#define BOTS_APP_DESC_ARG_SIZE_1)"
#endif
int bots_arg_size_1 = BOTS_APP_DEF_ARG_SIZE_1;
#endif
#ifdef BOTS_APP_USES_ARG_SIZE_2
#ifndef BOTS_APP_DEF_ARG_SIZE_2
#error "Default vaule for argument size must be specified (#define BOTS_APP_DEF_ARG_SIZE_2)"
#endif
#ifndef BOTS_APP_DESC_ARG_SIZE_2
#error "Help description for argument size must be specified (#define BOTS_APP_DESC_ARG_SIZE_2)"
#endif
int bots_arg_size_2 = BOTS_APP_DEF_ARG_SIZE_2;
#endif
#ifdef BOTS_APP_USES_ARG_REPETITIONS
#ifndef BOTS_APP_DEF_ARG_REPETITIONS
#error "Default vaule for argument repetitions must be specified (#define BOTS_APP_DEF_ARG_REPETITIONS)"
#endif
#ifndef BOTS_APP_DESC_ARG_REPETITIONS
#error "Help description for argument repetitions must be specified (#define BOTS_APP_DESC_ARG_REPETITIONS)"
#endif
int bots_arg_repetitions = BOTS_APP_DEF_ARG_REPETITIONS;
#endif
#ifdef BOTS_APP_USES_ARG_FILE
#ifndef BOTS_APP_DESC_ARG_FILE
#error "Help description for argument file must be specified (#define BOTS_APP_DESC_ARG_FILE)"
#endif
char bots_arg_file[255]="";
#endif
#ifdef BOTS_APP_USES_ARG_BLOCK
#ifndef BOTS_APP_DEF_ARG_BLOCK
#error "Default value for argument block must be specified (#define BOTS_APP_DEF_ARG_BLOCK)"
#endif
#ifndef BOTS_APP_DESC_ARG_BLOCK
#error "Help description for argument block must be specified (#define BOTS_APP_DESC_ARG_BLOCK)"
#endif
int bots_arg_block = BOTS_APP_DEF_ARG_BLOCK;
#endif
#ifdef BOTS_APP_USES_ARG_CUTOFF
#ifndef BOTS_APP_DEF_ARG_CUTOFF
#error "Default value for argument cutoff must be specified (#define BOTS_APP_DEF_ARG_CUTOFF)"
#endif
#ifndef BOTS_APP_DESC_ARG_CUTOFF
#error "Help description for argument cutoff must be specified (#define BOTS_APP_DESC_ARG_CUTOFF)"
#endif
int bots_app_cutoff_value = BOTS_APP_DEF_ARG_CUTOFF;
#endif
#ifdef BOTS_APP_USES_ARG_CUTOFF_1
#ifndef BOTS_APP_DEF_ARG_CUTOFF_1
#error "Default value for argument cutoff must be specified (#define BOTS_APP_DEF_ARG_CUTOFF_1)"
#endif
#ifndef BOTS_APP_DESC_ARG_CUTOFF_1
#error "Help description for argument cutoff must be specified (#define BOTS_APP_DESC_ARG_CUTOFF_1)"
#endif
int bots_app_cutoff_value_1 = BOTS_APP_DEF_ARG_CUTOFF_1;
#endif
#ifdef BOTS_APP_USES_ARG_CUTOFF_2
#ifndef BOTS_APP_DEF_ARG_CUTOFF_2
#error "Default value for argument cutoff must be specified (#define BOTS_APP_DEF_ARG_CUTOFF_2)"
#endif
#ifndef BOTS_APP_DESC_ARG_CUTOFF_2
#error "Help description for argument cutoff must be specified (#define BOTS_APP_DESC_ARG_CUTOFF_2)"
#endif
int bots_app_cutoff_value_2 = BOTS_APP_DEF_ARG_CUTOFF_2;
#endif
#if defined(MANUAL_CUTOFF) || defined(IF_CUTOFF) || defined(FINAL_CUTOFF)
int bots_cutoff_value = BOTS_CUTOFF_DEF_VALUE;
#endif
/***********************************************************************
* print_usage:
**********************************************************************/
void bots_print_usage()
{
fprintf(stderr, "\n");
fprintf(stderr, "Usage: %s -[options]\n", bots_execname);
fprintf(stderr, "\n");
fprintf(stderr, "Where options are:\n");
#ifdef BOTS_APP_USES_REPETITIONS
fprintf(stderr, " -r <value> : Set the number of repetitions (default = 1).\n");
#endif
#ifdef BOTS_APP_USES_ARG_SIZE
fprintf(stderr, " -n <size> : "BOTS_APP_DESC_ARG_SIZE"\n");
#endif
#ifdef BOTS_APP_USES_ARG_SIZE_1
fprintf(stderr, " -m <size> : "BOTS_APP_DESC_ARG_SIZE_1"\n");
#endif
#ifdef BOTS_APP_USES_ARG_SIZE_2
fprintf(stderr, " -l <size> : "BOTS_APP_DESC_ARG_SIZE_2"\n");
#endif
#ifdef BOTS_APP_USES_ARG_FILE
fprintf(stderr, " -f <file> : "BOTS_APP_DESC_ARG_FILE"\n");
#endif
#if defined(MANUAL_CUTOFF) || defined(IF_CUTOFF) || defined(FINAL_CUTOFF)
fprintf(stderr, " -x <value> : OpenMP tasks cut-off value (default=%d)\n",BOTS_CUTOFF_DEF_VALUE);
#endif
#ifdef BOTS_APP_USES_ARG_CUTOFF
fprintf(stderr, " -y <value> : "BOTS_APP_DESC_ARG_CUTOFF"(default=%d)\n", BOTS_APP_DEF_ARG_CUTOFF);
#endif
#ifdef BOTS_APP_USES_ARG_CUTOFF_1
fprintf(stderr, " -a <value> : "BOTS_APP_DESC_ARG_CUTOFF_1"(default=%d)\n", BOTS_APP_DEF_ARG_CUTOFF_1);
#endif
#ifdef BOTS_APP_USES_ARG_CUTOFF_2
fprintf(stderr, " -b <value> : "BOTS_APP_DESC_ARG_CUTOFF_2"(default=%d)\n", BOTS_APP_DEF_ARG_CUTOFF_2);
#endif
fprintf(stderr, "\n");
fprintf(stderr, " -e <str> : Include 'str' execution message.\n");
fprintf(stderr, " -v <level> : Set verbose level (default = 1).\n");
fprintf(stderr, " 0 - none.\n");
fprintf(stderr, " 1 - default.\n");
fprintf(stderr, " 2 - debug.\n");
fprintf(stderr, " -o <value> : Set output format mode (default = 1).\n");
fprintf(stderr, " 0 - no benchmark output.\n");
fprintf(stderr, " 1 - detailed list format.\n");
fprintf(stderr, " 2 - detailed row format.\n");
fprintf(stderr, " 3 - abridged list format.\n");
fprintf(stderr, " 4 - abridged row format.\n");
fprintf(stderr, " -z : Print row header (if output format is a row variant).\n");
fprintf(stderr, "\n");
#ifdef KERNEL_SEQ_CALL
fprintf(stderr, " -s : Run sequential version.\n");
#endif
#ifdef BOTS_APP_CHECK_USES_SEQ_RESULT
fprintf(stderr, " -c : Check mode ON (implies running sequential version).\n");
#else
fprintf(stderr, " -c : Check mode ON.\n");
#endif
fprintf(stderr, "\n");
fprintf(stderr, " -h : Print program's usage (this help).\n");
fprintf(stderr, "\n");
}
/***********************************************************************
* bots_get_params_common:
**********************************************************************/
void
bots_get_params_common(int argc, char **argv)
{
int i;
strcpy(bots_execname, basename(argv[0]));
bots_get_date(bots_exec_date);
strcpy(bots_exec_message,"");
for (i=1; i<argc; i++)
{
if (argv[i][0] == '-')
{
switch (argv[i][1])
{
#ifdef BOTS_APP_USES_ARG_CUTOFF_1
case 'a':
argv[i][1] = '*';
i++;
if (argc == i) { bots_print_usage(); exit(100); }
bots_app_cutoff_value_1 = atoi(argv[i]);
break;
#endif
#ifdef BOTS_APP_USES_ARG_CUTOFF_2
case 'b':
argv[i][1] = '*';
i++;
if (argc == i) { bots_print_usage(); exit(100); }
bots_app_cutoff_value_2 = atoi(argv[i]);
break;
#endif
case 'c': /* set/unset check mode */
argv[i][1] = '*';
//i++;
//if (argc == i) { bots_print_usage(); exit(100); }
//bots_check_flag = atoi(argv[i]);
bots_check_flag = TRUE;
break;
case 'e': /* include execution message */
argv[i][1] = '*';
i++;
if (argc == i) { bots_print_usage(); exit(100); }
strcpy(bots_exec_message, argv[i]);
break;
#ifdef BOTS_APP_USES_ARG_FILE
case 'f': /* read argument file name */
argv[i][1] = '*';
i++;
if (argc == i) { bots_print_usage(); exit(100); }
strcpy(bots_arg_file,argv[i]);
break;
#endif
case 'h': /* print usage */
argv[i][1] = '*';
bots_print_usage();
exit (100);
#ifdef BOTS_APP_USES_ARG_SIZE_2
case 'l': /* read argument size 2 */
argv[i][1] = '*';
i++;
if (argc == i) { bots_print_usage(); exit(100); }
bots_arg_size_2 = atoi(argv[i]);
break;
#endif
#ifdef BOTS_APP_USES_ARG_SIZE_1
case 'm': /* read argument size 1 */
argv[i][1] = '*';
i++;
if (argc == i) { bots_print_usage(); exit(100); }
bots_arg_size_1 = atoi(argv[i]);
break;
#endif
#ifdef BOTS_APP_USES_ARG_SIZE
case 'n': /* read argument size 0 */
argv[i][1] = '*';
i++;
if (argc == i) { bots_print_usage(); exit(100); }
bots_arg_size = atoi(argv[i]);
break;
#endif
#ifdef BOTS_APP_USES_ARG_BLOCK
/*TODO*/
#endif
case 'o': /* set output mode */
argv[i][1] = '*';
i++;
if (argc == i) { bots_print_usage(); exit(100); }
bots_output_format = atoi(argv[i]);
break;
#ifdef BOTS_APP_USES_REPETITIONS
case 'r': /* set number of repetitions */
argv[i][1] = '*';
i++;
if (argc == i) { bots_print_usage(); exit(100); }
bots_arg_repetition = atoi(argv[i]);
break;
#endif
#ifdef KERNEL_SEQ_CALL
case 's': /* set sequential execution */
argv[i][1] = '*';
//i++;
//if (argc == i) { bots_print_usage(); exit(100); }
//bots_sequential_flag = atoi(argv[i]);
bots_sequential_flag = TRUE;
break;
#endif
case 'v': /* set/unset verbose level */
argv[i][1] = '*';
i++;
if (argc == i) { bots_print_usage(); exit(100); }
bots_verbose_mode = (bots_verbose_mode_t) atoi(argv[i]);
#ifndef BOTS_DEBUG
if ( bots_verbose_mode > 1 ) {
fprintf(stderr, "Error: Configure the suite using '--debug' option in order to use a verbose level greather than 1.\n");
exit(100);
}
#endif
break;
#if defined(MANUAL_CUTOFF) || defined(IF_CUTOFF) || defined(FINAL_CUTOFF)
case 'x':
argv[i][1] = '*';
i++;
if (argc == i) { bots_print_usage(); exit(100); }
bots_cutoff_value = atoi(argv[i]);
break;
#endif
#ifdef BOTS_APP_USES_ARG_CUTOFF
case 'y':
argv[i][1] = '*';
i++;
if (argc == i) { bots_print_usage(); exit(100); }
bots_app_cutoff_value = atoi(argv[i]);
break;
#endif
case 'z':
argv[i][1] = '*';
bots_print_header = TRUE;
break;
default:
// As at the moment there are only common paramenters
// we launch an error. Otherwise we have to ignore the
// parameter and to check, after specific parameters are
// completely read, if there are unrecognized parameters.
fprintf(stderr, "Error: Unrecognized parameter.\n");
bots_print_usage();
exit (100);
}
}
else
{
// As at the moment there are only common paramenters
// we launch an error. Otherwise we have to ignore the
// parameter and to check, after specific parameters are
// completely read, if there are unrecognized parameters.
fprintf(stderr, "Error: Unrecognized parameter.\n");
bots_print_usage();
exit (100);
}
}
}
/***********************************************************************
* bots_get_params_common:
**********************************************************************/
void
bots_get_params(int argc, char **argv)
{
bots_get_params_common(argc, argv);
// bots_get_params_specific(argc, argv);
}
/***********************************************************************
* bots_set_info
**********************************************************************/
void bots_set_info ()
{
/* program specific info */
sprintf(bots_name,BOTS_APP_NAME);
sprintf(bots_parameters,BOTS_APP_PARAMETERS_DESC BOTS_APP_PARAMETERS_LIST);
sprintf(bots_model,BOTS_MODEL_DESC);
sprintf(bots_resources,"%d", omp_get_max_threads());
/* compilation info (do not modify) */
strcpy(bots_comp_date,CDATE);
strcpy(bots_comp_message,CMESSAGE);
strcpy(bots_cc,CC);
strcpy(bots_cflags,CFLAGS);
strcpy(bots_ld,LD);
strcpy(bots_ldflags,LDFLAGS);
#if defined(MANUAL_CUTOFF)
sprintf(bots_cutoff,"manual (%d)",bots_cutoff_value);
#elif defined(IF_CUTOFF)
sprintf(bots_cutoff,"pragma-if (%d)",bots_cutoff_value);
#elif defined(FINAL_CUTOFF)
sprintf(bots_cutoff,"final (%d)",bots_cutoff_value);
#else
strcpy(bots_cutoff,"none");
#endif
}
/***********************************************************************
* main:
**********************************************************************/
cilk int main(int argc, char* argv[])
{
#ifndef BOTS_APP_SELF_TIMING
long bots_t_start;
long bots_t_end;
#endif
Node root;
bots_get_params(argc,argv);
//BOTS_APP_INIT;
uts_read_file(bots_arg_file);
bots_set_info();
#ifdef KERNEL_SEQ_CALL
#ifdef BOTS_APP_CHECK_USES_SEQ_RESULT
if (bots_sequential_flag || bots_check_flag)
#else
if (bots_sequential_flag)
#endif
{
bots_sequential_flag = 1;
KERNEL_SEQ_INIT;
#ifdef BOTS_APP_SELF_TIMING
bots_time_sequential = KERNEL_SEQ_CALL;
#else
bots_t_start = bots_usecs();
KERNEL_SEQ_CALL;
bots_t_end = bots_usecs();
bots_time_sequential = ((double)(bots_t_end-bots_t_start))/1000000;
#endif
KERNEL_SEQ_FINI;
}
#endif
KERNEL_INIT;
#ifdef BOTS_APP_SELF_TIMING
bots_time_program = KERNEL_CALL;
#else
bots_t_start = bots_usecs();
KERNEL_CALL;
sync;
bots_t_end = bots_usecs();
bots_time_program = ((double)(bots_t_end-bots_t_start))/1000000;
#endif
KERNEL_FINI;
#ifdef KERNEL_CHECK
if (bots_check_flag) {
bots_result = KERNEL_CHECK;
}
#endif
BOTS_APP_FINI;
bots_print_results();
return (0);
}