Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenMP get_num_threads for parallel for

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

like image 898
inthecrossfire Avatar asked Dec 12 '11 16:12

inthecrossfire


1 Answers

You could use a call to omp_get_max_threads().

like image 199
Tudor Avatar answered Oct 12 '22 10:10

Tudor