Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 7. Using Automatic Parallelizati... > Using OpenMP to Produce a Parallel A...

Using OpenMP to Produce a Parallel Application

With OpenMP, directives in the source code are used to express parallel constructs. These directives start with the phrase #pragma omp. Under appropriate compilation flags, they are read by the compiler and used to generate a parallel version of the application. If the required compiler flags are not provided, the directives are ignored. The OpenMP API specification details these directives as well as library calls to determine or modify runtime parameters such as the current number of threads. As we saw in Chapter 3, “Identifying Opportunities for Parallelization,” a benefit of using OpenMP directives is that it separates the parallelism from the algorithm. The code can be read without having to worry about how the parallelization is implemented. Some other advantages to using OpenMP are as follows:

  • The directives are recognized only when compiled with a particular compiler flag, so the same source base can be used to generate the serial and parallel versions of the code. This simplifies debugging since it is relatively easy to determine whether, for a given problem, the parallel version produces a different answer to the serial version and therefore whether a bug is because of the parallelization or the original algorithm.

  • Each directive is limited in scope to the region of code to which it applies. Consequently, the developer can focus on making the critical section of the code parallel without having to be concerned about changing the rest of the code to support this parallelization. This is often referred to as the ability to perform incremental parallelization.

  • Possibly the biggest advantage is that the compiler and supporting library are responsible for all the parallelization work and the runtime management of threads.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint