且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在没有默认构造函数的情况下,每个线程在OpenMP中执行一次代码

更新时间:2022-12-13 15:41:23

考虑以下未经测试的代码:

Consider untested code like this :

#pragma omp parallel
{
// --- Construct one tree in each per thread ---
  Tree tree(*(gp_boolean_operator->mp_group_manager));

#pragma omp for
  for (long i = 0; i < static_cast<long>(general_triangles.size()); ++i)
  {
      TrianglePointer tri = general_triangles[i];
      if (tri.GetClassification() == TO_CLASSIFY)
      {
          bool tri_has_correct_normal = true;

          if (tree.IsTriangleExternal(tri, tri_has_correct_normal))
          {
              tri.SetClassification(IS_EXTERNAL);
          }
      }
  }
}

这表明您可以在可移植,独立于操作系统,OpenMP内完成所有这些操作,并且不会引入不必要的静态变量.

It shows that you can do all this inside portable, OS independent, OpenMP, and that you don't introduce an unnecessary static variable.