I have a c program as below:
int a[10];
int b;
for(int i = 0; i < 10; i++)
function1(a[i]);
function1(b);
Now I want to parallelize all these 11 calls of function function1(). How can I do this using openmp?
I have tried
#pragma omp parallel sections
{
#pragma omp section
#pragmal omp parallel for
for(int i = 0; i < 10; i++)
function1(a[i]);
#pragma omp section
function1(b);
}
But the above code doesn’t seem to work.
EDIT: Please read function1(b) as some different function, ie function2(b).
A simple way, that doesn’t depend on OpemMP, is to add
bto theaarray.This way, you have a single loop to parallelize.
Just make
a11 ints long, and put the value ofbin the last one.In a more general case (assuming the members of
aare not integers, but something larger), you may want to changefunction1to get a pointer. Then build another array, of 11 pointers. Set 10 to point to cells ofa, the last tob.In an even more general case, the function called for
bis a different one (possibly with entirely different parameters). In this case, you can still use one loop: