llvm/llvm-project
openmp
openmp/ ships LLVM's OpenMP runtime libraries — the executables loaded into a program at runtime to support #pragma omp ... constructs. The runtime implements thread pools, work distribution, synchronization, tasking, and the bookkeeping that backs the OpenMP execution model.
Purpose
OpenMP is a directive-based parallel-programming standard. The compiler (Clang or Flang) lowers #pragma omp parallel for { ... } into calls into a runtime that schedules the loop iterations across threads. That runtime is what openmp/ provides. Historically the project also hosted offload (GPU) infrastructure here; that has since been carved out into the standalone offload subproject.
Directory layout
openmp/
├── runtime/ # libomp — the host-side OpenMP runtime
├── tools/ # archer (race detector for OpenMP), multiplex
├── docs/
├── cmake/
├── README.rst
└── CMakeLists.txtThe runtime/src/ tree is the implementation; tests live under runtime/test/ and are run by check-openmp (which excludes the Offload tests now hosted by offload).
What ships
libomp— the host runtime. Implements thread management, parallel regions, work-sharing constructs (for,single,sections), tasking (including untied tasks, taskloop, taskgroup), synchronization (locks, barriers, atomics),targetconstructs that need host-side coordination, and the OpenMP environment variables (OMP_NUM_THREADS,OMP_SCHEDULE, etc.).libomptarget— historically here; offload runtime is now inoffload/.archer— a TSan-based race detector specialized for OpenMP semantics (openmp/tools/archer/).
Key abstractions
| Type | File | Role |
|---|---|---|
kmp_team_t |
openmp/runtime/src/kmp.h |
A team of OpenMP threads |
kmp_info_t |
same | Per-thread state |
__kmpc_* entry points |
scattered in runtime/src/ |
The ABI Clang/Flang call into |
kmp_task_t |
openmp/runtime/src/kmp_tasking.cpp |
Task descriptor |
| Scheduling functions | kmp_dispatch.cpp |
static, dynamic, guided, runtime schedules |
How it works
graph LR
src["#pragma omp parallel for"] -->|Clang/Flang lowers to| call["__kmpc_fork_call"]
call --> rt[libomp]
rt --> threads[Thread pool]
threads --> work[__kmpc_for_static_init / dynamic_next]
work --> body[User loop body]
body --> barrier[__kmpc_barrier]The compiler outlines the body of a parallel region into a function and replaces the directive with a call into libomp's __kmpc_fork_call. The runtime expands the team to the requested number of threads (creating or waking them from the pool), each thread executes the outlined function, and a barrier joins them at the end of the region.
Integration points
- Clang lowers OpenMP via
clang/lib/CodeGen/CGOpenMPRuntime*. The emitted symbols are__kmpc_*and__tgt_*entry points. - Flang lowers OpenMP via
flang/lib/Lower/OpenMP/and theompMLIR dialect. - Offload (
offload) provides the device-side runtime that pairs with libomp's host side fortargetregions.
Entry points for modification
- Adding a runtime entry point: add the implementation under
openmp/runtime/src/and the corresponding__kmpc_*declaration. Don't forget the ABI test underopenmp/runtime/test/. - Tuning a scheduling policy: edit
openmp/runtime/src/kmp_dispatch.cpp. - Adding a task feature:
kmp_tasking.cppis the central file.
Reference
- OpenMP API specification
- OpenMP runtime documentation
- Offload subproject — for
targetconstructs
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.
Previous
polly
Next
compiler-rt