Google just smashed the world record for calculating digits of pi

Happy π day! We now know the first 31.4 trillion digits of the tastiest mathematical constant
Getty Images

Pi just got bigger. Google’s Compute Engine has calculated the most digits of pi ever, setting a new world record.

Emma Haruka Iwao, who works in high performance computing and programming language communities at Google, used infrastructure powered by Google Cloud to calculate 31.4 trillion digits of pi. The previous world record was set by Peter Trueb in 2016, who calculated the digits of pi to 22.4 trillion digits. This is the first time that a publicly available cloud software has been used for a pi calculation of this magnitude.

Iwao became fascinated by pi when she learned about it in math class at school. At university, one of her professors, Daisuke Takahashi, was the record holder for the most-calculated digits of pi using a supercomputer. Now, y-cruncher is the software of choice for pi enthusiasts. Created in 2009, y-cruncher is designed to compute mathematical constants like pi to trillions of digits.

“You need a pretty big computer to break the world record,” says Iwao. “But you can’t just do this with a computer from a hardware store, so people have previously built custom machines.” In September of 2018, Iwao started to consider how the process of calculating even more digits of pi would work technically. Something which came up quickly was the amount of data that would be necessary to carry out the calculations, and store them – 170 terabytes of data, which wouldn’t be easily hosted by a piece of hardware. Rather than building a whole new machine Iwao used Google Cloud.

Iwao used 25 virtual machines to carry out those calculations. “But instead of clicking that virtual machine button 25 times, I automated it,” she explains. “You can do it in a couple of minutes, but if you needed that many computers, it could take days just to get the next ones set up.” Iwao ran y-cruncher on those 25 virtual machines, continuously, for 121 days.

In order to make sure nothing went wrong, the virtual machines had to be running constantly. Just like a calculation by hand, or on a whiteboard, every step had to be clearly visible, something which would only be possible if the cloud kept the program continuously running. “You can’t take a nap and then start over when you’re doing it by hand, so you have to store all the data necessary to do the math,” says Iwao. “So, with pen and paper, you need a lot of sheets of paper. In this case, you need a lot of storage.” She also set up a monitoring system, which would alert her if something had gone wrong – for example, if one of her virtual machines had suddenly crashed. Just one crash – even for a couple of minutes – could have jeopardised the whole process.

“Y-cruncher, and Google Cloud, both have these methods of making copies – so it’s like photocopying at certain points, and I set it up so that you can take copies of these disks instantly without stopping the calculation,” says Iwao. That data is then copied and saved externally, on other discs, as snapshots.

“There were a couple of parametres I did tweak at the beginning, like how much data you could read or write at one time, and how the boundaries would change as it got bigger,” says Iwao.

As the calculations became increasingly complex, the greater the strain it was on the virtual machines, and the more time it took. Y-cruncher’s calculations don’t work at a linear rate – if you wanted to calculate twice as many digits, it takes more than twice as much time and storage, which proved difficult when Iwao was making the initial calculations, to figure out how many virtual machines she would need.

But the real pressure came closer to the end. Built into y-cruncher are two base algorithms – one for the calculations of pi itself, and another for the verification. The verification algorithm runs alongside the calculation, but it only calculates one single digit of pi, and it takes a lot of time and resources. So you couldn’t use the verification program to calculate every single digit, because it would simply take even more time and storage. What it can do is prove that your results are correct. “The final multiplication is important, because if you miss one digit during those calculating processes, then the entire result is wrong,” says Iwao.

While it may seem like a niche hobby, pi is often used by developers and programmers to test the performance of new hardware. Its uses can even stretch further than just cloud computing, into areas like healthcare. “There are a lot of applications that require a lot of complex computing resources, like weather forecasts, and actually, this proves that the cloud is capable of handling those calculations,” says Iwao.

Those snapshots of Iwao’s calculations, which were saved on external discs in Google Cloud, are now publicly available too, which means that enthusiasts can copy those calculations and use them elsewhere. As for Iwao, it means that she can relax a little bit more. “I was confident in the infrastructure, but I was nervous for the entire thing,” she says. “But it’s like when you take a math test, no matter how confident you are, you feel better when you’ve got your results.”

This article was originally published by WIRED UK