September 2018
Intermediate to advanced
606 pages
14h 32m
English
C and C++ programs can access OpenMP functionality by including the omp.h header file and by linking to the correct library. The compiler will generate parallel code according to preprocessor directives preceding the performance-critical sections. In this recipe, we will build the following example source code (example.cpp). This code sums integers from 1 to N, where N is given as a command-line argument:
#include <iostream>#include <omp.h>#include <string>int main(int argc, char *argv[]) { std::cout << "number of available processors: " << omp_get_num_procs() << std::endl; std::cout << "number of threads: " << omp_get_max_threads() << std::endl; auto n = std::stol(argv[1]); std::cout << "we will form sum of numbers from 1 to ...Read now
Unlock full access