Open mdekstrand opened 6 years ago
Thanks for the request, it will be discussed at the next core developer meeting (next week).
General question to help drive discussion: What is the practical reason for wanting to do this? Is it to test e.g. the standard nopython=True
CPU target vs. parallel
+ 1 thread vs. parallel
+ n
threads ?
A bit of background...
parallel
code generation. The parallel
target makes it such that there is a function that can be executed in parallel, the internal scheduling of which is left to the threading backend. AFAIR setting the number of threads to one (or indeed any other number) does not impact the creation or representation of the function amenable to parallel execution. Further, parallel
target functions depend on the threading backend for execution, calls to the threading layer are generated and compiled into the jitted code.parallel
target compiler passes for the non-parallel cpu target, this somewhat aligning code generation between the two targets.As a quick work around, could you augment your code with something like:
if os.environ.get('NUMBA_DISABLE_PARALLEL', None) is not None:
nb_parallel = False
from numba import njit
else:
nb_parallel = True
from numba import jit
njit = jit(parallel=True, nopython=True)
for a similar effect?
As to the issue with NUMBA_NUM_THREADS=1
and TBB, this is a bug, thanks, reported here.
Yes, that is precisely the purpose. There are two main reasons for this:
The quick workaround is exactly what I was going to do if I need it more urgently than it can get added to Numba 😃 .
+1 for the NUMBA_DISABLE_PARALLEL environment variable to exist by default. Was running a workshop with ~20 people installing a library dependent on Numba and had problems with the parallel layer for many of them. Had to tell them to use NUMBA_DISABLE_JIT before loading the library which made it ~100x slower, while not an ideal situation NUMBA_DISABLE_PARALLEL would have been very useful...
I don't think that this is a hugely involved task, I've scheduled it for the 0.44 RC (the next release cycle). @hugohadfield (or indeed anyone) If you'd like to have sooner, PRs are welcome and the core developers can assist/provide guidance as needed.
Feature request
Right now, there is not a (documented) way to disable Numba parallelism from environment variables. Setting
NUMBA_NUM_THREADS=1
still does something with the threading layer, and with the TBB threading layer this also results in a TBB shutdown error:I see 3 reasonable solutions:
NUMBA_DISABLE_PARALLEL
environment variable that is the equivalent of ignoringparallel=True
none
option forNUMBA_THREADING_LAYER
that disables threading entirely.