0
你好我得到一个奇怪的错误OpenMP的“共享”无效“的#pragma OMP
#include <omp.h>
#define N 1000
main()
{
int i, nthreads;
int chunk = 10;
float a[N], b[N], c[N], d[N];
double result =0;
#pragma omp parallel
{
nthreads = omp_get_num_threads();
printf("no of threads %d", nthreads);
#pragma omp for shared(a,b,c,d,result) private(i) schedule(static,chunk) // line 18
for (i=0; i < N; i++){
a[i] = i * 1.5;
b[i] = i + 22.35;
}
#pragma omp barrier
#pragma omp for schedule(static,chunk) shared(a,b,c,d,result) private(i) reduction(+:result) // line 26
for(i=0; i < N; i++){
result = result + (a[i]+b[i]);
}
}
printf("value is %f", result);
}
根据OpenMP的编译的规则,共享是允许的,但在这里IAM得到一个编译错误,只是因为IAM在这里使用共享。有人能帮助我吗?
test2.c:18: error: ‘shared’ is not valid for ‘#pragma omp for’
test2.c:26: error: ‘shared’ is not valid for ‘#pragma omp for’
'shared'被允许'OMP for'?你从哪里得到这个?根据这份文件,'共享'不列为可用。 http://publib.boulder.ibm.com/infocenter/cellcomp/v101v121/index.jsp?topic=/com.ibm.xlcpp101.cell.doc/compiler_ref/prag_omp_for.html – 2012-03-28 10:29:01
所以则只有平行“编译OMP平行为“允许共享? – user602774 2012-03-28 10:37:23
是 - 描述变量共享的子句与并行区域相关联,而不是并行区域内的工作共享构造。所以你把它们放在#pragma omp平行线上,而不是#pragma omp for line。您可以通过在并行块内本地定义变量来帮助自己;那些都是私人的。 – 2012-03-28 11:30:53