1. <i id='b4c9z'><tr id='b4c9z'><dt id='b4c9z'><q id='b4c9z'><span id='b4c9z'><b id='b4c9z'><form id='b4c9z'><ins id='b4c9z'></ins><ul id='b4c9z'></ul><sub id='b4c9z'></sub></form><legend id='b4c9z'></legend><bdo id='b4c9z'><pre id='b4c9z'><center id='b4c9z'></center></pre></bdo></b><th id='b4c9z'></th></span></q></dt></tr></i><div id='b4c9z'><tfoot id='b4c9z'></tfoot><dl id='b4c9z'><fieldset id='b4c9z'></fieldset></dl></div>

    2. <small id='b4c9z'></small><noframes id='b4c9z'>

      1. <legend id='b4c9z'><style id='b4c9z'><dir id='b4c9z'><q id='b4c9z'></q></dir></style></legend>
        <tfoot id='b4c9z'></tfoot>
          <bdo id='b4c9z'></bdo><ul id='b4c9z'></ul>

        OpenMP 4 中的任务依赖

        Task Dependency in OpenMP 4(OpenMP 4 中的任务依赖)
        <tfoot id='2tZJy'></tfoot>

        <small id='2tZJy'></small><noframes id='2tZJy'>

        1. <i id='2tZJy'><tr id='2tZJy'><dt id='2tZJy'><q id='2tZJy'><span id='2tZJy'><b id='2tZJy'><form id='2tZJy'><ins id='2tZJy'></ins><ul id='2tZJy'></ul><sub id='2tZJy'></sub></form><legend id='2tZJy'></legend><bdo id='2tZJy'><pre id='2tZJy'><center id='2tZJy'></center></pre></bdo></b><th id='2tZJy'></th></span></q></dt></tr></i><div id='2tZJy'><tfoot id='2tZJy'></tfoot><dl id='2tZJy'><fieldset id='2tZJy'></fieldset></dl></div>
        2. <legend id='2tZJy'><style id='2tZJy'><dir id='2tZJy'><q id='2tZJy'></q></dir></style></legend>

          • <bdo id='2tZJy'></bdo><ul id='2tZJy'></ul>

                    <tbody id='2tZJy'></tbody>
                • 本文介绍了OpenMP 4 中的任务依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  以下代码基于 OpenMP 4.0 规范:

                  The following code works based on the OpenMP 4.0 specification:

                  out 和 inout 依赖类型.生成的任务将是所有先前生成的兄弟任务的依赖任务引用 in、out 或 inout 中的至少一个列表项依赖类型列表.

                  The out and inout dependence-types. The generated task will be a dependent task of all previously generated sibling tasks that reference at least one of the list items in an in, out, or inout dependence-type list.

                  这意味着 task3 变得依赖于 task2.对?但这没有意义!为什么输入输出依赖任务应该是输入依赖任务的依赖?

                  This means that task3 becomes dependent of task2. Right? but it does not make sense! Why should an input-output dependency task be a dependent of an input dependency task?

                  我需要做什么才能让他们独立?p.s:在 Linux 上使用 g++ 4.9 测试的代码.

                  What do I need to do in order to make them independent? p.s: code tested with g++ 4.9 on Linux.

                  #include <stdio.h>
                  #include <omp.h>
                  #include <unistd.h>
                  int main() {
                  int x,y;
                  #pragma omp parallel num_threads(10)
                  {
                  #pragma omp single nowait
                   {
                  #pragma omp task depend (out:x)  //task1
                    {
                          x=1;
                    }
                  #pragma omp task depend(in:x) depend(out:y)  //task2
                    {
                          sleep(2); //Does task3 wait for us? Yes!
                          y=x+1;
                    }
                  #pragma omp task depend (inout:x)  //task3
                    {
                          x++;
                          printf("task3(x): %d
                  " , x);
                    }
                  #pragma omp task depend (in:x,y)  //task4
                   {
                          printf("task4 (x+y): %d
                  " , x+y);
                   }
                   }
                  }
                  return 0;
                  }
                  

                  推荐答案

                  问题 1 :这意味着 task3 变得依赖于 task2.对吗?

                  根据OpenMP 4.0标准上的depend 子句(强调我的):

                  According to the OpenMP 4.0 standard on the depend clause (emphasis mine):

                  任务依赖来源于depend的依赖类型子句及其列表项,其中依赖类型是其中之一以下:

                  Task dependences are derived from the dependence-type of a depend clause and its list items, where dependence-type is one of the following:

                  in 依赖类型.生成的任务将是一个依赖 所有先前生成的兄弟任务的任务,这些任务引用了out 或 inout 依赖类型中的至少一个列表项列表.

                  The in dependence-type. The generated task will be a dependent task of all previously generated sibling tasks that reference at least one of the list items in an out or inout dependence-type list.

                  out 和 inout 依赖类型.生成的任务将是依赖于的所有先前生成的兄弟任务,这些任务至少引用了一个列表项中的一个输入、输出或输入依赖类型列表.

                  The out and inout dependence-types. The generated task will be a dependent task of all previously generated sibling tasks that reference at least one of the list items in an in, out, or inout dependence-type list.

                  从这个描述如下:

                  • 子句 depend(in:x) 将生成一个依赖于所有先前使用 depend(out:x)depend(inout) 生成的任务的任务:x)
                  • 子句 depend(out:x) 或子句 depend(inoout:x) 将生成一个依赖于所有先前生成的提到 x 的任务的任务depend 子句中
                  • the clause depend(in:x) will generate a task dependent on all the previously generated tasks with depend(out:x) or depend(inout:x)
                  • the clause depend(out:x) or the clause depend(inoout:x) will generate a task dependent on all the previously generated tasks mentioning x in a depend clause

                  将其应用于您的特定情况会产生这样的依赖链:

                  Applying this to your specific case gives a chain of dependencies of this kind:

                         task1 (out:x) -> task2 (in:x,out:y) -> task4 (in:x,y)
                                                     |            ^
                                                     |            |
                                                     > task3 (inout:x)   
                  

                  因此task3依赖task2的完成.

                  问题 2:为什么输入-输出依赖任务应该是输入依赖任务的依赖?

                  我只想让您注意到,使用此规则,您将在运行结束时获得变量 xy 的确定性值(假设您小心同步访问内存).如果 task3 依赖于 task1 而不是 task2,则此确定性将不成立(并且 inout 依赖项将等同于 in 依赖项).

                  I would just let you notice that with this rule you will have a deterministic value of your variables x and y at the end of the run (assuming you take care of synchronizing accesses to memory). If task3 was dependent on task1 instead of task2, this determinism wouldn't hold (and an inout dependency would have been equivalent to an in dependency).

                  问题 3:我需要做什么才能让他们独立?

                  inout:x 依赖转换为 in:x 依赖,并通过 atomic 同步对 x 的访问条款.这样你就可以运行:

                  Turn the inout:x dependency into an in:x dependency and synchronize accesses to x via atomic clauses. That way you will have runs in which either:

                  • x == 2y == 2
                  • x == 2y == 3
                  • x == 2 and y == 2
                  • x == 2 and y == 3

                  取决于 task2 是否在 task3 之前执行.

                  depending on whether task2 executes before task3 or not.

                  这篇关于OpenMP 4 中的任务依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Constructor initialization Vs assignment(构造函数初始化 Vs 赋值)
                  Is a `=default` move constructor equivalent to a member-wise move constructor?(`=default` 移动构造函数是否等同于成员移动构造函数?)
                  Has the new C++11 member initialization feature at declaration made initialization lists obsolete?(声明时新的 C++11 成员初始化功能是否使初始化列表过时了?)
                  Order of constructor call in virtual inheritance(虚继承中构造函数调用的顺序)
                  How to use sfinae for selecting constructors?(如何使用 sfinae 选择构造函数?)
                  Initializing a union with a non-trivial constructor(使用非平凡的构造函数初始化联合)
                    • <bdo id='UzQiH'></bdo><ul id='UzQiH'></ul>

                      <small id='UzQiH'></small><noframes id='UzQiH'>

                        <i id='UzQiH'><tr id='UzQiH'><dt id='UzQiH'><q id='UzQiH'><span id='UzQiH'><b id='UzQiH'><form id='UzQiH'><ins id='UzQiH'></ins><ul id='UzQiH'></ul><sub id='UzQiH'></sub></form><legend id='UzQiH'></legend><bdo id='UzQiH'><pre id='UzQiH'><center id='UzQiH'></center></pre></bdo></b><th id='UzQiH'></th></span></q></dt></tr></i><div id='UzQiH'><tfoot id='UzQiH'></tfoot><dl id='UzQiH'><fieldset id='UzQiH'></fieldset></dl></div>
                        <legend id='UzQiH'><style id='UzQiH'><dir id='UzQiH'><q id='UzQiH'></q></dir></style></legend><tfoot id='UzQiH'></tfoot>
                              <tbody id='UzQiH'></tbody>