I have a C++ program that has a double
for loop that I'd like to parallelize using opeMP. It is simple (a polynomial product) of varying length (between 100 and 8000 coefficients) and the function is called millions of times per execution.
I have the parallel
pragma around the outer loop and the
for pragma just below the
parallel pragma. I have found that if the number of elements is big, near 8000, the execution time is good, lower than without parallelization. However, for small number of coefficients, the performance is degraded, and the parallel version is slower than the serial one.
I suppose it is due to the creation/destruction of parallel threads every time the function is called. I can limit the creation of threads with an
if in the pragma, so it is only parallelized for big polynomials, but I was wondering if there is a way to avoid creation/destruction of the threads, so I could create them once and leave them "waiting" between calls, so they would be ready when needed. That function is the only one I'm parallelizing and I cannot move the parallelization to the caller function.
I'm using g++.