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

  1. <legend id='tPvUs'><style id='tPvUs'><dir id='tPvUs'><q id='tPvUs'></q></dir></style></legend><tfoot id='tPvUs'></tfoot>

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

        <bdo id='tPvUs'></bdo><ul id='tPvUs'></ul>

      使用 openmp &amp; 并行化 for 循环替换 push_back

      Parallelizing a for loop using openmp amp; replacing push_back(使用 openmp amp; 并行化 for 循环替换 push_back)

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

                <tbody id='5Ji7v'></tbody>
            1. <small id='5Ji7v'></small><noframes id='5Ji7v'>

              1. 本文介绍了使用 openmp &amp; 并行化 for 循环替换 push_back的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我想并行化以下代码段,但我是 openmp 和创建并行代码的新手.

                I'd like to parallelize the following piece of code but am new to openmp and creating parallel code.

                std::vector<DMatch> good_matches;
                for (int i = 0; i < descriptors_A.rows; i++) {
                   if (matches_RM[i].distance < 3 * min_dist) {
                      good_matches.push_back(matches_RM[i]);
                   }
                }
                

                我试过了

                std::vector<DMatch> good_matches;
                #pragma omp parallel for
                for (int i = 0; i < descriptors_A.rows; i++) {
                   if (matches_RM[i].distance < 3 * min_dist) {
                      good_matches[i] = matches_RM[i];
                   }
                }
                

                std::vector<DMatch> good_matches;
                cv::DMatch temp;
                #pragma omp parallel for
                for (int i = 0; i < descriptors_A.rows; i++) {
                   if (matches_RM[i].distance < 3 * min_dist) {
                      temp = matches_RM[i];
                      good_matches[i] = temp;
                      // AND ALSO good_matches.push_back(temp);
                   }
                

                我也试过

                #omp parallel critical 
                good_matches.push_back(matches_RM[i]);
                

                此条款有效,但不会加快任何速度.这个 for 循环可能无法加速,但如果可以的话就太好了.我也想加快速度

                This clause works but does not speed anything up. It may be the case that this for loop cannot be sped up but it'd be great if it can be. I'd also like to speed this up as well

                std::vector<Point2f> obj, scene;
                for (int i = 0; i < good_matches.size(); i++) {
                   obj.push_back(keypoints_A[good_matches[i].queryIdx].pt);
                   scene.push_back(keypoints_B[good_matches[i].trainIdx].pt);
                }
                

                如果这个问题得到解答,我们深表歉意,非常感谢任何可以提供帮助的人.

                Apologies if this question as been answered and thank you very much to anyone who can help.

                推荐答案

                我在这里展示了如何做到这一点 c-openmp-parallel-for-loop-alternatives-to-stdvector

                I showed how to do this here c-openmp-parallel-for-loop-alternatives-to-stdvector

                制作 std::vector 的私有版本,并在临界区填充共享 std::vector,如下所示:

                Make private versions of the std::vector and fill the shared std::vector in a critical section like this:

                std::vector<DMatch> good_matches;
                #pragma omp parallel
                {
                    std::vector<DMatch> good_matches_private;
                    #pragma omp for nowait
                    for (int i = 0; i < descriptors_A.rows; i++) {
                       if (matches_RM[i].distance < 3 * min_dist) {
                          good_matches_private.push_back(matches_RM[i]);
                       }
                    }
                    #pragma omp critical
                    good_matches.insert(good_matches.end(), good_matches_private.begin(), good_matches_private.end());
                }
                

                这篇关于使用 openmp &amp; 并行化 for 循环替换 push_back的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                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(使用非平凡的构造函数初始化联合)

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

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