8 void bench(); // defined by user
9 void start_thread_group(int nth
, void(*f
)(int tid
));
11 int main(int argc
, char **argv
) {
14 bench_nthread
= atoi(argv
[1]);
17 bench_niter
= atoi(argv
[2]);
19 bench_mode
= atoi(argv
[3]);
22 clock_gettime(CLOCK_MONOTONIC
, &tp0
);
25 clock_gettime(CLOCK_MONOTONIC
, &tp1
);
26 unsigned long long t
=
27 (tp1
.tv_sec
* 1000000000ULL + tp1
.tv_nsec
) -
28 (tp0
.tv_sec
* 1000000000ULL + tp0
.tv_nsec
);
29 fprintf(stderr
, "%llu ns/iter\n", t
/ bench_niter
);
30 fprintf(stderr
, "DONE\n");
33 void start_thread_group(int nth
, void(*f
)(int tid
)) {
34 pthread_t
*th
= (pthread_t
*)malloc(nth
* sizeof(pthread_t
));
35 for (int i
= 0; i
< nth
; i
++)
36 pthread_create(&th
[i
], 0, (void*(*)(void*))f
, (void*)(long)i
);
37 for (int i
= 0; i
< nth
; i
++)
38 pthread_join(th
[i
], 0);