• <small id='KUrrv'></small><noframes id='KUrrv'>

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

        openMP 嵌套并行 for 循环与内部并行 for

        openMP nested parallel for loops vs inner parallel for(openMP 嵌套并行 for 循环与内部并行 for)

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

                <small id='39IDC'></small><noframes id='39IDC'>

                • <bdo id='39IDC'></bdo><ul id='39IDC'></ul>
                  <legend id='39IDC'><style id='39IDC'><dir id='39IDC'><q id='39IDC'></q></dir></style></legend>
                • 本文介绍了openMP 嵌套并行 for 循环与内部并行 for的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如果我像这样使用嵌套并行 for 循环:

                  If I use nested parallel for loops like this:

                  #pragma omp parallel for schedule(dynamic,1)
                  for (int x = 0; x < x_max; ++x) {
                      #pragma omp parallel for schedule(dynamic,1)
                      for (int y = 0; y < y_max; ++y) { 
                      //parallelize this code here
                     }
                  //IMPORTANT: no code in here
                  }
                  

                  这相当于:

                  for (int x = 0; x < x_max; ++x) {
                      #pragma omp parallel for schedule(dynamic,1)
                      for (int y = 0; y < y_max; ++y) { 
                      //parallelize this code here
                     }
                  //IMPORTANT: no code in here
                  }
                  

                  除了创建新任务之外,外部并行是否可以做任何其他事情?

                  Is the outer parallel for doing anything other than creating a new task?

                  推荐答案

                  如果您的编译器支持 OpenMP 3.0,您可以使用 collapse 子句:

                  If your compiler supports OpenMP 3.0, you can use the collapse clause:

                  #pragma omp parallel for schedule(dynamic,1) collapse(2)
                  for (int x = 0; x < x_max; ++x) {
                      for (int y = 0; y < y_max; ++y) { 
                      //parallelize this code here
                      }
                  //IMPORTANT: no code in here
                  }
                  

                  如果不支持(例如仅支持 OpenMP 2.5),有一个简单的解决方法:

                  If it doesn't (e.g. only OpenMP 2.5 is supported), there is a simple workaround:

                  #pragma omp parallel for schedule(dynamic,1)
                  for (int xy = 0; xy < x_max*y_max; ++xy) {
                      int x = xy / y_max;
                      int y = xy % y_max;
                      //parallelize this code here
                  }
                  

                  您可以使用 omp_set_nested(1); 启用嵌套并行性,并且您的嵌套 omp parallel for 代码将起作用,但这可能不是最好的主意.

                  You can enable nested parallelism with omp_set_nested(1); and your nested omp parallel for code will work but that might not be the best idea.

                  顺便说一下,为什么要动态调度?是否每次循环迭代都在非常数时间内进行评估?

                  By the way, why the dynamic scheduling? Is every loop iteration evaluated in non-constant time?

                  这篇关于openMP 嵌套并行 for 循环与内部并行 for的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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(使用非平凡的构造函数初始化联合)
                  <tfoot id='gWqLx'></tfoot>
                    <bdo id='gWqLx'></bdo><ul id='gWqLx'></ul>
                      <i id='gWqLx'><tr id='gWqLx'><dt id='gWqLx'><q id='gWqLx'><span id='gWqLx'><b id='gWqLx'><form id='gWqLx'><ins id='gWqLx'></ins><ul id='gWqLx'></ul><sub id='gWqLx'></sub></form><legend id='gWqLx'></legend><bdo id='gWqLx'><pre id='gWqLx'><center id='gWqLx'></center></pre></bdo></b><th id='gWqLx'></th></span></q></dt></tr></i><div id='gWqLx'><tfoot id='gWqLx'></tfoot><dl id='gWqLx'><fieldset id='gWqLx'></fieldset></dl></div>
                          <tbody id='gWqLx'></tbody>
                      1. <legend id='gWqLx'><style id='gWqLx'><dir id='gWqLx'><q id='gWqLx'></q></dir></style></legend>
                        • <small id='gWqLx'></small><noframes id='gWqLx'>