From 52490375a7869bec148369c503e74fb8aeeda530 Mon Sep 17 00:00:00 2001 From: Yichao Yu Date: Tue, 17 May 2016 13:35:21 -0400 Subject: [PATCH] Allow building julia with more than one worker thread by default. --- Make.inc | 4 +++- src/options.h | 4 +++- src/threading.c | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Make.inc b/Make.inc index 0b6f173861435..e8e4222a31e42 100644 --- a/Make.inc +++ b/Make.inc @@ -55,6 +55,8 @@ USE_INTEL_JITEVENTS ?= 0 USEICC ?= 0 USEIFC ?= 0 +JULIA_THREADS := 1 # Enable threading with one thread + ifeq ($(USE_MKL), 1) $(warning "The julia make variable USE_MKL has been renamed to USE_INTEL_MKL") USE_INTEL_MKL := 1 @@ -896,7 +898,7 @@ endif # Threads ifneq ($(JULIA_THREADS), 0) -JCPPFLAGS += -DJULIA_ENABLE_THREADING +JCPPFLAGS += -DJULIA_ENABLE_THREADING -DJULIA_NUM_THREADS=$(JULIA_THREADS) endif # Intel VTune Amplifier diff --git a/src/options.h b/src/options.h index 74a852b99ae31..37c82a6c21d6a 100644 --- a/src/options.h +++ b/src/options.h @@ -97,7 +97,9 @@ // defaults for # threads #define NUM_THREADS_NAME "JULIA_NUM_THREADS" -#define DEFAULT_NUM_THREADS 1 +#ifndef JULIA_NUM_THREADS +# define JULIA_NUM_THREADS 1 +#endif // affinitization behavior #define MACHINE_EXCLUSIVE_NAME "JULIA_EXCLUSIVE" diff --git a/src/threading.c b/src/threading.c index bfc47c8e3676f..cadc1160b9064 100644 --- a/src/threading.c +++ b/src/threading.c @@ -282,13 +282,15 @@ void jl_init_threading(void) // how many threads available, usable int max_threads = jl_cpu_cores(); - jl_n_threads = DEFAULT_NUM_THREADS; + jl_n_threads = JULIA_NUM_THREADS; cp = getenv(NUM_THREADS_NAME); if (cp) { jl_n_threads = (uint64_t)strtol(cp, NULL, 10); } if (jl_n_threads > max_threads) jl_n_threads = max_threads; + if (jl_n_threads <= 0) + jl_n_threads = 1; // set up space for per-thread heaps jl_all_heaps = (struct _jl_thread_heap_t **)malloc(jl_n_threads * sizeof(void*));