[llvm-dev] clang only spawns one thread

zhi chen via llvm-dev llvm-dev at lists.llvm.org
Wed Dec 2 13:52:53 PST 2015


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20151202/ea22865c/attachment.html>


More information about the llvm-dev mailing list