source: benchmark/readyQ/cycle.cpp@ 753fb978

ADT ast-experimental enum forall-pointer-decay pthread-emulation qualifiedEnum
Last change on this file since 753fb978 was ebb6158, checked in by Thierry Delisle <tdelisle@…>, 4 years ago

Minor fixes to warnings, printing and ridiculous go/rust requirements.

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