I am having a race problem with the current situation. I am trying to create the amount of threads as there are cores, use locks on OMP. I have tried to do #pragma omp critical and also #pragma amp atomic and none of them are helping. I am getting some crazy negative numbers... I know how to do it using private, but I want to actually synchronize the threads, not create multiple variables for the threads and then combine at the end.
// multiplication
#pragma omp parallel for
for (i = 0; i < N; i++)
{
for (j = 0; j < N; j++)
{
c[i][j] = 0.;
for (k = 0; k < N; k++)
{
omp_set_lock(&lock);
//#pragma omp critical
//#pragma omp atomic
c[i][j] += a[i][k] * b[k][j];
threadTasks[omp_get_thread_num()]++;
omp_unset_lock(&lock);
}
printf("[%d, %d]: Thread ID %d\n", i, j, omp_get_thread_num());
}
}
omp_unset_lockend of the second loop?