y-cruncher - Developments

(Last updated: June 4, 2017)



Back To:


Active Branches:

At any time, there are usually two branches of y-cruncher that are active maintained. The following table lists the changes that are confirmed for each active branch.


Most easy-to-fix bugs get patched and cherrypicked into all active branches. But an actual release is only done when the bugs involved collectively reach a sufficient level of severity. So the current version that is available for download might be (and quite often is) behind the release branch.


Publicly released versions of y-cruncher tend to lag behind the internal ones by several months or more. This is mostly for QC reasons since there is usually zero tolerance for bugs that affect the correctness of a computation.

Branch Version # Changes (from v0.7.2.9469)
v0.7.2 v0.7.2.9470


  • Fixed a bug in swap mode that causes the primary formula for the Euler-Mascheroni Constant to require much more memory than is necessary. This bug was introduced when fixing the "working memory is too small" bug in v0.7.2.

  • Fixed an issue in the Custom Compute swap mode menu that may cause it to fail an internal assertion. This is also related to the Euler-Mascheroni Constant memory calculations.

In reality, the Euler-Mascheroni Constant's memory calculation code is a rat's nest of technical debt that needs to be thrown out and redone at some point.

trunk v0.7.3.9468-134

New Features:

  • Configuration Files:
    • The Custom Compute and I/O Benchmark menus now have support for saving to and loading from configuration files.
    • The functionalities for these menus can also be triggered directly from the command line with a configuration file.
    • Unlike command line options, configuration files provide all the functionality of the console UI plus some additional undocumented features.

  • Memory Allocator Improvements:
    • New memory allocators that support node interleaving. This may improve performance on NUMA systems.
    • Allocators now have sub-options that can be selected.
    • The memory allocator can now be set with the command line options.
    • On Windows, it is now possible to lock pages without using large pages.


  • Improved detection of available memory in Linux. In the past, it only detected unused pages. Now it detects all available memory including those used for caching which can be released if needed.

  • Invalid command-line options will now terminate the program instead of being silently skipped.

  • Fixed a bug in swap mode that causes the primary formula for the Euler-Mascheroni Constant to require much more memory than is necessary. This bug was introduced when fixing the "working memory is too small" bug in v0.7.2.

  • Fixed an issue in the Custom Compute swap mode menu that may cause it to fail an internal assertion. This is also related to the Euler-Mascheroni Constant memory calculations.


  • The dynamically-linked Linux binaries now have a dependency on libnuma due to the new node-interleaving allocators.
  • The concept of local and global "Min I/O Size" has been renamed and replaced with "Bytes per Seek".




y-cruncher was pretty heavily developed between 2008 - 2013. But I've since left school and found a full-time job. While y-cruncher will probably remain a side-hobby for the near future, it won't get as much attention as it used to get. At the very least, I'll continue to fix whatever bugs that are discovered. And I'll make an effort to keep the program up-to-date with the latest instruction set extensions and development toolchains. But for the most part, the project is done.


Most of the work right now is in cleaning up the code and refactoring it into idiomatic C++ for long-term maintainability. The program was (and still largely is) a fragile mess of unreadable C hackery with little to no documentation. So at the very least, I'd like to get it into a state where someone other than myself can read it.


Nevertheless, it's a never-ending project. So there are things on the to-do list. But it can be a long time before anything gets done.


Feature Description Status

Development on AVX512 began in 2014. And as of 2016, most of the work that could be done without the hardware has been completed.


Internally, there are currently 3 binaries with AVX512. But none of them are enabled publicly yet.

  • 16-KNL (Knights Landing)
  • 17-SKX (Skylake Purley)
  • 18-CNL (Cannonlake)

All of these are working and tested through emulation on both Windows and Linux. What's needed now is the actual hardware for final testing and performance tuning. So there's a lot of AVX512 code that's been sitting around while we wait for the hardware.


As of June 2017, the first line of Skylake X processors are around the corner. But due to conflicting rumors and leaked benchmarks, it is unclear whether this first line of SKylake X processors will have full-throughput AVX512 or only half-throughput. If they don't have the full-throughput AVX512, it's quite possible that y-cruncher's AVX512 support will not be ready until 2018.

Rewrite the Radix Conversion

The current radix conversion code is actually a prototype that ended up in production. It has so many problems that it's basically unsalvageable.

  • It's not possible to do checkpoints.
  • It uses more memory than necessary.
  • It's completely inflexible to any modifications that affect the memory layout.
  • It's very fragile and very easy to break.

The current code is actually the 3rd radix conversion to be used in y-cruncher (and the 2nd to use the Scaled Remainder Tree). But it's still a prototype since it's the first to combine all of the following features/optimizations:

  • Scaled Remainder Tree
  • Middle Product
  • Removal of Trailing Zeros
  • Precomputation of the forward FFTs of the powers.
  • Parallelization with bounded memory usage.
  • Swap Mode (out-of-core) Computation

At the time (2011), this was very ambitious - perhaps a little too ambitious. In the end, it required so many hacks that the thing became a complete mess.


The radix conversion will need to be completely redesigned and rewritten.

Still trying to figure out a way to approach this in a way that will be maintainable without sacrificing any performance...


The existing radix conversion has virtually no internal abstraction. This makes it both very fast and unmaintainable.

Reduced Memory Mode

For Pi Chudnovsky and Ramanujan, add a mode that will allow a computation to be done using less memory/disk at the cost of slower performance.


For a typical computation, most of the work requires very little memory. It's the occasional memory spike that causes y-cruncher to have such a high memory requirement.


There are about 4 large memory spikes in a Pi computation. In approximate descending order of size, they are:

  1. The final Binary Splitting merge in the series summation.

  2. The Final Multiply.

  3. The radix conversion verification.

  4. The first split of the radix conversion.

These spikes can be flattened via space-time tradeoffs in the respective algorithms. Since the trade-off only needs to be done at the spikes, the overall performance hit should be reasonably small.

As of v0.6.8, only the first two memory spikes have been suppressed. The overall memory reduction is not enough to be worth enabling the feature publicly.


The last two spikes both involve the radix conversion which is completely blocked pending the rewrite of the radix conversion code.


This partially completed feature was used for the 12.1 trillion digit computation of Pi.



Areas of Research:


Silent Data Corruption:

Disk I/O is the bane of large number computations. Historically, it was bad only because it is slow. Nowadays, it's also unreliable.


"Unreliability" comes in several forms:

  1. Basic I/O errors where an API call to read or write fails.
  2. The entire drive fails completely leading to permenant data loss.
  3. Silent data corruption that is neither detected by the hardware nor the operating system.

(1) and (2) are easily solved using checkpoint-restart and periodic backups. y-cruncher has supported checkpointing this since v0.5.4 so it isn't really a problem anymore. But (3) is very scary and remains a huge problem today.


Silent data corruption is the worst since it's undetected. It plagues database applications, and unfortunately, y-cruncher is extremely vulnerable as well. If an error manages to slip through y-cruncher's built-in redundancy checks, it will cause a computation to finish with the wrong digits.





Hard drives already use error-correction and CRCs to ensure data integrity. And transfers between the drive to the controller are also protected with CRCs. So you would expect that data corruption would be detected by the operating system right? Nope...


When a hard drive fails to read a sector due to CRC failures, it usually propagates all the way back into the program and manifests as a (1). So that's not a problem. But transfer errors between the drive and the controller are less ideal. Supposedly, transfer errors lead to retransmission. But this isn't always the case.


Throughout the years of developing y-cruncher, transfer errors have also been observed to:

  1. Severely slow down or hang the drive in question.
  2. Silent data corruption.
  3. Silent data corruption and an increase to the S.M.A.R.T. "Ultra ATA CRC error count".

(1) is to be expected if the connection quality is so bad that the data gets stuck in a retransmission loop.

(2) is also be expected if the corrupted data passes a CRC by chance. (I have no idea how long the CRC is, but if it's CRC32, a 1 in 4 billion chance isn't small.)

(3) makes absolutely no sense at all. If the hard drive was able to detect the error, then why the hell doesn't it notify the OS that the operation failed?


In any case, there are other things that don't add up. And in the end, we are forced to accept the reality.


To date, y-cruncher's only defense for silent data corruption is the RAID3. When the swap file configuration is set to use RAID3, (almost) all reads are parity checked. And if the data is bad, it will report a failure. The parity bits are flipped so that zeroing errors that zero everything will fail the parity.


Unfortunately, this is far from sufficient:

To date, silent data corruption has yet to bring down a world-record attempt. But it happens regularly in the development test machines (which contain some very old hard drives). There has also been an instance reported on a forum where a 1 trillion digit computation of Pi failed - presumably due to silent data corruption.


Approximately 80% of the disk I/Os that y-cruncher does are covered by redundancy checks at a higher level. So in the absence of RAID 3, silent data corruption will be detected with 80% probability if we assume uniform distribution. To put it simply, 80% is not good enough. But at the very least, failing a redundancy check should be an immediate and serious red flag.



Possible Solutions:


Use a filesystem designed for data integrity (such ZFS). While this is almost too obvious, there will also be performance trade-offs.


The other approaches involve adding checksumming into y-cruncher's raid-file implementation. But this is easier said than done:

Inlining checksums into the data will break sector-alignment and incur copy-shifting overhead. But perhaps this can be merged with the RAID interleaving. Placing the checksums elsewhere will add seek overhead. Either way, it will be messy.


Due to the poor state of the current raid-file code, any significant change will likely imply a complete rewrite of the entire raid-file implementation.



Non-Uniform Memory Access (NUMA):

y-cruncher is currently a shared memory program. So it will run efficiently given the following assumptions:

  1. All the memory in the system is shared and can be accessed by all processor cores.
  2. All processor cores have low latency and high-bandwidth access to all the memory.

As of 2016, these assumptions hold for almost all single-socket systems - which include the majority of personal desktop computers and low-end servers.


But due to the laws of physics and the speed of light, assumption #2 does not hold for larger systems. So now we're into the territory of Non-Uniform Memory Access (NUMA), cluster/distributed computing. For now the focus will be on NUMA systems since that's what the majority of the multi-socket systems are.


In short, y-cruncher does not run efficiently on NUMA. While it scales reasonably well onto dual-socket, it all goes downhill after that. There have been numerous reports of non-scaling (and even backwards scaling) on quad-Opteron systems. And all of this is due to the NUMA.


To exacerbate the problem, OS's normally default to a "first-touch" policy for memory allocation. The problem is that y-cruncher allocates all its memory at the start of a computation with a single thread. With the first-touch policy, all the memory will be allocated (or heavily biased) on one NUMA mode. So during the computation, all the cores from all the NUMA nodes will be hammering that one node for memory access. The interconnect going in and out of that one node will be overwhelmed by the traffic which leads to terrible performance.


This can be solved by telling the either the OS or the BIOS to use an interleaved allocation policy that spreads out the memory across all the nodes. This balances the interconnect traffic and leads to a significant performance on modern dual and quad-socket systems. But ultimately, this doesn't actually solve the problem of NUMA since the memory accesses (which are now randomized) will still be hitting remote nodes over the interconnect.


To be efficient, the program needs to be aware of the NUMA and needs to be designed specifically for it. This is a fairly difficult task which is made worse by the unlimited combinations of NUMA topologies. Long story short, making y-cruncher NUMA aware will require changing the way that memory is fundamentally stored and managed. This means that it will need to be done as a new "mode" much like how "Ram Only" and "Swap Mode" have completely different data storage formats.



Currently, the most promising solution is to generalize the functionality of swap mode in the following ways:

  1. Instead of using a disk array, replace it with a "far memory" interface which can be anything from disk to interleaved NUMA or even cloud storage.
  2. Leverage the swap mode algorithms for minimizing disk access to minimize access to far memory.
  3. Duplicate shared resources into each NUMA node to reduce interconnect thrashing.


GCD Factorization:

Many binary splitting recursions have a lot of common factors between the fraction numerators and denominators. Implement an optimization that seeks to remove these common factors so that the numbers are smaller in size.


GCD Factorization was first described here (now a dead link). Since then, there have been subsequent publications that describe the method:

The general idea of the optimization is to keep the prime factorization of some of the recursion variables. Then use this factorization to obtain the GCD of the numerator and denominator terms. Obtaining this prime factorization is done using a sieve.


Current implementations of this optimization include GMP Pi Chudnovsky and TachusPi. And most literature reports a speedup of about 20 - 30% for Pi Chudnovsky.


In the context of y-cruncher, this optimization is applicable to the following constants/algorithms:


Current Problems:


Even though GCD factorization has been known for years, y-cruncher has yet to use it for a number of reasons:

  1. The naive approach to sieving the index terms will require to prohibitive amount of memory. This problem exists in GMP Pi Chudnovsky. Fabrice Bellard's TachusPi has a more efficient approach that does it using O( sqrt(N) ) memory - presumably using some sort of sieve segmentation. But he left few details on this approach.

  2. The data structure that is needed to perform the sieve and store the prime factorization is somewhat incompatible with y-cruncher's memory model.

  3. y-cruncher lacks the ability to efficiently perform integer divisions.

While (1) and (3) are certainly solvable, (2) is more difficult. All the ideas so far for attacking (2) are either complicated and fragile, or they require breaking out of the current memory model. For now, there's bigger fish to fry.