Lightweight and multithreaded implementation of the Chudnovsky algorithm. Calculate a million digits of Pi within seconds.
-
multithreaded calculation of Pi using the Chudnovsky algorithm and binary splitting
-
simple command line interface
-
Pi is printed to
STDOUTor a file -
results of time measurements and additional information are printed to
STDERR -
only the result, i.e. Pi is printed to
STDOUT
Provided that the Rust toolchain is installed:
git clone "https://github.com/elkasztano/piday25"
cd piday25
cargo build --releaseFor obvious reasons, it is recommended to run the program in release mode in order to get the best results.
Number of digits to calculate. Defaults to 30,000.
Number of threads to be used. Defaults to available parallelism.
Caution: The largest power of two, that is smaller or equal to the specified number will be used. If for example the number of 15 is given, it will fall back to 8, whereas 16 will be fine because it already is a power of two.
Verbosity level. Prints additional information to STDERR.
-
-vshows the number of used threads, and shows a warning if the given number is not a power of two - also shows if the number of requested digits is clamped -
-vvshows different stages of the calculation -
-vvvshows completion of each individual thread
Shows elapsed time in seconds, prints to STDERR.
Calculate Pi, but omit the output.
Print the result to a file.
Warning: Overwrites without prompt. See std::fs::write.
Print help.
Print version.
-
Panics if obtaining the available parallelism fails.
-
Panics if output to a file is specified but std::fs::write returns the Error variant.
Due to reported crashes when requesting fewer than 434 (or 882) digits, the program now calculates a minimum of 1000 digits by default. However, only the number of digits specified by the user will be displayed.
cargo run --releaseIf command line arguments are omitted, 30,000 digits of Pi will be printed to STDOUT using the maximum appropriate parralelism, i.e. the largest power of two, that is smaller or equal to the number of actually available threads.
cargo run --release -- -d 1000200 -m -vvv | tail -c 200Calculate 1,000,200 digits of Pi, but only show the last 200 of them. Additional informations with the maximum verbosity is printed to STDERR, including the amount of time it took to calculate the digits.
cargo run --release -- -hShow help text.
-
dashu for arbitrary precision mathematics
-
crossbeam-channel for multithreaded calculations
-
last but not least clap for an easy-to-use command line interface
External source of 1,000,200 digits of Pi, used for verification:
http://newton.ex.ac.uk/research/qsystems/collabs/pi/
Keep in mind that trailing zeroes are omitted in the output.