Why does openmp give me this error :-
error: for statement expected before ‘{’ token
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
#include <unistd.h>
int main (int argc, char *argv[])
{
#pragma omp parallel
{
int a[100],b[100],c[100];
int i =0;
for(; i < 100; i++){
a[i] = i;
b[i] = i;
}
#pragma omp parallel for schedule(static,5)
{
int i = 0;
for( ; i < 100 ; i++){ // this is the for loop that is referred in the error message
c[i] = a[i] + b[i];
}
}
}
printf("Outside parallel block \n");
}
First, the second OpenMP pragma shouldn't have a "parallel" in it; you've already opened a parallel block, you just now need to share the work of the for loop.
Second, you can't have the parallel for enclose a general block; it has to be a for loop. If you really want a different i than is used above, do:
#pragma omp for schedule(static,5)
for (int i=0; i < 100; i++)
{
c[i] = a[i] + b[i];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With