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
254ea20e
Commit
254ea20e
authored
Dec 06, 2021
by
da-woods
Committed by
GitHub
Dec 06, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support cpp_locals and std::move on prange temps (GH-4358)
Fixes
https://github.com/cython/cython/issues/4354
parent
56a5c9ec
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
3 deletions
+49
-3
Cython/Compiler/Nodes.py
Cython/Compiler/Nodes.py
+16
-3
tests/run/cpp_locals_parallel.pyx
tests/run/cpp_locals_parallel.pyx
+33
-0
No files found.
Cython/Compiler/Nodes.py
View file @
254ea20e
...
...
@@ -9248,7 +9248,10 @@ class ParallelStatNode(StatNode, ParallelNode):
if
not
lastprivate
or
entry
.
type
.
is_pyobject
:
continue
type_decl
=
entry
.
type
.
empty_declaration_code
()
if
entry
.
type
.
is_cpp_class
and
not
entry
.
type
.
is_fake_reference
and
code
.
globalstate
.
directives
[
'cpp_locals'
]:
type_decl
=
entry
.
type
.
cpp_optional_declaration_code
(
""
)
else
:
type_decl
=
entry
.
type
.
empty_declaration_code
()
temp_cname
=
"__pyx_parallel_temp%d"
%
temp_count
private_cname
=
entry
.
cname
...
...
@@ -9262,10 +9265,17 @@ class ParallelStatNode(StatNode, ParallelNode):
# Declare the parallel private in the outer block
c
.
putln
(
"%s %s%s;"
%
(
type_decl
,
temp_cname
,
init
))
self
.
parallel_private_temps
.
append
((
temp_cname
,
private_cname
,
entry
.
type
))
if
entry
.
type
.
is_cpp_class
:
# moving is fine because we're quitting the loop and so won't be directly accessing the variable again
code
.
globalstate
.
use_utility_code
(
UtilityCode
.
load_cached
(
"MoveIfSupported"
,
"CppSupport.cpp"
))
private_cname
=
"__PYX_STD_MOVE_IF_SUPPORTED(%s)"
%
private_cname
# Initialize before escaping
code
.
putln
(
"%s = %s;"
%
(
temp_cname
,
private_cname
))
self
.
parallel_private_temps
.
append
((
temp_cname
,
private_cname
))
code
.
end_block
()
# end critical section
...
...
@@ -9386,7 +9396,10 @@ class ParallelStatNode(StatNode, ParallelNode):
code
.
putln
(
"if (%s) {"
%
Naming
.
parallel_why
)
for
temp_cname
,
private_cname
in
self
.
parallel_private_temps
:
for
temp_cname
,
private_cname
,
temp_type
in
self
.
parallel_private_temps
:
if
temp_type
.
is_cpp_class
:
# utility code was loaded earlier
temp_cname
=
"__PYX_STD_MOVE_IF_SUPPORTED(%s)"
%
temp_cname
code
.
putln
(
"%s = %s;"
%
(
private_cname
,
temp_cname
))
code
.
putln
(
"switch (%s) {"
%
Naming
.
parallel_why
)
...
...
tests/run/cpp_locals_parallel.pyx
0 → 100644
View file @
254ea20e
# mode: run
# tag: cpp, cpp17, no-cpp-locals, openmp
# no-cpp-locals because the test is already run with it explicitly set
# cython: cpp_locals=True
from
cython.parallel
cimport
prange
cdef
extern
from
*
:
"""
class Test {
public:
Test() = delete;
Test(int v) : value(v) {}
int get_value() const { return value; }
private:
int value;
};
"""
cdef
cppclass
Test
:
Test
(
int
)
nogil
int
get_value
()
def
test
():
"""
>>> test()
9
"""
cdef
int
i
for
i
in
prange
(
10
,
nogil
=
True
):
var
=
Test
(
i
)
print
(
var
.
get_value
())
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