F2PY and Windows Intel Fortran We will consider the classic example of the generation of Fibonnaci numbers,
fib1.f , given by:
C FILE : FIB1 . F
SUBROUTINE FIB ( A , N )
C
C CALCULATE FIRST N FIBONACCI NUMBERS
C
INTEGER N
REAL * 8 A ( N )
DO I = 1 , N
IF ( I . EQ . 1 ) THEN
A ( I ) = 0.0D0
ELSEIF ( I . EQ . 2 ) THEN
A ( I ) = 1.0D0
ELSE
A ( I ) = A ( I - 1 ) + A ( I - 2 )
ENDIF
ENDDO
END
C END FILE FIB1 . F
For cmd.exe fans, using the Intel oneAPI command prompt is the easiest approach, as
it loads the required environment for both ifort and msvc . Helper batch
scripts are also provided.
# cmd.exe
"C:\Program Files (x86)\Intel\oneAPI\setvars.bat"
python -m numpy.f2py -c fib1.f -m fib1
python -c "import fib1; import numpy as np; a=np.zeros(8); fib1.fib(a); print(a)"
Powershell usage is a little less pleasant, and this configuration now works with MSVC as:
python -m numpy . f2py -c fib1 . f -m fib1 - -f77exec = 'C:\Program Files (x86)\Intel\oneAPI\compiler\latest\windows\bin\intel64\ifort.exe' - -f90exec = 'C:\Program Files (x86)\Intel\oneAPI\compiler\latest\windows\bin\intel64\ifort.exe' -L 'C:\Program Files (x86)\Intel\oneAPI\compiler\latest\windows\compiler\lib\ia32'
python -c "import fib1; import numpy as np; a=np.zeros(8); fib1.fib(a); print(a)"
cmd . exe / k '"C:\Program Files (x86)\Intel\oneAPI\setvars.bat" && powershell'
python -m numpy . f2py -c fib1 . f -m fib1
python -c "import fib1; import numpy as np; a=np.zeros(8); fib1.fib(a); print(a)"
Note that the actual path to your local installation of ifort may vary, and the command above will need to be updated accordingly.