source: benchmark/readyQ/cycle.cfa @ 0b84b15

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 0b84b15 was 0b84b15, checked in by Thierry Delisle <tdelisle@…>, 3 years ago

Fixed the cycle benchmark, and implemented go equivalent

  • Property mode set to 100644
File size: 1.9 KB
RevLine 
[b35ab2d]1#include "rq_bench.hfa"
2
3thread Partner {
4        Partner * partner;
5        unsigned long long count;
6};
7
8void ?{}( Partner & this ) {
9        ((thread&)this){ bench_cluster };
10}
11
12void main( Partner & this ) {
[0b84b15]13        this.count = 0;
14        for() {
[b35ab2d]15                park();
16                unpark( *this.partner );
[0b84b15]17                this.count ++;
18                if( clock_mode && stop) break;
19                if(!clock_mode && this.count >= stop_count) break;
[b35ab2d]20        }
21
22        __atomic_fetch_add(&threads_left, -1, __ATOMIC_SEQ_CST);
23}
24
25int main(int argc, char * argv[]) {
26        unsigned ring_size = 2;
27        cfa_option opt[] = {
28                BENCH_OPT,
29                { 'r', "ringsize", "Number of threads in a cycle", ring_size }
30        };
31        BENCH_OPT_PARSE("cforall cycle benchmark");
32
33        {
34                unsigned long long global_counter = 0;
35                unsigned tthreads = nthreads * ring_size;
36                Time start, end;
37                BenchCluster bc = { nprocs };
38                {
39                        threads_left = tthreads;
40                        Partner threads[tthreads];
41                        for(i; tthreads) {
42                                unsigned pi = (i + nthreads) % tthreads;
43                                threads[i].partner = &threads[pi];
44                        }
45                        printf("Starting\n");
46
47                        bool is_tty = isatty(STDOUT_FILENO);
48                        start = getTimeNsec();
49
50                        for(i; nthreads) {
51                                unpark( threads[i] );
52                        }
[0b84b15]53                        wait(start, is_tty);
[b35ab2d]54
55                        stop = true;
56                        end = getTimeNsec();
57                        printf("\nDone\n");
58
59                        for(i; tthreads) {
60                                global_counter += join( threads[i] ).count;
61                        }
62                }
63
64                printf("Took %'ld ms\n", (end - start)`ms);
65                printf("Yields per second   : %'18.2lf\n", ((double)global_counter) / (end - start)`s);
66                printf("ns per yields       : %'18.2lf\n", ((double)(end - start)`ns) / global_counter);
67                printf("Total yields        : %'15llu\n", global_counter);
68                printf("Yields per threads  : %'15llu\n", global_counter / tthreads);
69                printf("Yields per procs    : %'15llu\n", global_counter / nprocs);
70                printf("Yields/sec/procs    : %'18.2lf\n", (((double)global_counter) / nprocs) / (end - start)`s);
71                printf("ns per yields/procs : %'18.2lf\n", ((double)(end - start)`ns) / (global_counter / nprocs));
72                fflush(stdout);
73        }
74
75        return 0;
76}
Note: See TracBrowser for help on using the repository browser.