[f2py] user fortran type declaration

Pearu Peterson pearu.peterson at gmail.com
Thu Sep 2 10:04:35 EEST 2010



On 09/02/2010 06:01 AM, Xavier Barthelemy wrote:
> Hello every one
>
> I have been using f2py since a few month, and I want to congrat Pearu
> Peterson for this. After using swig, f2py is way more simple and it
> work very well.

Thanks for your kind words:)

> I have wrap different subroutine and it works well in python, thanks
> to f2py. My problem is I can't reach certain calculus precision in
> standard fortran. So I need to use user defined type.
> I have understood that f2py does not handle user-defined variable
> type, and i think it doesn't do that in sense of I can't get this kind
> of variable in or out.
> But i would like to use user define type as inner variable of my
> fortran program.
>
> I'll explain myself with an example:
>
> this is my fortran code:
>
>         SUBROUTINE InteriorField()
>         use mpmodule
>         implicit none
>         integer:: NpointsIn
>         parameter(NpointsIn=5)
>         type (mp_real) :: FIELD(11,NpointsIn)
> !       call mpinit(100)
>
>         FIELD(1,1)='1.'
>         print*,FIELD(1,1)
>         return
>         end
>
>
> the mpmodule comes from the arprec (arbitrary precision package) that
> you can find here: http://crd.lbl.gov/~dhbailey/mpdist/
> It define user type and overload standard operator so you can make
> multiplication with as much significative digits as you wish, and you
> don't need to stick to the classic double precision.
> I would like to use this in my inner calculation and I can have an
> output in double precision on the result of my calculus.
>
> I wrap it using
> f2py --fcompiler=intelem -c -m Test Test.f  --opt=" -I<APPRECLIBDIR>
> -larprecmod -larprec -larprec_f_main -mp" --no-lower
> where  libarprecmod.a  libarprec. libarprec_f_main.a are my module

Perhaps `-mp` should read `-lmp`?

> It compiles, but when  I type in python
>
> import Test
> I have the following answer:ImportError: ./Test.so: undefined symbol:
> mprealmod_mp_mpeq_
> Looks like the compiler recongnize everything but something is wrong for python

The typical solution to this problem is to find out which library
defines the undefined symbol and specify this library in f2py command 
line for linking.

> then When I look at the ARPREC documentation, it says:
> f ->  o : ifort Test-f -c Test.o -I<APPRECLIBDIR>  -mp
> o ->  exec: gcc -o test Test.o -L<ARPRECLIBDIR>  -l<ARPRECLIBS>
> -L<BunchOfLibDir>  -lifport -lifcore -limf -lsvml -lm -lipgo -lirc
> -lirc_s -ldl
>
> The tests program of ARPREC are working fine.
>
> So any one has a guess on how I can link everything together?
> Thanks in advance for your answers,
> Xavier


HTH,
Pearu



More information about the f2py-users mailing list