• MPFR binding for Fortran

    From Thomas Koenig@21:1/5 to All on Mon Jul 18 21:21:07 2022
    Hi,

    I've been working on a little pet project of mine, an MPFR binding
    for Fortran. I have now released a very first version github,
    at https://github.com/tkoenig1/FMPFR .

    So, if anybody wants to try out some arbitrary-precision floating
    point calculations in Fortran, give it a spin.

    Suggestions for improvements are also welcome.

    A little code sample:

    program memain
    use fmpfr_oper
    implicit none
    type (fmpfr), dimension(:), allocatable :: a
    call set_default_prec (128)
    allocate (a(2))
    a(1) = fmpfr("1.3")
    a(2) = a(1) + 2
    print *,a
    print *,sin(a)
    end program memain

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From feanor@21:1/5 to Thomas Koenig on Tue Jul 19 05:45:56 2022
    Thomas Koenig schrieb am Montag, 18. Juli 2022 um 23:21:11 UTC+2:
    Hi,

    I've been working on a little pet project of mine, an MPFR binding
    for Fortran. I have now released a very first version github,
    at https://github.com/tkoenig1/FMPFR .

    So, if anybody wants to try out some arbitrary-precision floating
    point calculations in Fortran, give it a spin.

    Nice. Thanks for the effort. I tried it out immediately. I removed the symlinks for the autotools files and replaced them with copies
    from my own project. Then I compiled/link your example program as
    gfortran foo.f90 -L/home/reuter/local/lib -lfmpfr -I../src -lmpfr
    But both on Ubuntu 18.04 and on Apple Darwin x86_64 I got
    NaN NaN
    NaN NaN
    The dependencies look ok to me;
    $ ldd a.out
    linux-vdso.so.1 (0x00007fff175d5000)
    libmpfr.so.6 => /usr/lib/x86_64-linux-gnu/libmpfr.so.6 (0x00007f522538e000)
    libgfortran.so.4 => /usr/lib/x86_64-linux-gnu/libgfortran.so.4 (0x00007f5224faf000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f5224bbe000)
    libgmp.so.10 => /usr/lib/x86_64-linux-gnu/libgmp.so.10 (0x00007f522493d000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f5225819000)
    libquadmath.so.0 => /usr/lib/x86_64-linux-gnu/libquadmath.so.0 (0x00007f52246fd000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f522435f000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f5224147000)

    Any idea what goes wrong here?
    Cheers,
    JRR

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Koenig@21:1/5 to feanor on Tue Jul 19 17:16:33 2022
    feanor <juergen.reuter@desy.de> schrieb:
    Thomas Koenig schrieb am Montag, 18. Juli 2022 um 23:21:11 UTC+2:
    Hi,

    I've been working on a little pet project of mine, an MPFR binding
    for Fortran. I have now released a very first version github,
    at https://github.com/tkoenig1/FMPFR .

    So, if anybody wants to try out some arbitrary-precision floating
    point calculations in Fortran, give it a spin.

    Nice. Thanks for the effort. I tried it out immediately. I removed the symlinks for the autotools files and replaced them with copies
    from my own project.

    Ah, something I will have to do as well.

    Then I compiled/link your example program as
    gfortran foo.f90 -L/home/reuter/local/lib -lfmpfr -I../src -lmpfr
    But both on Ubuntu 18.04 and on Apple Darwin x86_64 I got
    NaN NaN
    NaN NaN

    Definitely seems wrong - maybe a too-early version of gfortran?
    That would be a bummer.

    What does "gfortran -v" give you on your two systems?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Koenig@21:1/5 to Thomas Koenig on Tue Jul 19 18:31:21 2022
    Thomas Koenig <tkoenig@netcologne.de> schrieb:
    feanor <juergen.reuter@desy.de> schrieb:
    Thomas Koenig schrieb am Montag, 18. Juli 2022 um 23:21:11 UTC+2:
    Hi,

    I've been working on a little pet project of mine, an MPFR binding
    for Fortran. I have now released a very first version github,
    at https://github.com/tkoenig1/FMPFR .

    So, if anybody wants to try out some arbitrary-precision floating
    point calculations in Fortran, give it a spin.

    Nice. Thanks for the effort. I tried it out immediately. I removed the symlinks for the autotools files and replaced them with copies
    from my own project.

    Ah, something I will have to do as well.

    Then I compiled/link your example program as
    gfortran foo.f90 -L/home/reuter/local/lib -lfmpfr -I../src -lmpfr
    But both on Ubuntu 18.04 and on Apple Darwin x86_64 I got
    NaN NaN
    NaN NaN

    Definitely seems wrong - maybe a too-early version of gfortran?
    That would be a bummer.

    What does "gfortran -v" give you on your two systems?

    Never mind that - I have found the bug, and I will fix it.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Koenig@21:1/5 to Thomas Koenig on Tue Jul 19 20:26:38 2022
    Thomas Koenig <tkoenig@netcologne.de> schrieb:
    Thomas Koenig <tkoenig@netcologne.de> schrieb:
    feanor <juergen.reuter@desy.de> schrieb:
    Thomas Koenig schrieb am Montag, 18. Juli 2022 um 23:21:11 UTC+2:
    Hi,

    I've been working on a little pet project of mine, an MPFR binding
    for Fortran. I have now released a very first version github,
    at https://github.com/tkoenig1/FMPFR .

    So, if anybody wants to try out some arbitrary-precision floating
    point calculations in Fortran, give it a spin.

    Nice. Thanks for the effort. I tried it out immediately. I removed the symlinks for the autotools files and replaced them with copies
    from my own project.

    Ah, something I will have to do as well.

    Then I compiled/link your example program as
    gfortran foo.f90 -L/home/reuter/local/lib -lfmpfr -I../src -lmpfr
    But both on Ubuntu 18.04 and on Apple Darwin x86_64 I got
    NaN NaN
    NaN NaN

    Definitely seems wrong - maybe a too-early version of gfortran?
    That would be a bummer.

    What does "gfortran -v" give you on your two systems?

    Never mind that - I have found the bug, and I will fix it.

    OK, fixed now. I fell into a trap that is easy to fall into
    when doing C-style rc = "some pure function", this
    was optimized away (and I hadn't tested it with -O2 before,
    it worked with -O0).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From feanor@21:1/5 to Thomas Koenig on Wed Jul 20 05:39:09 2022
    Thomas Koenig schrieb am Dienstag, 19. Juli 2022 um 22:26:42 UTC+2:

    Never mind that - I have found the bug, and I will fix it.
    OK, fixed now. I fell into a trap that is easy to fall into
    when doing C-style rc = "some pure function", this
    was optimized away (and I hadn't tested it with -O2 before,
    it worked with -O0).

    Now I cannot link anymore, during compilation I get the warning: mpfr_glue.c:56:3: warning: implicit declaration of function ‘mpfr_set_float128’; did you mean ‘fmpfr_set_float128’? [-Wimplicit-function-declaration]
    56 | mpfr_set_float128 (rop, op, rnd);
    | ^~~~~~~~~~~~~~~~~
    | fmpfr_set_float128
    and at linking the test program I get:
    Undefined symbols for architecture x86_64:
    "_mpfr_set_float128", referenced from:
    _fmpfr_set_float128 in libfmpfr.a(fmpfr_glue.o)
    ld: symbol(s) not found for architecture x86_64

    mpfr_set_float128 appears in mpfr.h as
    __MPFR_DECLSPEC mpfr_set_float128
    this seems for Windows DLL !?
    On Ubuntu 18.04 compilation and linking works now (with gcc/gfortran 7.5.0), on Darwin x86_64 (Intel, not M1 arm64) it doesn't

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Koenig@21:1/5 to feanor on Wed Jul 20 17:36:57 2022
    feanor <juergen.reuter@desy.de> schrieb:
    Thomas Koenig schrieb am Dienstag, 19. Juli 2022 um 22:26:42 UTC+2:

    Never mind that - I have found the bug, and I will fix it.
    OK, fixed now. I fell into a trap that is easy to fall into
    when doing C-style rc = "some pure function", this
    was optimized away (and I hadn't tested it with -O2 before,
    it worked with -O0).

    Now I cannot link anymore, during compilation I get the warning: mpfr_glue.c:56:3: warning: implicit declaration of function ‘mpfr_set_float128’; did you mean ‘fmpfr_set_float128’? [-Wimplicit-function-declaration]
    56 | mpfr_set_float128 (rop, op, rnd);
    | ^~~~~~~~~~~~~~~~~
    | fmpfr_set_float128
    and at linking the test program I get:
    Undefined symbols for architecture x86_64:
    "_mpfr_set_float128", referenced from:
    _fmpfr_set_float128 in libfmpfr.a(fmpfr_glue.o)
    ld: symbol(s) not found for architecture x86_64

    mpfr_set_float128 appears in mpfr.h as
    __MPFR_DECLSPEC mpfr_set_float128
    this seems for Windows DLL !?
    On Ubuntu 18.04 compilation and linking works now (with gcc/gfortran 7.5.0), on Darwin x86_64 (Intel, not M1 arm64) it doesn't

    Fixed, thanks for the reports!

    Hope you can do a bit more with it now :-)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From JRR@21:1/5 to All on Thu Jul 21 17:07:22 2022
    Am 20.07.22 um 19:36 schrieb Thomas Koenig:
    feanor <juergen.reuter@desy.de> schrieb:
    Thomas Koenig schrieb am Dienstag, 19. Juli 2022 um 22:26:42 UTC+2:

    Never mind that - I have found the bug, and I will fix it.
    OK, fixed now. I fell into a trap that is easy to fall into
    when doing C-style rc = "some pure function", this
    was optimized away (and I hadn't tested it with -O2 before,
    it worked with -O0).

    Now I cannot link anymore, during compilation I get the warning:
    mpfr_glue.c:56:3: warning: implicit declaration of function ‘mpfr_set_float128’; did you mean ‘fmpfr_set_float128’? [-Wimplicit-function-declaration]
    56 | mpfr_set_float128 (rop, op, rnd);
    | ^~~~~~~~~~~~~~~~~
    | fmpfr_set_float128
    and at linking the test program I get:
    Undefined symbols for architecture x86_64:
    "_mpfr_set_float128", referenced from:
    _fmpfr_set_float128 in libfmpfr.a(fmpfr_glue.o)
    ld: symbol(s) not found for architecture x86_64

    mpfr_set_float128 appears in mpfr.h as
    __MPFR_DECLSPEC mpfr_set_float128
    this seems for Windows DLL !?
    On Ubuntu 18.04 compilation and linking works now (with gcc/gfortran 7.5.0), on Darwin x86_64 (Intel, not M1 arm64) it doesn't

    Fixed, thanks for the reports!

    Hope you can do a bit more with it now :-)


    Thanks, Thomas. I still have an issue on Darwin x86_64:
    Undefined symbols for architecture x86_64:
    "_fmpfr_set_ld", referenced from:
    ___fmpfr_oper_MOD_ass_set_ld in libfmpfr.a(fmpfr_oper.o)
    ___fmpfr_oper_MOD_fun_set_ld in libfmpfr.a(fmpfr_oper.o)
    ld: symbol(s) not found for architecture x86_64

    I think the C compiler also needs the preprocessor flags that you
    only hand over to the Fortran code, I hackfixed this by

    AM_CFLAGS = = @fc_preprocessor_flag@ @fc_preflags@

    in the src/Makefile.am
    but there is probably a more elegant way. Then it also works on Darwin
    x86_64. I haven't tried the arm64 yet.


    --
    Juergen Reuter
    Theoretical Particle Physics
    Deutsches Elektronen-Synchrotron (DESY)
    Hamburg, Germany

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Koenig@21:1/5 to JRR on Thu Jul 21 16:53:37 2022
    JRR <juergen.reuter@invalid.com> schrieb:
    Am 20.07.22 um 19:36 schrieb Thomas Koenig:
    feanor <juergen.reuter@desy.de> schrieb:
    Thomas Koenig schrieb am Dienstag, 19. Juli 2022 um 22:26:42 UTC+2:

    Never mind that - I have found the bug, and I will fix it.
    OK, fixed now. I fell into a trap that is easy to fall into
    when doing C-style rc = "some pure function", this
    was optimized away (and I hadn't tested it with -O2 before,
    it worked with -O0).

    Now I cannot link anymore, during compilation I get the warning:
    mpfr_glue.c:56:3: warning: implicit declaration of function ‘mpfr_set_float128’; did you mean ‘fmpfr_set_float128’? [-Wimplicit-function-declaration]
    56 | mpfr_set_float128 (rop, op, rnd);
    | ^~~~~~~~~~~~~~~~~
    | fmpfr_set_float128
    and at linking the test program I get:
    Undefined symbols for architecture x86_64:
    "_mpfr_set_float128", referenced from:
    _fmpfr_set_float128 in libfmpfr.a(fmpfr_glue.o)
    ld: symbol(s) not found for architecture x86_64

    mpfr_set_float128 appears in mpfr.h as
    __MPFR_DECLSPEC mpfr_set_float128
    this seems for Windows DLL !?
    On Ubuntu 18.04 compilation and linking works now (with gcc/gfortran 7.5.0), on Darwin x86_64 (Intel, not M1 arm64) it doesn't

    Fixed, thanks for the reports!

    Hope you can do a bit more with it now :-)


    Thanks, Thomas. I still have an issue on Darwin x86_64:
    Undefined symbols for architecture x86_64:
    "_fmpfr_set_ld", referenced from:
    ___fmpfr_oper_MOD_ass_set_ld in libfmpfr.a(fmpfr_oper.o)
    ___fmpfr_oper_MOD_fun_set_ld in libfmpfr.a(fmpfr_oper.o)
    ld: symbol(s) not found for architecture x86_64

    I think the C compiler also needs the preprocessor flags that you
    only hand over to the Fortran code, I hackfixed this by

    AM_CFLAGS = = @fc_preprocessor_flag@ @fc_preflags@

    in the src/Makefile.am
    but there is probably a more elegant way. Then it also works on Darwin x86_64. I haven't tried the arm64 yet.

    Again, thanks for the testing!

    I have just added the -D flags to configure.ac and (which is also
    important) added a #define MPFR_WANT_FLOAT128 if float128 is supported.

    I hope it works now.

    Best regards

    Thomas

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)