diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index b81c0d56ebfdab9c74d94db83841ac9958685ba5..31ce0643afef88656f75487d5a87bb330273fa91 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -6146,8 +6146,20 @@ class ParallelRangeNode(ParallelStatNode): # Note: nsteps is private in an outer scope if present code.putln("%(nsteps)s = (%(stop)s - %(start)s) / %(step)s;" % fmt_dict) + # The target iteration variable might not be initialized, do it only if + # we are executing at least 1 iteration, otherwise we should leave the + # target unaffected. The target iteration variable is firstprivate to + # shut up compiler warnings caused by lastprivate, as the compiler + # erroneously believes that nsteps may be <= 0, leaving the private + # target index uninitialized + code.putln("if (%(nsteps)s > 0)" % fmt_dict) + code.begin_block() + code.putln("%(target)s = 0;" % fmt_dict) + self.generate_loop(code, fmt_dict) + code.end_block() + # And finally, release our privates and write back any closure # variables for temp in start_stop_step: @@ -6173,6 +6185,8 @@ class ParallelRangeNode(ParallelStatNode): if op and op in "+*-&^|" and entry != self.target.entry: code.put(" reduction(%s:%s)" % (op, entry.cname)) else: + if entry == self.target.entry: + code.put(" firstprivate(%s)" % entry.cname) code.put(" lastprivate(%s)" % entry.cname) if self.schedule: diff --git a/tests/run/sequential_parallel.pyx b/tests/run/sequential_parallel.pyx index ae6d084ad50d3731e1b1389016fce42d408f3f07..58c8a9eb993ed64afbfb56786efb3f9844d09397 100644 --- a/tests/run/sequential_parallel.pyx +++ b/tests/run/sequential_parallel.pyx @@ -2,7 +2,7 @@ cimport cython.parallel from cython.parallel import prange, threadid -from libc.stdlib cimport malloc, free +from libc.stdlib cimport malloc, free, abort from libc.stdio cimport puts import sys @@ -67,11 +67,7 @@ def test_propagation(): def test_unsigned_operands(): """ - This test is disabled, as this currently does not work (neither does it - for 'for i from x < i < y:'. I'm not sure we should strife to support - this, at least the C compiler gives a warning. - - test_unsigned_operands() + >>> test_unsigned_operands() 10 """ cdef int i @@ -83,6 +79,8 @@ def test_unsigned_operands(): for i in prange(start, stop, step, nogil=True): steps_taken += 1 + if steps_taken > 10: + abort() return steps_taken