[SciPy-dev] Solution for problem with f90 allocatable arrays on 64-bit systems

Neilen Marais nmarais@sun.ac...
Thu Apr 19 18:06:15 CDT 2007


Hi,

I've found the problem in the generated code that results in the bug
described here: http://projects.scipy.org/scipy/numpy/ticket/147

The problem is an index which should be specified as pointer size but is
specified as integer in the fortran part of the module code. When
wrapping the following code:

(geomwrap.f90)
MODULE mesh
  ! The 4 node indices per element that define all the mesh elements
  INTEGER, DIMENSION(:,:), ALLOCATABLE :: element_nodes

CONTAINS
  SUBROUTINE init_mesh()
    ALLOCATE(element_nodes(4,2))
    element_nodes(:,1) = (/1, 2, 3, 4/)
    element_nodes(:,2) = (/1, 3, 4, 5/)
  END SUBROUTINE init_mesh
END MODULE mesh

and generating wrappers:

 f2py --fcompiler=gnu95 -m geo --build-dir test -c geomwrap.f90

in the file geo-f2pywrappers2.f90

!     -*- f90 -*-
!     This file is autogenerated with f2py (version:2_3718)
!     It contains Fortran 90 wrappers to fortran functions.

      subroutine f2py_mesh_getdims_element_nodes(r,s,f2pysetdata,flag)
      use mesh, only: d => element_nodes

      integer flag
      external f2pysetdata
      logical ns
      integer s(*),r,i,j

the definition for s(*) should be interger(8) (at least on 64-bit
machines), i.e.
!     -*- f90 -*-
!     This file is autogenerated with f2py (version:2_3718)
!     It contains Fortran 90 wrappers to fortran functions.

      subroutine f2py_mesh_getdims_element_nodes(r,s,f2pysetdata,flag)
      use mesh, only: d => element_nodes

      integer flag
      external f2pysetdata
      logical ns
      integer(8) s(*)
      integer r,i,j

is correct.

I'm going to patch f2py on my machine to generate integer(8) sized s(*),
but this will of course be wrong on 32-bit machines. What is the
recommended way of getting a pointer-sized int  in fortran?

Thanks
Neilen




More information about the Scipy-dev mailing list