0

given the next iteration:

double calculateClusterDistance(Cluster* cluster, const int NUM_OF_DIMENSIONS)
{
    double tempRadius = 0;
    int i, j;
    #pragma omp parallel for private (i, j) shared(cluster)
    for(i = 0 ; i < cluster->numOfPoints ; i++)
    {
        for(j = 0 ; j < cluster->numOfPoints ; j++)
        {
            if(i != j)
            {
                double calculatedRadius = getDistanceBetweenTwoPoints(cluster->points[i], cluster->points[j], NUM_OF_DIMENSIONS);
                if(calculatedRadius > tempRadius)
                {
                    tempRadius = calculatedRadius;
                }
            }
        }
    }
    return tempRadius;
}

When I put in comment the pragma, the program run faster. In average, cluster->numOfPoints is between 60-70. Any help?

edit:

I measure time using

clock_t start, finish;  
start = clock();  
finish = clock();

In before and after this function.

Without omp it will be about 1.8~ sec With omp it will be about 3.2~ sec

Jens Gustedt
  • 76,821
  • 6
  • 102
  • 177
Shay Zambrovski
  • 401
  • 5
  • 21
  • How do you measure time? Please provide a [mcve], a complete system description and specific measurement results. – Zulan Nov 26 '17 at 08:50
  • @Zulan I edited the question, is it ok? – Shay Zambrovski Nov 26 '17 at 08:54
  • 2
    `clock` is not the right function to measure time, it is for CPU time. And that a parallelized version uses more CPU time is normal. You'd have to use something that measures "wall clock time", `timespec_get` in C11, e.g. Also OpenMP has its own time measuring functions. – Jens Gustedt Nov 26 '17 at 08:55

0 Answers0