Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
c8bf02a1
Commit
c8bf02a1
authored
Feb 05, 2012
by
Mark Florisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup object temporaries in parallel contexts from with gil blocks
parent
630d0edd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
13 deletions
+50
-13
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+27
-13
tests/run/sequential_parallel.pyx
tests/run/sequential_parallel.pyx
+23
-0
No files found.
Cython/Compiler/Nodes.py
View file @
c8bf02a1
...
...
@@ -6935,6 +6935,7 @@ class ParallelStatNode(StatNode, ParallelNode):
body
=
None
is_prange
=
False
is_nested_prange
=
False
error_label_used
=
False
...
...
@@ -7250,15 +7251,16 @@ class ParallelStatNode(StatNode, ParallelNode):
c
.
put
(
" shared(%s)"
%
', '
.
join
(
shared_vars
))
def
cleanup_slice_temps
(
self
,
code
):
# Now clean up any memoryview slice temporaries
first
=
True
for
temp
,
type
in
self
.
temps
:
if
type
.
is_memoryviewslice
:
if
first
:
first
=
False
code
.
putln
(
"/* Clean up any temporary slices */"
)
code
.
put_xdecref_memoryviewslice
(
temp
,
have_gil
=
False
)
def
cleanup_temps
(
self
,
code
):
# Now clean up any memoryview slice and object temporaries
if
self
.
is_parallel
and
not
self
.
is_nested_prange
:
code
.
putln
(
"/* Clean up any temporaries */"
)
for
temp
,
type
in
self
.
temps
:
if
type
.
is_memoryviewslice
:
code
.
put_xdecref_memoryviewslice
(
temp
,
have_gil
=
False
)
elif
type
.
is_pyobject
:
code
.
put_xdecref
(
temp
,
type
)
code
.
putln
(
"%s = NULL;"
%
temp
)
def
setup_parallel_control_flow_block
(
self
,
code
):
"""
...
...
@@ -7306,7 +7308,15 @@ class ParallelStatNode(StatNode, ParallelNode):
self
.
begin_of_parallel_block
=
code
.
insertion_point
()
def
end_parallel_block
(
self
,
code
):
"Acquire the GIL, deallocate threadstate, release"
"""
To ensure all OpenMP threads have thread states, we ensure the GIL
in each thread (which creates a thread state if it doesn't exist),
after which we release the GIL.
On exit, reacquire the GIL and release the thread state.
If compiled without OpenMP support (at the C level), then we still have
to acquire the GIL to decref any object temporaries.
"""
if
self
.
error_label_used
:
begin_code
=
self
.
begin_of_parallel_block
end_code
=
code
...
...
@@ -7318,11 +7328,16 @@ class ParallelStatNode(StatNode, ParallelNode):
end_code
.
putln
(
"#ifdef _OPENMP"
)
end_code
.
putln
(
"Py_END_ALLOW_THREADS"
)
end_code
.
putln
(
"#else"
)
end_code
.
put_safe
(
"{
\
n
"
)
end_code
.
put_ensure_gil
()
end_code
.
putln
(
"#endif /* _OPENMP */"
)
self
.
cleanup_temps
(
end_code
)
end_code
.
put_release_ensured_gil
()
end_code
.
putln
(
"#ifndef _OPENMP"
)
end_code
.
put_safe
(
"}
\
n
"
)
end_code
.
putln
(
"#endif /* _OPENMP */"
)
self
.
cleanup_slice_temps
(
code
)
def
trap_parallel_exit
(
self
,
code
,
should_flush
=
False
):
"""
Trap any kind of return inside a parallel construct. 'should_flush'
...
...
@@ -7643,7 +7658,6 @@ class ParallelRangeNode(ParallelStatNode):
start
=
stop
=
step
=
None
is_prange
=
True
is_nested_prange
=
False
nogil
=
None
schedule
=
None
...
...
tests/run/sequential_parallel.pyx
View file @
c8bf02a1
...
...
@@ -681,3 +681,26 @@ def test_chunksize():
sum
+=
i
print
sum
cdef
class
PrintOnDealloc
(
object
):
def
__dealloc__
(
self
):
print
"deallocating..."
def
error
():
raise
Exception
(
"propagate me"
)
def
test_clean_temps
():
"""
>>> test_clean_temps()
deallocating...
propagate me
"""
cdef
Py_ssize_t
i
try
:
for
i
in
prange
(
100
,
nogil
=
True
,
num_threads
=
1
):
with
gil
:
x
=
PrintOnDealloc
()
+
error
()
except
Exception
,
e
:
print
e
.
args
[
0
]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment