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
3b7426f5
Commit
3b7426f5
authored
Apr 20, 2011
by
Mark Florisson
Committed by
Vitja Makarov
May 05, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Separate openmp tests from numpy + openmp tests
parent
8787fd36
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
197 additions
and
191 deletions
+197
-191
tests/run/numpy_parallel.pyx
tests/run/numpy_parallel.pyx
+3
-191
tests/run/parallel.pyx
tests/run/parallel.pyx
+194
-0
No files found.
tests/run/numpy_parallel.pyx
View file @
3b7426f5
...
...
@@ -2,203 +2,15 @@
# distutils: libraries = gomp
# distutils: extra_compile_args = -fopenmp
cimport
cython.parallel
from
cython.parallel
import
prange
,
threadid
cimport
openmp
from
libc.stdlib
cimport
malloc
,
free
from
libc.stdio
cimport
puts
cimport
cython
from
cython.parallel
import
prange
cimport
numpy
as
np
import
sys
#@cython.test_assert_path_exists(
# "//ParallelWithBlockNode//ParallelRangeNode[@schedule = 'dynamic']",
# "//GILStatNode[@state = 'nogil]//ParallelRangeNode")
def
test_prange
():
"""
>>> test_prange()
(9, 9, 45, 45)
"""
cdef
Py_ssize_t
i
,
j
,
sum1
=
0
,
sum2
=
0
with
nogil
,
cython
.
parallel
.
parallel
:
for
i
in
prange
(
10
,
schedule
=
'dynamic'
):
sum1
+=
i
for
j
in
prange
(
10
,
nogil
=
True
):
sum2
+=
j
return
i
,
j
,
sum1
,
sum2
def
test_descending_prange
():
"""
>>> test_descending_prange()
5
"""
cdef
int
i
,
start
=
5
,
stop
=
-
5
,
step
=
-
2
cdef
int
sum
=
0
for
i
in
prange
(
start
,
stop
,
step
,
nogil
=
True
):
sum
+=
i
return
sum
def
test_propagation
():
"""
>>> test_propagation()
(9, 9, 9, 9, 450, 450)
"""
cdef
int
i
,
j
,
x
,
y
cdef
int
sum1
=
0
,
sum2
=
0
for
i
in
prange
(
10
,
nogil
=
True
):
for
j
in
prange
(
10
):
sum1
+=
i
with
nogil
,
cython
.
parallel
.
parallel
:
for
x
in
prange
(
10
):
with
cython
.
parallel
.
parallel
:
for
y
in
prange
(
10
):
sum2
+=
y
return
i
,
j
,
x
,
y
,
sum1
,
sum2
def
test_parallel
():
"""
>>> test_parallel()
"""
cdef
int
maxthreads
=
openmp
.
omp_get_max_threads
()
cdef
int
*
buf
=
<
int
*>
malloc
(
sizeof
(
int
)
*
maxthreads
)
if
buf
==
NULL
:
raise
MemoryError
with
nogil
,
cython
.
parallel
.
parallel
:
buf
[
threadid
()]
=
threadid
()
for
i
in
range
(
maxthreads
):
assert
buf
[
i
]
==
i
free
(
buf
)
def
test_unsigned_operands
():
"""
This test is disabled, as this currently does not work (neither does it
for 'for i from x < i < y:'. I'm not sure we should strife to support
this, at least the C compiler gives a warning.
test_unsigned_operands()
10
"""
cdef
int
i
cdef
int
start
=
-
5
cdef
unsigned
int
stop
=
5
cdef
int
step
=
1
cdef
int
steps_taken
=
0
for
i
in
prange
(
start
,
stop
,
step
,
nogil
=
True
):
steps_taken
+=
1
return
steps_taken
def
test_reassign_start_stop_step
():
"""
>>> test_reassign_start_stop_step()
20
"""
cdef
int
start
=
0
,
stop
=
10
,
step
=
2
cdef
int
i
cdef
int
sum
=
0
for
i
in
prange
(
start
,
stop
,
step
,
nogil
=
True
):
start
=
-
2
stop
=
2
step
=
0
sum
+=
i
return
sum
def
test_closure_parallel_privates
():
"""
>>> test_closure_parallel_privates()
9 9
45 45
0 0 9 9
"""
cdef
int
x
def
test_target
():
nonlocal
x
for
x
in
prange
(
10
,
nogil
=
True
):
pass
return
x
print
test_target
(),
x
def
test_reduction
():
nonlocal
x
cdef
int
i
x
=
0
for
i
in
prange
(
10
,
nogil
=
True
):
x
+=
i
return
x
print
test_reduction
(),
x
def
test_generator
():
nonlocal
x
cdef
int
i
x
=
0
yield
x
x
=
2
for
i
in
prange
(
10
,
nogil
=
True
):
x
=
i
yield
x
g
=
test_generator
()
print
g
.
next
(),
x
,
g
.
next
(),
x
def
test_pure_mode
():
"""
>>> test_pure_mode()
0
1
2
3
4
4
3
2
1
0
0
"""
import
Cython.Shadow
pure_parallel
=
sys
.
modules
[
'cython.parallel'
]
for
i
in
pure_parallel
.
prange
(
5
):
print
i
for
i
in
pure_parallel
.
prange
(
4
,
-
1
,
-
1
,
schedule
=
'dynamic'
,
nogil
=
True
):
print
i
with
pure_parallel
.
parallel
:
print
pure_parallel
.
threadid
()
@
cython
.
boundscheck
(
False
)
def
test_parallel_numpy_arrays
():
"""
Disabled for now, need to handle buffer auxiliary variables.
test_parallel_numpy_arrays()
>>> test_parallel_numpy_arrays()
-5
-4
-3
...
...
tests/run/parallel.pyx
0 → 100644
View file @
3b7426f5
# tag: run
# distutils: libraries = gomp
# distutils: extra_compile_args = -fopenmp
cimport
cython.parallel
from
cython.parallel
import
prange
,
threadid
cimport
openmp
from
libc.stdlib
cimport
malloc
,
free
from
libc.stdio
cimport
puts
import
sys
#@cython.test_assert_path_exists(
# "//ParallelWithBlockNode//ParallelRangeNode[@schedule = 'dynamic']",
# "//GILStatNode[@state = 'nogil]//ParallelRangeNode")
def
test_prange
():
"""
>>> test_prange()
(9, 9, 45, 45)
"""
cdef
Py_ssize_t
i
,
j
,
sum1
=
0
,
sum2
=
0
with
nogil
,
cython
.
parallel
.
parallel
:
for
i
in
prange
(
10
,
schedule
=
'dynamic'
):
sum1
+=
i
for
j
in
prange
(
10
,
nogil
=
True
):
sum2
+=
j
return
i
,
j
,
sum1
,
sum2
def
test_descending_prange
():
"""
>>> test_descending_prange()
5
"""
cdef
int
i
,
start
=
5
,
stop
=
-
5
,
step
=
-
2
cdef
int
sum
=
0
for
i
in
prange
(
start
,
stop
,
step
,
nogil
=
True
):
sum
+=
i
return
sum
def
test_propagation
():
"""
>>> test_propagation()
(9, 9, 9, 9, 450, 450)
"""
cdef
int
i
,
j
,
x
,
y
cdef
int
sum1
=
0
,
sum2
=
0
for
i
in
prange
(
10
,
nogil
=
True
):
for
j
in
prange
(
10
):
sum1
+=
i
with
nogil
,
cython
.
parallel
.
parallel
:
for
x
in
prange
(
10
):
with
cython
.
parallel
.
parallel
:
for
y
in
prange
(
10
):
sum2
+=
y
return
i
,
j
,
x
,
y
,
sum1
,
sum2
def
test_parallel
():
"""
>>> test_parallel()
"""
cdef
int
maxthreads
=
openmp
.
omp_get_max_threads
()
cdef
int
*
buf
=
<
int
*>
malloc
(
sizeof
(
int
)
*
maxthreads
)
if
buf
==
NULL
:
raise
MemoryError
with
nogil
,
cython
.
parallel
.
parallel
:
buf
[
threadid
()]
=
threadid
()
for
i
in
range
(
maxthreads
):
assert
buf
[
i
]
==
i
free
(
buf
)
def
test_unsigned_operands
():
"""
This test is disabled, as this currently does not work (neither does it
for 'for i from x < i < y:'. I'm not sure we should strife to support
this, at least the C compiler gives a warning.
test_unsigned_operands()
10
"""
cdef
int
i
cdef
int
start
=
-
5
cdef
unsigned
int
stop
=
5
cdef
int
step
=
1
cdef
int
steps_taken
=
0
for
i
in
prange
(
start
,
stop
,
step
,
nogil
=
True
):
steps_taken
+=
1
return
steps_taken
def
test_reassign_start_stop_step
():
"""
>>> test_reassign_start_stop_step()
20
"""
cdef
int
start
=
0
,
stop
=
10
,
step
=
2
cdef
int
i
cdef
int
sum
=
0
for
i
in
prange
(
start
,
stop
,
step
,
nogil
=
True
):
start
=
-
2
stop
=
2
step
=
0
sum
+=
i
return
sum
def
test_closure_parallel_privates
():
"""
>>> test_closure_parallel_privates()
9 9
45 45
0 0 9 9
"""
cdef
int
x
def
test_target
():
nonlocal
x
for
x
in
prange
(
10
,
nogil
=
True
):
pass
return
x
print
test_target
(),
x
def
test_reduction
():
nonlocal
x
cdef
int
i
x
=
0
for
i
in
prange
(
10
,
nogil
=
True
):
x
+=
i
return
x
print
test_reduction
(),
x
def
test_generator
():
nonlocal
x
cdef
int
i
x
=
0
yield
x
x
=
2
for
i
in
prange
(
10
,
nogil
=
True
):
x
=
i
yield
x
g
=
test_generator
()
print
g
.
next
(),
x
,
g
.
next
(),
x
def
test_pure_mode
():
"""
>>> test_pure_mode()
0
1
2
3
4
4
3
2
1
0
0
"""
import
Cython.Shadow
pure_parallel
=
sys
.
modules
[
'cython.parallel'
]
for
i
in
pure_parallel
.
prange
(
5
):
print
i
for
i
in
pure_parallel
.
prange
(
4
,
-
1
,
-
1
,
schedule
=
'dynamic'
,
nogil
=
True
):
print
i
with
pure_parallel
.
parallel
:
print
pure_parallel
.
threadid
()
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