No speed-up with useless printf's using OpenMP
        Posted  
        
            by t2k32316
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by t2k32316
        
        
        
        Published on 2010-04-26T06:27:25Z
        Indexed on 
            2010/04/26
            6:33 UTC
        
        
        Read the original article
        Hit count: 534
        
I just wrote my first OpenMP program that parallelizes a simple for loop. I ran the code on my dual core machine and saw some speed up when going from 1 thread to 2 threads. However, I ran the same code on a school linux server and saw no speed-up. After trying different things, I finally realized that removing some useless printf statements caused the code to have significant speed-up. Below is the main part of the code that I parallelized:
#pragma omp parallel for private(i)
for(i = 2; i <= n; i++)
{
  printf("useless statement");
  prime[i-2] = is_prime(i);
}
I guess that the implementation of printf has significant overhead that OpenMP must be duplicating with each thread. What causes this overhead and why can OpenMP not overcome it?
© Stack Overflow or respective owner