What's the best way to find the number of threads that will be used for an omp parallel for
? I want to allocate enough memory for use with all the threads, but can't make use of omp_get_num_threads
until I'm inside 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's the proper way of doing it so that I can know how many threads will be used and can allocate accordingly? Thanks
You could use a call to omp_get_max_threads()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With