multithreading - How to run two set of code in parallel using openmp in c++ -
i have 2 function not related each other 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 suing them follow:
auto x=add(100); auto m=mul(200); cout<<a<< " " <<m<<endl; how can run them in parallel using openmp? know can run them in parallel if create new thread , run 1 of functions in thread , implement sync mechanizim make sure both threads finisshes time cout called.
also know can use openmp parallel for loops, assume not there.
the usual way sort out problem in openmp sections construct. enables define parts of sequential code, can computed concurrently different threads. each section starts omp section directive/pragma.
Comments
Post a Comment