Error in cancellation nested for loops using OMP

47 views Asked by At

I am trying to parallelize nested for loops using OMP in c, and in some point i want to break both loops and stop all threads and exit the function. i tried to use #pragma omp cancel and #pragma omp cancellation point for but i am getting this error:

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;

}
0

There are 0 answers