简体   繁体   English

OpenMP任务(如果最终)

[英]OpenMP task if or final

if I want no more tasks to be created if (array length < 100). 如果我不想再创建更多任务,如果(数组长度<100)。 Is if(r - l >= 100) or final(r - l < 100) satisfying this condition? if(r - l >= 100)final(r - l < 100)满足此条件吗? (l = minIndex; r = maxIndex) (l = minIndex; r = maxIndex)

They both work. 他们俩都工作。 Relevant parts of the specification are: 规范的相关部分是:

undeferred task A task for which execution is not deferred with respect to its generating task region. undeferred task (未延迟的任务)相对于其生成任务区域而言,不推迟执行的任务。 That is, its generating task region is suspended until execution of the undeferred task is completed. 即,其生成任务区域将被挂起,直到未延迟任务的执行完成。

included task A task for which execution is sequentially included in the generating task region. 包含的任务在生成的任务区域中顺序包含执行的任务。 That is, an included task is undeferred and executed immediately by the encountering thread. 也就是说,包含的任务是不受延迟的,并由遇到的线程立即执行。

final task A task that forces all of its child tasks to become final and included tasks. 最终任务强制其所有子任务变为最终任务和包含任务的任务。

[...] [...]

When an if clause is present on a task construct, and the if clause expression evaluates to false, an undeferred task is generated, and the encountering thread must suspend the current task region, for which execution cannot be resumed until the generated task is completed. 当if子句出现在任务构造上并且if子句表达式的计算结果为false时,将生成未延迟的任务,并且遇到的线程必须挂起当前任务区域,在完成生成的任务之前,无法恢复执行该任务区域。 The use of a variable in an if clause expression of a task construct causes an implicit reference to the variable in all enclosing constructs. 在任务构造的if子句表达式中使用变量会导致所有封闭构造中对该变量的隐式引用。

When a final clause is present on a task construct and the final clause expression evaluates to true, the generated task will be a final task. 当最终子句出现在任务构造上并且最终子句表达式的计算结果为true时,生成的任务将是最终任务。 All task constructs encountered during execution of a final task will generate final and included tasks. 在执行最终任务期间遇到的所有任务构造都会生成最终任务和包含的任务。 Note that the use of a variable in a final clause expression of a task construct causes an implicit reference to the variable in all enclosing constructs. 请注意,在任务构造的final子句表达式中使用变量会导致在所有封闭构造中隐式引用该变量。

----- OpenMP Architecture Review Board. ----- OpenMP体系结构审查委员会。 “OpenMP Application Programming Interface.” Specification Version 4.5, November 2015. “ OpenMP应用程序编程接口”。规范版本4.5,2015年11月。

This means that if(false) and final(true) both execute task's content immediately. 这意味着if(false)final(true)都立即执行任务的内容。 The only difference is if there is another task construct inside your task. 唯一的区别是您的任务中是否还有其他任务构造。

#pragma omp task if(0)
{
     // this task is created and executed normally
     #pragma omp task
     foo();
}
#pragma omp task final(1)
{
     // this task is "included", i.e. executed sequentially and immediately
     #pragma omp task
     foo();
}

From the wording, it also seems that if(false) will create a task and run it immediately, while final will simply run the code sequentially without creating a task. 从措辞上看, 似乎 if(false)将创建一个任务并立即运行它,而final仅将按顺序运行代码而不创建任务。 However I'm not sure that this is true, nor that there are performance implications. 但是,我不确定这是否正确,也不确定性能是否影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM