Compiling Fortan modules in python using f2py and ifort

Compiling Fortan modules in python using f2py and ifort

Hello,Could someone advise me as to whether I can (and if yes, then how) use ifort compiler with python's f2py package to develop modules in fortran that can be called by python? I am trying the following from the ipython terminal window:!f2py --fcompiler=ifort -c inputDataModule.f90 -m inputModulebut then it can't find the compiler. Any tips on what to do? Or whether the compatibility between f2py and ifort exists (or being worked upon)?(I also tried it with gfortran btw, but there it gives a different kind of problem - but that's a different matter.)

10 Beiträge / 0 neu
Letzter Beitrag
Nähere Informationen zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.

Did you "source" the Intel Fortran compiler first?

Steve Intel Developer Support

Could you explain as to what this would entail ?I have currently ifort installed and aliased on my bashrc.

As described in the documentation:

Establishing the Compiler Environment
The compilervars.sh script is used to establish the compiler environment.
The command takes the form:
source /bin/compilervars.sh argument
Where argument is either ia32 or intel64 as appropriate
for the architecture you are building for. Establishing the compiler environment also establishes
the environment for the Intel® Debugger, Intel® Performance Libraries and, if present, Intel®
C++ Compiler.

So, for example:

source /opt/intel/composer_xe_2011_sp1/bin/compilervars.sh ia32

There is also a .csh version.

Steve Intel Developer Support

Can you call ifort from a traditional shell? It's likely you or your sys admin is sourcing the intel environment setup scripts from one of your "dot" initialization files (if you're on a *nix system) such as .profile or . bashrc. If this is the case I would suspect that ipython is not enheriting the same environment that you have under bash or csh etc. If this is the case, why not call f2py from a traditional shell?

Also, a word of warning on f2py: It's abilities to automatically wrap fortran modules are somewhat limited and not terribly general. It doesn't support some new Fortran features, and even with Fortran 90/95 the success of f2py is contingent on your coding style.

There is also another project called fwrap, but I haven't ever tried it.

-Zaak

I'm having a similar problem under Mac OS X Mountain Lion (10.8.2). I have ifort version 13.0.1 installed, I just reinstalled Enthought python distribution version 7.3.

I'm accessing both ifort and python from the command line in Terminal.

When I run

f2py -c --help-fcompiler

I get

Fortran compilers found:
--fcompiler=gnu GNU Fortran 77 compiler (3.4.0)
--fcompiler=gnu95 GNU Fortran 95 compiler (4.7.2)
Compilers available for this platform, but not found:
--fcompiler=absoft Absoft Corp Fortran Compiler
--fcompiler=g95 G95 Fortran Compiler
--fcompiler=ibm IBM XL Fortran Compiler
--fcompiler=intel Intel Fortran Compiler for 32-bit apps
--fcompiler=nag NAGWare Fortran 95 Compiler
--fcompiler=pg Portland Group Fortran Compiler
Compilers not available on this platform:
--fcompiler=compaq Compaq Fortran Compiler
--fcompiler=hpux HP Fortran 90 Compiler
--fcompiler=intele Intel Fortran Compiler for Itanium apps
--fcompiler=intelem Intel Fortran Compiler for 64-bit apps
--fcompiler=intelev Intel Visual Fortran Compiler for Itanium apps
--fcompiler=intelv Intel Visual Fortran Compiler for 32-bit apps
--fcompiler=intelvem Intel Visual Fortran Compiler for 64-bit apps
--fcompiler=lahey Lahey/Fujitsu Fortran 95 Compiler
...

For the life of me, I can't figure out how to get f2py to "see" the ifort compiler, despite trying some of the things listed in this thread. Is there a configuration script for f2py that can be directly executed and/or modified?

Perhaps it would be a good idea to ask this in a Python forum, or wherever you found f2py. Does "which f2py" tell you anything useful? Did you "source" the Intel compiler as mentioned above?

Steve Intel Developer Support

I highly suspect that f2py is not inheriting your environment correctly. I suspect that looking at a python forum as Steve suggested is the most useful option. Alternatively you can try to dig around in the f2py source and inspect what sort of environment it inherits from the shell. If f2py is written in Python, Python is typically quite careful and not very permissive when it launches a bash/sh shell, and it is likely that it is not going to source any of your "dot files" that might automatically source the ifortvars.sh script. You might be able to hack around this. Also, I don't think f2py is, or has been, actively developed for some time, but I might be wrong.

Let us know if you have success. I will try to look into this some more, as it is a topic that interests me, but not until after the holidays.

-Zaak

I think that I have managed to make some progress in using intel fortran, ifort, and f2py in windows xp. In order to let f2py know where your compiler, which in my case is intel 11.0, is located, you need to run ia32. I did something like: c:\program files\Intel\Compiler\11.1\065\bin\ifortvars.bat ia32. after running this, i was able to user intel fortran as compiler build the module which is callable in python. It is similar for digital fortran.

Are you using Windows or Linux? This forum is for Linux and OS X users. We have a separate forum section for Windows users.

Steve Intel Developer Support

Melden Sie sich an, um einen Kommentar zu hinterlassen.