提问人:ahmad hajyahia 提问时间:8/8/2023 最后编辑:ahmad hajyahia 更新时间:8/8/2023 访问量:35
使用 OMP 取消嵌套 for 循环时出错
Error in cancellation nested for loops using OMP
问:
我正在尝试在 c 中使用 OMP 并行化嵌套的 for 循环,在某些时候我想中断两个循环并停止所有线程并退出函数。我尝试使用,但我收到此错误:#pragma omp cancel
#pragma omp cancellation point for
error: ‘#pragma omp cancel for’ construct not closely nested inside of ‘#pragma omp for’
146 | #pragma omp cancel for
int findPoints(GivenData* data, Point* allPoints, double t, Result* result)
{
int a = 0; // pointsID index counter.
int pointsID[3]; // Array that stores the Proximity Criteria points id.
int countForSpecificPoint = 0; // To check whether we found K – minimal number of points.
int countForSpecificT = 0; // To Check whether we found 3 points for t.
int isPointsFound = 0; // Shared flag variable to indicate whether the result is found.
omp_set_num_threads(2);
/// For each point find K – minimal number of points that their distance < D.
#pragma omp parallel for collapse(2)
for (int i = 0; i < data->numOfPoints; i++)
{
for (int j = 0; j < data->numOfPoints; j++)
{
#pragma omp cancellation point for
if (i != j)
{
double distance = calcDistance(&allPoints[i], &allPoints[j]);
if (distance < data->distance)
{
#pragma omp atomic
countForSpecificPoint++;
}
}
if (countForSpecificPoint >= data->miniNumOfPCPoints)
{
if (countForSpecificPoint > data->miniNumOfPCPoints)
{
continue;
}
else
{
#pragma omp critical
{
if (allPoints[i].id != pointsID[0] && allPoints[i].id != pointsID[1] && allPoints[i].id != pointsID[2])
{
pointsID[a] = allPoints[i].id;
a++;
countForSpecificT++;
}
}
}
}
#pragma omp cancellation point for
if (countForSpecificT == 3 && !isPointsFound)
{
#pragma omp critical
{
result->t = t;
result->point1ID = pointsID[0];
result->point2ID = pointsID[1];
result->point3ID = pointsID[2];
isPointsFound = 1;
#pragma omp cancel for
}
}
if (j + 1 == data->numOfPoints)
{
countForSpecificPoint = 0;
}
}
}
return isPointsFound;
}
答: 暂无答案
评论
cancel
critical