1 | #include "rq_bench.hfa" |
---|
2 | |
---|
3 | thread __attribute__((aligned(128))) Yielder { |
---|
4 | unsigned long long count; |
---|
5 | }; |
---|
6 | void ?{}( Yielder & this ) { |
---|
7 | ((thread&)this){ "Yielder Thread", bench_cluster }; |
---|
8 | this.count = 0; |
---|
9 | } |
---|
10 | |
---|
11 | void main( Yielder & this ) { |
---|
12 | park(); |
---|
13 | for() { |
---|
14 | yield(); |
---|
15 | this.count++; |
---|
16 | if( clock_mode && stop) break; |
---|
17 | if(!clock_mode && this.count >= stop_count) break; |
---|
18 | } |
---|
19 | |
---|
20 | __atomic_fetch_add(&threads_left, -1, __ATOMIC_SEQ_CST); |
---|
21 | } |
---|
22 | |
---|
23 | int main(int argc, char * argv[]) { |
---|
24 | cfa_option opt[] = { |
---|
25 | BENCH_OPT |
---|
26 | }; |
---|
27 | BENCH_OPT_PARSE("cforall yield benchmark"); |
---|
28 | |
---|
29 | { |
---|
30 | unsigned long long global_counter = 0; |
---|
31 | |
---|
32 | Time start, end; |
---|
33 | BenchCluster bc = { nprocs }; |
---|
34 | { |
---|
35 | threads_left = nthreads; |
---|
36 | Yielder * threads = alloc(nthreads); |
---|
37 | for(i; nthreads) { |
---|
38 | (threads[i]){}; |
---|
39 | } |
---|
40 | |
---|
41 | printf("Starting\n"); |
---|
42 | |
---|
43 | bool is_tty = isatty(STDOUT_FILENO); |
---|
44 | start = timeHiRes(); |
---|
45 | |
---|
46 | for(i; nthreads) { |
---|
47 | unpark( threads[i] ); |
---|
48 | } |
---|
49 | wait(start, is_tty); |
---|
50 | |
---|
51 | stop = true; |
---|
52 | end = timeHiRes(); |
---|
53 | printf("\nDone\n"); |
---|
54 | |
---|
55 | for(i; nthreads) { |
---|
56 | Yielder & y = join( threads[i] ); |
---|
57 | global_counter += y.count; |
---|
58 | ^(threads[i]){}; |
---|
59 | } |
---|
60 | free(threads); |
---|
61 | } |
---|
62 | |
---|
63 | printf("Duration (ms) : %'ld\n", (end - start)`dms); |
---|
64 | printf("Number of processors : %'d\n", nprocs); |
---|
65 | printf("Number of threads : %'d\n", nthreads); |
---|
66 | printf("Total Operations(ops): %'15llu\n", global_counter); |
---|
67 | printf("Ops per second : %'18.2lf\n", ((double)global_counter) / (end - start)`s); |
---|
68 | printf("ns per ops : %'18.2lf\n", (end - start)`dns / global_counter); |
---|
69 | printf("Ops per threads : %'15llu\n", global_counter / nthreads); |
---|
70 | printf("Ops per procs : %'15llu\n", global_counter / nprocs); |
---|
71 | printf("Ops/sec/procs : %'18.2lf\n", (((double)global_counter) / nprocs) / (end - start)`s); |
---|
72 | printf("ns per ops/procs : %'18.2lf\n", (end - start)`dns / (global_counter / nprocs)); |
---|
73 | fflush(stdout); |
---|
74 | } |
---|
75 | } |
---|