Sorting an array in openmp
问题 I have an array of 100 elements that needs to be sorted with insertion sort using OpenMP. When I parallelize my sort it does not give correct values. Can some one help me void insertionSort(int a[]) { int i, j, k; #pragma omp parallel for private(i) for(i = 0; i < 100; i++) { k = a[i]; for (j = i; j > 0 && a[j-1] > k; j--) #pragma omp critical a[j] = a[j-1]; a[j] = k; } } 回答1: Variables "j" and "k" need to be private on the parallel region. Otherwise you have a data race condition. 回答2: