summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Behnel <stefan_ml@behnel.de>2016-05-16 08:43:05 +0200
committerStefan Behnel <stefan_ml@behnel.de>2016-07-15 08:12:59 +0200
commit93c2d0846b99d84128ae47c0b406213e05505848 (patch)
treec8d0489df89a2594aa9abd941bd4b8dae0d35cd6
parentd9a5b0602e799c65f1bbea36d12f912d4abc9047 (diff)
downloadcython-93c2d0846b99d84128ae47c0b406213e05505848.tar.gz
modernise setup.py example in OpenMP docs
-rw-r--r--docs/src/userguide/parallelism.rst43
1 files changed, 16 insertions, 27 deletions
diff --git a/docs/src/userguide/parallelism.rst b/docs/src/userguide/parallelism.rst
index 075fead40..e8fe1bfdf 100644
--- a/docs/src/userguide/parallelism.rst
+++ b/docs/src/userguide/parallelism.rst
@@ -160,48 +160,37 @@ It currently supports OpenMP, but later on more backends might be supported.
Returns the id of the thread. For n threads, the ids will range from 0 to
n-1.
+
Compiling
=========
+
To actually use the OpenMP support, you need to tell the C or C++ compiler to
-enable OpenMP. For gcc this can be done as follows in a setup.py::
+enable OpenMP. For gcc this can be done as follows in a setup.py::
from distutils.core import setup
from distutils.extension import Extension
- from Cython.Distutils import build_ext
+ from Cython.Build import cythonize
- ext_module = Extension(
- "hello",
- ["hello.pyx"],
- extra_compile_args=['-fopenmp'],
- extra_link_args=['-fopenmp'],
- )
+ ext_modules = [
+ Extension(
+ "hello",
+ ["hello.pyx"],
+ extra_compile_args=['-fopenmp'],
+ extra_link_args=['-fopenmp'],
+ )
+ ]
setup(
- name = 'Hello world app',
- cmdclass = {'build_ext': build_ext},
- ext_modules = [ext_module],
+ name='hello-parallel-world',
+ ext_modules=cythonize(ext_modules),
)
-For Microsoft Visual C++ compiler::
+For Microsoft Visual C++ compiler, use ``'/openmp'`` instead of ``'-fopenmp'``.
- from distutils.core import setup
- from distutils.extension import Extension
- from Cython.Distutils import build_ext
-
- ext_module = Extension(
- "hello",
- ["hello.pyx"],
- extra_compile_args=['/openmp'],
- )
-
- setup(
- name = 'Hello world app',
- cmdclass = {'build_ext': build_ext},
- ext_modules = [ext_module],
- )
Breaking out of loops
=====================
+
The parallel with and prange blocks support the statements break, continue and
return in nogil mode. Additionally, it is valid to use a ``with gil`` block
inside these blocks, and have exceptions propagate from them.