GMP logo Computing billions of π digits using GMP

This program, written by Hanhong Xue, can be used to compute tens of billions of digits of π, provided you have enough memory in your system: gmp-chudnovsky.c

For the program to work properly for more than 231 bits (about 600 million digits) you need to to use GMP 4.2 (or later).

Here are timing results with GMP 4.2.2 (sorted after processor speed):

Number of digits Time (s)
Athlon64
2.6 GHz
Time (s)
"Core 2"
3.0 GHz
Time (s)
PowerPC 970
2.7 GHz
Time (s)
Itanium 2
1.6 GHz
Time (s)
Pentium 4
3.2 GHz
100,000 0.05 0.08 0.13 0.13 0.15
1,000,000 1.23 1.68 1.92 2.33 2.9
10,000,000 22.5 30.9 33.3 42.2 52.3
100,000,000 393 549 565 740 902
1,000,000,000 6860 9278   14400  

How do these numbers compare to other π computing programs out there? It seems gmp-chudnovsky.c with GMP 4.2 is faster than all specialized π programs on Athlon, but a tad bit slower on Pentium 4.

Many π programs proclaim themselves as "the fastest", but then they are actually slower than gmp-chudnovsky.c with the current GMP release. Compare the numbers!

The next version of GMP will make gmp-chudnovsky.c beat 'em also on Pentium 4 and crush them on Athlon. E.g., linking gmp-chudnovsky.c with the current development version of GMP, computing 100,000,000 digits needs about 200 seconds on a high end Athlon64 system.

Using GMP 4.2, a fast 64-bit computer, and sufficient memory, it should be possible to compute up to 41 billion (41e9) digits. Unfortunately, the memory requirements are about 8n bytes for computing n digits, which will make most desktop computers unfit for 41 billion digit computations. Memory locality in GMP 4.2's FFT multiply code is not good enough for efficient computation with operands on disk.

Attempting computations of more than 41 billion digits will cause overflow in the mpz type. The fabled GMP 5 will allow the patient and wealthy to compute up to at least 1 quintillion (1e15) digits, and unlike GMP 4.x, GMP 5 will operate fine with operands on disk. You'll need around 10000 high-end swap disks in order to compute 1 quintillion digits, but surely that will qualify you for a good discount ("buy 10000, pay for 9999").



Please send comments about this page to gmp-discuss@swox.com
Copyright 2005, 2006, 2007 Free Software Foundation
Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved.