| [b35ab2d] | 1 | #include "rq_bench.hfa" | 
|---|
|  | 2 |  | 
|---|
| [2c7eee0] | 3 | struct Partner { | 
|---|
| [b35ab2d] | 4 | unsigned long long count; | 
|---|
| [2c7eee0] | 5 | unsigned long long blocks; | 
|---|
|  | 6 | bench_sem self; | 
|---|
|  | 7 | bench_sem * next; | 
|---|
| [b35ab2d] | 8 | }; | 
|---|
|  | 9 |  | 
|---|
|  | 10 | void ?{}( Partner & this ) { | 
|---|
| [2c7eee0] | 11 | this.count = this.blocks = 0; | 
|---|
|  | 12 | } | 
|---|
|  | 13 |  | 
|---|
|  | 14 | thread BThrd { | 
|---|
|  | 15 | Partner & partner; | 
|---|
|  | 16 | }; | 
|---|
|  | 17 |  | 
|---|
|  | 18 | void ?{}( BThrd & this, Partner * partner ) { | 
|---|
| [b35ab2d] | 19 | ((thread&)this){ bench_cluster }; | 
|---|
| [2c7eee0] | 20 | &this.partner = partner; | 
|---|
| [b35ab2d] | 21 | } | 
|---|
|  | 22 |  | 
|---|
| [2c7eee0] | 23 | void ^?{}( BThrd & mutex this ) {} | 
|---|
|  | 24 |  | 
|---|
|  | 25 | void main( BThrd & thrd ) with(thrd.partner) { | 
|---|
|  | 26 | count = 0; | 
|---|
| [0b84b15] | 27 | for() { | 
|---|
| [2c7eee0] | 28 | blocks += wait( self ); | 
|---|
|  | 29 | post( *next ); | 
|---|
|  | 30 | count ++; | 
|---|
| [0b84b15] | 31 | if( clock_mode && stop) break; | 
|---|
| [2c7eee0] | 32 | if(!clock_mode && count >= stop_count) break; | 
|---|
| [b35ab2d] | 33 | } | 
|---|
|  | 34 |  | 
|---|
|  | 35 | __atomic_fetch_add(&threads_left, -1, __ATOMIC_SEQ_CST); | 
|---|
|  | 36 | } | 
|---|
|  | 37 |  | 
|---|
|  | 38 | int 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; | 
|---|
| [2c7eee0] | 48 | unsigned long long global_blocks  = 0; | 
|---|
| [b35ab2d] | 49 | unsigned tthreads = nthreads * ring_size; | 
|---|
|  | 50 | Time start, end; | 
|---|
|  | 51 | BenchCluster bc = { nprocs }; | 
|---|
|  | 52 | { | 
|---|
|  | 53 | threads_left = tthreads; | 
|---|
| [2c7eee0] | 54 | BThrd * threads[tthreads]; | 
|---|
|  | 55 | Partner thddata[tthreads]; | 
|---|
| [b35ab2d] | 56 | for(i; tthreads) { | 
|---|
|  | 57 | unsigned pi = (i + nthreads) % tthreads; | 
|---|
| [2c7eee0] | 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] }; | 
|---|
| [b35ab2d] | 63 | } | 
|---|
|  | 64 | printf("Starting\n"); | 
|---|
|  | 65 |  | 
|---|
|  | 66 | bool is_tty = isatty(STDOUT_FILENO); | 
|---|
| [e54d0c3] | 67 | start = timeHiRes(); | 
|---|
| [b35ab2d] | 68 |  | 
|---|
|  | 69 | for(i; nthreads) { | 
|---|
| [2c7eee0] | 70 | post( thddata[i].self ); | 
|---|
| [b35ab2d] | 71 | } | 
|---|
| [0b84b15] | 72 | wait(start, is_tty); | 
|---|
| [b35ab2d] | 73 |  | 
|---|
|  | 74 | stop = true; | 
|---|
| [e54d0c3] | 75 | end = timeHiRes(); | 
|---|
| [b35ab2d] | 76 | printf("\nDone\n"); | 
|---|
|  | 77 |  | 
|---|
|  | 78 | for(i; tthreads) { | 
|---|
| [69d1748] | 79 | post( thddata[i].self ); | 
|---|
| [2c7eee0] | 80 | Partner & partner = join( *threads[i] ).partner; | 
|---|
|  | 81 | global_counter += partner.count; | 
|---|
|  | 82 | global_blocks  += partner.blocks; | 
|---|
|  | 83 | delete(threads[i]); | 
|---|
| [b35ab2d] | 84 | } | 
|---|
|  | 85 | } | 
|---|
|  | 86 |  | 
|---|
| [b5d51b0] | 87 | printf("Duration (ms)        : %'ld\n", (end - start)`dms); | 
|---|
| [2c7eee0] | 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); | 
|---|
| [b5d51b0] | 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); | 
|---|
| [2c7eee0] | 95 | printf("Ops per threads      : %'15llu\n", global_counter / tthreads); | 
|---|
|  | 96 | printf("Ops per procs        : %'15llu\n", global_counter / nprocs); | 
|---|
| [b5d51b0] | 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)); | 
|---|
| [b35ab2d] | 99 | fflush(stdout); | 
|---|
|  | 100 | } | 
|---|
|  | 101 |  | 
|---|
|  | 102 | return 0; | 
|---|
| [e54d0c3] | 103 | } | 
|---|