Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

openmp for block error

Tags:

c

openmp

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

}
like image 796
user602774 Avatar asked Aug 09 '26 11:08

user602774


1 Answers

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];
}
like image 149
Jonathan Dursi Avatar answered Aug 11 '26 03:08

Jonathan Dursi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!