F2PY + PGI compilers?

0 views
Skip to first unread message

Jeffrey Layton

unread,
Jul 30, 2017, 11:50:39 AM7/30/17
to anaconda
Hello,

I'm trying to use F2PY to build a Python module from Fortran using the PGI compilers (16.10). I've done it before with the gfortran compilers, but I'm having some trouble with the PGI compilers.

Here is my command line:

f2py --fcompiler=pg -c -m mdevice mdevice.f90


Here is the output I get from f2py:


running build               
running config_cc           
unifing config_cc, config, build_clib, build_ext, build commands --compiler options
running config_fc
unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options
running build_src
build_src
building extension "mdevice" sources
f2py options: []
f2py:> /tmp/tmpwLmPGK/src.linux-x86_64-2.7/mdevicemodule.c
creating /tmp/tmpwLmPGK/src.linux-x86_64-2.7
Reading fortran codes...
        Reading file 'mdevice.f90' (format:free)
Post-processing...
        Block: mdevice
                        Block: devicequery
In: :mdevice:mdevice.f90:devicequery
get_useparameters: no module cudafor info used by devicequery
Post-processing (stage 2)...
Building modules...
        Building module "mdevice"...
                Constructing wrapper function "devicequery"...
                  devicequery()
        Wrote C/API module "mdevice" to file "/tmp/tmpwLmPGK/src.linux-x86_64-2.7/mdevicemodule.c"
  adding '/tmp/tmpwLmPGK/src.linux-x86_64-2.7/fortranobject.c' to sources.
  adding '/tmp/tmpwLmPGK/src.linux-x86_64-2.7' to include_dirs.
copying /home/laytonjb/anaconda2/lib/python2.7/site-packages/numpy/f2py/src/fortranobject.c -> /tmp/tmpwLmPGK/src.linux-x86_64-2.7
copying /home/laytonjb/anaconda2/lib/python2.7/site-packages/numpy/f2py/src/fortranobject.h -> /tmp/tmpwLmPGK/src.linux-x86_64-2.7
build_src: building npy-pkg config files
running build_ext
customize UnixCCompiler
customize UnixCCompiler using build_ext
customize PGroupFCompiler
Found executable /opt/pgi/linux86-64/pgidir/pgf90
Found executable /opt/pgi/linux86-64/pgidir/pgf77
Found executable /opt/pgi/linux86-64/16.10/bin/pgfortran
customize PGroupFCompiler using build_ext
building 'mdevice' extension
compiling C sources
C compiler: /opt/pgi/linux86-64/pgidir/pgcc -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC

creating /tmp/tmpwLmPGK/tmp
creating /tmp/tmpwLmPGK/tmp/tmpwLmPGK
creating /tmp/tmpwLmPGK/tmp/tmpwLmPGK/src.linux-x86_64-2.7
compile options: '-I/tmp/tmpwLmPGK/src.linux-x86_64-2.7 -I/home/laytonjb/anaconda2/lib/python2.7/site-packages/numpy/core/include -I/home/laytonjb/anaconda2/include/python2.7 -c'
pgcc: /tmp/tmpwLmPGK/src.linux-x86_64-2.7/mdevicemodule.c
pgcc-Error-Unknown switch: -fno-strict-aliasing
pgcc-Error-Unknown switch: -fwrapv
pgcc-Error-Unknown switch: -Wall
pgcc-Error-Unknown switch: -Wstrict-prototypes
pgcc-Error-Unknown switch: -fno-strict-aliasing
pgcc-Error-Unknown switch: -fwrapv
pgcc-Error-Unknown switch: -Wall
pgcc-Error-Unknown switch: -Wstrict-prototypes
error: Command "/opt/pgi/linux86-64/pgidir/pgcc -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/tmp/tmpwLmPGK/src.linux-x86_64-2.7 -I/home/laytonjb/anaconda2/lib/python2.7/site-packages/numpy/core/include -I/home/laytonjb/anaconda2/include/python2.7 -c /tmp/tmpwLmPGK/src.linux-x86_64-2.7/mdevicemodule.c -o /tmp/tmpwLmPGK/tmp/tmpwLmPGK/src.linux-x86_64-2.7/mdevicemodule.o" failed with exit status 1


Any suggestions? (I'm a bit lost on this).

BTW - conda=4.3.2.1, python 2.7.

Thanks!

Jeff



Will Warner

unread,
Aug 1, 2017, 2:12:52 PM8/1/17
to Anaconda - Public
It seems F2PY is now part of NumPy, so you may want to post this to the NumPy discussion list: https://www.scipy.org/scipylib/mailing-lists.html

Someone on this list may be able to chime in with useful info here, too.

Jeffrey Layton

unread,
Aug 1, 2017, 2:40:58 PM8/1/17
to anaconda
Thanks! I will do that!

Jeff


--
Anaconda Community Support Group Brought to you by Continuum Analytics
---
You received this message because you are subscribed to the Google Groups "Anaconda - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to anaconda+unsubscribe@continuum.io.
To post to this group, send email to anac...@continuum.io.
Visit this group at https://groups.google.com/a/continuum.io/group/anaconda/.

Travis Oliphant

unread,
Aug 1, 2017, 6:13:01 PM8/1/17
to Anaconda
This looks like a configuration problem.   It seems to be that the command-line flags are coming from the native gcc compiler. 

Perhaps you should give the --compiler flag as well.

f2py --compiler=pg --fcompiler=pg -c -m mdevice mdevice.f90

Otherwise, asking on the NumPy mailing list about how you switch the command-line flags to f2py

Best,

-Travis



--
Anaconda Community Support Group Brought to you by Continuum Analytics
---
You received this message because you are subscribed to the Google Groups "Anaconda - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to anaconda+unsubscribe@continuum.io.
To post to this group, send email to anac...@continuum.io.
Visit this group at https://groups.google.com/a/continuum.io/group/anaconda/.



--
Continuum Analytics Banner

Travis Oliphant
Chief Data Scientist & Co-Founder
C: 512-826-7480 
E: tra...@continuum.io 
@ContinuumIO @teoliphant

Anaconda Powered By Continuum Analytics
Follow us on TwitterConnect with us on LinkedInSubscribe to our Youtube channelConnect with us on SlideShare


Jeffrey Layton

unread,
Aug 7, 2017, 10:48:48 AM8/7/17
to anaconda
Travis,

Apologies for taking so long to get back to you. I'm pretty sure it's a configuration issue :)  I tried your suggestion and it got a little further. There is the command line


f2py --compiler=pg --fcompiler=pg -c -m mdevice mdevice.f90


The output is below. BTW - I posted in the numpy list and didn't hear anything back. I've also engaged the PGI folks but they don't know f2py well and the issues appear to be the options for f2py.

Thanks!

Jeff



running build
running config_cc
unifing config_cc, config, build_clib, build_ext, build commands --compiler options
running config_fc
unifing config_fc, config, build_clib, build_ext, build commands --fcompiler options
running build_src
build_src
building extension "mdevice" sources
f2py options: []
f2py:> /tmp/tmpAMXFG_/src.linux-x86_64-2.7/mdevicemodule.c
creating /tmp/tmpAMXFG_/src.linux-x86_64-2.7

Reading fortran codes...
        Reading file 'mdevice.f90' (format:free)
Post-processing...
        Block: mdevice
                        Block: devicequery
In: :mdevice:mdevice.f90:devicequery
get_useparameters: no module cudafor info used by devicequery
Post-processing (stage 2)...
Building modules...
        Building module "mdevice"...
                Constructing wrapper function "devicequery"...
                  devicequery()
        Wrote C/API module "mdevice" to file "/tmp/tmpAMXFG_/src.linux-x86_64-2.7/mdevicemodule.c"
  adding '/tmp/tmpAMXFG_/src.linux-x86_64-2.7/fortranobject.c' to sources.
  adding '/tmp/tmpAMXFG_/src.linux-x86_64-2.7' to include_dirs.
copying /home/laytonjb/anaconda2/lib/python2.7/site-packages/numpy/f2py/src/fortranobject.c -> /tmp/tmpAMXFG_/src.linux-x86_64-2.7
copying /home/laytonjb/anaconda2/lib/python2.7/site-packages/numpy/f2py/src/fortranobject.h -> /tmp/tmpAMXFG_/src.linux-x86_64-2.7

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

Ian Stokes Rees

unread,
Aug 7, 2017, 10:56:31 AM8/7/17
to anac...@continuum.io
Hi Jeff,


On 7/30/17 12:50 PM, Jeffrey Layton wrote:
I'm trying to use F2PY to build a Python module from Fortran using the PGI compilers (16.10). I've done it before with the gfortran compilers, but I'm having some trouble with the PGI compilers.

Further to what my colleagues have mentioned I can also say that Continuum offers a (paid) package build service, that could then get you a configuration that can be reused to create a conda package version of whatever software you are trying to build with PGI.  And additionally you'd walk away with pre-compiled binary conda packages for whatever platforms you needed of the software you had.

If you're interested in that option please be in touch with sa...@continuum.io

Cheers,

Ian

Travis Oliphant

unread,
Aug 17, 2017, 1:39:05 AM8/17/17
to Anaconda
Hey Jeff, 

I see that you posted to the NumPy mailing list and didn't get a lot of help (though good advice that building f2py from source won't help).    

The issue here is that you do need a C-compiler to compile the Python extension.      The C-compiler it is picking up by default is here (pgcc) from the portland group.     This seems good.   However, the problem is that the flags it is picking up are all wrong (it seems to have grabbed the flags from a gcc configuration). 

C compiler: /opt/pgi/linux86-64/pgidir/pgcc -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC

My original suggestion to try using --compiler was not a good idea.   That option is for Windows as Sturla describes in this thread:  https://groups.google.com/forum/#!topic/f2py-users/P3fAh1SOMVE

I wonder if it would help to set the environment variable CC:

export CC=gcc
f2py --fcompiler=pg -c -m mdevice mdevice.f90

Let me know if that helps. 

-Travis



Michael Sarahan

unread,
Aug 17, 2017, 8:24:01 AM8/17/17
to Anaconda - Public

Jeffrey Layton

unread,
Aug 17, 2017, 3:57:07 PM8/17/17
to anaconda
Travis,

Thanks for noticing! The lists didn't provide much help to move things forward. Your suggestion has really helped. I can now build a Python module! It fails when I load but I think that problem falls on me :)  I'm going to keep working on it and I will let you know what progress I make.

Thanks a million!

Jeff

P.S. Is there a good way to provide feedback to the Numpy developers or work with them to test PGI?

Travis Oliphant

unread,
Aug 17, 2017, 4:13:43 PM8/17/17
to Anaconda
This is great news.  I'm glad it helped.    If you can report back to the NumPy list the solution that worked (once you get things working) that would be great. 

I would submit an issue to the github tracker.   There aren't many who work on that part of the code, but at least it will be tracked.   A fix to the documentation may be all that can be done here.

Good luck getting the module to work.   Fun times.  I worked a lot on f2py with Pearu back in the day --- but not as much on the configuration side.     f2py has always been an impressive project from my vantage point.

Best,

-Travis

Reply all
Reply to author
Forward
0 new messages