OpenMP-线程如何确定何时推迟任务以及何时立即执行 [英] OpenMP - How does the thread decide when to defer a task and when to execute immediately

查看:140
本文介绍了OpenMP-线程如何确定何时推迟任务以及何时立即执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OpenMP规范文档说:当线程遇到任务构造时,它可能
选择立即执行任务还是将其推迟到以后再执行."但是,规范没有说明如何选择此任务.

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.

线程如何决定何时立即执行任务以及何时推迟执行?如果这是特定于实现的,那么gcc之类的编译器如何解决此问题?

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. 如果存在if子句并求值为false,则新任务是 undeferred任务,该任务立即由当前线程执行(旧任务是被暂停).

  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).

final子句使新任务及其所有子任务成为 final included . 包含的任务未延迟的,并由遇到线程立即执行.

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.

以上内容是从标准中粗略复制的

GCC(在当前主机中)还可以立即执行任务(GOMP_TASK_UNDEFERRED),如果

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

  • 没有活动的线程团队,即正在并行区域之外构造任务.
  • 当前线程小组的任务数大于64 *小组中的线程数.

另请参见: task.c ,寻找GOMP_task.

LLVM OpenMP运行时使用最大大小的任务双端队列,如果此双端队列已满,则立即执行任务.默认大小为256(1 << 8),但似乎在某些情况下会使其加倍.我不太确定团队中任务队列的组织方式.

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.

另请参见: kmp_tasking.cpp ,查找TASK_NOT_PUSHED.

这篇关于OpenMP-线程如何确定何时推迟任务以及何时立即执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆