From 0107aafc87b61c0bcf64982c4fbd75a369137b3d Mon Sep 17 00:00:00 2001 From: Noah Evans Date: Mon, 5 Dec 2016 10:26:37 -0700 Subject: [PATCH] Add thread ring benchmark Add a thread ring benchmark to tune performance. Begins to address issue #48. --- test/benchmarks/.gitignore | 1 + test/benchmarks/Makefile.am | 6 ++- test/benchmarks/generic/time_thread_ring.c | 58 ++++++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 test/benchmarks/generic/time_thread_ring.c diff --git a/test/benchmarks/.gitignore b/test/benchmarks/.gitignore index 1b73419d3..57df6af94 100644 --- a/test/benchmarks/.gitignore +++ b/test/benchmarks/.gitignore @@ -42,6 +42,7 @@ time_task_spawn time_thrcrt_bench time_thrcrt_bench_pthread time_threading +time_thread_ring time_uts_aligned time_uts_donecount time_uts_donecount2 diff --git a/test/benchmarks/Makefile.am b/test/benchmarks/Makefile.am index 418417411..fbec33612 100644 --- a/test/benchmarks/Makefile.am +++ b/test/benchmarks/Makefile.am @@ -19,7 +19,9 @@ generic_benchmarks = \ time_halo_swap_all \ time_prodcons_comm \ time_qt_loops \ - time_qt_loopaccums + time_qt_loopaccums \ + time_thread_ring + thesis_benchmarks = \ time_allpairs \ time_wavefront @@ -254,6 +256,8 @@ time_syncvar_producerconsumer_SOURCES = generic/time_syncvar_producerconsumer.c time_threading_SOURCES = generic/time_threading.c +time_thread_ring_SOURCES = generic/time_thread_ring.c + if COMPILE_OMP_BENCHMARKS time_threading_omp_SOURCES = generic/time_threading.omp.c time_threading_omp_CFLAGS = @OPENMP_CFLAGS@ diff --git a/test/benchmarks/generic/time_thread_ring.c b/test/benchmarks/generic/time_thread_ring.c new file mode 100644 index 000000000..10871f363 --- /dev/null +++ b/test/benchmarks/generic/time_thread_ring.c @@ -0,0 +1,58 @@ +#include +#include +#include +#include +#include +#include + + +// native qthreads version of thread-ring, based on Chapel's release version +// https://github.com/chapel-lang/chapel/blob/master/test/release/examples/benchmarks/shootout/threadring.chpl + +//static int n = 1000, ntasks = 503; +static int n = 50000000, ntasks = 503; +static aligned_t *mailbox; + +static void passTokens(size_t start, size_t stop, void* arg) { + uint64_t id = start; + + // printf("entering tokens\n"); + uint64_t numPasses = 0; + do { + // printf("numpasses %lld n %d\n", numPasses, n); + qthread_readFE(&numPasses, &mailbox[id]); + qthread_writeEF_const(&mailbox[(id+1)%ntasks], numPasses+1); + if (numPasses == n) { + printf("%ld\n", (long)id+1); + } + } while (numPasses < n); + // printf("exiting tokens\n"); +} + +static void init() { + assert(qthread_initialize() == 0); + printf("%i threads...\n", qthread_num_workers()); + + // init array of syncvars (code grabbed from stress/feb_stream.c) + mailbox = malloc(ntasks * sizeof(aligned_t)); + for (int i=0; i