【问题标题】:why does openmp give warning when single block is enclosed in section block为什么当单个块包含在节块中时openmp会发出警告
【发布时间】:2012-02-14 12:06:53
【问题描述】:

我有一个单独的块包含在这样的部分块中

#include <stdio.h>
#include <stdlib.h>
#include <omp.h>

int main (int argc, char *argv[]) 
{

int nthreads, tid;

/* Fork a team of threads giving them their own copies of variables */
#pragma omp parallel private(tid) 
{

#pragma omp sections
{


#pragma omp section
{
printf("First section %d \n" , tid);
}

#pragma omp section
{


#pragma omp single
{
printf("Second Section block %d \n" , tid);
}

}

}

}  /* All threads join master thread and disband */

printf("Outside parallel block \n");


}

当我编译这段代码时,编译器会给出以下警告

工作共享区域不能紧密嵌套在工作共享、关键、有序或主区域内

为什么会这样?

【问题讨论】:

    标签: c openmp


    【解决方案1】:

    它会给你这个警告,因为你有一个 openmp 单个区域嵌套在一个 openmp 部分区域内,而没有一个 openmp 并行区域嵌套在它们之间。

    这被称为紧密嵌套的区域。

    在 C 中,工作共享结构有 for、section 和 single。

    有关详细信息,请参阅OpenMP Specification 或参阅Intel's Documentation on Improper nesting of OpenMP* constructs

    为了使代码编译干净,请尝试将您的 #pragma omp sections 替换为 #pragma omp parallel sections 或将#pragma omp sections#pragma omp parallel 括起来。

    有关更多信息和示例,请参阅Guide into OpenMP: Easy multithreading programming for C++

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多