source: benchmark/readyQ/cycle.cpp@ be73f30

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since be73f30 was 2c7eee0, checked in by Thierry Delisle <tdelisle@…>, 5 years ago

Fixed cycle benchmark to avoid extra unmatched unpark.
Added libfibre implementation.
Split out go common code into bench.go

  • Property mode set to 100644
File size: 2.5 KB
Line 
1
2#include "rq_bench.hpp"
3
4struct Partner {
5 unsigned long long count = 0;
6 unsigned long long blocks = 0;
7 bench_sem self;
8 bench_sem * next;
9};
10
11void partner_main( Partner * self ) {
12 self->count = 0;
13 for(;;) {
14 self->blocks += self->self.wait();
15 self->next->post();
16 self->count ++;
17 if( clock_mode && stop) break;
18 if(!clock_mode && self->count >= stop_count) break;
19 }
20
21 __atomic_fetch_add(&threads_left, -1, __ATOMIC_SEQ_CST);
22}
23
24int main(int argc, char * argv[]) {
25 unsigned ring_size = 2;
26 option_t 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 long long global_blocks = 0;
35 unsigned tthreads = nthreads * ring_size;
36 uint64_t start, end;
37 FibreInit(1, nprocs);
38 {
39 threads_left = tthreads;
40 Fibre * threads[tthreads];
41 Partner thddata[tthreads];
42 for(int i = 0; i < tthreads; i++) {
43 unsigned pi = (i + nthreads) % tthreads;
44 thddata[i].next = &thddata[pi].self;
45 }
46 for(int i = 0; i < tthreads; i++) {
47 threads[i] = new Fibre( reinterpret_cast<void (*)(void *)>(partner_main), &thddata[i] );
48 }
49 printf("Starting\n");
50
51 bool is_tty = isatty(STDOUT_FILENO);
52 start = getTimeNsec();
53
54 for(int i = 0; i < nthreads; i++) {
55 thddata[i].self.post();
56 }
57 wait(start, is_tty);
58
59 stop = true;
60 end = getTimeNsec();
61 printf("\nDone\n");
62
63 for(int i = 0; i < tthreads; i++) {
64 fibre_join( threads[i], nullptr );
65 global_counter += thddata[i].count;
66 global_blocks += thddata[i].blocks;
67 }
68 }
69
70 printf("Duration (ms) : %'ld\n", to_miliseconds(end - start));
71 printf("Number of processors : %'d\n", nprocs);
72 printf("Number of threads : %'d\n", tthreads);
73 printf("Cycle size (# thrds) : %'d\n", ring_size);
74 printf("Total Operations(ops): %'15llu\n", global_counter);
75 printf("Total blocks : %'15llu\n", global_blocks);
76 printf("Ops per second : %'18.2lf\n", ((double)global_counter) / to_fseconds(end - start));
77 printf("ns per ops : %'18.2lf\n", ((double)(end - start)) / global_counter);
78 printf("Ops per threads : %'15llu\n", global_counter / tthreads);
79 printf("Ops per procs : %'15llu\n", global_counter / nprocs);
80 printf("Ops/sec/procs : %'18.2lf\n", (((double)global_counter) / nprocs) / to_fseconds(end - start));
81 printf("ns per ops/procs : %'18.2lf\n", ((double)(end - start)) / (global_counter / nprocs));
82 fflush(stdout);
83 }
84
85 return 0;
86}
Note: See TracBrowser for help on using the repository browser.