Thinking Parallel

A Blog on Parallel Programming and Concurrency by Michael Suess

Top 15 Mistakes in OpenMP

A BugIt has been a while since I have done this little experiment, but I still find the results interesting. As some of you may know, I teach a class on parallel programming (this is an undergraduate class, by the way – may I have a million dollar in funding now as well, please? ๐Ÿ˜Ž ). The first parallel programming system we teach to our students is OpenMP. There is no written test at the end of the class, but instead the students get to do assignments in teams of two people, which have to be defended before us. This is really educational for us (and I think for the students as well), because we get to see and find the mistakes our students make. I have done a little statistic on what mistakes are made by our students, and in this post you will find the results. Why am I posting a list of mistakes? Because I think learning from other peoples mistakes is almost as good as learning from my own, and usually saves quite a lot of time compared to the first option. ๐Ÿ˜€

I have chosen to divide the mistakes into two groups: correctness mistakes and performance mistakes. Correctness mistakes impact the correctness of the program (I can’t believe I am explaining this – I must be on a writing spree ๐Ÿ™„ ), leading to wrong results when made. Performance mistakes merely lead to slower programs. And now I have kept you waiting long enough, here is my list of the top mistakes to make when programming in OpenMP:

Correctness Mistakes

  1. Access to shared variables not protected
  2. Use of locks without flush (as of OpenMP 2.5, this is no longer a mistake)
  3. Read of shared variable without obeying the memory model
  4. Forget to mark private variables as such
  5. Use of ordered clause without ordered construct
  6. Declare loop variable in for-construct as shared
  7. Forget to put down for in #pragma omp parallel for
  8. Try to change the number of threads in a parallel region, after it has been started already
  9. omp_unset_lock() called from non-owner thread
  10. Attempt to change loop variable while in #pragma omp for

Performance Mistakes

  1. Use of critical when atomic would be sufficient
  2. Put too much work inside critical region
  3. Use of orphaned construct outside parallel region
  4. Use of unnecessary flush
  5. Use of unnecessary critical

Disclaimer

Warning: This is not a statistically sound survey, but merely an experiment I did out of curiosity! Of course the mistakes here are correlated to the way we taught the lecture, as well as to the assignments given, therefore please do not give these findings any statistical significance!

Famous last words

With this out of the way, let me tell you that I have written a paper about the experiment and some best practices to avoid them in the first place (which I may post here later). If you don’t understand some of the mistakes posted above, please look up the verbose explanations there. There is blog by Yuan Lin dedicated to the sole purpose of showing common mistakes while programming in parallel – called Touch Dreams. Unfortunately, it appears to be no longer maintained. What a pity, I think we could use more resources on mistakes and how to avoid them…

4 Responses to Top 15 Mistakes in OpenMP »»


Comments

  1. Comment by Michael McCracken | 2007/08/31 at 19:36:28

    Hi, you might be interested in the HPC Bugbase – a public database of common mistakes and bugs in parallel programming that grew from Taiga Nakamura’s PhD thesis at UMD:

    http://hpcbugbase.org/index.php/Main_Page

  2. Comment by Michael Suess | 2007/09/06 at 10:13:27

    Thanks, Michael, this looks really useful.


Trackbacks & Pingbacks »»

  1. Pingback by Links: September 3, 2007 « SmoothSpan Blog | 2007/09/02 at 22:52:47

    […] Top 15 Mistakes in OpenMP:ร‚ย  aka Why parallel programming in Curly Braced Languages is Hard. […]

  2. Pingback by Top 15 Mistakes in OpenMP | 2007/11/27 at 17:02:58

    […] This is the cached version of http://www.thinkingparallel.com/2007/08/31/top-15-mistakes-in-openmp/ We are neither affiliated with the authors of this page nor responsible for its content. Top 15 Mistakes in OpenMP […]

Leave a Reply

HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>