[f2py] F90 Module Allocatable Arrays SegFault on Assignment using
Intel ia64
Howard Salis
salis at cems.umn.edu
Thu Oct 19 04:22:27 EEST 2006
Hi again,
I sent this to the mailing list back in June, but never found an
answer. I figure I'd give it a second try. Thank you for any help!
Hi all,
First off, let me say that f2py has automagically worked very well so
far and this is the first serious bug I've run into. So kudos to the
developers!
I did find a bug though related to running on a 64-bit machine. Here it is:
I'm using an Intel Itanium2 (ia64) running Linux 2.4.21-27.0.2.EL.
It's Python version v2.4.2 and numpy version v0.9.6 with the
accompanying f2py. I copy & pasted the example from chapter 4.6.1 of the
f2py documentation into "Test.f90". The example allocates a F90 module
allocatable array and assigns a Numpy array to it. I f2py'd it using
"f2py -m Test -c --f90exec=ifort --f90flags='-O3' --build-dir
/home/es7000/salis/Py3S/f2py -I/home/es7000/salis/Py3S/f2py
-L/opt/intel_fc_80/lib -lifcoremt -lcprts Test.f90". For some reason,
using "--fcompiler=intele" does not work. The output from f2py is pasted
below (but it seems to work fine).
After that, I try allocating and assigning data to the module
variable, using "Test.mod.b = [[1, 2], [3, 4], [5, 6]]" and it
segfaults. I also tried importing numpy ("from numpy import *") and
using "a = array([[1,2], [3,4], [5,6]], 'f')" and "Test.mod.b = a". That
also segfaults. In other tests, I was successful in assigning a numpy
scalar or a python scalar to a scalar module variable. I was also
successful in assigning a 1 dimensional numpy array to a module
variable, but it will raise the exception "ValueError: negative
dimensions are not allowed" when trying to read it.
Any suggestions or fixes (besides not using any module variables)?
Thank you,
Howard Salis
University of Minnesota
F90 file:
module mod
real, allocatable :: b(:,:)
contains
subroutine foo
IMPLICIT NONE
integer :: k
if (allocated(b)) then
print*, "b=["
do k = 1,size(b,1)
print*, b(k,1:size(b,2))
enddo
print*, "]"
else
print*, "b is not allocated"
endif
end subroutine foo
end module mod
F2py output:
running build
running config_fc
running build_src
building extension "Test" sources
f2py options: []
f2py:> /home/es7000/salis/Py3S/f2py/src/Testmodule.c
Reading fortran codes...
Reading file 'Test.f90' (format:free)
Post-processing...
Block: Test
Block: mod
Block: foo
Post-processing (stage 2)...
Block: Test
Block: unknown_interface
Block: mod
Block: foo
Building modules...
Building module "Test"...
Constructing F90 module support for "mod"...
Variables: b
Constructing wrapper function "mod.foo"...
foo()
Wrote C/API module "Test" to file
"/home/es7000/salis/Py3S/f2py/src/Testmodule.c"
Fortran 90 wrappers are saved to
"/home/es7000/salis/Py3S/f2py/src/Test-f2pywrappers2.f90"
adding '/home/es7000/salis/Py3S/f2py/src/fortranobject.c' to sources.
adding '/home/es7000/salis/Py3S/f2py/src' to include_dirs.
adding '/home/es7000/salis/Py3S/f2py/src/Test-f2pywrappers2.f90' to
sources.
running build_ext
customize UnixCCompiler
customize UnixCCompiler using build_ext
Could not locate executable gfortran
Could not locate executable f95
customize GnuFCompiler
customize GnuFCompiler
customize GnuFCompiler using build_ext
building 'Test' extension
compiling C sources
gcc options: '-pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall
-Wstrict-prototypes -fPIC'
compile options: '-I/home/es7000/salis/Py3S/f2py
-I/home/es7000/salis/Py3S/f2py/src
-I/home/es7000/salis/Python/Python-2.4.2/Lib/site-packages/numpy/core/include
-I/home/es7000/salis/Python/Python-2.4.2/Include
-I/home/es7000/salis/Python/Python-2.4.2 -c'
gcc: /home/es7000/salis/Py3S/f2py/src/Testmodule.c
/home/es7000/salis/Py3S/f2py/src/Testmodule.c: In function
`f2py_setup_mod':
/home/es7000/salis/Py3S/f2py/src/Testmodule.c:176: warning: assignment
from incompatible pointer type
XXX: module_build_dir='/home/es7000/salis/Py3S/f2py/' option ignored
XXX: Fix module_dir_switch for GnuFCompiler
XXX: module_dirs=[] option ignored
XXX: Fix module_include_switch for GnuFCompiler
compiling Fortran 90 module sources
g77(f77) options: '-Wall -fno-second-underscore -fPIC -O2 -funroll-loops'
ifort(f90) options: '-O3 -fPIC -O2 -funroll-loops'
ifort(fix) options: '-O3 -fPIC -O2 -funroll-loops'
compile options: '-I/home/es7000/salis/Py3S/f2py
-I/home/es7000/salis/Py3S/f2py/src
-I/home/es7000/salis/Python/Python-2.4.2/Lib/site-packages/numpy/core/include
-I/home/es7000/salis/Python/Python-2.4.2/Include
-I/home/es7000/salis/Python/Python-2.4.2 -c'
ifort:f90: Test.f90
ifort: Command line warning: overriding '-O3' with '-O2'
ifort: Command line warning: ignoring unknown option '-funroll-loops'
moving mod.mod -> /home/es7000/salis/Py3S/f2py/
compiling Fortran sources
g77(f77) options: '-Wall -fno-second-underscore -fPIC -O2 -funroll-loops'
ifort(f90) options: '-O3 -fPIC -O2 -funroll-loops'
ifort(fix) options: '-O3 -fPIC -O2 -funroll-loops'
compile options: '-I/home/es7000/salis/Py3S/f2py
-I/home/es7000/salis/Py3S/f2py/src
-I/home/es7000/salis/Python/Python-2.4.2/Lib/site-packages/numpy/core/include
-I/home/es7000/salis/Python/Python-2.4.2/Include
-I/home/es7000/salis/Python/Python-2.4.2 -c'
ifort:f90: /home/es7000/salis/Py3S/f2py/src/Test-f2pywrappers2.f90
ifort: Command line warning: overriding '-O3' with '-O2'
ifort: Command line warning: ignoring unknown option '-funroll-loops'
/usr/bin/g77 -shared /home/es7000/salis/Py3S/f2py/Testmodule.o
/home/es7000/salis/Py3S/f2py/fortranobject.o
/home/es7000/salis/Py3S/f2py/Test.o
/home/es7000/salis/Py3S/f2py/Test-f2pywrappers2.o -L/opt/intel_fc_80/lib
-lifcoremt -lcprts -lg2c -o ./Test.so
Python IDE:
Python 2.4.2 (#1, Mar 18 2006, 15:42:52)
[GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-53)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Test
>>> from numpy import *
>>> print Test.mod.__doc__
b - 'f'-array(-1,-1), not allocated
foo - Function signature:
foo()
>>> a = array([[ 1., 2., 3.],[4., 5., 6.]],'f')
>>> Test.mod.b = a
Segmentation fault
More information about the f2py-users
mailing list