我里面有一个for循环,还有另外两个for循环,我不太渴望并行化。但是在外部for循环内部有一个函数调用,我想称之为并行。但是,我遇到了段错误。下面是代码片段,我正在尝试并行化。
#pragma omp parallel for private(j,k)
for (k=0; k < numatoms; k++) { // Loops over all atoms (k)
# I dont case about parallelizing this loop, tried both with and without critical section still segfault.
#pragma omp critical
{
for (j=0; j < numatoms; j++) { // Loop over all atoms
all_nbrs_index[j] = j; // Get the indeces of neighbours in nbrs_ind struct
all_nbrs_values[j] = dist_mat[k][j];// Get the distances of neighbours in nbrs_ind struct
}
}
#I want this function call to be executed in parallel
QuickSort(all_nbrs_values, all_nbrs_index, 0, numatoms-1);
// if (k ==0) {
// printf("\nThe sorted neighbour indices are. \n");
// }
/// From sorted distances and indices get get the 4 closest.
#This loop also need not to be parallelized but if possible its a bonus
#pragma omp critical
{
for(j=0; j <=4 ;j++) {
nbrs_ind[k][j] = all_nbrs_index[j];
// printf("%d\t ", all_nbrs_index[i] );
}
}
// printf("\n");
}
我认为这与私有化有关。我的错误是由于没有在内部循环中私有化那些数组而引起的。如果是这种情况,如何将数组设为私有?任何帮助将非常有用。