From ebbc5f9030ca55e29615d0ddafb5193cbc81b0b4 Mon Sep 17 00:00:00 2001 From: da-woods Date: Fri, 15 May 2020 18:00:17 +0100 Subject: [PATCH] Run ParallelRangeTransform also recursively on function arguments (GH-3608) --- Cython/Compiler/ParseTreeTransforms.py | 1 + tests/run/parallel.pyx | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/Cython/Compiler/ParseTreeTransforms.py b/Cython/Compiler/ParseTreeTransforms.py index 15feda18f..60319f992 100644 --- a/Cython/Compiler/ParseTreeTransforms.py +++ b/Cython/Compiler/ParseTreeTransforms.py @@ -1190,6 +1190,7 @@ class ParallelRangeTransform(CythonTransform, SkipDeclarations): def visit_CallNode(self, node): self.visit(node.function) if not self.parallel_directive: + self.visitchildren(node, exclude=('function',)) return node # We are a parallel directive, replace this node with the diff --git a/tests/run/parallel.pyx b/tests/run/parallel.pyx index c3526556f..c3739b10b 100644 --- a/tests/run/parallel.pyx +++ b/tests/run/parallel.pyx @@ -8,6 +8,9 @@ from libc.stdlib cimport malloc, free openmp.omp_set_nested(1) +cdef int forward(int x) nogil: + return x + def test_parallel(): """ >>> test_parallel() @@ -20,6 +23,9 @@ def test_parallel(): with nogil, cython.parallel.parallel(): buf[threadid()] = threadid() + # Recognise threadid() also when it's used in a function argument. + # See https://github.com/cython/cython/issues/3594 + buf[forward(cython.parallel.threadid())] = forward(threadid()) for i in range(maxthreads): assert buf[i] == i -- 2.25.1