oneAPI Threading Building Blocks (oneTBB)

repository·master·Indexed 27 days ago

https://github.com/uxlfoundation/onetbb

A C++ library providing high-level abstractions for parallel programming, enabling the implementation of scalable, data-parallel algorithms using templates and logical parallelism. It includes a Python module for threading composability and monkey-patching, support for HWLOC, and comprehensive CMake-based build configurations for various architectures including 32-bit, Windows UWP, and Windows Drivers.

Tokens
284.4K
Snippets
594
Records
1.4K
Agent score
92%

What's inside oneTBB

  1. Overview of oneTBB

    master

    oneAPI Threading Building Blocks (oneTBB) is a runtime-based parallel programming model for C++ code that uses tasks. It is a template-based runtime library designed to harness the performance of multi-core processors by breaking computations into parallel running tasks. Within a single process, parallelism is achieved by mapping these tasks to threads.

    Key features include:

    • Logical Parallel Structure: Allows you to specify parallel structure instead of managing individual threads.
    • Data-Parallel Programming: Emphasizes data-parallel patterns.
    • Concurrent Collections and Parallel Algorithms: Provides built-in support for these patterns.
    • Nested Parallelism and Load Balancing: Supports nested parallelism and manages load balancing to prevent oversubscribing the system.
  2. Overview of oneAPI Threading Building Blocks (oneTBB)

    master
    oneTBB is a flexible C++ library designed to simplify adding parallelism to complex applications. It allows developers to write portable, composable, and scalable parallel programs by focusing on logical parallelism rather than managing individual threads. The library relies heavily on generic programming and templates to provide high-performance, data-parallel programming capabilities.
  3. Overview of oneTBB Concurrent Containers

    master

    oneTBB provides highly concurrent container classes designed to allow multiple threads to access and update items simultaneously. Unlike standard C++ STL containers, which typically require external synchronization (like a mutex) that can eliminate parallel speedup, oneTBB containers use two primary methods to enable concurrency:

    • Fine-grained locking: Threads lock only the specific portions of the container they need, allowing concurrent access to different parts of the data structure.
    • Lock-free techniques: Threads use atomic operations to account for and correct the effects of interfering threads without traditional locks.

    Usage Note: Highly-concurrent containers have higher overhead than regular STL containers. They should be used when the performance gains from increased concurrency outweigh the slower sequential performance of the container itself.

  4. Overview of oneTBB programming model

    master
    oneTBB (oneAPI Threading Building Blocks) is a programming model designed for scalable parallel programming using standard ISO C++ code. It allows developers to specify logical parallelism within algorithms, which the oneTBB implementation then maps onto physical execution threads. The library leverages C++ templates and generic programming to provide flexible and efficient APIs that can be customized to specific application needs.
  5. Introduction to oneAPI Threading Building Blocks (oneTBB)

    master

    oneAPI Threading Building Blocks (oneTBB) is a library designed for scalable data parallel programming using standard ISO C++ code. It allows developers to specify tasks rather than managing raw threads, with the library handling the efficient mapping of tasks to threads.

    Key features include:

    • Scalable Parallelism: Supports both data parallel programming and nested parallelism (building large parallel components from smaller ones).
    • Generic Programming: Many interfaces use generic programming (similar to the C++ Standard Template Library), allowing for flexibility and customization through type requirements rather than specific types.
    • Standard C++: Does not require special languages or compilers, though it does require C++11 standard compiler support.
  6. Use oneapi::tbb::concurrent_multimap

    master

    oneapi::tbb::concurrent_multimap is a sorted associative container template that allows multiple elements with equal keys to be stored. It is designed for high-performance concurrent environments, supporting concurrent insertion, lookup, and traversal.

    Important Thread-Safety Note: While it supports concurrent insertion and lookup, it does not support concurrent erasure. Erasure operations are categorized as unsafe_erase and should be managed carefully to avoid data races.

  7. Use concurrent_vector for thread-safe container growth

    master

    oneapi::tbb::concurrent_vector is a class template for a vector that allows multiple threads to concurrently grow the container and append new elements.

    Key features:

    • Concurrent Growth: Multiple threads can safely append elements.
    • Random Access: Elements can be accessed by index (starting at 0).
    • Iterator Stability: Growing the container does not invalidate existing iterators or indices.

    Defined in header <oneapi/tbb/concurrent_vector.h>.

  8. Implement graph parallelism with Flow Graph

    master

    oneTBB supports graph parallelism to create highly scalable and sequential graphs. A flow graph implementation consists of three core components:

    1. graph class instance: The owner of all tasks created by the flow graph. You use the graph instance to wait for task completion and to manage the execution lifecycle.
    2. Nodes: The processing units within the graph.
    3. Ports and edges: The mechanism used to connect nodes and manage message flow.

    To implement a custom node, you must inherit from graph_node and implement the appropriate interfaces: sender (to send messages) and/or receiver (to accept messages).

  9. Manage task dependencies using `task_dynamic_state`

    master

    The task_dynamic_state class is the internal mechanism that enables dynamic dependencies within a task_group. It manages:

    • Task Status: Tracks whether a task is in progress, completed, or transferred.
    • Successor Management: Maintains a list of tasks that depend on the current task.
    • Linkage: Handles the connection to a new task when transfer_this_task_completion_to(new_task) is invoked.

    Every task in a task group that has predecessors or successors is associated with a task_dynamic_state instance. The lifetime of this state is extended until the last tbb::task_completion_handle referencing the task is destroyed.