A prime generation application written in C++ featured in the Multi-Threading section of the Understanding Node.js: Core Concepts course. This code is then used in this Node.js project as a native addon. The reason for doing this is to gain a significant performance boost in our Node.js application, and also to see Node.js Addons and native multi-threading in Node.js in action.
To get the project up and running after cloning the repository, follow these steps (instructions only for unix-based machines):
GMP is used to be able to generate arbitrarily large prime numbers. Run the following script to download and compile the GMP library:
./gmp.sh
This script will:
- Download GMP version 6.3.0
- Extract the source code to the
deps/GMP
directory - Configure and compile GMP with C++ support
After GMP is set up, configure CMake by running:
./cmake.sh
This script will:
- Create a
build
directory if it doesn't exist - Run CMake to generate the necessary build files
Finally, compile the code and run the application with:
./run.sh
This script will:
- Compile the code in the
build
directory - Execute the
prime_generator
application
Ensure that your machine is properly setup for C++ development. The gmp.sh
script takes care of GMP, but you need to have other tools like CMake and Make installed as well. Running sudo apt install m4 cmake autoconf automake libtool
on Linux should get all these tools installed.
On Linux, the ./gmp.sh
file may not be able to properly setup the library. If that's the case, install GMP like this:
sudo apt install libgmp-dev