This project implements a parallelized Sieve of Eratosthenes algorithm in Go, C++, and Rust to find all prime numbers up to a given integer 10^N.
This project uses the Nix package manager to provide a consistent development environment with all the necessary compilers and build tools.
You can build and run each language's implementation individually. Replace
9 with the desired upper limit (N).
sh cd sieve_go go run . 9
To build an optimized executable:
The C++ version uses the Meson build system.
-
Configure the build (only needs to be done once):
sh cd sieve_cpp meson setup builddir -
Compile the code:
sh cd sieve_cpp meson compile -C builddir -
Run the executable:
sh ./sieve_cpp/builddir/sieve_cpp 9
The Fortran version also uses Meson.
-
Configure the build (only needs to be done once):
sh cd sieve_fortran meson setup builddir -
Compile the code:
sh cd sieve_fortran meson compile -C builddir -
Run the executable:
sh ./sieve_fortran/builddir/sieve_fortran 9
The Rust version uses Cargo.
-
Build the optimized executable:
sh cd sieve_rust cargo build --release -
Run the executable:
sh ./sieve_rust/target/release/sieve_rust 9
The benchmark script in the root of the project will automatically build and
run all implementations, executing each one multiple times to provide stable
performance metrics. It uses hyperfine for benchmarking and runs within a
consistent Nix development environment.
To run the full benchmark suite:
sh ./benchmark
To see the output from the build commands, use the -v (verbose) flag:
sh ./benchmark -v