source: benchmark/readyQ/cycle.cpp @ 7711064

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 7711064 was 56ac392, checked in by Thierry Delisle <tdelisle@…>, 3 years ago

Moved single_sem to rq_bench.hpp which was duplicated across multiple fibre benchmarks.

  • Property mode set to 100644
File size: 2.5 KB
Line 
1
2#include "rq_bench.hpp"
3#include <libfibre/fibre.h>
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        };
31        BENCH_OPT_PARSE("libfibre cycle benchmark");
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];
43                        for(int i = 0; i < tthreads; i++) {
44                                unsigned pi = (i + nthreads) % tthreads;
45                                thddata[i].next = &thddata[pi].self;
46                        }
47                        for(int i = 0; i < tthreads; i++) {
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);
53                        start = timeHiRes();
54
55                        for(int i = 0; i < nthreads; i++) {
56                                thddata[i].self.post();
57                        }
58                        wait<Fibre>(start, is_tty);
59
60                        stop = true;
61                        end = timeHiRes();
62                        printf("\nDone\n");
63
64                        for(int i = 0; i < tthreads; i++) {
65                                thddata[i].self.post();
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;
88}
Note: See TracBrowser for help on using the repository browser.