I'm currently working on a project to invert matrices on the GPU using OpenMP. However, when normalizing a row of a matrix I have a data race. The code looks like this:
#pragma omp target data map(tofrom: matrix[0:dim*dim], iden[0:dim*dim]) map(alloc: factor)
for (int i = 0; i < dim; i++) {
// fix data race on cpu, this should not be necessary
#pragma omp target update from(matrix[i * dim + i])
factor = matrix[i * dim + i];
#pragma omp target update to(factor)
#pragma omp target teams distribute shared(factor)
for (int x = i; x < dim + i + 1; x++) {
//barrier doesn't help
// float factor = matrix[i * dim + i];
//#pragma omp barrier
if (x < dim) {
matrix[i * dim + x] /= factor;
} else {
iden[i * dim + x - dim] /= factor;
}
}
...
}
The data race happens because matrix[i * dim + i]
will get replaced by 1.0
at some point during the calculation. Replacing it in the last iteration didn't fix the problem either.
Maybe you have any suggestions?
Thank you in advance!