source: benchmark/readyQ/cycle.cfa @ 56ac392

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 56ac392 was e54d0c3, checked in by Peter A. Buhr <pabuhr@…>, 3 years ago

Fixed benchmarks after another change to getTimeNsec()

  • Property mode set to 100644
File size: 2.6 KB
Line 
1#include "rq_bench.hfa"
2
3struct Partner {
4        unsigned long long count;
5        unsigned long long blocks;
6        bench_sem self;
7        bench_sem * next;
8};
9
10void ?{}( Partner & this ) {
11        this.count = this.blocks = 0;
12}
13
14thread BThrd {
15        Partner & partner;
16};
17
18void ?{}( BThrd & this, Partner * partner ) {
19        ((thread&)this){ bench_cluster };
20        &this.partner = partner;
21}
22
23void ^?{}( BThrd & mutex this ) {}
24
25void main( BThrd & thrd ) with(thrd.partner) {
26        count = 0;
27        for() {
28                blocks += wait( self );
29                post( *next );
30                count ++;
31                if( clock_mode && stop) break;
32                if(!clock_mode && count >= stop_count) break;
33        }
34
35        __atomic_fetch_add(&threads_left, -1, __ATOMIC_SEQ_CST);
36}
37
38int main(int argc, char * argv[]) {
39        unsigned ring_size = 2;
40        cfa_option opt[] = {
41                BENCH_OPT,
42                { 'r', "ringsize", "Number of threads in a cycle", ring_size }
43        };
44        BENCH_OPT_PARSE("cforall cycle benchmark");
45
46        {
47                unsigned long long global_counter = 0;
48                unsigned long long global_blocks  = 0;
49                unsigned tthreads = nthreads * ring_size;
50                Time start, end;
51                BenchCluster bc = { nprocs };
52                {
53                        threads_left = tthreads;
54                        BThrd * threads[tthreads];
55                        Partner thddata[tthreads];
56                        for(i; tthreads) {
57                                unsigned pi = (i + nthreads) % tthreads;
58                                thddata[i].next = &thddata[pi].self;
59                        }
60                        for(int i = 0; i < tthreads; i++) {
61                                threads[i] = malloc();
62                                (*threads[i]){ &thddata[i] };
63                        }
64                        printf("Starting\n");
65
66                        bool is_tty = isatty(STDOUT_FILENO);
67                        start = timeHiRes();
68
69                        for(i; nthreads) {
70                                post( thddata[i].self );
71                        }
72                        wait(start, is_tty);
73
74                        stop = true;
75                        end = timeHiRes();
76                        printf("\nDone\n");
77
78                        for(i; tthreads) {
79                                post( thddata[i].self );
80                                Partner & partner = join( *threads[i] ).partner;
81                                global_counter += partner.count;
82                                global_blocks  += partner.blocks;
83                                delete(threads[i]);
84                        }
85                }
86
87                printf("Duration (ms)        : %'ld\n", (end - start)`dms);
88                printf("Number of processors : %'d\n", nprocs);
89                printf("Number of threads    : %'d\n", tthreads);
90                printf("Cycle size (# thrds) : %'d\n", ring_size);
91                printf("Total Operations(ops): %'15llu\n", global_counter);
92                printf("Total blocks         : %'15llu\n", global_blocks);
93                printf("Ops per second       : %'18.2lf\n", ((double)global_counter) / (end - start)`ds);
94                printf("ns per ops           : %'18.2lf\n", (end - start)`dns / global_counter);
95                printf("Ops per threads      : %'15llu\n", global_counter / tthreads);
96                printf("Ops per procs        : %'15llu\n", global_counter / nprocs);
97                printf("Ops/sec/procs        : %'18.2lf\n", (((double)global_counter) / nprocs) / (end - start)`ds);
98                printf("ns per ops/procs     : %'18.2lf\n", (end - start)`dns / (global_counter / nprocs));
99                fflush(stdout);
100        }
101
102        return 0;
103}
Note: See TracBrowser for help on using the repository browser.