Commit 36ab0511 authored by Boxiang Sun's avatar Boxiang Sun

Test

parent 1b0999f9
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
from distutils.core import setup from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize from Cython.Build import cythonize
ext_modules = [
Extension(
'test',
['test.pyx'],
extra_compile_args=['-fopenmp'],
extra_link_args=['-fopenmp'],
)
]
setup( setup(
ext_modules = cythonize("test.pyx") ext_modules = cythonize(ext_modules)
) )
#cython: language_level = 3 #cython: language_level = 3
from cython.parallel import parallel
from libc.stdio cimport printf from libc.stdio cimport printf
""" """
GOAL: implement nogil option in cdef class (extension types) GOAL: implement nogil option in cdef class (extension types)
...@@ -53,8 +54,8 @@ cdef class SomeMemory nogil: ...@@ -53,8 +54,8 @@ cdef class SomeMemory nogil:
It is possible to define native C/Cython methods It is possible to define native C/Cython methods
that release the GIL (cool...) that release the GIL (cool...)
""" """
pass while 1:
# self.a = self.b self.a += 1
# Not allowed to define pure Python function in the extension type with nogil option now # Not allowed to define pure Python function in the extension type with nogil option now
# since we want this extension type is CPython free # since we want this extension type is CPython free
...@@ -76,6 +77,7 @@ cdef double bar() nogil: # yet this is what we would like to ...@@ -76,6 +77,7 @@ cdef double bar() nogil: # yet this is what we would like to
# cdef SomeMemory o = SomeMemory(42.0, 3.14) # for this we need class allocation to handle memory without libpython # cdef SomeMemory o = SomeMemory(42.0, 3.14) # for this we need class allocation to handle memory without libpython
cdef SomeMemory o1 = SomeMemory(1, 1.0) cdef SomeMemory o1 = SomeMemory(1, 1.0)
cdef SomeMemory o2 = SomeMemory(2, 2.0) cdef SomeMemory o2 = SomeMemory(2, 2.0)
with nogil, parallel():
o1.foo() o1.foo()
o2.foo() o2.foo()
# o.foo() # and we need method selection to be independent of libpython # o.foo() # and we need method selection to be independent of libpython
......
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