Reference: http://www.2cto.com/kf/201405/304168.html
Reference: http://blog.csdn.net/darren2015zdc/article/details/54574868
The Pyx file is a Python C extension file that conforms to the Cython specification and writes with whatever editor. I wrote it on the Eric4, and as a result it was interpreted by default with the Python interpreter and prompted with bugs, "syntax errors."
The above Pyx file is only a source code file, to be called by Python, to run, just write the source code is not enough. Specifically, you will also want to convert to. C or. C + + files, and then go further into the. pyd file. PYD files are files that can be used directly. To achieve this, write a setup.py script, as follows:
#!/usr/bin/python
#python version:2.7.3
#Filename: setuptestomp.py
# Run as:
# python setup.py Build_ext--inplace
Import sys
sys.path.insert (0, "..")
From Distutils.core Import Setup from
distutils.extension import extension to
cython.build import cythonize< C10/>from cython.distutils Import build_ext
# ext_module = cythonize ("Testomp.pyx")
Ext_module = Extension ( c13/> "Testomp",
["Testomp.pyx"],
extra_compile_args=["/openmp"],
extra_link_args=["/openmp"],
)
Setup (
cmdclass = {' Build_ext ': Build_ext},
ext_modules = [Ext_module],
)
This is a completely Python script that can be run under the Python interpreter. Under the console, run the following command ' python setup.py build_ext--inplace ' to generate testomp.pyd files. Of course, there are also some assorted files, such as the ' Lib ' file under the ' Build ' directory. This is prompted by the Windows Vistual Studio environment. In the LINUX+GCC environment, it is necessary to generate the. so file, and the "/openmp" option will be written "-fopenmp"
Write testomp.py
The two steps in the file are equivalent to writing Python's C extension form in more efficient code for a Python efficiency bottleneck module (which needs to be positioned with profile tools), and then to call them in Python code. Testomp.py is the script for this call, as follows:
From Testomp Import Test
test ()
This is easy, import and call. Under the console, type "Python testomp.py" to run.