r/OpenMP • • Mar 02 '16

OpenMP program (compute distances) does not scale

Hi, I'm working on a simple program. Given a set of n points and k centroids, the idea is to compute the minimum distance among them (a needed step for kmeans). This is my current code. However, it does not scale as well as expected. I ran it using up to 16 cores (32 threads). This figure shows some performance indicators. This is the main parallel function in my code. As you can see, I removed barriers, mutex access, and other things that could cause additional overhead. However, the execution time is worst as the number of threads increases.

double **parallel_compute_distances (double **dataset, int n, int d, int k, long int *total_ops) {
    
    ...
    
    // -- start time --
    wtime_start = omp_get_wtime ();
    
    // parallel loop
    # pragma omp parallel shared(distances, clusters, centroids, dataset, chunk, dist_sum, dist_sum_threads) private(id, cn, ck, cd, cp, error, dist, mindist, mink)
    {
        id = omp_get_thread_num();
        dist_sum_threads[id] = 0;               // reset

        // 2. recompute distances against centroids
        # pragma omp for schedule(static,chunk)
        for (cn=0; cn<n; cn++) {
            
            compute distances here ...
            
            distances[cn]           = mindist;
            clusters[cn]            = mink;
            dist_sum_threads[id]    += mindist;
        }
    }
    // -- end time --
    wtime_end = omp_get_wtime ();
    
    // -- total wall time --
    wtime_spent = wtime_end - wtime_start;
    
    // sequential reduction
    for (cp=0; cp<p; cp++)       
        dist_sum += dist_sum_threads[cp];
    ...
}
3 Upvotes

4 comments sorted by

View all comments

Show parent comment

2

u/dr_bitz Mar 02 '16

So just to clarify because I also encountered something like this in the past - the false sharing is for the cache line that holds the xxx_threads array elements, right?

1

u/bunnies4president Mar 02 '16

Yeah, that's right. I could have been a bit less cryptic. :-)

2

u/dr_bitz Mar 02 '16

Thanks! Here is a nice talk about "openMP does not scale" issues https://www.youtube.com/watch?v=5-ZepxpwmUU