#include #include #include #include #include #include #include #include volatile bool stop = false; bool clock_mode; double duration = -1; unsigned long long stop_count = 0; unsigned nprocs = 1; unsigned nthreads = 1; volatile unsigned long long threads_left; #define thread_loop for(this.count = 0;; this.count++) #define BENCH_OPT \ {'d', "duration", "Duration of the experiments in seconds", duration }, \ {'i', "iterations", "Number of iterations of the experiments", stop_count }, \ {'t', "nthreads", "Number of threads to use", nthreads }, \ {'p', "nprocs", "Number of processors to use", nprocs } #define BENCH_OPT_PARSE(name) \ { \ int opt_cnt = sizeof(opt) / sizeof(cfa_option); \ char **left; \ parse_args( argc, argv, opt, opt_cnt, "[OPTIONS]...\n" name, left ); \ if(duration > 0 && stop_count > 0) { \ fprintf(stderr, "--duration and --iterations cannot be used together\n"); \ print_args_usage(argc, argv, opt, opt_cnt, "[OPTIONS]...\n" name, true); \ } else if(duration > 0) { \ clock_mode = true; \ stop_count = 0xFFFFFFFFFFFFFFFF; \ printf("Running for %lf seconds\n", duration); \ } else if(stop_count > 0) { \ clock_mode = false; \ printf("Running for %lu iterations\n", stop_count); \ } else { \ duration = 5; clock_mode = true;\ printf("Running for %lf seconds\n", duration); \ } \ } struct cluster & bench_cluster; struct BenchCluster { cluster cl; processor * procs; unsigned nprocs; }; void ?{}( BenchCluster & this, unsigned nprocs ) { (this.cl){ "Benchmark Cluster" }; &bench_cluster = &this.cl; this.nprocs = nprocs; this.procs = alloc( this.nprocs ); for(i; this.nprocs){ processor * p = &this.procs[i]; (*p){ "Benchmark Processor", this.cl }; } } void ^?{}( BenchCluster & this ) { adelete( this.nprocs, this.procs ); ^(this.cl){}; } void wait(const Time & start, bool is_tty) { for() { sleep(100`ms); Time end = getTimeNsec(); Duration delta = end - start; if(is_tty) { printf(" %.1f\r", delta`ds); fflush(stdout); } if( clock_mode && delta >= duration`s ) { break; } else if( !clock_mode && threads_left == 0 ) { break; } } }