Home > Parallel Programming > Common Mistakes in Using OpenMP 1: Incorrect Directive Format

Common Mistakes in Using OpenMP 1: Incorrect Directive Format

December 30th, 2005

In C/C++, OpenMP directives are specified by using the #pragma mechanism; and in Fortran, they are specified by using special comments that are identified by unique sentinels.

This design allows users to write OpenMP programs that can be compiled with compilers that do not support OpenMP or compiled with OpenMP compiles with OpenMP support disabled.

However, if you do not follow the directive format, you might get a
program that compiles and runs but gives unexpected results, because
the compiler does not recognize your OpenMP directives and thinks they are non-OpenMP related pragmas (C/C++) or regular comments (Fortran).

Quiz:

How many “me”s does the following code print? Assume a team of 4 threads are executing the parallel region.

foo()
{
    #pragma omp parallel
    {
        #pragma single
        {
            printf("men");
        }
    }
}
Categories: Parallel Programming Tags:
  1. January 27th, 2009 at 18:18 | #1

    Great! Thank you!
    I always wanted to write in my site something like that. Can I take part of your post to my site?
    Of course, I will add backlink?

    Sincerely, Timur I.

  2. February 5th, 2009 at 17:08 | #2

    Hi. Your site displays incorrectly in Mozilla, but content excellent! Thank you for your wise words:)

  3. February 5th, 2009 at 21:57 | #3

    Sure. Of course!

  1. No trackbacks yet.