numba / numba

NumPy aware dynamic Python compiler using LLVM
https://numba.pydata.org/
BSD 2-Clause "Simplified" License
9.95k stars 1.13k forks source link

Add (or document) environment variable to disable parallelism #3438

Open mdekstrand opened 6 years ago

mdekstrand commented 6 years ago

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:

terminate called after throwing an instance of 'tbb::missing_wait'
  what():  wait() was not called on the structured_task_group

I see 3 reasonable solutions:

stuartarchibald commented 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...

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.

mdekstrand commented 6 years ago

Yes, that is precisely the purpose. There are two main reasons for this:

mdekstrand commented 6 years ago

The quick workaround is exactly what I was going to do if I need it more urgently than it can get added to Numba 😃 .

hugohadfield commented 5 years ago

+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...

stuartarchibald commented 5 years ago

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.