Reputation: 1103
Hi i am getting a weird error
#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);
}
According to openmp pragma for rules , shared is allowed, but here iam getting a compile error simply because iam using shared here. Could someone please help me out.
test2.c:18: error: ‘shared’ is not valid for ‘#pragma omp for’
test2.c:26: error: ‘shared’ is not valid for ‘#pragma omp for’
Upvotes: 1
Views: 10814
Reputation: 1861
From the comments to your question, I do understand the fixed code should be like:
#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 shared(a,b,c,d,result) private(i)
{
nthreads = omp_get_num_threads();
printf("no of threads %d", nthreads);
#pragma omp for 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) reduction(+:result) // line 26
for(i=0; i < N; i++){
result = result + (a[i]+b[i]);
}
}
printf("value is %f", result);
}
Upvotes: 2