Factory.ai

Open-Source Wikis

/

LLVM

/

Subprojects

/

openmp

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.txt

The 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), target constructs that need host-side coordination, and the OpenMP environment variables (OMP_NUM_THREADS, OMP_SCHEDULE, etc.).
  • libomptarget — historically here; offload runtime is now in offload/.
  • 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

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 under openmp/runtime/test/.
  • Tuning a scheduling policy: edit openmp/runtime/src/kmp_dispatch.cpp.
  • Adding a task feature: kmp_tasking.cpp is the central file.

Reference

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

openmp – LLVM wiki | Factory