# oneapi-src/onetbb architecture

> Architecture diagram of the GitHub repository oneapi-src/onetbb, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/oneapi-src/onetbb
- Repository: https://github.com/oneapi-src/onetbb

## Overview

Based on our review of the file tree and the README, the project is oneAPI Threading Building Blocks (oneTBB), which is a high-performance C++ library designed to simplify parallel programming. The project is structured as a comprehensive library that exposes a wide range of concurrency patterns and parallel algorithms (such as parallel_for, parallel_reduce, flow graph, etc.), along with robust components like memory allocation (via tbbmalloc) and task scheduling. It supports multiple build systems (CMake, Bazel, and even Python wrappers) and includes extensive documentation, examples, tests, and integration files.

##### Main Components
- Core Library Components:
- Task Scheduling & Threading Engine: Represent the core runtime (found in src/tbb) that manages tasking, thread management, schedulers, arenas, and related algorithms.
- Concurrency and Parallel Algorithms: Include components such as parallel_for, parallel_invoke, flow graph, and other utilities contained in the API (these are exposed via header files in the include/oneapi/tbb and include/tbb directories).
- Memory Management System: Represent the tbbmalloc subsystem (found in src/tbbmalloc and src/tbbmalloc_proxy) which handles scalable, high-performance memory allocation.

- Build, Integration, and Configuration:
- Integration Scripts: Include integration scripts for various platforms (Linux, macOS, Windows) and support for package systems like NuGet.

- Documentation, Examples, and Tests:
- Documentation: Show a separate block for documentation (doc/ folder, Doxygen configuration, and user guides in the tbb_userguide section).
- Examples & Samples: Indicate sample applications (in examples/) that demonstrate usage of various parallel patterns.
- Testing & Conformance: Represent the extensive testing suite (in test/ and test/tbb, test/conformance) that validates performance, conformance, and portability.

- Language Bindings and Wrappers:
- Python binding: Represent the Python directory (with python/TBB.py and related CMakeLists.txt) that provides wrappers and extensions.

- Community & Contribution Infrastructure:
- While not a technical “execution” component, acknowledge support files (e.g., CONTRIBUTING.md, SECURITY.md, ISSUE templates, GitHub workflows) that support community contributions and CI/CD. This could be represented as peripheral “support” components ensuring project sustainability.

##### Relationships and Interactions
- The core runtime (task scheduler, memory management, thread control) is central to oneTBB. APIs in the include directories interact with the runtime.
- The parallel algorithms and flow graph nodes are built on top of the scheduler and make use of the memory management system.
- The build systems (CMake/Bazel) are used to compile all these components and ensure that integration files and platform-specific configurations are properly applied.
- Examples and tests serve as clients that utilize the API, demonstrating how higher-level parallel patterns invoke the core functionalities.
- Python bindings wrap around the core C++ API, enabling similar functionality in Python environments.

##### Architectural Patterns and Design Principles
- Emphasis on generic programming and template-based APIs.
- An event-driven, task-based parallelism model.
- Separation of concerns between scheduling, execution, and memory management.
- Strong modular separation: distinct modules for core tasking, concurrency containers, memory allocation, and flow graph components.
- Cross-platform build and integration support.

##### Relevant Technologies, Frameworks, and Libraries
- C++ as the primary language with templates as a key design aspect.
- CMake and Bazel as build orchestration tools.
- Documentation tools such as Doxygen for auto-generating reference materials.
- GitHub Actions and code analysis tools (e.g., CodeQL, Coverity) integrated via GitHub workflows.
- Python for wrappers—indicating multi-language interoperability.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Core Runtime Layer
    subgraph "Core Runtime"
        TS["Task Scheduling & Threading Engine"]:::core
        MM["Memory Management (tbbmalloc)"]:::core
    end

    %% API & Parallel Algorithms Layer
    subgraph "API & Parallel Algorithms"
        CA["Concurrency and Parallel Algorithms"]:::api
    end

    %% Build & Integration Layer
    subgraph "Build & Integration"
        cmake["Build Systems (CMake)"]:::build
        bazel["Build Systems (Bazel)"]:::build
        integ["Integration Scripts"]:::build
    end

    %% Support & Extras Layer
    subgraph "Support & Extras"
        doc["Documentation"]:::support
        ex["Examples & Samples"]:::support
        test["Testing & Conformance"]:::support
        py["Python Bindings & Wrappers"]:::support
        comm["Community & Contribution Infrastructure"]:::support
    end

    %% Relationships between layers
    CA -->|"uses"| TS
    CA -->|"allocates"| MM

    cmake -->|"builds"| TS
    cmake -->|"builds"| MM
    cmake -->|"builds"| CA
    bazel -->|"builds"| TS
    bazel -->|"builds"| MM
    bazel -->|"builds"| CA

    integ -->|"supports"| cmake
    integ -->|"supports"| bazel

    ex -->|"demonstrate"| CA
    test -->|"validate"| CA
    py -->|"wraps"| CA
    doc -->|"documents"| CA

    comm -->|"supports"| integ

    %% Click Events
    click TS "https://github.com/oneapi-src/onetbb/tree/master/src/tbb"
    click CA "https://github.com/oneapi-src/onetbb/tree/master/include/oneapi/tbb"
    click MM "https://github.com/oneapi-src/onetbb/tree/master/src/tbbmalloc"
    click cmake "https://github.com/oneapi-src/onetbb/blob/master/CMakeLists.txt"
    click bazel "https://github.com/oneapi-src/onetbb/blob/master/BUILD.bazel"
    click integ "https://github.com/oneapi-src/onetbb/tree/master/integration/"
    click doc "https://github.com/oneapi-src/onetbb/tree/master/doc/"
    click ex "https://github.com/oneapi-src/onetbb/tree/master/examples/"
    click test "https://github.com/oneapi-src/onetbb/tree/master/test/"
    click py "https://github.com/oneapi-src/onetbb/tree/master/python/"
    click comm "https://github.com/oneapi-src/onetbb/tree/master/.github/"

    %% Styles
    classDef core fill:#ffcccc,stroke:#660000,stroke-width:2px;
    classDef api fill:#ccffcc,stroke:#006600,stroke-width:2px;
    classDef build fill:#ccccff,stroke:#000066,stroke-width:2px;
    classDef support fill:#ffffcc,stroke:#666600,stroke-width:2px;
```
