One million digits of Pi using the crate 'compute-pi'
Unlocking Precision Computing on the Raspberry Pi 2
Despite its age, the Raspberry Pi 2 Model B remains a surprisingly capable tool for precision computing tasks. Recently, I revisited this classic single-board computer (SBC) to explore its potential for high-precision numerical calculations, leveraging lightweight software and efficient coding practices.
Experiment: Computing π to One Million Digits
Using the compute-pi utility (installed via Rust's cargo), the Raspberry Pi 2 successfully calculated π to one million decimal places in just seconds. This performance underscores the Pi's ability to handle computationally intensive tasks, even within the constraints of its 32-bit architecture and modest 900 MHz quad-core CPU.
Setup Overview
OS: Alpine Linux 3.21.0
Kernel: Linux 6.12.1
Hardware: Raspberry Pi 2 Model B Rev 1.1
Software: Rust compute-pi, managed via the lightweight apk package manager
Why the Pi 2 Still Matters
Low-Cost Precision Computing: At its core, the Pi 2 offers a budget-friendly platform for exploring high-precision mathematics, making it accessible for students, hobbyists, and educators.
Efficient Resource Usage: Running Alpine Linux, the system utilized less than 6% of its 1 GB memory, leaving ample room for other tasks.
Scalable Learning Platform: Paired with tools like Rust or Python, the Pi 2 enables hands-on learning in numerical methods, cryptography, and more.
A Hidden Gem for Lightweight Workloads
While it lacks the raw power of its successors, the Raspberry Pi 2's efficiency and compatibility with modern tools like Rust prove its value for precision tasks. Whether you're diving into mathematics, optimizing algorithms, or teaching computational concepts, this modest SBC is still up to the challenge.
Code:
/home/ubu/pi/src # cargo install ripgrep Updating crates.io index Downloaded ripgrep v14.1.1 Downloaded 1 crate (213.6 KB) in 0.75s Installing ripgrep v14.1.1 Updating crates.io index Locking 52 packages to latest compatible versions Downloaded grep v0.3.2 Downloaded cfg-if v1.0.0 Downloaded same-file v1.0.6 Downloaded globset v0.4.15 Downloaded grep-regex v0.1.13 Downloaded termcolor v1.4.1 Downloaded walkdir v2.5.0 Downloaded crossbeam-utils v0.8.20 Downloaded ignore v0.4.23 Downloaded grep-printer v0.2.2 Downloaded memchr v2.7.4 Downloaded anyhow v1.0.94 Downloaded serde_json v1.0.133 Downloaded regex-automata v0.4.9 Downloaded aho-corasick v1.1.3 Downloaded memmap2 v0.9.5 Downloaded log v0.4.22 Downloaded serde v1.0.215 Downloaded regex-syntax v0.8.5 Downloaded bstr v1.11.0 Downloaded ryu v1.0.18 Downloaded grep-searcher v0.1.14 Downloaded lexopt v0.3.0 Downloaded encoding_rs_io v0.1.7 Downloaded crossbeam-deque v0.8.5 Downloaded itoa v1.0.14 Downloaded grep-matcher v0.1.7 Downloaded libc v0.2.168 Downloaded textwrap v0.16.1 Downloaded grep-cli v0.1.11 Downloaded crossbeam-epoch v0.9.18 Downloaded encoding_rs v0.8.35 Downloaded 32 crates (4.7 MB) in 3.44s (largest was `encoding_rs` at 1.4 MB) Compiling memchr v2.7.4 Compiling regex-syntax v0.8.5 Compiling libc v0.2.168 Compiling log v0.4.22 Compiling serde v1.0.215 Compiling aho-corasick v1.1.3 Compiling cfg-if v1.0.0 Compiling crossbeam-utils v0.8.20 Compiling encoding_rs v0.8.35 Compiling grep-matcher v0.1.7 Compiling serde_json v1.0.133 Compiling regex-automata v0.4.9 Compiling encoding_rs_io v0.1.7 Compiling memmap2 v0.9.5 Compiling itoa v1.0.14 Compiling termcolor v1.4.1 Compiling ryu v1.0.18 Compiling crossbeam-epoch v0.9.18 Compiling anyhow v1.0.94 Compiling same-file v1.0.6 Compiling walkdir v2.5.0 Compiling bstr v1.11.0 Compiling globset v0.4.15 Compiling grep-searcher v0.1.14 Compiling grep-printer v0.2.2 Compiling grep-cli v0.1.11 Compiling grep-regex v0.1.13 Compiling crossbeam-deque v0.8.5 Compiling ripgrep v14.1.1 Compiling ignore v0.4.23 Compiling grep v0.3.2 Compiling textwrap v0.16.1 Compiling lexopt v0.3.0 Finished `release` profile [optimized + debuginfo] target(s) in 15m 28s Installing /root/.cargo/bin/rg Installed package `ripgrep v14.1.1` (executable `rg`)/home/ubu/pi/src #/home/ubu/pi/src # apk add m4(1/1) Installing m4 (1.4.19-r3)Executing busybox-1.37.0-r8.triggerOK: 1110 MiB in 448 packages/home/ubu/pi/src # apk add build-base bash(1/8) Installing libmagic (5.46-r0)(2/8) Installing file (5.46-r0)(3/8) Installing libstdc++-dev (14.2.0-r4)(4/8) Installing g++ (14.2.0-r4)(5/8) Installing make (4.4.1-r2)(6/8) Installing fortify-headers (1.1-r5)(7/8) Installing patch (2.7.6-r10)(8/8) Installing build-base (0.5-r3)Executing busybox-1.37.0-r8.triggerOK: 1164 MiB in 456 packages/home/ubu/pi/src # cargo install compute-pi Updating crates.io index Downloaded compute-pi v1.0.0 Downloaded 1 crate (5.1 KB) in 0.23s Installing compute-pi v1.0.0 Updating crates.io index Locking 15 packages to latest compatible versions Downloaded az v1.2.1 Downloaded libm v0.2.11 Downloaded rug v1.26.1 Downloaded gmp-mpfr-sys v1.6.4 Downloaded 4 crates (6.1 MB) in 5.65s (largest was `gmp-mpfr-sys` at 5.6 MB) Compiling libc v0.2.168 Compiling gmp-mpfr-sys v1.6.4 Compiling az v1.2.1 Compiling libm v0.2.11 Compiling rug v1.26.1 Compiling compute-pi v1.0.0 Finished `release` profile [optimized] target(s) in 32m 08s Installing /root/.cargo/bin/compute-pi Installed package `compute-pi v1.0.0` (exe)
Code:
/home/ubu/pi/src # compute-pi 100Pi to 100 decimal places: 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679/home/ubu/pi/src # compute-pi 1000000 >pimillion.txt/home/ubu/pi/src # mcsh: mc: not found/home/ubu/pi/src # apk add mc(1/4) Installing gpm-libs (1.20.7-r5)(2/4) Installing slang (2.3.3-r3)(3/4) Installing libssh2 (1.11.1-r0)(4/4) Installing mc (4.8.32-r0)Executing busybox-1.37.0-r8.triggerOK: 1167 MiB in 460 packages/home/ubu/pi/src # mc/home/ubu/pi/src # fastfetch --logo noneubu@localhost-------------OS: Alpine Linux 3.21.0 armv7lHost: Raspberry Pi 2 Model B Rev 1.1Kernel: Linux 6.12.1-0-rpiUptime: 1 hour, 11 minsPackages: 460 (apk)Shell: shTerminal: /dev/pts/1CPU: BCM2835 (4) @ 0.90 GHzMemory: 51.85 MiB / 921.50 MiB (6%)Swap: DisabledDisk (/): 1.66 GiB / 14.21 GiB (12%) - ext4Local IP (eth0): 192.168.1.104/24Locale: C.UTF-8
Statistics: Posted by geev03 — Tue Dec 10, 2024 9:16 pm