Thanks again for making Numba! I am still a big fan and since my last post I have gotten my entire body covered in Numba-inspired tattooes! (OK, that’s also not true, but it could be!)
My question this time is whether it is possible to somehow switch whether a Numba Jit function will run in parallel or serial mode.
The reason this is important to me, is that I am using a function foo()
from a Python package, which indirectly calls another function in the same package called bar()
, which has been wrapped in Numba Jit, like this:
from numba import njit, prange
def foo(x):
# Do something ...
y = bar(x)
# Do something ...
return y
@njit(parallel=False)
def bar(x):
for i in prange(len(x)):
x[i] += i
return x
I can call both foo()
and bar()
from my own code. Sometimes I would like to run bar()
in parallel mode and sometimes in serial mode. And I would also like this mode to be used when foo()
calls bar()
.
Is there a way to change the parallel / serial mode of a Jit function after it has been defined?
Perhaps something like this:
# Switch to parallel mode for the bar-function.
bar.parallel = True
# Switch to serial mode for the bar-function.
bar.parallel = False
If this is currently not possible, would it be possible to implement this? Or is there a work-around / hack to make this work?
Thanks!