Questions tagged [f2py]

F2PY is a tool that provides an interface between the Python and Fortran programming languages.

F2PY is a tool that provides an interface between the and programming languages. F2PY is part of .

491 questions
5
votes
0 answers

Python multiprocessing with fortran library

I am using the multiprocessing module in Python to map a set of jobs onto as many cores as I have. The jobs I am wrapping are mostly performed with some wrapped fortran code (wrapped with f2py). When I call the jobs only, they go through fine using…
StevenMurray
  • 742
  • 2
  • 7
  • 18
5
votes
2 answers

f2py, Python function that returns an array (vector-valued function)

In the following Python I have five functions contained in the array returned by func which I have to integrate. The code calls an external Fortran module generated using f2py: import numpy as np from numpy import cos, sin , exp from trapzdv import…
Saullo G. P. Castro
  • 56,802
  • 26
  • 179
  • 234
5
votes
2 answers

callback Python from Fortran

Now I am using the f2py to call Python function from Fortran code. I have tried a very easy example but it didn't work. Fortran90 code: subroutine foo(fun,r) external fun integer ( kind = 4 ) i real ( kind = 8 ) r r=0.0D+00 do i= 1,5 …
lbjx
  • 195
  • 1
  • 3
  • 12
5
votes
3 answers

I want Python as front end, Fortran as back end. I also want to make fortran part parallel - best strategy?

I have a python script I hope to do roughly this: calls some particle positions into an array runs algorithm over all 512^3 positions to distribute them to an NxNxN matrix feed that matrix back to python use plotting in python to visualise matrix…
Griff
  • 2,064
  • 5
  • 31
  • 47
5
votes
3 answers

making python and fortran friends

Assume we need to call fortran function, which returns some values, in python program. I found out that rewriting fortran code in such way: subroutine pow2(in_x, out_x) implicit none real, intent(in) :: in_x !f2py real, intent(in,…
user983302
  • 1,377
  • 3
  • 14
  • 23
4
votes
1 answer

f2py error: undefined symbol

I need to wrap a simply fortran90 code with f2py. The fortran module "test.f90" is module util contains FUNCTION gasdev(idum) implicit none INTEGER(kind=4), intent(inout) :: idum REAL(kind=8) :: gasdev, ran2 print*,idum gasdev =…
nye17
  • 12,857
  • 11
  • 58
  • 68
4
votes
1 answer

ImportError: How can I get F2PY working on Apple M1?

I want to import fortran files to my python script by using f2py. For that I compile them via f2py -c -m my_lib *.f which produces the file "my_lib.cpython-38-darwin.so" which I import to my script by import my_lib. On my Intel-based Macbook that…
stegmaja
  • 63
  • 2
4
votes
2 answers

Link f2py generated *.so file in a python package using setuptools

I wish to deploy a package to PyPi using setuptools. However, the core part of the package is actually written in Fortran, and I am using f2py to wrap it in python. Basically the project's structure looks like…
Peaceful
  • 4,920
  • 15
  • 54
  • 79
4
votes
1 answer

Installing numpy before using numpy.distutils.core.setup

I am using numpy.distutils to setup a package (mypackage) that has a frotran module. The problem is that if I do pip install mypackage on an environment that does not have numpy, I get the following error: ModuleNotFoundError: No module named…
Felix
  • 170
  • 9
4
votes
0 answers

import numpy causes Python crash with NumPy version 1.16.0 and upwards

Using a fresh installation of Python 3.7.3 on Windows Server 2012 import numpy causes a Python crash when NumPy versions 1.16.0 or above is installed. Downgrading back to 1.15.4 solves the problem, but I am failing to see the cause of this. In…
Kocas
  • 302
  • 1
  • 12
4
votes
0 answers

Why does f2py compile with the -qopenmp ifort flag even in the serial mode?

I have a Fortran 90 code, with OpenMP implemented for some parts. Now to compile the Fortran code using f2py with OpenMP support I have to pass the f90 compiler flags. Now the code should compile with OpenMP support only if I provide the OpenMP…
Eular
  • 1,707
  • 4
  • 26
  • 50
4
votes
1 answer

fortran matrix product slows when called with f2py by python

I've been trying to use f2py to interface an optimized fortran code for vector and matrix multiplication with python. To obtain a performance comparison useful for my purposes I perform the same product inside a cycle 100000 times. With a full…
MartaR
  • 43
  • 3
4
votes
2 answers

F2PY with Subroutine having a Call-back argument and an assumed-shape array argument

I am trying to use F2PY to wrap a fortran subroutine which takes a function and an assumed-shape array as arguments. This results in an error. I am using GNU Fortran (GCC) 4.8.5 20150623 (Red Hat 4.8.5-11) and F2PY version 2 with Scientific Linux…
Niklas M.
  • 91
  • 1
  • 7
4
votes
1 answer

F2py unable to compile module with private functions

I am building a Python module from a Fortran module using f2py. The Fortran module contains private procedures which do not need to be available in the Python module. Here is a code example that reproduces the issue: module testmodule implicit…
Felix
  • 170
  • 9
4
votes
0 answers

f2py and capi_return is NULL woes

I've run into what I think might be a bug in f2py and callbacks to python. Or, maybe I'm not using things correctly. I have created a very minimal example which illustrates my problem at: https://github.com/soylentdeen/fluffy-kumquat To reproduce…
soylentdeen
  • 101
  • 7