source: benchmark/readyQ/churn.cfa@ a8ef59e

ADT ast-experimental enum pthread-emulation qualifiedEnum
Last change on this file since a8ef59e was 75965a6, checked in by Peter A. Buhr <pabuhr@…>, 4 years ago

replace thread_rand with prng, replace xorshift64 with xorshift_13_7_17

  • Property mode set to 100644
File size: 2.5 KB
Line 
1#include "rq_bench.hfa"
2
3unsigned spot_cnt = 2;
4bench_sem * volatile * spots;
5
6thread BThrd {
7 unsigned long long count;
8 unsigned long long blocks;
9 bench_sem sem;
10};
11
12void ?{}( BThrd & this ) {
13 ((thread&)this){ bench_cluster };
14 this.count = 0;
15 this.blocks = 0;
16}
17
18void ^?{}( BThrd & mutex this ) {}
19
20void main( BThrd & this ) with( this ) {
21 wait( sem );
22 for() {
23 uint32_t r = prng();
24 bench_sem * next = __atomic_exchange_n(&spots[r % spot_cnt], &sem, __ATOMIC_SEQ_CST);
25 if(next) post( *next );
26 blocks += wait( sem );
27 count ++;
28 if( clock_mode && stop) break;
29 if(!clock_mode && count >= stop_count) break;
30 }
31
32 __atomic_fetch_add(&threads_left, -1, __ATOMIC_SEQ_CST);
33}
34
35
36int main(int argc, char * argv[]) {
37 cfa_option opt[] = {
38 BENCH_OPT,
39 { 's', "spots", "Number of spots in the system", spot_cnt }
40 };
41 BENCH_OPT_PARSE("cforall cycle benchmark");
42
43 {
44 unsigned long long global_counter = 0;
45 unsigned long long global_blocks = 0;
46 Time start, end;
47 BenchCluster bc = { nprocs };
48 {
49 spots = aalloc(spot_cnt);
50 for(i; spot_cnt) {
51 spots[i] = 0p;
52 }
53
54 threads_left = nthreads;
55 BThrd * threads[nthreads];
56 for(i; nthreads ) {
57 threads[i] = malloc();
58 (*threads[i]){};
59 }
60 printf("Starting\n");
61
62 bool is_tty = isatty(STDOUT_FILENO);
63 start = timeHiRes();
64
65 for(i; nthreads) {
66 post( threads[i]->sem );
67 }
68 wait(start, is_tty);
69
70 stop = true;
71 end = timeHiRes();
72 printf("\nDone\n");
73
74 for(i; nthreads) {
75 post( threads[i]->sem );
76 BThrd & thrd = join( *threads[i] );
77 global_counter += thrd.count;
78 global_blocks += thrd.blocks;
79 delete(threads[i]);
80 }
81
82 free(spots);
83 }
84
85 printf("Duration (ms) : %'lf\n", (end - start)`dms);
86 printf("Number of processors : %'d\n", nprocs);
87 printf("Number of threads : %'d\n", nthreads);
88 printf("Number of spots : %'d\n", spot_cnt);
89 printf("Total Operations(ops): %'15llu\n", global_counter);
90 printf("Total blocks : %'15llu\n", global_blocks);
91 printf("Ops per second : %'18.2lf\n", ((double)global_counter) / (end - start)`ds);
92 printf("ns per ops : %'18.2lf\n", (end - start)`dns / global_counter);
93 printf("Ops per threads : %'15llu\n", global_counter / nthreads);
94 printf("Ops per procs : %'15llu\n", global_counter / nprocs);
95 printf("Ops/sec/procs : %'18.2lf\n", (((double)global_counter) / nprocs) / (end - start)`ds);
96 printf("ns per ops/procs : %'18.2lf\n", (end - start)`dns / (global_counter / nprocs));
97 fflush(stdout);
98 }
99
100 return 0;
101}
Note: See TracBrowser for help on using the repository browser.