Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

MPFR binding for Fortran

123 views
Skip to first unread message

Thomas Koenig

unread,
Jul 18, 2022, 5:21:11 PM7/18/22
to
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

feanor

unread,
Jul 19, 2022, 8:45:58 AM7/19/22
to
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

Thomas Koenig

unread,
Jul 19, 2022, 1:16:36 PM7/19/22
to
feanor <juergen...@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?

Thomas Koenig

unread,
Jul 19, 2022, 2:31:25 PM7/19/22
to
Thomas Koenig <tko...@netcologne.de> schrieb:
Never mind that - I have found the bug, and I will fix it.

Thomas Koenig

unread,
Jul 19, 2022, 4:26:42 PM7/19/22
to
Thomas Koenig <tko...@netcologne.de> schrieb:
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).

feanor

unread,
Jul 20, 2022, 8:39:11 AM7/20/22
to
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

Thomas Koenig

unread,
Jul 20, 2022, 1:37:00 PM7/20/22
to
feanor <juergen...@desy.de> schrieb:
Fixed, thanks for the reports!

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


JRR

unread,
Jul 21, 2022, 11:07:26 AM7/21/22
to
Am 20.07.22 um 19:36 schrieb Thomas Koenig:
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


Thomas Koenig

unread,
Jul 21, 2022, 12:53:40 PM7/21/22
to
JRR <juergen...@invalid.com> schrieb:
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
0 new messages