I know this might look like a duplicate but since I am learning OpenMP for the first time and after going through multiple sources and posts, still I am confused so I decided to post a question itself.
I am learning OpenMP and while learning more on loop parallelism, I got to know that "Nested Parallelism" is disabled in OpenMP - source:
according to the article this code:
#pragma omp parallel for
for (int i = 0; i < 3; ++i) {
#pragma omp parallel for
for (int j = 0; j < 6; ++j) {
}
}
according to the article,
this does not work as two loops paralleled because when the second pragma is reached it is ignored by OpenMP.
while, in one of the StackOverflow answers to a similar question's post, I had read that this kind of making parallelism does not work because all the available threads are already reserved by upper iteration.
I don't understand if that second logic is correct because if it is so can we work with the number of threads specified?
Regarding the parallelization on nested for loop, I know we can use collapse which basically performs the task for us to collapse two nested iteration into a single iteration, but how can we parallelize this kind of loop which is not perfectly nested?
for (i=0; i<N; i++) {
y[i] = 0.;
for (j=0; j<N; j++)
y[i] += A[i][j] * x[j]
}
and the same source suggest that this loop can be written as:
for (i=0; i<N; i++)
y[i] = 0.;
for (i=0; i<N; i++) {
for (j=0; j<N; j++)
y[i] += A[i][j] * x[j]
}
since now this is a correctly nested loop, can we use collapse directive in this kind of loop or is there any workaround?
I am confused on how to make parallel nested for loops which is not correctly nested: i.e
for (){
for(){
}
}