I try parallelize this code (the Gram-Schimdt QR factorization algorithm):

- Code: Select all
`int i, j, k;`

double r[50][50], q[50][50], a[50][50];

#pragma omp parallel for private (k, i, j) shared (r, a, q)

for (k=0; k<50; k++)

{

r[k][k]=0;

for (i=0; i<50; i++)

{

r[k][k] = r[k][k] + a[i][k] * a[i][k];

}

r[k][k] = sqrt(r[k][k]);

for (i=0; i<50; i++)

{

q[i][k] = a[i][k]/r[k][k];

}

for(j=k+1; j<50; j++)

{

r[k][j]=0;

for(i=0; i<50; i++) r[k][j] += q[i][k] * a[i][j];

for (i=0; i<50; i++) a[i][j] = a[i][j] - r[k][j]*q[i][k];

}

}

but it doesn't work correctly...

it produces bad, meaningless results, completely different than non-paraller version.

I observed that a problematic fragment is:

- Code: Select all
`for (i=0; i<3; i++)`

{

q[i][k] = a[i][k]/r[k][k];

}

but I don't know why it's working wrong.

Anybody help / tell me how can I implement the algorihtm as a paraller, good working version ?