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
4657fff3
Commit
4657fff3
authored
May 25, 2011
by
Mark Florisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initialize threads when cython.parallel is imported
parent
468c17af
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
86 additions
and
7 deletions
+86
-7
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+12
-2
Cython/Compiler/ParseTreeTransforms.py
Cython/Compiler/ParseTreeTransforms.py
+5
-0
Cython/Compiler/PyrexTypes.py
Cython/Compiler/PyrexTypes.py
+0
-3
tests/run/sequential_parallel.pyx
tests/run/sequential_parallel.pyx
+68
-1
tests/run/with_gil.pyx
tests/run/with_gil.pyx
+1
-1
No files found.
Cython/Compiler/Nodes.py
View file @
4657fff3
...
...
@@ -6224,7 +6224,8 @@ class ParallelWithBlockNode(ParallelStatNode):
code
.
put
(
"#pragma omp parallel "
)
if
self
.
privates
:
privates
=
[
e
.
cname
for
e
in
self
.
privates
]
privates
=
[
e
.
cname
for
e
in
self
.
privates
if
not
e
.
type
.
is_pyobject
]
code
.
put
(
'private(%s)'
%
', '
.
join
(
privates
))
self
.
privatization_insertion_point
=
code
.
insertion_point
()
...
...
@@ -6239,6 +6240,9 @@ class ParallelWithBlockNode(ParallelStatNode):
self
.
trap_parallel_exit
(
code
)
code
.
end_block
()
# end parallel block
# After the parallel block all privates are undefined
self
.
initialize_privates_to_nan
(
code
)
continue_
=
code
.
label_used
(
code
.
continue_label
)
break_
=
code
.
label_used
(
code
.
break_label
)
...
...
@@ -6489,7 +6493,9 @@ class ParallelRangeNode(ParallelStatNode):
else
:
if
entry
==
self
.
target
.
entry
:
code
.
put
(
" firstprivate(%s)"
%
entry
.
cname
)
code
.
put
(
" lastprivate(%s)"
%
entry
.
cname
)
if
not
entry
.
type
.
is_pyobject
:
code
.
put
(
" lastprivate(%s)"
%
entry
.
cname
)
if
self
.
schedule
:
code
.
put
(
" schedule(%s)"
%
self
.
schedule
)
...
...
@@ -7576,6 +7582,10 @@ proto="""
#endif
"""
)
init_threads
=
UtilityCode
(
init
=
"PyEval_InitThreads();
\
n
"
,
)
#------------------------------------------------------------------------------------
# Note that cPython ignores PyTrace_EXCEPTION,
...
...
Cython/Compiler/ParseTreeTransforms.py
View file @
4657fff3
...
...
@@ -650,6 +650,8 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
self
.
wrong_scope_error
(
node
.
pos
,
key
,
'module'
)
del
node
.
directive_comments
[
key
]
self
.
module_scope
=
node
.
scope
directives
=
copy
.
deepcopy
(
Options
.
directive_defaults
)
directives
.
update
(
copy
.
deepcopy
(
self
.
compilation_directive_defaults
))
directives
.
update
(
node
.
directive_comments
)
...
...
@@ -684,6 +686,8 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
directive
[
-
1
]
not
in
self
.
valid_parallel_directives
):
error
(
pos
,
"No such directive: %s"
%
full_name
)
self
.
module_scope
.
use_utility_code
(
Nodes
.
init_threads
)
return
result
def
visit_CImportStatNode
(
self
,
node
):
...
...
@@ -699,6 +703,7 @@ class InterpretCompilerDirectives(CythonTransform, SkipDeclarations):
self
.
cython_module_names
.
add
(
u"cython"
)
self
.
parallel_directives
[
u"cython.parallel"
]
=
node
.
module_name
self
.
module_scope
.
use_utility_code
(
Nodes
.
init_threads
)
elif
node
.
as_name
:
self
.
directive_names
[
node
.
as_name
]
=
node
.
module_name
[
7
:]
else
:
...
...
Cython/Compiler/PyrexTypes.py
View file @
4657fff3
...
...
@@ -387,9 +387,6 @@ class PyObjectType(PyrexType):
else
:
return
cname
def
invalid_value
(
self
):
return
"1"
class
BuiltinObjectType
(
PyObjectType
):
# objstruct_cname string Name of PyObject struct
...
...
tests/run/sequential_parallel.pyx
View file @
4657fff3
...
...
@@ -233,8 +233,14 @@ def test_nan_init():
raise
Exception
(
"One of the values was not initialized to a maximum "
"or NaN value"
)
c1
=
20
with
nogil
,
cython
.
parallel
.
parallel
():
c1
=
16
assert
c1
not
in
(
16
,
20
),
c1
cdef
void
nogil_print
(
char
*
s
)
with
gil
:
print
s
print
s
.
decode
(
'ascii'
)
def
test_else_clause
():
"""
...
...
@@ -343,3 +349,64 @@ def test_return():
"""
print
parallel_return
()
def
test_parallel_exceptions
():
"""
>>> test_parallel_exceptions()
('I am executed first', 0)
('propagate me',) 0
"""
cdef
int
i
,
j
,
sum
=
0
mylist
=
[]
try
:
for
i
in
prange
(
10
,
nogil
=
True
):
try
:
for
j
in
prange
(
10
):
with
gil
:
raise
Exception
(
"propagate me"
)
sum
+=
i
*
j
sum
+=
i
finally
:
with
gil
:
mylist
.
append
((
"I am executed first"
,
sum
))
except
Exception
,
e
:
print
mylist
[
0
]
print
e
.
args
,
sum
def
test_parallel_with_gil_return
():
"""
>>> test_parallel_with_gil_return()
True
45
"""
cdef
int
i
,
sum
=
0
for
i
in
prange
(
10
,
nogil
=
True
):
with
gil
:
obj
=
i
sum
+=
obj
print
obj
in
range
(
10
)
with
nogil
,
cython
.
parallel
.
parallel
():
with
gil
:
return
sum
def
test_parallel_with_gil_continue
():
"""
>>> test_parallel_with_gil_continue()
20
"""
cdef
int
i
,
sum
=
0
for
i
in
prange
(
10
,
nogil
=
True
):
with
cython
.
parallel
.
parallel
():
with
gil
:
if
i
%
2
:
continue
sum
+=
i
print
sum
tests/run/with_gil.pyx
View file @
4657fff3
...
...
@@ -202,7 +202,7 @@ def test_loops_and_boxing():
with
nogil
:
with
gil
:
print
string
.
decode
(
'
ASCII
'
)
print
string
.
decode
(
'
ascii
'
)
for
c
in
string
[
4
:]:
print
"%c"
%
c
else
:
...
...
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