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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
3a446eee
Commit
3a446eee
authored
Jul 09, 2011
by
Mark Florisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Disallow object reductions + support CF
parent
b8a6081e
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
2 deletions
+58
-2
Cython/Compiler/FlowControl.py
Cython/Compiler/FlowControl.py
+7
-0
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+10
-2
tests/errors/e_cython_parallel_pyobject_reduction.pyx
tests/errors/e_cython_parallel_pyobject_reduction.pyx
+16
-0
tests/run/sequential_parallel.pyx
tests/run/sequential_parallel.pyx
+25
-0
No files found.
Cython/Compiler/FlowControl.py
View file @
3a446eee
...
@@ -820,6 +820,13 @@ class CreateControlFlowGraph(CythonTransform):
...
@@ -820,6 +820,13 @@ class CreateControlFlowGraph(CythonTransform):
self
.
flow
.
block
=
None
self
.
flow
.
block
=
None
return
node
return
node
def
visit_ParallelRangeNode
(
self
,
node
):
# if node.target is None an error will have been previously issued
if
node
.
target
is
not
None
:
node
=
self
.
visit_ForInStatNode
(
node
)
return
node
def
visit_ForFromStatNode
(
self
,
node
):
def
visit_ForFromStatNode
(
self
,
node
):
condition_block
=
self
.
flow
.
nextblock
()
condition_block
=
self
.
flow
.
nextblock
()
next_block
=
self
.
flow
.
newblock
()
next_block
=
self
.
flow
.
newblock
()
...
...
Cython/Compiler/Nodes.py
View file @
3a446eee
...
@@ -5977,7 +5977,7 @@ class ParallelStatNode(StatNode, ParallelNode):
...
@@ -5977,7 +5977,7 @@ class ParallelStatNode(StatNode, ParallelNode):
if
entry
.
cname
in
self
.
seen_closure_vars
:
if
entry
.
cname
in
self
.
seen_closure_vars
:
return
entry
.
cname
return
entry
.
cname
cname
=
code
.
funcstate
.
allocate_temp
(
entry
.
type
,
Fals
e
)
cname
=
code
.
funcstate
.
allocate_temp
(
entry
.
type
,
Tru
e
)
# Add both the actual cname and the temp cname, as the actual cname
# Add both the actual cname and the temp cname, as the actual cname
# will be replaced with the temp cname on the entry
# will be replaced with the temp cname on the entry
...
@@ -6297,6 +6297,11 @@ class ParallelRangeNode(ParallelStatNode):
...
@@ -6297,6 +6297,11 @@ class ParallelRangeNode(ParallelStatNode):
valid_keyword_arguments
=
[
'schedule'
,
'nogil'
,
'num_threads'
]
valid_keyword_arguments
=
[
'schedule'
,
'nogil'
,
'num_threads'
]
def
__init__
(
self
,
pos
,
**
kwds
):
super
(
ParallelRangeNode
,
self
).
__init__
(
pos
,
**
kwds
)
# Pretend to be a ForInStatNode for control flow analysis
self
.
iterator
=
PassStatNode
(
pos
)
def
analyse_declarations
(
self
,
env
):
def
analyse_declarations
(
self
,
env
):
super
(
ParallelRangeNode
,
self
).
analyse_declarations
(
env
)
super
(
ParallelRangeNode
,
self
).
analyse_declarations
(
env
)
self
.
target
.
analyse_target_declaration
(
env
)
self
.
target
.
analyse_target_declaration
(
env
)
...
@@ -6512,6 +6517,9 @@ class ParallelRangeNode(ParallelStatNode):
...
@@ -6512,6 +6517,9 @@ class ParallelRangeNode(ParallelStatNode):
for
entry
,
op
in
self
.
privates
.
iteritems
():
for
entry
,
op
in
self
.
privates
.
iteritems
():
# Don't declare the index variable as a reduction
# Don't declare the index variable as a reduction
if
op
and
op
in
"+*-&^|"
and
entry
!=
self
.
target
.
entry
:
if
op
and
op
in
"+*-&^|"
and
entry
!=
self
.
target
.
entry
:
if
entry
.
type
.
is_pyobject
:
error
(
self
.
pos
,
"Python objects cannot be reductions"
)
else
:
code
.
put
(
" reduction(%s:%s)"
%
(
op
,
entry
.
cname
))
code
.
put
(
" reduction(%s:%s)"
%
(
op
,
entry
.
cname
))
else
:
else
:
if
entry
==
self
.
target
.
entry
:
if
entry
==
self
.
target
.
entry
:
...
...
tests/errors/e_cython_parallel_pyobject_reduction.pyx
0 → 100644
View file @
3a446eee
# mode: error
from
cython.parallel
cimport
prange
def
invalid_closure_reduction
():
sum
=
0
def
inner
():
nonlocal
sum
cdef
int
i
for
i
in
prange
(
10
,
nogil
=
True
):
with
gil
:
sum
+=
i
_ERRORS
=
u"""
e_cython_parallel_pyobject_reduction.pyx:10:23: Python objects cannot be reductions
"""
tests/run/sequential_parallel.pyx
View file @
3a446eee
...
@@ -147,6 +147,31 @@ def test_closure_parallel_privates():
...
@@ -147,6 +147,31 @@ def test_closure_parallel_privates():
g
=
test_generator
()
g
=
test_generator
()
print
next
(
g
),
x
,
next
(
g
),
x
print
next
(
g
),
x
,
next
(
g
),
x
def
test_closure_parallel_with_gil
():
"""
>>> test_closure_parallel_with_gil()
45
45
"""
cdef
int
sum
=
0
temp1
=
5
temp2
=
-
5
def
test_reduction
():
nonlocal
sum
,
temp1
,
temp2
cdef
int
i
for
i
in
prange
(
10
,
nogil
=
True
):
with
gil
:
sum
+=
temp1
+
temp2
+
i
assert
abs
(
sum
-
sum
)
==
0
return
sum
print
test_reduction
()
print
sum
def
test_pure_mode
():
def
test_pure_mode
():
"""
"""
>>> test_pure_mode()
>>> test_pure_mode()
...
...
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