I have the following nested for loops. I want to parallelize the first loop but the second loop must NOT be parallelized. So I want that each thread executes the second loop in itself, which means that second loop must be special for each thread (for each “i” in the code).
How can I do that?
#pragma omp parallel for
for (i=k+1;i<row;i++){
for (n=0;n<k;n++){
// #pragma omp atomic
dummy += L[i][n]*L[k][n];
L[i][k] = (A[i][k] - dummy)/L[k][k];
}
dummy = 0;
}
The
omp parallel forpragma applies only to the loop that follows it immediately. Theiloop will be distributed between threads. Within each iteration ofi, thenloop will be executed on the same thread. Your code already does what you are trying to do.