Expand gmp number and I calculated pi 121 billion digits

cents2823 at yahoo.co.jp cents2823 at yahoo.co.jp
Thu Apr 22 22:05:11 UTC 2021


Hi again.
The previous posting was from windows mail tool and was not very readable.
Hopefully, this posting is better.
Sorry,
Susumu Tsukamoto

Hi GMP users,
I am making a program that calculates pi with gmp, but the number of pi calculation digits is limited by the limit of the number of gmp.
There seems to be no release of gmp number expansion for the time being.

limit on the digits of gmp number: (2^31-1)*64*log(2) = 41,373,247,548 digits
Expand gmp number:  (2^63-1)*64*log(2)   = 177,696,745,232,747,428,213 digits

I changed the base struct of gmp to expand the number of gmp, gmp edits are shown in Section 2.
However, this change alone will cause gcc to cause some errors.
 (gcc error: internal compiler error: Segmentation fault)
The cause was taught by the gcc developer that GCC uses GMP,MPFR (which uses GMP internally) and MPC (which uses MPFR).
I am not MPFR user, and MPC user, so I have not confirmed the effect of gmp base struct change on MPFR and MPC.
The problem was solved by source installing gcc that supports gmp struct change.

The procedure for gmp number expansion is shown in Section 1.
I haven't done enough confirmation, if you try please take measures such as backup for safety.

Disadvantage of doing this I think:
a. Be careful when upgrading gcc or gmp.
b. About 900GB of memory + swap is required to calculate pi in 50 billion digits  using "Parallel GMP-Chudnovsky using OpenMP"(2008/10 gmp-discus Archive) program.
c. I don't think there is a need to revert to the original gmp,  but I'm not familiar with unix and I don't know how to revert safely  so ubuntu clear install which destroys all data programs when reverting.

I used this gmp to calculate pi in 121 billion digits with my pi calculate program(calculate and output time: about 86 hours) and "Parallel GMP-Chudnovsky using OpenMP"(2008/10 gmp-discus Archive) program.
 The calculation result was also calculated by y-cruncher and the match of the values was confirmed.
Thanks to gmp.
Susumu Tsukamoto

test pc:
cpu: i9-7940X 14core 28threads
memory: 128GB
os: ubuntu 20.04.2 LTS
gcc: 9.3.0 --> 10.0.1
gmp: 6.2.0

1. procedure
1.1 gcc source install
   Please refer to the appropriate web for the gcc source installation method.
   I show only the addition of steps.
   There is a download of related modules needed to build gcc    in the gcc source installation procedure.    ./contrib/download_prerequisites   (GMP,MPFR,MPC,.:download)
   Change section 2  to the download gmp after this download.
  Please switch to the gcc installed after installing the gcc source.

1.2 Edit gmp and install with new gcc
   I refer to the following for gmp installation   “how I install GMP onto my ubuntu Machines” on the web.
   I show only the addition of steps.
   Change section 2 to the download GMP.

1.3 enable installed gmp
  Notes I'm not sure if the following command can be applied to your pc  different from my pc environment.
  ln -nfs /usr/local/lib/libgmp.so.10.4.0 /usr/lib/x86_64-linux-gnu/libgmp.so.10
 description:
 In my pc environment, the install gmp execution part is not used, the gmp execution part attached to ubuntu is use, so it is necessary to switch to the install gmp.

2.gmp edit(gmp version: 6.2.0)
2.1 gmp-h.in 152,154 line  __mpz_struct   int _mp_alloc  --> long int _mp_alloc
  int _mp_size  --> long int _mp_size

2.2 gmp-h.in 190,194 line  __mpf_struct
  int _mp_prec  --> long int _mp_prec
  int _mp_size  --> long int _mp_size

2.3 mpz/init2.c 43-50 line comment out as follows
//  if (sizeof (unsigned long) > sizeof (int)) /* param vs _mp_size field */
//    {
//      if (UNLIKELY (new_alloc > INT_MAX))
// {
//   fprintf (stderr, "gmp: overflow in mpz type\n");
//   abort ();
// }
//    }

2.4 mpz/realloc.c 52-60 line comment out as follows
//  else
//    {
//      if (UNLIKELY (new_alloc > INT_MAX))
// {
//   fprintf (stderr, "gmp: overflow in mpz type\n");
//   abort ();
// }
//    }

2.5 mpz/realloc2.c 43-50 line comment out as follows
//  if (sizeof (unsigned long) > sizeof (int)) /* param vs _mp_size field */
//    {
//      if (UNLIKELY (new_alloc > INT_MAX))
// {
//   fprintf (stderr, "gmp: overflow in mpz type\n");
//   abort ();
// }
//    }
削除 ▲ページトップへ


More information about the gmp-discuss mailing list