OpenMP
OpenMP is an application programming interface (API) that supports multi-platform shared-memory multiprocessing programming in C, C++, and Fortran, on many platforms, instruction-set architectures and operating systems, including Solaris…
≈ 5 min read
OpenMP. encyclopegia.org, snapshot enwiki-001369227206. /a/openmp
Names in other languages
No names in other languages are held for this entry yet.
Article bodies are English and are not machine-translated. A name in another language is not a translation of the article.
OpenMP is an application programming interface (API) that supports multi-platform shared-memory multiprocessing programming in C, C++, and Fortran, on many platforms, instruction-set architectures and operating systems, including Solaris, AIX, FreeBSD, HP-UX, Linux, macOS, Windows and OpenHarmony. It consists of a set of compiler directives, library routines, and environment variables that influence run-time behavior.
OpenMP is managed by the nonprofit technology consortium OpenMP Architecture Review Board (or OpenMP ARB), jointly defined by a broad swath of leading computer hardware and software vendors, including Arm, AMD, IBM, Intel, Cray, HP, Fujitsu, Nvidia, NEC, Red Hat, Texas Instruments, and Oracle Corporation. OpenMP uses a portable, scalable model that gives programmers a simple and flexible interface for developing parallel applications for platforms ranging from the standard desktop computer to the supercomputer.
An application built with the hybrid model of parallel programming can run on a computer cluster using both OpenMP and Message Passing Interface (MPI), such that OpenMP is used for parallelism within a (multi-core) node while MPI is used for parallelism between nodes. There have also been efforts to run OpenMP on software distributed shared memory systems, to translate OpenMP into MPI and to extend OpenMP for non-shared memory systems. include include int main(void) { #pragma omp parallel printf("Hello, world.\n"); return 0; } Use flag -fopenmp to compile using GCC: $ gcc -fopenmp hello.c -o hello -ldl Output on a computer with two cores, and thus two threads: Hello, world.
Hello, world. However, the output may also be garbled because of the race condition caused from the two threads sharing the standard output. Hello, wHello, woorld. rld.
Whether printf is atomic depends on the underlying implementation unlike C++11's std::cout , which is thread-safe by default. // define N as some constant for array length define N 100000 int main(int argc, char* argv[]) { int a[N]; #pragma omp parallel for for (int i = 0; i This example is embarrassingly parallel, and depends only on the value of i . The OpenMP parallel for flag tells the OpenMP system to split this task among its working threads. The threads will each receive a unique and private version of the variable.
For instance, with two worker threads, one thread might be handed a version of i that runs from 0 to 49999 while the second gets a version running from 50000 to 99999.
Variant directives
Variant directives are one of the major features introduced in OpenMP 5.0 specification to facilitate programmers to improve performance portability. They enable adaptation of OpenMP pragmas and user code at compile time.
The specification defines traits to describe active OpenMP constructs, execution devices, and functionality provided by an implementation, context selectors based on the traits and user-defined conditions, and metadirective and declare directive directives for users to program the same code region with variant directives. The metadirective is an executable directive that conditionally resolves to another directive at compile time by selecting from multiple directive variants based on traits that define an OpenMP condition or context.
The declare variant directive has similar functionality as metadirective but selects a function variant at the call-site based on context or user-defined conditions. The mechanism provided by the two variant directives for selecting variants is more convenient to use than the C/C++ preprocessing since it directly supports variant selection in OpenMP and allows an OpenMP compiler to analyze and determine the final directive from variants and context. // define array size as some constant for array length: define N 100000 // code adaptation using preprocessing directives int v1[N]; int v2[N]; int v3[N]; if defined(nvptx) pragma omp target teams distribute parallel for map(to:v1,v2) map(from:v3) for (int i = 0; i
Benchmarks
A variety of benchmarks has been developed to demonstrate the use of OpenMP, test its performance and evaluate correctness. Simple examples OmpSCR: OpenMP Source Code Repository Performance benchmarks include: NAS Parallel Benchmark Barcelona OpenMP Task Suite a collection of applications that allow to test OpenMP tasking implementations.
SPEC series SPEC OMP 2012 The SPEC ACCEL benchmark suite testing OpenMP 4 target offloading API The SPEChpc 2002 benchmark CORAL benchmarks Exascale Proxy Applications Rodinia focusing on accelerators. Problem Based Benchmark Suite Correctness benchmarks include: OpenMP Validation Suite OpenMP Validation and Verification Testsuite DataRaceBench is a benchmark suite designed to systematically and quantitatively evaluate the effectiveness of OpenMP data race detection tools.
AutoParBench is a benchmark suite to evaluate compilers and tools which can automatically insert OpenMP directives.
Text derived from https://en.wikipedia.org/w/index.php?oldid=1369227206 under CC BY-SA 4.0; modifications have been made.