Controlling the threading environment
Since we’re using OpenMP for our multithreading support, setting up the threading environment is very easy. All we need to do is take the number of threads specified by command-line arguments or from environment variables and call omp_set_num_threads to set the number of threads to use in subsequent parallel blocks. If you’re using other threading libraries, such as Intel Thread Building Blocks (TBB) or Apple Grand Central Dispatch, or some bespoke implementation, this might involve setting up the thread pool and configuring the settings just like here. In our case, the only code that is needed is as follows, which is the body of the setup_threading function:
auto num_threads = omp_get_max_threads();
if (args.count("jobs")) {
auto requested_threads = args["jobs"].as<int>();
num_threads = std::min(num_threads, requested_threads);
} else {
// set a very conservative default
num_threads...