OpenMP - How does the thread decide when to defer a task and when to execute immediately

别等时光非礼了梦想. 提交于 2020-01-24 15:37:26

问题


The OpenMP specification document says that "When a thread encounters a task construct, it may
choose to execute the task immediately or defer its execution until a later time". However, the specification does not say how this choice is made.

How does the thread decide when to execute the task immediately and when to defer the execution? If this is implementation specific, how does compilers like gcc solve this?


回答1:


There are two conditions coming from the standard:

  1. When an if clause is present and evaluates to false, then the new task is a undeferred task which is executed right now by the current thread (the old task is suspended).

  2. A final clause makes the new task and all it's child tasks final and included. An included task is undeferred and executed immediately by the encountering thread.

The above is loosely copied from the standard

GCC (in the current master) also executes tasks immediately (GOMP_TASK_UNDEFERRED) if

  • There is no active thread team, i.e. a task is being constructed outside of a parallel region.
  • The task count of the current thread team is larger than 64 * the number of threads in the team.

See also: task.c, look for GOMP_task.

The LLVM OpenMP runtime uses a task deque that has with a maximum size, and executes tasks immediately if this deque is full. The default size is 256 (1 << 8), but there seem to be conditions under which it doubles. I am not quite sure how exactly the task queue is organized within a team.

See also: kmp_tasking.cpp, look for TASK_NOT_PUSHED.



来源:https://stackoverflow.com/questions/46601207/openmp-how-does-the-thread-decide-when-to-defer-a-task-and-when-to-execute-imm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!