[Cython] OpenMP thread private variable not recognized (bug report + discussion)

Sturla Molden sturla.molden at gmail.com
Tue Aug 12 16:26:31 CEST 2014


Cython does not do an error here:

- i is recognized as private
- r is recognized as reduction
- w is (correctly) recognized as shared

If you need thread local storage, use threading.local()

I agree that scoped cdefs would be an advantage.

Personally I prefer to avoid OpenMP and just use Python threads and an
internal function (closure) or an internal class. If you start to use
OpenMP, Apple's libdispatch ("GCD"), Intel TBB, or Intel clikplus, you will
soon discover that they are all variations over the same theme: a thread
pool and a closure. Whether you call it a parallel block in OpenMP or an
anonymous block in GCD, it is fundamentally a closure. That's all there is.
You can easily do this with Python threads: Python, unlike C, supports
closures or internal classes directly in the language, and does not need
special extensions like C. Python threads and OpenMP threads will scale
equally well (they are all native OS threads, scheduled in the same way),
and there will be no scoping problems. The sooner you discover you do not
need Cython's prange, the less pain it will cause.

Sturla



More information about the cython-devel mailing list