Pi in the sky: Calculating a record-breaking 31.4 trillion digits of Archimedes’ constant on Google Cloud
Emma Haruka Iwao
[Editor’s note: It’s been two years since Googler Emma Haruka Iwao set a world record for calculating the most digits of Pi using Google Cloud. But just like the constant itself, our love for this story never ends. On this March 14, 2021 may you celebrate Pi Day with a slice of something delicious, and this story.]
Ever since the ancient Babylonians, people have been calculating the digits of π, the ratio of the circumference of a circle to its diameter that starts as 3.1415… and goes on forever. In honor of Pi Day, today March 14 (represented as 3/14 in many parts of the world), we’re excited to announce that we successfully computed π to 31.4 trillion decimal places—31,415,926,535,897 to be exact, or π * 1013. This has broken a GUINNESS WORLD RECORDSTM title , and the first time the record was broken using the cloud, proving Google Cloud’s infrastructure works reliably for long and compute-heavy tasks.
We achieved this feat using y-cruncher, a Pi-benchmark program developed by Alexander J. Yee, using a Google Compute Engine virtual machine cluster. 31.4 trillion digits is almost 9 trillion digits more than the previous world record set in November 2016 by Peter Trueb. Yee independently verified the calculation using Bellard's formula and BBP formula. Here are the last 97 digits of the result.
6394399712 5311093276 9814355656 1840037499 3573460992
1433955296 8972122477 1577728930 8427323262 4739940
You can read more details of this record from y-cruncher's perspective in Yee’s report.
A constant race
Granted, most scientific applications don’t need π beyond a few hundred digits, but that isn’t stopping anyone; starting in 2009, engineers have used customized personal computers to calculate trillions of digits of π. In fact, the race to calculate more π digits has only accelerated as of late, with computer scientists using it as a way to test supercomputers, and mathematicians to compete against one another.
However, the complexity of Chudnovky's formula—a common algorithm for computing π—is O(n (log n)3). In layman’s terms, this means that the time and resources necessary to calculate digits increase more rapidly than the digits themselves. Furthermore, it gets harder to survive a potential hardware outage or failure as the computation goes on.
For our π calculation, we decided to go to the cloud. Using Compute Engine, Google Cloud’s high-performance infrastructure as a service offering, has a number of benefits over using dedicated physical machines. First, Compute Engine’s live migration feature lets your application continue running while Google takes care of the heavy lifting needed to keep our infrastructure up to date. We ran 25 nodes for 111.8 days, or 2,795 machine-days (7.6 machine-years), during which time Google Cloud performed thousands of live migrations uninterrupted and with no impact on the calculation process.
Running in the cloud also let us publish the computed digits entirely as disk snapshots. In less than an hour and for as little as $40/day, you can copy the snapshots, work on the results, and dispose of the computation resources. Before cloud, the only feasible way to distribute such a large dataset was to ship physical hard drives.
Then there are the general benefits of running in the cloud: availability of a broad selection of hardware, including the latest Intel Skylake processors with AVX-512 support. You can scale your instances up and down on demand, and kill off when you are done with them, only having paid for what you used.
Here are additional details about the program:
We selected an
n1-megamem-96 instance for the main computing node. It was the biggest virtual machine type available on Compute Engine that provided Intel Skylake processors at the beginning of the project. The Skylake generation of Intel processors supports AVX-512, which are 512-bit SIMD extensions that can perform floating point operations on 512-bit data or eight double-precision floating-point numbers at once.
Currently, each Compute Engine virtual machine can mount up to 64 TB of Persistent Disks. We used the iSCSI protocol to remotely attach Persistent Disks to add additional capacity. The number of nodes were decided based on y-cruncher's disk benchmark performance. We selected
n1-standard-16 for the iSCSI target machines to ensure sufficient bandwidth between the computing node and the storage as the network egress bandwidth and Persistent Disk throughput are determined by the number of vCPU cores.
How to get your hands on the digits
Our pi.delivery service provides a REST API to access the digits on the web. It also has a couple of fun experiments that lets you visualize and listen to π.
To make it easier for you to use these digits in your own work, we have made the resulting π digits available as snapshots on Google Cloud Platform. Each snapshot contains a single text file with the decimal digits and you can create a new Persistent Disk based on these images. We provide both XFS and NTFS disk formats to accommodate Linux and Windows operating systems respectively. The snapshots are located in the us multi-region.
You need to join the pi-31415926535897 Google Group to gain access. It will cost approximately $40 per day to keep the cloned disk in one of the us-central1, us-west1, and us-east1 regions in your project. We will keep the snapshots until March 14, 2020. The snapshots are available at the following locations.
To create a new disk named
pi314-decimal-digits-xfs in your project based on the XFS snapshot, for example, type the following command:
gcloud compute disks create pi314-decimal-digits-xfs --source-snapshot https://www.googleapis.com/compute/v1/projects/pi-31415926535897/global/snapshots/decimal-digits-xfs
Remember to delete the disk once you're done with it to avoid unexpected charges.
gcloud compute disks delete pi314-decimal-digits-xfs
Coming full circle
The world of math and sciences is full of records just waiting to be broken. We had a great time calculating 31.4 trillion π digits, and look forward to sinking our teeth into other great challenges. Until then, let's celebrate the day with fun experiments. Our Pi Day Celebration cloud experiment on our Showcase experiments website lets you generate a custom art piece from digits of π that you pick. And if you’re going to Google Cloud Next '19 in San Francisco, come to our deep-dive technical session together with Alexander Yee to discuss details and insights from this experiment, interact with the Showcase experiment and watch a live experiment with the π digits inside the DevZone.