I am currently working on matrix calculation using OpenMP. I have several loops in my code, and instead, when calling for each loop #pragma omp parallel for [...] (which creates all the threads and destroys them right after), I would like to create them all at the beginning and delete them at the end of the program to avoid overhead. I need something like:
#pragma omp parallel { #pragma omp for[...] for(...) #pragma omp for[...] for(...) }
The problem is that I have some parts that should be executed by only one thread, but in a loop that contains loops, they should be executed in parallel ... Here is what it looks like:
(The boundaries of the loop in my example are quite small. In my program, the number of iterations can go on up to 20,000 ...) One of my first ideas was to do something like this:
//have to be execute by only one thread
It does not compile, I get this error from gcc: "the sharing area cannot be closely nested in the workspace, the critical, ordered, main or explicit task area."
I know that this certainly comes from the βwrongβ nesting, but I donβt understand why this does not work. Do I need to add a barrier in front of the parallel zone? I lost a little and do not know how to solve it.
Thank you in advance for your help. Greetings.
source share