且构网

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

OpenMp在并行区域之前检测嵌套并行中的线程数

更新时间:2023-11-28 23:43:22

我已经解决了这一问题,方法是打开一个嵌套的并行区域来查询所有线程:

I've solved it, by opening a nested parallel region to query all threads:

int get_nested_num_threads(){
  int threads=1;

#pragma omp parallel shared(threads)
  {
  #pragma omp single
    {
      threads = omp_get_num_threads();

      #pragma omp parallel shared(threads)
      {
        #pragma omp single
        {
          threads *= omp_get_num_threads();
        }
      }
    }
  }

  return threads;
}

据我所知,在这种情况下,您无需在C中使用firstprivatelastprivate.但是您必须在Fortran中做到这一点.

As far as I know, you do not need to use firstprivate and lastprivate in C for this case. But you have to do it in Fortran.