Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is OpenMP?

What's a high-level description of OpenMP?

The Wikipedia article states that "OpenMP (Open Multi-Processing) is an application programming interface (API) that supports multi-platform shared memory multiprocessing programming in C, C++ and Fortran on many architectures, including Unix and Microsoft Windows platforms. It consists of a set of compiler directives, library routines, and environment variables that influence run-time behavior." What?

How does it compare to other approaches to concurrency, like threads, thread-pools, and work-stealing?

like image 299
OpenMP Avatar asked Aug 19 '10 16:08

OpenMP


1 Answers

It's a set of extensions to provide C/C++ with the ability to run certain parts of the code in parallel, without explicitly managing (creating, destroying, assigning) threads.

It basically abstract you from the complexity of managing threads your self by allowing you to declaratively run certain portions of your code in parallel. A code sample always help:

# pragma omp parallel \
  shared ( n, x, y ) \
  private ( i ) \
  reduction ( + : xdoty )

# pragma omp for

  for ( i = 0; i < n; i++ )
  {
    xdoty = xdoty + x[i] * y[i];
  }
like image 84
Pablo Santa Cruz Avatar answered Sep 29 '22 00:09

Pablo Santa Cruz