OpenMP get_num_threads for concurrency for

What is the best way to find the number of threads that will be used for omp parallel for ? I want to allocate enough memory to use with all threads, but I can not use omp_get_num_threads until I get to the parallel section. For instance:

 int thread_count = ? float *data = (float*)malloc(thread_count * data_count * sizeof(float)); #pragma omp parallel for default(shared) private(x) for (x=0; x<N; x++) { int threadid = omp_get_thread_num(); //... do stuff with data } free(data); 

What is the right way to do this so that I can know how many threads will be used and can be allocated accordingly? Thanks

+4
source share
1 answer

You can use omp_get_max_threads() call.

+5
source

Source: https://habr.com/ru/post/1385921/


All Articles