I think this is closest to what you want to achieve: subroutine f(fMatrix,oMatrix,N) implicit none integer,intent(in) :: N double precision,intent(in),dimension(N, mod(N,2)+1) :: fMatrix double precision,intent(out),dimension(N, mod(N,2)+1) :: oMatrix ! ... oMatrix = fMatrix end subroutine I personally would prefer one of the following solutions: Since both fMatrix and oMatrix are...
python,memory-management,fortran,out-of-memory,f2py
You are feeding double precision arrays to the Fortran subroutine. Each element in double precision requires 8 Byte of memory. For N=30,000 that makes coor(n,3) => 30,000*3*8 ~ 0.7 MB dist(n,n) => 30,000^2*8 ~ 6.7 GB Since the half precision floats are additionally required for Python, that accounts for another...
python,numpy,optimization,fortran,f2py
The flags -xhost -openmp -fp-model strict come from def get_flags_opt(self): return ['-xhost -openmp -fp-model strict'] in the file site-packages/numpy/distutils/fcompiler/intel.py for the classes that invoke ifort. You have two options to modify the behavior of these flags: call f2py with the --noopt flag to suppress these flags call f2py with the...
What I use is something as follows, i try to avoid the intent inout variable because I find it sometimes confusing with call by reference thing Instead I define a output variable in the subroutine itself and it automatically returns that subroutine f(fMatrix,oMatrix,N) implicit none; integer,intent(in)::N double precision,intent(in),dimension(N, 3):: fMatrix...
I ended up using the fortranname declaration in the signature files to generate both inplace and in,out flavors of the same subroutine. Here's the signature file: ! -*- f90 -*- ! Note: the context of this file is case sensitive. python module fib ! in interface ! in :fib subroutine...
I found an answer, even if I can't really say that I understand the rationale behind it. What causes the problem is the name of the common block: common/crot/cofsr(nmp) when switched with a different name such as common/testok/cofsr(nmp) everything works as expected, therefore my problem is solved....
python,module,fortran,gfortran,f2py
Your command: gfortran -c -fPIC libtest.f90 produces an object file with position independent code. This is a pre-requisite of a shared library, not a shared library. If you want to use the object as is, you can modify your f2py invocation: f2py -c --fcompiler=gfortran -I. libtest.o -m Main main.f90 This...
python,numpy,distutils,lapack,f2py
I think you just need ctypes, there is a complete example on calling a lapack function on this page: http://www.sagemath.org/doc/numerical_sage/ctypes.html You get your function like this: import ctypes from ctypes.util import find_library lapack = ctypes.cdll.LoadLibrary(find_library("lapack")) dgtsv = lapack.dgtsv_ ...
The interface for hw1 is missing in your code. Either specify it explicitly: program hwtest real*8 r1, r2 ,s real*8 hw1 c [...] Or, even better, put the functions into a module, and use the module. BTW: Change *8 by something better suited, like: program hwtest integer,parameter :: dp =...
In brief, this combo of flags seems to allow gdb to produce line number of any runtime errors in f1.f90 or f2.f90: C:\> gfortran -g -fbacktrace -c f1.f90 f2.f90 C:\> f2py --debug-capi -c -I. f1.o f2.o -m main main.f90 C:\> gdb python (gdb) run main.py Where main.py imports/calls main.f90 which...
I was using the g95 compiler which was generating a 32 bit code and all other tools that I was using were generating 64 bit code. I used gfortran instead of g95 and I got the right output. I had to separately install gfortran using MinGW.
python,fortran,precision,double-precision,f2py
You should set output in the Fortran code using double precision, output = 1.3d0 In Fortran 1.3 is a single precision constant....
You tell python that the array is intent(in): integer iwk(31*ndp + nip) !f2py intent(in) :: iwk You are not allowed to change it and expect the change will be retained. Probably you want intent(inout). Even better, forget !f2py intent and use directly: integer, intent(inout) :: iwk(31*ndp + nip) and the...
python,numpy,fortran,fortran90,f2py
Here's a work-around, in which dp is moved to a types module, and the use types statement is added to the function i1. ! testf2py.f90 module types implicit none integer, parameter :: dp=kind(0.d0) end module types module testf2py implicit none private public i1 contains real(dp) function i1(m) use types real(dp),...
If you have f2py, then it's either not on the search PATH, or it has not been made executable. I don't know if you are on Linux or Windows. Try to execute f2py manually and see if it starts. If not, try to locate it, and see where it is...
python,numpy,fortran,openmp,f2py
I was able to reproduce the error on Mac OS X (10.9.5), with gfortran installed using homebrew, and I was able to fix it by adding -lgomp to the command: f2py -m SOmod --fcompiler=gnu95 --f90flags='-march=native -O3 -fopenmp' -lgomp -c SOtest.f95 Added by @Mark: Note that -lgomp is an argument for...
It's not unusual for print statements to impact - and either create or remove the segfault. The reason is that they change the way memory is laid out to make room for the string being printed, or you will be making room for temporary strings if you're doing some formatting....
Working with dlls, as commented by MattDMo was a very good suggestion. However, that meant using ctypes, which becomes a bit tricky when the Fortran subroutine returns more than one variable (at least, for a newbe such me). Another option that worked perfectly fine for me was to make the...
imp.load_compiled() is for .pyc files. You're looking for imp.load_dynamic(). Alternatively, you can add the directory you want in sys.path, after which regular imports will work.