[Openmp-dev] omp_set_num_threads() with target region

Simone Atzeni via Openmp-dev openmp-dev at lists.llvm.org
Mon Oct 28 21:43:17 PDT 2019


Hi,

It looks like that "omp_set_num_threads()" does not affect the number of threads in a parallel region that belongs to a combined target construct.

Consider this code:

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

int main()
{
    int lp = 0;

    omp_set_num_threads(1);
#pragma omp target teams distribute parallel for lastprivate(lp)
    for(int i = 1; i < 10; i++) {
        printf("tid: %d\n", omp_get_thread_num());
        if(i == 1) {
            lp = 0;
        }
        lp++;
    }
    printf("lp: %d\n", lp);

    return 0;
}

This code when compiled with `clang -fopenmp test.c` returns a value of `lp` equal to 0, and the parallel region is executed by 9 threads in this case.
Shouldn't the `omp_set_num_threads(1)` set only one thread for the parallel region? Therefore, the expected result should be "9"?

Could this be a runtime bug? Otherwise, please help me understand this.

Thanks!
Simone

-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information.  Any unauthorized review, use, disclosure or distribution
is prohibited.  If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/openmp-dev/attachments/20191029/dcbb603f/attachment-0001.html>


More information about the Openmp-dev mailing list