1 | #include "rq_bench.hfa" |
---|
2 | |
---|
3 | thread Partner { |
---|
4 | Partner * partner; |
---|
5 | unsigned long long count; |
---|
6 | bool first; |
---|
7 | }; |
---|
8 | |
---|
9 | void ?{}( Partner & this ) { |
---|
10 | ((thread&)this){ bench_cluster }; |
---|
11 | } |
---|
12 | |
---|
13 | void main( Partner & this ) { |
---|
14 | thread_loop { |
---|
15 | park(); |
---|
16 | unpark( *this.partner ); |
---|
17 | } |
---|
18 | |
---|
19 | __atomic_fetch_add(&threads_left, -1, __ATOMIC_SEQ_CST); |
---|
20 | |
---|
21 | if(this.first) park(); |
---|
22 | } |
---|
23 | |
---|
24 | int main(int argc, char * argv[]) { |
---|
25 | unsigned ring_size = 2; |
---|
26 | cfa_option opt[] = { |
---|
27 | BENCH_OPT, |
---|
28 | { 'r', "ringsize", "Number of threads in a cycle", ring_size } |
---|
29 | }; |
---|
30 | BENCH_OPT_PARSE("cforall cycle benchmark"); |
---|
31 | |
---|
32 | { |
---|
33 | unsigned long long global_counter = 0; |
---|
34 | unsigned tthreads = nthreads * ring_size; |
---|
35 | Time start, end; |
---|
36 | BenchCluster bc = { nprocs }; |
---|
37 | { |
---|
38 | threads_left = tthreads; |
---|
39 | Partner threads[tthreads]; |
---|
40 | for(i; tthreads) { |
---|
41 | unsigned pi = (i + nthreads) % tthreads; |
---|
42 | threads[i].partner = &threads[pi]; |
---|
43 | threads[i].first = i < nthreads; |
---|
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 | } |
---|
53 | wait(start, end, is_tty); |
---|
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 | } |
---|