#include #include #include using namespace std; int main() { int threads{2}; int iterations{10}; vector hits(threads,0); omp_set_num_threads(threads); #pragma omp parallel { int id{omp_get_thread_num()}; double x,y; unsigned int seed{id* time(nullptr)}; #pragma omp for for(int i = 0; i < iterations; ++i) { x = rand_r(&seed) / static_cast(RAND_MAX); y = rand_r(&seed) / static_cast(RAND_MAX); if (x*x + y*y <= 1) { ++hits[id]; } } } int totalHits{0}; for(i =0; i < threads;++i) { totalHits += hits[i]; } return 0; }