Discussion:
[f2py] Override f2py compiler settings
Justin M Wozniak
2014-03-28 00:02:45 UTC
Permalink
Hi
I am trying to run f2py on the Blue Gene/Q. I am running it as:

f2py -c -m lib_discus --compiler=gnu --fcompiler=gnu ...

I get:

build_src: building npy-pkg config files
running build_ext
error: don't know how to compile C/C++ code on platform 'posix' with
'gnu' compiler

Is there some way to override the detected platform (to linux?), or
to completely override the compiler settings?
Thanks
--
Justin M Wozniak
Sturla Molden
2014-03-28 14:46:33 UTC
Permalink
Post by Justin M Wozniak
Hi
f2py -c -m lib_discus --compiler=gnu --fcompiler=gnu ...
build_src: building npy-pkg config files
running build_ext
error: don't know how to compile C/C++ code on platform 'posix' with
'gnu' compiler
Is there some way to override the detected platform (to linux?), or
to completely override the compiler settings?
Thanks
--fcompiler=gnu is the g77 compiler (only Fortran 77)
--fcompiler=gnu95 is the gfortran compiler (any Fortran version)

The C compiler should default to system CC on Unix-like systems. It is
called UnixCCompiler in distutils. You can override it like this:

$ export CC=gcc
$ export CXX=g++

There is no "gnu" C compiler in distutils.

Normally you should use the same C compiler as was used to build Python,
which is nearly always the system cc. Trying to control which C compiler to
use is usually inherently bad on Linux. The only exception is if you have
built your whole Python and NumPy stack with a different compiler than the
vendor supplied (e.g. Intel icc instead of GNU gcc).

On Windows, however, controlling the C compiler is very important. Here the
GNU compilers are called "mingw" or "cygwin". The option --compiler to
f2py and distutils is mostly useful on Windows.

Sturla
Justin M Wozniak
2014-03-28 19:07:04 UTC
Permalink
Post by Sturla Molden
f2py -c -m lib_discus ...
build_src: building npy-pkg config files
running build_ext
error: don't know how to compile C/C++ code on platform 'posix' with
'gnu' compiler
Is there some way to override the detected platform (to linux?), or
to completely override the compiler settings?
Thanks
--fcompiler=gnu is the g77 compiler (only Fortran 77)
--fcompiler=gnu95 is the gfortran compiler (any Fortran version)
Thanks- gnu95 seems to work.

Now, I would really like to use the IBM XL compilers. I used
--fcompiler=ibm .
It doesn't work so I added some debugging statements in f2py:

platform: linux2
args: ()
get_version
CCompiler_get_version()
environment _get_var: compiler_f90
/soft/compilers/ibmcmp-nov2013/xlf/bg/14.1/bin/xlf90
environment _get_var: compiler_f77
/soft/compilers/ibmcmp-nov2013/xlf/bg/14.1/bin/xlf
environment _get_var: compiler_fix
/soft/compilers/ibmcmp-nov2013/xlf/bg/14.1/bin/xlf90
environment _get_var: linker_so
/soft/compilers/ibmcmp-nov2013/xlf/bg/14.1/bin/xlf95
environment _get_var: version_cmd
/soft/compilers/ibmcmp-nov2013/xlf/bg/14.1/bin/xlf

Ultimately results in:

File
"/home/wozniak/Public/sfw/ppc64-login/Python-2.7.6/lib/python2.7/site-packages/numpy/distutils/fcompiler/__init__.py",
line 433, in get_version
raise CompilerNotFound()

I feel like if I could manually set the compiler locations and flags I
could fix this but I don't know how to do that.
Post by Sturla Molden
Normally you should use the same C compiler as was used to build Python,
which is nearly always the system cc. Trying to control which C compiler to
use is usually inherently bad on Linux.
This system is kind of complicated- it has many compilers and settings.
It's a cross-compiled system.
--
Justin M Wozniak
Skipper Seabold
2014-03-28 19:17:58 UTC
Permalink
Post by Justin M Wozniak
Post by Sturla Molden
f2py -c -m lib_discus ...
build_src: building npy-pkg config files
running build_ext
error: don't know how to compile C/C++ code on platform 'posix' with
'gnu' compiler
Is there some way to override the detected platform (to linux?), or
to completely override the compiler settings?
Thanks
--fcompiler=gnu is the g77 compiler (only Fortran 77)
--fcompiler=gnu95 is the gfortran compiler (any Fortran version)
Thanks- gnu95 seems to work.
Now, I would really like to use the IBM XL compilers. I used
--fcompiler=ibm .
platform: linux2
args: ()
get_version
CCompiler_get_version()
environment _get_var: compiler_f90
/soft/compilers/ibmcmp-nov2013/xlf/bg/14.1/bin/xlf90
environment _get_var: compiler_f77
/soft/compilers/ibmcmp-nov2013/xlf/bg/14.1/bin/xlf
environment _get_var: compiler_fix
/soft/compilers/ibmcmp-nov2013/xlf/bg/14.1/bin/xlf90
environment _get_var: linker_so
/soft/compilers/ibmcmp-nov2013/xlf/bg/14.1/bin/xlf95
environment _get_var: version_cmd
/soft/compilers/ibmcmp-nov2013/xlf/bg/14.1/bin/xlf
File
"/home/wozniak/Public/sfw/ppc64-login/Python-2.7.6/lib/python2.7/site-packages/numpy/distutils/fcompiler/__init__.py",
line 433, in get_version
raise CompilerNotFound()
I feel like if I could manually set the compiler locations and flags I
could fix this but I don't know how to do that.
You can find the available compilers with

f2py -c --help-fcompiler

See here for manually setting locations. The compiler flag options are
down the page. You can also just use f2py -h.

http://cens.ioc.ee/projects/f2py2e/usersguide/
Post by Justin M Wozniak
Post by Sturla Molden
Normally you should use the same C compiler as was used to build Python,
which is nearly always the system cc. Trying to control which C compiler to
use is usually inherently bad on Linux.
This system is kind of complicated- it has many compilers and settings.
It's a cross-compiled system.
--
Justin M Wozniak
_______________________________________________
f2py-users mailing list
http://cens.ioc.ee/mailman/listinfo/f2py-users
Sturla Molden
2014-03-28 19:43:59 UTC
Permalink
Post by Justin M Wozniak
Now, I would really like to use the IBM XL compilers. I used
--fcompiler=ibm .
It seems to be supported:

https://github.com/numpy/numpy/blob/master/numpy/distutils/fcompiler/ibm.py
Post by Justin M Wozniak
Post by Sturla Molden
Normally you should use the same C compiler as was used to build Python,
which is nearly always the system cc. Trying to control which C compiler to
use is usually inherently bad on Linux.
This system is kind of complicated- it has many compilers and settings.
It's a cross-compiled system.
Same rule applies to cross-compilation: Point CC to whatever C compiler you
want to use. There is just one C compiler class for Unix/Linux in
distutils.

--compiler is for choosing between Microsoft Visual C++, Borland C++
Builder, MinGW GCC and Cygwin GCC on Windows. You cannot use it for
anything on Linux.

Sturla

Loading...