开发者

What is OpenMP?

What's a hi开发者_运维百科gh-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?


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];
  }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜