[Openmp-dev] Local variables and yielding of untied tasks

Joseph Schuchart via Openmp-dev openmp-dev at lists.llvm.org
Wed May 30 06:49:51 PDT 2018


I am experimenting with the behavior of taskyield under different OpenMP 
implementations and have written a test program that creates a set of 
untied tasks that each contain two taskyield regions. The program makes 
sure that only one thread is executing the relevant branch in the tasks 
by trapping all but thread 0 in a loop. Before the first yield, a shared 
variable is incremented and read into a local variable. After the first 
yield, the local variable is printed and a second taskyield is executed. 
Eventually the threads are released as soon as all tasks have reached 
the second yield. The complete code is attached.

I am observing some strange behavior with Clang 6.0 (built from release 
tarball, libomp built from master): the local variable contains the 
value zero where it should contain a value similar to flag_one_cntr:

```
[0] task_id 0 : flag_one_cntr 1 : flag_two_cntr 0
[0] task_id 0 : flag_one_cntr 3 : flag_two_cntr 1
[0] task_id 0 : flag_one_cntr 4 : flag_two_cntr 1
[0] task_id 0 : flag_one_cntr 5 : flag_two_cntr 3
```
(notice that there appears to be no output for flag_one_cntr=2 and 7)

Interestingly, the behavior seems correct if either of the taskyield 
regions is commented out. Similarly, the behavior seems correct if the 
tasks are tied (in which case there are no tasks to yield to). Using 
tied tasks and disabling the task stealing constraint 
(KMP_TASK_STEALING_CONSTRAINT=0) seems to provide the expected behavior:

```
[0] task_id 257 : flag_one_cntr 257 : flag_two_cntr 0
[0] task_id 256 : flag_one_cntr 257 : flag_two_cntr 1
[0] task_id 255 : flag_one_cntr 257 : flag_two_cntr 2
[0] task_id 254 : flag_one_cntr 257 : flag_two_cntr 3
[0] task_id 253 : flag_one_cntr 257 : flag_two_cntr 4
[0] task_id 252 : flag_one_cntr 257 : flag_two_cntr 5
```
(the tasks last put on the stack arrive at the printf first)

Any idea what could be going wrong here and how to debug this further? I 
tried different other implementations (incl. Cray, GCC, OmpSs) which 
seem to work correctly (albeit with different behavior of taskyield). I 
originally found this issue with the Intel 18.0.1 compiler.

Any help would be much appreciated!

Best regards,
Joseph

-- 
Dipl.-Inf. Joseph Schuchart
High Performance Computing Center Stuttgart (HLRS)
Nobelstr. 19
D-70569 Stuttgart

Tel.: +49(0)711-68565890
Fax: +49(0)711-6856832
E-Mail: schuchart at hlrs.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: openmp_yield_clang.c
Type: text/x-csrc
Size: 1180 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-dev/attachments/20180530/0bff1e46/attachment.c>


More information about the Openmp-dev mailing list