0

I have two function which are not related to each other for example:

int add(int num)
{ 
     int sum=0;
     for(i=0;i<num;++i)
         sum+=i;
    return sum;
}

int mul(int num)
{  
    int mul=1;
    for(int i=1;i<num;++i)
       mul * i;
    return mul;
}

and I am suing them as follow:

auto x=add(100);
auto m=mul(200);
cout<<a<< "    " <<m<<endl;

How can I run them in parallel using OpenMP? I know that I can run them in parallel if I create a new thread and run one of the functions in that thread and implement a sync mechanizim to make sure that both threads finisshes by time that cout is called.

Also I know that I can use openMP parallel for for my loops, but assume that it is not there.

mans
  • 17,104
  • 45
  • 172
  • 321

1 Answers1

1

The usual way to sort out this problem in OpenMP is the sections construct. It enables you to define parts of your sequential code, that can be computed concurrently by different threads. Each section starts with the omp section directive/pragma.