source: benchmark/readyQ/cycle.cfa@ 994028dc

ADT ast-experimental
Last change on this file since 994028dc was 1f950c3b, checked in by Thierry Delisle <tdelisle@…>, 3 years ago

Fixed some small errors in benchmarks

  • Property mode set to 100644
File size: 2.7 KB
RevLine 
[b35ab2d]1#include "rq_bench.hfa"
2
[2c7eee0]3struct Partner {
[b35ab2d]4 unsigned long long count;
[2c7eee0]5 unsigned long long blocks;
6 bench_sem self;
7 bench_sem * next;
[b35ab2d]8};
9
10void ?{}( Partner & this ) {
[2c7eee0]11 this.count = this.blocks = 0;
12}
13
14thread BThrd {
15 Partner & partner;
16};
17
18void ?{}( BThrd & this, Partner * partner ) {
[b35ab2d]19 ((thread&)this){ bench_cluster };
[2c7eee0]20 &this.partner = partner;
[b35ab2d]21}
22
[2c7eee0]23void ^?{}( BThrd & mutex this ) {}
24
25void 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
38int 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;
[8fe35be]54 BThrd ** threads = alloc(tthreads);
55 Partner * thddata = alloc(tthreads);
[b35ab2d]56 for(i; tthreads) {
[1f950c3b]57 (thddata[i]){};
[b35ab2d]58 unsigned pi = (i + nthreads) % tthreads;
[2c7eee0]59 thddata[i].next = &thddata[pi].self;
60 }
61 for(int i = 0; i < tthreads; i++) {
62 threads[i] = malloc();
63 (*threads[i]){ &thddata[i] };
[b35ab2d]64 }
65 printf("Starting\n");
66
67 bool is_tty = isatty(STDOUT_FILENO);
[e54d0c3]68 start = timeHiRes();
[b35ab2d]69
70 for(i; nthreads) {
[2c7eee0]71 post( thddata[i].self );
[b35ab2d]72 }
[0b84b15]73 wait(start, is_tty);
[b35ab2d]74
75 stop = true;
[e54d0c3]76 end = timeHiRes();
[b35ab2d]77 printf("\nDone\n");
78
79 for(i; tthreads) {
[69d1748]80 post( thddata[i].self );
[2c7eee0]81 Partner & partner = join( *threads[i] ).partner;
82 global_counter += partner.count;
83 global_blocks += partner.blocks;
84 delete(threads[i]);
[b35ab2d]85 }
[8fe35be]86 free(threads);
87 free(thddata);
[b35ab2d]88 }
89
[ebf3989]90 printf("Duration (ms) : %'lf\n", (end - start)`dms);
[2c7eee0]91 printf("Number of processors : %'d\n", nprocs);
92 printf("Number of threads : %'d\n", tthreads);
93 printf("Cycle size (# thrds) : %'d\n", ring_size);
94 printf("Total Operations(ops): %'15llu\n", global_counter);
95 printf("Total blocks : %'15llu\n", global_blocks);
[b5d51b0]96 printf("Ops per second : %'18.2lf\n", ((double)global_counter) / (end - start)`ds);
97 printf("ns per ops : %'18.2lf\n", (end - start)`dns / global_counter);
[2c7eee0]98 printf("Ops per threads : %'15llu\n", global_counter / tthreads);
99 printf("Ops per procs : %'15llu\n", global_counter / nprocs);
[b5d51b0]100 printf("Ops/sec/procs : %'18.2lf\n", (((double)global_counter) / nprocs) / (end - start)`ds);
101 printf("ns per ops/procs : %'18.2lf\n", (end - start)`dns / (global_counter / nprocs));
[b35ab2d]102 fflush(stdout);
103 }
104
105 return 0;
[e54d0c3]106}
Note: See TracBrowser for help on using the repository browser.