1 | #include "rq_bench.hfa" |
---|
2 | |
---|
3 | thread Partner { |
---|
4 | Partner * partner; |
---|
5 | unsigned long long count; |
---|
6 | }; |
---|
7 | |
---|
8 | void ?{}( Partner & this ) { |
---|
9 | ((thread&)this){ bench_cluster }; |
---|
10 | } |
---|
11 | |
---|
12 | void main( Partner & this ) { |
---|
13 | this.count = 0; |
---|
14 | for() { |
---|
15 | park(); |
---|
16 | unpark( *this.partner ); |
---|
17 | this.count ++; |
---|
18 | if( clock_mode && stop) break; |
---|
19 | if(!clock_mode && this.count >= stop_count) break; |
---|
20 | } |
---|
21 | |
---|
22 | __atomic_fetch_add(&threads_left, -1, __ATOMIC_SEQ_CST); |
---|
23 | } |
---|
24 | |
---|
25 | int 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 | } |
---|
53 | wait(start, 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 | } |
---|