I'm trying various ways to set my number of threads by either using clause or setting in the environment, but none of them has worked. Is there any way to force OpenMP to get a custom number of threads?
#include <cmath>
#include <random>
#include <iostream>
#include <chrono>
#include <cfloat>
#include <iomanip>
#include <cstdlib>
#include <omp.h>
#include <trng/yarn2.hpp>
#include <trng/mt19937_64.hpp>
#include <trng/uniform01_dist.hpp>
using namespace std;
double function(double x) {
return cos(x) / landa;
}
int main() {
int rank;
const int N = 1000000;
double sum = 0.0;
omp_set_num_threads(6);
omp_set_dynamic(0);
#pragma omp reduction(+ : sum) //default(none)
{
trng::yarn2 r;
int size = omp_get_num_threads();
cout<<size<<endl;
int rank = omp_get_thread_num();
trng::uniform01_dist<> u;
r.jump(2 * (rank * N / size));
for (long i = rank * N/ size; i < (rank + 1) * N / size; ++i) {
double x= u(r);
x = (-1.0) * log(1.0 - x);
sum = sum+function(x);
}
}
return 0;
}