I have problem to parallel for-loop code in OpenMP, result of parallel for-loop is different with a sequential for-loop. How to make this code parallel with same result as sequential code.
counter = 0; #pragma omp parallel for for(i=0; i<L; i++) { int sum_found = 0; for(j=0; j<M; j++) { int found = 0; for(k=0; k<N_SUBSET; k++) { if (i==0 && unsorted_arr[j*N_SUBSET + k] < intervals[i]) { s_prime[counter] = unsorted_arr[j*N_SUBSET + k]; counter++; found++; } else if (i!=0 && unsorted_arr[j*N_SUBSET + k] >= intervals[i-1] && unsorted_arr[j*N_SUBSET + k] < intervals[i]) { s_prime[counter] = unsorted_arr[j*N_SUBSET + k]; counter++; found++; } else if (i==L-1 && unsorted_arr[j*N_SUBSET + k] >= intervals[i-1]) { s_prime[counter] = unsorted_arr[j*N_SUBSET + k]; counter++; found++; } } C[i][j] = found; sum_found += found; } n_intervals_len[i] = sum_found; }
-fsanitize=thread. It will tell you if and where you have a data race