Skip to content

elkasztano/piday25

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Piday25

Lightweight and multithreaded implementation of the Chudnovsky algorithm. Calculate a million digits of Pi within seconds.

Features

  • multithreaded calculation of Pi using the Chudnovsky algorithm and binary splitting

  • simple command line interface

  • Pi is printed to STDOUT or a file

  • results of time measurements and additional information are printed to STDERR

  • only the result, i.e. Pi is printed to STDOUT

How to compile

Provided that the Rust toolchain is installed:

git clone "https://github.com/elkasztano/piday25"
cd piday25
cargo build --release

For obvious reasons, it is recommended to run the program in release mode in order to get the best results.

Command line options

-d, --digits

Number of digits to calculate. Defaults to 30,000.

-t, --threads

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.

-v...

Verbosity level. Prints additional information to STDERR.

  • -v shows 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

  • -vv shows different stages of the calculation

  • -vvv shows completion of each individual thread

-m, --measure-time

Shows elapsed time in seconds, prints to STDERR.

--silent

Calculate Pi, but omit the output.

-o, --output

Print the result to a file.

Warning: Overwrites without prompt. See std::fs::write.

-h, --help

Print help.

-v, --version

Print version.

Panics

Note

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.

Examples

cargo run --release

If 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 200

Calculate 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 -- -h

Show help text.

Dependencies

  • dashu for arbitrary precision mathematics

  • crossbeam-channel for multithreaded calculations

  • last but not least clap for an easy-to-use command line interface

Verification

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.

About

multithreaded implementation of the Chudnovsky algorithm

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages