Commit 070a130a authored by Julien Jerphanion's avatar Julien Jerphanion

Use the effective number of threads for the Scheduler

One can now use `taskset(1)` and limit the number of workers
accordingly.
parent a8f1170b
INCLUDE_DIRS = -I/usr/include/python3.9
EXE = kdtree
CXX = g++
CPPFLAGS = -O2 -g -Wno-unused-result -Wsign-compare -pthread $(INCLUDE_DIRS)
CPPFLAGS = -O2 -g -Wno-unused-result -Wsign-compare -pthread $(INCLUDE_DIRS) -fopenmp
LDFLAGS += -Wl,--unresolved-symbols=ignore-all
MACROS = -DNPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION
EXT_SUFFIX := $(shell python3 -c "import sysconfig; print(sysconfig.get_config_var('EXT_SUFFIX'))")
......
......@@ -8,6 +8,8 @@ np.import_array()
from runtime.runtime cimport BatchMailBox, NullResult, Scheduler, WaitResult
from libc.stdio cimport printf
from libc.stdlib cimport malloc, free
from openmp cimport omp_get_max_threads
from cython.parallel import prange
......@@ -479,6 +481,12 @@ cdef cypclass KDTree:
cdef I_t n = X.shape[0]
cdef I_t d = X.shape[1]
cdef I_t initialised = 0
# Accessing _SC_NPROCESSORS_ONLN does not return the
# effective number of threads which were assigned to
# this task using `taskset(1)` for instance.
#
# This OpenMP API is a workable way to access it.
cdef I_t num_workers = omp_get_max_threads()
self._n = n
self._d = d
......@@ -491,7 +499,7 @@ cdef cypclass KDTree:
# Recurvisely building the tree here
global scheduler
scheduler = Scheduler()
scheduler = Scheduler(num_workers)
cdef active Counter counter = consume Counter()
self._root = consume Node()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment