clang only spawns one thread

Hi,

I am using LLVM 3.6.1 to test the following code:

#include <omp.h>
#include <stdio.h>
#include <stdlib.h>

int main() {

int tid, nthreads;
#pragma omp parallel sections private(nthreads, tid)
{
#pragma omp section
{
tid = omp_get_thread_num();
printf("Hello, tid = %d\n ", tid);
}

#pragma omp section
{
tid = omp_get_thread_num();
printf("Hello, tid = %d\n ", tid);
}
}
if (tid == 0) {
nthreads = omp_get_num_threads();
printf(“number of threads = %d \n”, nthreads);
}

return 0;
}

I used the following command:
clang -fopenmp -I/path/to/omp.h -L/path/to/libomp.so test.c -o test

I only get one thread when I run test, for example it yields:
Hello, tid = 0
Hello, tid = 0
number of threads = 1

However, I can get different thread id if I compile the code using gcc. Any idea about what’s wrong here?

I found a similarly problem in the following link:
http://stackoverflow.com/questions/31663996/clang-llvm-openmp-program-not-spawning-threads/31673394#31673394

But I don’t know where should I add -fopenmp=libomp. Any help will be appreciated. Thanks.

Zhi

Hi Zhi,

take a look at this thread: http://stackoverflow.com/questions/33357029/using-openmp-with-clang

Regards,
Jakub

Hi Jakub,

Thanks. I upgraded my LLVM and everything worked.

Best,
Zhi