[Openmp-commits] [PATCH] D110699: [OpenMP][OMPT] thread_num determination during execution of nested serialized parallel regions

Vladimir Inđić via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Wed Sep 29 05:04:50 PDT 2021


vladaindjic created this revision.
vladaindjic added reviewers: protze.joachim, AndreyChurbanov, hbae.
Herald added subscribers: guansong, yaxunl.
vladaindjic requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: openmp-commits, sstefan1.
Herald added a project: OpenMP.

__ompt_get_task_info_internal function is adapted to support thread_num
determination during the execution of multiple nested serialized
parallel regions enclosed by a regular parallel region.

Consider the following program that contains parallel region R1 <https://reviews.llvm.org/diffusion/L/> executed 
by two threads. Let the worker thread T of region R1 <https://reviews.llvm.org/diffusion/L/> executes serialized
parallel regions R2 <https://reviews.llvm.org/source/clang-tools-extra/> that encloses another serialized parallel region R3 <https://reviews.llvm.org/source/clang/>.
Note that the thread T is the master thread of both R2 <https://reviews.llvm.org/source/clang-tools-extra/> and R3 <https://reviews.llvm.org/source/clang/> regions.

Assume that __ompt_get_task_info_internal function is called with the 
argument “ancestor_level == 1” during the execution of region R3 <https://reviews.llvm.org/source/clang/>. 
The function should determine the “thread_num” of the thread T inside 
the team of region R2 <https://reviews.llvm.org/source/clang-tools-extra/>, whose implicit task is at level 1 inside the 
hierarchy of active tasks. Since the thread T is the master thread of 
region R2 <https://reviews.llvm.org/source/clang-tools-extra/>, one should expected that “thread_num” takes a value 0. 
After the while loop finishes, the following stands: “lwt != NULL”, 
“prev_lwt == NULL”, “prev_team” represents the team information about 
the innermost serialized parallel region R3 <https://reviews.llvm.org/source/clang/>. This results in executing 
the assignment “thread_num = prev_team->t.t_master_tid”. Note that 
“prev_team->t.t_master_tid” was initialized at the moment of 
R2 <https://reviews.llvm.org/source/clang-tools-extra/>’s creation and represents the “thread_num” of the thread T inside 
the region R1 <https://reviews.llvm.org/diffusion/L/> which encloses R2 <https://reviews.llvm.org/source/clang-tools-extra/>. Since the thread T is the worker thread
of the region R1 <https://reviews.llvm.org/diffusion/L/>, “the thread_num” takes value 1, which is a contradiction.

This patch proposes to use “lwt” instead of “prev_lwt” when determining 
the “thread_num”. If “lwt” exists, the task at the requested level belongs
to the serialized parallel region. Since the serialized parallel region 
is executed by one thread only, the “thread_num” takes value 0.

Similarly, assume that __ompt_get_task_info_internal function is called 
with the argument “ancestor_level == 2” during the execution of region R3 <https://reviews.llvm.org/source/clang/>. 
The function should determine the “thread_num” of the thread T inside the 
team of region R1 <https://reviews.llvm.org/diffusion/L/>. Since the thread is the worker inside the region R1 <https://reviews.llvm.org/diffusion/L/>, 
one should expected that “thread_num” takes value 1. After the loop finishes, 
the following stands: “lwt == NULL”, “prev_lwt != NULL”, “prev_team” represents 
the team information about the innermost serialized parallel region R3 <https://reviews.llvm.org/source/clang/>. 
This leads to execution of the assignment “thread_num = 0”, which causes 
a contradiction.

Ignoring the “prev_lwt” leads to executing the assignment 
“thread_num = prev_team->t.t_master_tid” instead. From the previous explanation, 
it is obvious that “thread_num” takes value 1.

Note that the “prev_lwt” variable is marked as unnecessary and thus removed.

This patch introduces the test case which represents the OpenMP program 
described earlier in the summary.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110699

Files:
  openmp/runtime/src/ompt-specific.cpp
  openmp/runtime/test/ompt/parallel/nested_lwt_thread_num.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110699.375837.patch
Type: text/x-patch
Size: 6252 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20210929/f8491438/attachment-0001.bin>


More information about the Openmp-commits mailing list