Commit 40417d36 authored by Mark Florisson's avatar Mark Florisson

Allocate thread-state for each OpenMP thread

Save exc_info in parallel section and re-raise outside in master thread
parent 04a8c7fe
...@@ -1400,7 +1400,7 @@ class CCodeWriter(object): ...@@ -1400,7 +1400,7 @@ class CCodeWriter(object):
self.putln("#ifdef WITH_THREAD") self.putln("#ifdef WITH_THREAD")
if declare_gilstate: if declare_gilstate:
self.put("PyGILState_STATE ") self.put("PyGILState_STATE ")
self.putln("_save = PyGILState_Ensure();") self.putln("__pyx_gilstate_save = PyGILState_Ensure();")
self.putln("#endif") self.putln("#endif")
def put_release_ensured_gil(self): def put_release_ensured_gil(self):
...@@ -1408,7 +1408,7 @@ class CCodeWriter(object): ...@@ -1408,7 +1408,7 @@ class CCodeWriter(object):
Releases the GIL, corresponds to `put_ensure_gil`. Releases the GIL, corresponds to `put_ensure_gil`.
""" """
self.putln("#ifdef WITH_THREAD") self.putln("#ifdef WITH_THREAD")
self.putln("PyGILState_Release(_save);") self.putln("PyGILState_Release(__pyx_gilstate_save);")
self.putln("#endif") self.putln("#endif")
def put_acquire_gil(self): def put_acquire_gil(self):
...@@ -1427,7 +1427,7 @@ class CCodeWriter(object): ...@@ -1427,7 +1427,7 @@ class CCodeWriter(object):
def declare_gilstate(self): def declare_gilstate(self):
self.putln("#ifdef WITH_THREAD") self.putln("#ifdef WITH_THREAD")
self.putln("PyGILState_STATE _save;") self.putln("PyGILState_STATE __pyx_gilstate_save;")
self.putln("#endif") self.putln("#endif")
# error handling # error handling
......
...@@ -108,6 +108,14 @@ exc_value_name = pyrex_prefix + "exc_value" ...@@ -108,6 +108,14 @@ exc_value_name = pyrex_prefix + "exc_value"
exc_tb_name = pyrex_prefix + "exc_tb" exc_tb_name = pyrex_prefix + "exc_tb"
exc_lineno_name = pyrex_prefix + "exc_lineno" exc_lineno_name = pyrex_prefix + "exc_lineno"
parallel_exc_type = pyrex_prefix + "parallel_exc_type"
parallel_exc_value = pyrex_prefix + "parallel_exc_value"
parallel_exc_tb = pyrex_prefix + "parallel_exc_tb"
parallel_filename = pyrex_prefix + "parallel_filename"
parallel_lineno = pyrex_prefix + "parallel_lineno"
parallel_clineno = pyrex_prefix + "parallel_clineno"
parallel_why = pyrex_prefix + "parallel_why"
exc_vars = (exc_type_name, exc_value_name, exc_tb_name) exc_vars = (exc_type_name, exc_value_name, exc_tb_name)
api_name = pyrex_prefix + "capi__" api_name = pyrex_prefix + "capi__"
......
This diff is collapsed.
...@@ -6,6 +6,8 @@ from cython.parallel import prange, threadid ...@@ -6,6 +6,8 @@ from cython.parallel import prange, threadid
cimport openmp cimport openmp
from libc.stdlib cimport malloc, free from libc.stdlib cimport malloc, free
openmp.omp_set_nested(1)
def test_parallel(): def test_parallel():
""" """
>>> test_parallel() >>> test_parallel()
......
...@@ -402,6 +402,25 @@ def test_parallel_exceptions(): ...@@ -402,6 +402,25 @@ def test_parallel_exceptions():
print mylist[0] print mylist[0]
print e.args, sum print e.args, sum
def test_parallel_exceptions2():
"""
>>> test_parallel_exceptions2()
Traceback (most recent call last):
...
Exception: propagate me
"""
cdef int i, j, k
for i in prange(10, nogil=True):
for j in prange(10):
for k in prange(10):
if i + j + k > 20:
with gil:
raise Exception("propagate me")
break
continue
return
def test_parallel_with_gil_return(): def test_parallel_with_gil_return():
""" """
>>> test_parallel_with_gil_return() >>> test_parallel_with_gil_return()
......
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