Skip to content

Commit

Permalink
Add thread ring benchmark
Browse files Browse the repository at this point in the history
Add a thread ring benchmark to tune performance. Begins to address issue #48.
  • Loading branch information
npe9 committed Dec 5, 2016
1 parent f698e86 commit 0107aaf
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
1 change: 1 addition & 0 deletions test/benchmarks/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion test/benchmarks/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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@
Expand Down
58 changes: 58 additions & 0 deletions test/benchmarks/generic/time_thread_ring.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <qthread/qthread.h>
#include <qthread/qloop.h>
#include <qthread/qtimer.h>


// 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<ntasks; i++) {
mailbox[i] = 0;
qthread_empty(&mailbox[i]);
}
}

int main(int argc, char **argv) {
qtimer_t timer = qtimer_create();
double ring_time;
init();

qtimer_start(timer);
qthread_writeEF_const(&mailbox[0], 0);
qt_loop_simple(0, ntasks, passTokens, NULL);
qtimer_stop(timer);
ring_time = qtimer_secs(timer);

printf("\tThread ring time: %f usecs, %f/sec\n", 1000000 * ring_time / ntasks, ntasks / ring_time);

return 0;
}

0 comments on commit 0107aaf

Please sign in to comment.