Commit 84ee26c5 authored by Mark Florisson's avatar Mark Florisson

OpenMP header pxd

parent 0994de57
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()
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
cimport cython.parallel cimport cython.parallel
from cython.parallel import prange, threadid from cython.parallel import prange, threadid
cimport openmp
from libc.stdlib cimport malloc, free from libc.stdlib cimport malloc, free
from libc.stdio cimport puts from libc.stdio cimport puts
cimport numpy as np cimport numpy as np
...@@ -67,28 +68,29 @@ def test_nested_prange(): ...@@ -67,28 +68,29 @@ def test_nested_prange():
return sum return sum
# threadsavailable test, disable this for now as it won't compile
#def test_parallel(): def test_parallel():
# """ """
# >>> test_parallel() >>> test_parallel()
# """ """
# cdef int *buf = <int *> malloc(sizeof(int) * threadsavailable()) cdef int maxthreads = openmp.omp_get_max_threads()
# cdef int *buf = <int *> malloc(sizeof(int) * maxthreads)
# if buf == NULL:
# raise MemoryError if buf == NULL:
# raise MemoryError
# with nogil, cython.parallel.parallel:
# buf[threadid()] = threadid() with nogil, cython.parallel.parallel:
# buf[threadid()] = threadid()
# for i in range(threadsavailable()):
# assert buf[i] == i for i in range(maxthreads):
# assert buf[i] == i
# free(buf)
free(buf)
def test_unsigned_operands(): def test_unsigned_operands():
""" """
This test is disabled, as this currently does not work (neither does it 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. this, at least the C compiler gives a warning.
test_unsigned_operands() test_unsigned_operands()
...@@ -215,18 +217,19 @@ def test_parallel_numpy_arrays(): ...@@ -215,18 +217,19 @@ def test_parallel_numpy_arrays():
""" """
cdef Py_ssize_t i cdef Py_ssize_t i
cdef np.ndarray[np.int_t] x cdef np.ndarray[np.int_t] x
try: try:
import numpy import numpy
except ImportError: except ImportError:
for i in range(-5, 5): for i in range(-5, 5):
print i print i
return return
x = numpy.zeros(10, dtype=np.int) x = numpy.zeros(10, dtype=np.int)
for i in prange(x.shape[0], nogil=True): for i in prange(x.shape[0], nogil=True):
x[i] = i - 5 x[i] = i - 5
for i in x: for i in x:
print x print x
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment