Answer the question
In order to leave comments, you need to log in
How to parallelize a for loop with OpenMP?
Help parallelize with OpenMP
for (i=0; i<N-1; i++) {
for (k=i+1; k <= N-1; k++)
for (j=i+1; j <= N; j++)
A(k,j) = A(k,j)-A(k,i)*A(i,j)/A(i,i);
}
X[N-1] = A(N-1,N)/A(N-1,N-1);
for (j=N-2; j>=0; j--) {
for (k=0; k <= j; k++)
A(k,N) = A(k,N)-A(k,j+1)*X[j+1];
X[j]=A(j,N)/A(j,j);
}
Answer the question
In order to leave comments, you need to log in
What is A(i, j)?
It looks like you have a Gaussian algorithm there, and it should be an array.
The outer loop over i cannot be parallelized in Gauss, but row subtraction can.
Add this before the loops for j and k:
#pragma omp parallel for collapse(2)
In the last two loops, the outer loop cannot be parallelized either, because the result of subsequent calculations depends on the previous iterations. But before the inner loop, feel free to stick #pragma omp parallel for
.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question