parallel=True does not work for functions with a jitclass instance as an argument
See original GitHub issueI am using version 0.53.1.
Here is a MWE:
import numpy as np
from numba.experimental import jitclass
from numba import njit, prange, int32, float32, deferred_type
spec = [('value', int32)]
@jitclass(spec)
class Bag(object):
def __init__(self, value):
self.value = value
Bag_type = deferred_type()
Bag_type.define(Bag.class_type.instance_type)
spec = [('value', int32),('bag',Bag_type)]
@jitclass(spec)
class Sack(object):
def __init__(self, value):
self.value = value
self.bag = Bag(value+5)
def call_foo(self,n):
print(foo(self.bag,n))
def call_foo_parallel(self,n):
print(foo_parallel(self.bag,n))
@njit
def foo(bag,n):
out = 0
for i in prange(n):
out += bag.value
return out
@njit(parallel=True)
def foo_parallel(bag,n):
out = 0
for i in prange(n):
out += bag.value
return out
sack = Sack(10)
print(sack.value)
print(sack.bag.value)
sack.call_foo(3)
sack.call_foo_parallel(3)
Which outputs the following:
10 15 45 Traceback (most recent call last):
File “C:\Users\MTH31973\Desktop\commz\commz\tests\benchmark\parallel_processing_benchmark.py”, line 51, in <module> sack.call_foo_parallel(3)
File “C:\Aeroapps\AnacondaP3x64-2020.07\lib\site-packages\numba\experimental\jitclass\boxing.py”, line 60, in wrapper return method(*args, **kwargs)
File “C:\Aeroapps\AnacondaP3x64-2020.07\lib\site-packages\numba\core\dispatcher.py”, line 420, in _compile_for_args error_rewrite(e, ‘typing’)
File “C:\Aeroapps\AnacondaP3x64-2020.07\lib\site-packages\numba\core\dispatcher.py”, line 361, in error_rewrite raise e.with_traceback(None)
TypingError: - Resolution failure for literal arguments: Failed in nopython mode pipeline (step: nopython frontend) Internal error at <numba.core.typeinfer.CallConstraint object at 0x000002588836FD60>. Failed in nopython mode pipeline (step: nopython mode backend) cannot store %“deferred.2578128644272.value” to %“deferred.2578128644272.data”*: mismatching types
File “parallel_processing_benchmark.py”, line 43: def foo_parallel(bag,n): <source elided> out = 0 for i in prange(n): ^
During: lowering “id=11[LoopNest(index_variable = parfor_index.1771, range = (0, n, 1))]{16: <ir.Block at C:\Users\MTH31973\Desktop\commz\commz\tests\benchmark\parallel_processing_benchmark.py (43)>}Var(parfor_index.1771, parallel_processing_benchmark.py:43)” at C:\Users\MTH31973\Desktop\commz\commz\tests\benchmark\parallel_processing_benchmark.py (43) During: resolving callee type: type(CPUDispatcher(<function foo_parallel at 0x0000025887FD3550>)) During: typing of call at C:\Users\MTH31973\Desktop\commz\commz\tests\benchmark\parallel_processing_benchmark.py (31)
Enable logging at debug level for details.
File “parallel_processing_benchmark.py”, line 31: def call_foo_parallel(self,n): print(foo_parallel(self.bag,n)) ^
- Resolution failure for non-literal arguments: None
During: resolving callee type: BoundFunction((<class ‘numba.core.types.misc.ClassInstanceType’>, ‘call_foo_parallel’) for instance.jitclass.Sack#2584933e0d0value:int32,bag:DeferredType#2578128644272) During: typing of call at <string> (3)
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (5 by maintainers)

Top Related StackOverflow Question
@hunterdsp no problem. As to future support, @DrTodd13 might have a view.
As a work around, if you dereference the members of the jitclass you want to use in the
prangebody into temporary variables outside of the loop, it’ll probably compile (just a guess from what the error is).Example:
@songololo no problem!