Commit e2a70313 authored by Stefan Behnel's avatar Stefan Behnel

Re-allow None as argument in "parallel(num_threads=None)", seems to be explicitly allowed.

But at least detect and disallow duplicate keyword arguments to parallel() and prange().
parent 227fdb1e
......@@ -8016,11 +8016,17 @@ class ParallelStatNode(StatNode, ParallelNode):
if self.kwargs:
# Try to find num_threads and chunksize keyword arguments
pairs = []
seen = set()
for dictitem in self.kwargs.key_value_pairs:
if dictitem.key.value in seen:
error(self.pos, "Duplicate keyword argument found: %s" % dictitem.key.value)
seen.add(dictitem.key.value)
if dictitem.key.value == 'num_threads':
self.num_threads = dictitem.value
if not dictitem.value.is_none:
self.num_threads = dictitem.value
elif self.is_prange and dictitem.key.value == 'chunksize':
self.chunksize = dictitem.value
if not dictitem.value.is_none:
self.chunksize = dictitem.value
else:
pairs.append(dictitem)
......
......@@ -149,9 +149,6 @@ with nogil, cython.parallel.parallel():
with cython.parallel.parallel():
pass
with nogil, cython.parallel.parallel(num_threads=None):
pass
_ERRORS = u"""
3:8: cython.parallel.parallel is not a module
......@@ -187,6 +184,4 @@ _ERRORS = u"""
139:62: Chunksize not valid for the schedule runtime
145:70: Calling gil-requiring function not allowed without gil
149:33: Nested parallel with blocks are disallowed
152:49: Cannot assign None to int
152:49: Coercion from Python not allowed without the GIL
"""
......@@ -9,12 +9,18 @@ with nogil, parallel(num_threads=None):
pass
# invalid
with nogil, parallel(num_threads=None, num_threads=None):
pass
with nogil, parallel(num_threads=0):
pass
with nogil, parallel(num_threads=i):
pass
with nogil, parallel(num_threads=2, num_threads=2):
pass
with nogil, parallel(num_threads=2):
for i in prange(10, num_threads=2):
pass
......@@ -28,7 +34,9 @@ for i in prange(10, nogil=True, num_threads=2):
pass
_ERRORS = u"""
e_invalid_num_threads.pyx:12:20: argument to num_threads must be greater than 0
e_invalid_num_threads.pyx:19:19: num_threads already declared in outer section
e_invalid_num_threads.pyx:23:19: num_threads must be declared in the parent parallel section
12:20: Duplicate keyword argument found: num_threads
15:20: argument to num_threads must be greater than 0
21:20: Duplicate keyword argument found: num_threads
25:19: num_threads already declared in outer section
29:19: num_threads must be declared in the parent parallel section
"""
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