OpenMPToolsInterface / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies. Note: the repository does not accept github pull requests at this moment. Please submit your patches at http://reviews.llvm.org.
http://llvm.org
2 stars 4 forks source link

#pragma num_threads(1) results in associated task information erroneously indicating tasks are NOT In a parallel region. #29

Open elliebinkley opened 3 years ago

elliebinkley commented 3 years ago

See the program below. Imagine 4 test cases, where a debugger halts all threads at lines 29, 39, 52 and 65. All fo the lines have the same code, e.g. int k=id; // someplace to put a breakpoint.

So there are four test cases. At each breakpoint, query the OMPD runtime library for task information. For test cases 2 and 3, at lines 29 and 39 respectively, the retrieved task information indicates the tasks are NOT associated with a parallel_region. For test case 2 and 4, at lines 39 and 65 respectively, the retrieved task information indicates the tasks are associated with a parallel_region. The differences is that cases 1 and 3 pass in a #threads=1; e.g. #pragma omp parallel num_threads(1) while 2 and 4 pass in #threads>2; e.g. #pragma omp parallel num_threads(2)

It appears that a num_threads(1) results in the ompd library not indicating that the associated tasks in the parallel region are actually NOT in the parallel regions, when to the casual programmer, they actually are in a parallel region.

/ Sample OpenMP program to test OMPD handling. /

include

include

include

include <sys/wait.h>

include

include

static volatile int volatile_int;

int main ( int argc, char *argv [] ) {

int id;
int test_num = 0;
int i;
printf ( "main  \n");

// PartI. implicit pragma section
test_num++;
i = 1;
printf ( "Part I: implicit pragma section  test == %d nthreads == %d\n", test_num, i );

pragma omp parallel num_threads(i), private(id)

{
    id = omp_get_thread_num ();
    printf ( "    num_threads==%d   id==%d\n", i, id );
    int k=id;  // someplace to put a breakpoint
}

test_num++;    
i = 2;
printf ( "Part I: implicit pragma section  test == %d nthreads == %d\n", test_num, i );

pragma omp parallel num_threads(i), private(id)

{
    id = omp_get_thread_num ();
    printf ( "    num_threads==%d   id==%d\n", i, id );
    int k=id;  // someplace to put a breakpoint
}

// Part II. explicit task section
test_num++;
i=1;
printf ( "Part II: explict task pragma section  test == %d nthreads == %d\n", test_num, i );

pragma omp parallel num_threads(i), private(id)

{
    id = omp_get_thread_num ();

pragma omp task

    {
        printf ( "    num_threads==%d   id==%d\n", i, id );
        int k=id;  // someplace to put a breakpoint
    }
}

test_num++;
i=2;
printf ( "Part II: explict task pragma section  test == %d nthreads == %d\n", test_num, i );

pragma omp parallel num_threads(i), private(id)

{
    id = omp_get_thread_num ();

pragma omp task

    {
        printf ( "    num_threads==%d   id==%d\n", i, id );
        int k=id;  // someplace to put a breakpoint
    }
}

return 0;

} / main /

elliebinkley commented 3 years ago

In test3; using gdb10 using a ompd plugin I see that there is no annotation on the task for frame0, indicating that it is an explicit task. That is because the icv value for the icv-name "active_levels_var" for that associated task came back with a value of zero, indicating that the task was NOT associated with a parallel region.

(gdb) bt

0 @thread 1: omp_task_entry. () at ../../src/tx_omp_parallel_simple.c:52

1 0x00007ffff7b1459f in @thread 1: __kmp_invoke_task (gtid=0, task=0x719dc0, current_task=0x607680)

at /home/lburley/src/tools-external/llvm-project-OpenMPToolsInterface/llvm-project/openmp/runtime/src/kmp_tasking.cpp:1578

2 0x00007ffff7b1480b in @thread 1: __kmp_omp_task (gtid=0, new_task=0x719dc0, serialize_immediate=true)

at /home/lburley/src/tools-external/llvm-project-OpenMPToolsInterface/llvm-project/openmp/runtime/src/kmp_tasking.cpp:1700

3 0x00007ffff7b14b4f in @thread 1: __kmpc_omp_task (loc_ref=0x7fffffffcb80, gtid=0, new_task=0x719dc0)

at /home/lburley/src/tools-external/llvm-project-OpenMPToolsInterface/llvm-project/openmp/runtime/src/kmp_tasking.cpp:1760

4 0x0000000000400ba5 in @thread 1: "#pragma omp parallel" (.global_tid.=0x7fffffffcc40, .bound_tid.=0x7fffffffcc38, i=@0x7fffffffd344: 1)

at ../../src/tx_omp_parallel_simple.c:49