2012-02-13 25 views
1

我有封闭在一个部分一个块阻止这样为什么OpenMP的给予警告,当单块被封闭在部分块

#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"); 


} 

当我编译这个代码的编译器会发出如下警告

工作共享区域可能没有紧密嵌套在工作共享区域,关键区域,有序区域或主区域内

为什么会这样?

回答

3

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

这被称为紧密嵌套区域。

在C中,工作共享结构用于,部分和单个。

欲了解更多信息,请参阅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++