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
84ee26c5
Commit
84ee26c5
authored
Apr 16, 2011
by
Mark Florisson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
OpenMP header pxd
parent
0994de57
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
74 additions
and
22 deletions
+74
-22
Cython/Includes/openmp.pxd
Cython/Includes/openmp.pxd
+49
-0
tests/run/parallel.pyx
tests/run/parallel.pyx
+25
-22
No files found.
Cython/Includes/openmp.pxd
0 → 100644
View file @
84ee26c5
cdef
extern
from
"omp.h"
:
ctypedef
struct
omp_lock_t
ctypedef
struct
omp_nest_lock_t
ctypedef
enum
omp_sched_t
:
omp_sched_static
=
1
,
omp_sched_dynamic
=
2
,
omp_sched_guided
=
3
,
omp_sched_auto
=
4
extern
void
omp_set_num_threads
(
int
)
extern
int
omp_get_num_threads
()
extern
int
omp_get_max_threads
()
extern
int
omp_get_thread_num
()
extern
int
omp_get_num_procs
()
extern
int
omp_in_parallel
()
extern
void
omp_set_dynamic
(
int
)
extern
int
omp_get_dynamic
()
extern
void
omp_set_nested
(
int
)
extern
int
omp_get_nested
()
extern
void
omp_init_lock
(
omp_lock_t
*
)
extern
void
omp_destroy_lock
(
omp_lock_t
*
)
extern
void
omp_set_lock
(
omp_lock_t
*
)
extern
void
omp_unset_lock
(
omp_lock_t
*
)
extern
int
omp_test_lock
(
omp_lock_t
*
)
extern
void
omp_init_nest_lock
(
omp_nest_lock_t
*
)
extern
void
omp_destroy_nest_lock
(
omp_nest_lock_t
*
)
extern
void
omp_set_nest_lock
(
omp_nest_lock_t
*
)
extern
void
omp_unset_nest_lock
(
omp_nest_lock_t
*
)
extern
int
omp_test_nest_lock
(
omp_nest_lock_t
*
)
extern
double
omp_get_wtime
()
extern
double
omp_get_wtick
()
void
omp_set_schedule
(
omp_sched_t
,
int
)
void
omp_get_schedule
(
omp_sched_t
*
,
int
*
)
int
omp_get_thread_limit
()
void
omp_set_max_active_levels
(
int
)
int
omp_get_max_active_levels
()
int
omp_get_level
()
int
omp_get_ancestor_thread_num
(
int
)
int
omp_get_team_size
(
int
)
int
omp_get_active_level
()
tests/run/parallel.pyx
View file @
84ee26c5
...
...
@@ -4,6 +4,7 @@
cimport
cython.parallel
from
cython.parallel
import
prange
,
threadid
cimport
openmp
from
libc.stdlib
cimport
malloc
,
free
from
libc.stdio
cimport
puts
cimport
numpy
as
np
...
...
@@ -67,28 +68,29 @@ def test_nested_prange():
return
sum
# threadsavailable test, disable this for now as it won't compile
#def test_parallel():
# """
# >>> test_parallel()
# """
# cdef int *buf = <int *> malloc(sizeof(int) * threadsavailable())
#
# if buf == NULL:
# raise MemoryError
#
# with nogil, cython.parallel.parallel:
# buf[threadid()] = threadid()
#
# for i in range(threadsavailable()):
# assert buf[i] == i
#
# free(buf)
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
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()
...
...
@@ -215,18 +217,19 @@ def test_parallel_numpy_arrays():
"""
cdef
Py_ssize_t
i
cdef
np
.
ndarray
[
np
.
int_t
]
x
try
:
import
numpy
except
ImportError
:
for
i
in
range
(
-
5
,
5
):
print
i
return
x
=
numpy
.
zeros
(
10
,
dtype
=
np
.
int
)
for
i
in
prange
(
x
.
shape
[
0
],
nogil
=
True
):
x
[
i
]
=
i
-
5
for
i
in
x
:
print
x
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