I'm trying to get started with using basic OpenMP functionality in C. My basic understanding of 'omp parallel for' leads me to believe the following should distribute the following iterations of the loop between threads and should execute concurrently. The output I am getting is as follows. Code Below. Is there something subtle I am missing in my hello world example?
Hello World from omp thread 0 Hello World from omp thread 0 Hello World from omp thread 0 Hello World from omp thread 0 Hello World from omp thread 0 Hello World from omp thread 0 etc..
int HelloFunc()
{
int i;
int numthreads = 8;
#pragma omp parallel for default(none) num_threads(numthreads) private(i)
for (i = 0; i < 100; i++)
{
int tid = omp_get_thread_num();
printf("Hello world from omp thread %d\n", tid);
}
return -1;
}
int main()
{
int result = HelloFunc();
}
OMP_NUM_THREADS
environment variable. The maximum number of threads can be queried from inside the code withomp_get_max_threads()
– halfflat