1. The TASK construct defines an explicit task, which may be executed by the encountering thread, or deferredfor execution by any other thread in the team. 2. The data environment of the task is determined by the data sharing attribute clauses. 3. Task execution is subject to task scheduling - see the OpenMP 3.0 specification document for details.
其中task(1000);就属于一个隐式的任务。因为执行完for后,会执行这一个任务,而上面的任务可能也会同时执行。
(4)task的嵌套
A task construct may be nested inside an outer task, but the task region of the inner task is not a part of the task region of the outer task.
任务构造结构可以嵌套在另一个task结构中,但是内部的task结构并不属于外部的task区域的一部分。
#pragma omp task
{
task(a[i]);
#pragma omp task
task(a[i]);
}
简单的理解,OpenMP遇到task指令就会定义一个显式的任务,就会在当前的线程或者延迟等待其它线程去执行,而不是将嵌套task的部分当作外部task的一部分。
(4)task指令的子句
if子句:
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. Note that 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
如果给一个task使用了if子句,如果if子句的表达式是false,会生成一个不延迟的任务,这样,遇到这个task的当前线程必须挂起当前的task区域,直到当前的任务完成之后才会恢复。个人理解,当前线程挂起,那么这个task是不是由其它的线程去执行呢,还是就是当前的这个线程执行这个任务?
final子句:
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. 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.
如果给task使用了final子句,如果final表达式的值为true,生成的任务是一个终结任务。所有任务遇到终结任务执行的时候会生成终结和包含的任务。PS:不太理解!
default、private 、firstprivate、shared等数据属性子句就不多说了。
mergeable、untied等参考OpenMP Spec:http://www.openmp.org/mp-documents/OpenMP3.1.pdf
(5)其它:
和task相关的还有一些其他深入一些的内容,包括上面的task指令的子句也有一些需要深入理解,在这里就不讨论了。在以后的学习过程中再总结。毕竟,task是OpenMP的一个新的特性,也是很有用的。这里主要是理解task的基本使用,
从OpenMP3.0开始,OpenMP增加了task指令,这是OpenMP3.0中最激动人心的一个新特性。本文的”术语“大多数是根据个人理解用词,不保证用词准确性。(1)task基础OpenMP Tutorials: 任务构造https://computing.llnl.gov/tutorials/openMP/#Task从功能上说:1. The TAS