Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Paul_N_2
Beginner
333 Views

Using Intel compilers in distutils

It seems that it is not possible to use the Intel compilers with distutils build and build_ext functionality under Py35 (and likely Py27 as well).  Is this going to be supported in later versions?  This would aid in getting around limitations set by Visual Studio 2015 (e.g. importing complex.h in Cython).

- Paul

 

0 Kudos
5 Replies
Frank_S_Intel
Employee
333 Views

Hi Paul,

it should be possible to compile with icc. 

Setting environment variable CC to icc should work without Intel's distribution (yes, also on windows).

What's the issue you're seeing?

frank

Paul_N_2
Beginner
333 Views

I can build with the Intel compilers using the NumPy distutils, but the Intel compilers are not recognized by Python distutils.  The package I work on performs runtime code generation in Cython and compiles via the Cython pyxinstall command.  I can specify the compiler used by this function by generating a distutils.cfg file.  However, on Windows, the only options are the default VS compilers, or mingw32.  Intel compilers are not recognized, and mingw32 is not Py35 compatible.  VS is not an option as I need to include complex.h, and the Cython code that is generated is not compatible with the complex.h from VS 2015.  I thought that since Intel has their own compilers that their Python distro would have support for them.

- Paul

P__Robert
Beginner
333 Views

Hello,
 

What are the required environment variables to set the Fortran compiler?

 

Setting FC77 and FC90 to ifort enables .f compilation, but during a particular build, gfortran seems to be called for linking.

 

Any suggestions?

 

Thanks,

Rob

Rohit_J_Intel
Employee
333 Views


Hi Paul,

Assuming that you have Intel compiler set to PATH, here's a simple example of how you'd use Intel compiler with cython:

1. Create helloworld.pyx

print "Hello World"

2. Create setup.py

from distutils.core import setup
from Cython.Build import cythonize

setup(
    ext_modules = cythonize("helloworld.pyx")
)

3. Run:
LDSHARED="icc -shared" CC=icc python setup.py build_ext --inplace


To check if the build was successful:

python -c "import helloworld"

 

We have modified distutils so that it pays heed to environment variables on Windows. In order to use Intel compilers on Windows, you'd have to set these to environment before building:
SET CC=icl
SET CXX=icl
SET LD=xilink
SET AR=xilib

Thanks,
Rohit

Rohit_J_Intel
Employee
333 Views

An example illustrating the manner in which Fortran code can be built as a native extension using Intel compiler and Numpy's distutils - 

1. Create helloworld.f

subroutine foo
    print*, "Hello World!"
end

2. Create setup.py

from numpy.distutils.core import Extension
from numpy.distutils.core import setup

if __name__ == "__main__":
    ext = Extension(name = 'helloworld', sources = ['helloworld.f'])
    setup(ext_modules = [ext])

3. For building, 
i.  On Windows: python setup.py build_ext --inplace --fcompiler=intelvem --compiler=intelemw
ii. On Linux / OSX: python setup.py build_ext --inplace --fcompiler=intelem --compiler=intelem

To check if the module was correctly built: python -c "from helloworld import foo; foo()"

Thanks,
Rohit
(p.s. If you have trouble importing this module on Linux, you should do the following:
1. cd IDP_installation/lib/python(2.7|3.5)/site-packages/numpy/distutils/fcompiler
2. In intel.py, remove all instances of -openmp.
3. Rebuild your code using the instructions listed above.)

 

Reply