Top Related Projects
oneAPI Threading Building Blocks (oneTBB)
This repo hosts the source for the DirectX Shader Compiler which is based on LLVM/Clang.
The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
Quick Overview
oneTBB (Threading Building Blocks) is an open-source C++ library developed by Intel for parallel programming on multi-core processors. It provides a rich set of components for efficient development of parallel applications, offering high-level abstractions to simplify the complexities of parallel programming.
Pros
- High-level abstractions for parallel programming, reducing complexity
- Excellent scalability and performance on multi-core systems
- Cross-platform support (Windows, Linux, macOS)
- Actively maintained with regular updates and improvements
Cons
- Steep learning curve for developers new to parallel programming
- Can be overkill for simple parallelization tasks
- Limited support for GPU acceleration compared to some alternatives
- Potential overhead for very fine-grained parallelism
Code Examples
- Parallel For Loop:
#include <oneapi/tbb.h>
#include <vector>
void parallel_increment(std::vector<int>& vec) {
tbb::parallel_for(tbb::blocked_range<size_t>(0, vec.size()),
[&](const tbb::blocked_range<size_t>& r) {
for (size_t i = r.begin(); i != r.end(); ++i) {
vec[i]++;
}
});
}
This example demonstrates a parallel for loop that increments each element in a vector.
- Parallel Reduction:
#include <oneapi/tbb.h>
#include <vector>
int parallel_sum(const std::vector<int>& vec) {
return tbb::parallel_reduce(tbb::blocked_range<size_t>(0, vec.size()), 0,
[&](const tbb::blocked_range<size_t>& r, int local_sum) {
for (size_t i = r.begin(); i != r.end(); ++i) {
local_sum += vec[i];
}
return local_sum;
},
std::plus<int>());
}
This example shows how to perform a parallel reduction to calculate the sum of a vector.
- Task-based Parallelism:
#include <oneapi/tbb.h>
void parallel_fibonacci(int n, int& result) {
if (n < 2) {
result = n;
} else {
int x, y;
tbb::task_group g;
g.run([&] { parallel_fibonacci(n - 1, x); });
g.run([&] { parallel_fibonacci(n - 2, y); });
g.wait();
result = x + y;
}
}
This example demonstrates task-based parallelism using TBB's task_group to compute Fibonacci numbers.
Getting Started
To get started with oneTBB, follow these steps:
-
Install oneTBB:
- On Ubuntu:
sudo apt-get install libtbb-dev
- On macOS with Homebrew:
brew install tbb
- On Windows, download from the official Intel website
- On Ubuntu:
-
Include the oneTBB header in your C++ file:
#include <oneapi/tbb.h>
-
Compile your program with the TBB library:
g++ -std=c++17 your_program.cpp -ltbb
-
Run your compiled program and enjoy the benefits of parallel programming with oneTBB!
Competitor Comparisons
oneAPI Threading Building Blocks (oneTBB)
Pros of oneTBB
- Identical repositories, so all features and benefits are the same
- Both provide Threading Building Blocks (TBB) for parallel programming
- Equally maintained and supported by the Unified Extensible Firmware Interface (UEFI) Foundation
Cons of oneTBB
- No unique advantages over the other repository
- Potential confusion for users due to identical repositories
- Possible redundancy in maintenance efforts
Code Comparison
Both repositories contain identical code, so a comparison is not applicable. Here's a sample from the main TBB header file found in both repos:
#ifndef __TBB_tbb_H
#define __TBB_tbb_H
#include "oneapi/tbb/version.h"
#include "oneapi/tbb/aligned_space.h"
#include "oneapi/tbb/cache_aligned_allocator.h"
The repositories are mirrors of each other, maintained by the same organization. Users can choose either one for their TBB implementation needs without any functional differences.
This repo hosts the source for the DirectX Shader Compiler which is based on LLVM/Clang.
Pros of DirectXShaderCompiler
- Specialized for DirectX shader compilation, offering optimized performance for graphics programming
- Supports HLSL (High-Level Shader Language) and provides advanced shader optimization features
- Actively maintained by Microsoft, ensuring compatibility with the latest DirectX technologies
Cons of DirectXShaderCompiler
- Limited to DirectX-specific shader compilation, less versatile than oneTBB's general-purpose parallelism
- Steeper learning curve for developers not familiar with DirectX or shader programming
- Larger codebase and potentially more complex setup compared to oneTBB
Code Comparison
DirectXShaderCompiler (HLSL shader code):
float4 PSMain(float4 position : SV_POSITION) : SV_TARGET
{
return float4(1.0, 0.0, 0.0, 1.0); // Red color
}
oneTBB (C++ parallel algorithm):
#include <tbb/parallel_for.h>
#include <vector>
std::vector<int> data(1000);
tbb::parallel_for(0, 1000, [&](int i) {
data[i] = i * 2;
});
This comparison highlights the different focus areas of these projects: DirectXShaderCompiler for graphics programming and oneTBB for general-purpose parallel computing.
The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
Pros of llvm-project
- Comprehensive compiler infrastructure with multiple front-ends and back-ends
- Extensive documentation and community support
- Widely used in industry and academia for various programming languages
Cons of llvm-project
- Steeper learning curve due to its complexity and size
- Larger codebase, which may lead to longer build times
- More resource-intensive to work with, especially on smaller systems
Code Comparison
llvm-project (LLVM IR example):
define i32 @add(i32 %a, i32 %b) {
%result = add i32 %a, %b
ret i32 %result
}
oneTBB (Parallel for loop example):
#include <tbb/parallel_for.h>
tbb::parallel_for(0, n, [&](int i) {
result[i] = compute(data[i]);
});
Summary
llvm-project is a comprehensive compiler infrastructure project, offering a wide range of tools and libraries for building compilers and related tools. It's more complex and resource-intensive but provides extensive capabilities for various programming languages. oneTBB, on the other hand, is focused on parallel programming and offers a simpler, more specialized toolkit for multi-threaded applications. The choice between them depends on the specific needs of your project, with llvm-project being more suitable for compiler-related tasks and oneTBB for parallel computing optimizations.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
oneAPI Threading Building Blocks (oneTBB)
oneTBB is a flexible C++ library that simplifies the work of adding parallelism to complex applications, even if you are not a threading expert.
The library lets you easily write parallel programs that take full advantage of the multi-core performance. Such programs are portable, composable and have a future-proof scalability. oneTBB provides you with functions, interfaces, and classes to parallelize and scale the code. All you have to do is to use the templates.
The library differs from typical threading packages in the following ways:
- oneTBB enables you to specify logical parallelism instead of threads.
- oneTBB targets threading for performance.
- oneTBB is compatible with other threading packages.
- oneTBB emphasizes scalable, data parallel programming.
- oneTBB relies on generic programming.
Refer to oneTBB examples and samples to see how you can use the library.
oneTBB is a part of the UXL Foundation and is an implementation of oneAPI specification.
NOTE: Threading Building Blocks (TBB) is now called oneAPI Threading Building Blocks (oneTBB) to highlight that the tool is a part of the oneAPI ecosystem.
Release Information
See Release Notes and System Requirements.
Documentation
- oneTBB Specification
- oneTBB Developer Guide and Reference
- Migrating from TBB to oneTBB
- README for the CMake build system
- oneTBB Testing Approach
- Basic support for the Bazel build system
- oneTBB Discussions
- WASM Support
Installation
See Installation from Sources to learn how to install oneTBB.
Governance
The oneTBB project is governed by the UXL Foundation. You can get involved in this project in following ways:
- Join the Open Source and Specification Working Group meetings.
- Join the mailing lists for the UXL Foundation to receive meetings schedule and latest updates.
- Contribute to oneTBB project or oneTBB specification. Read CONTRIBUTING for more information.
Support
See our documentation to learn how to request help.
How to Contribute
We welcome community contributions, so check our Contributing Guidelines to learn more.
Use GitHub Issues for feature requests, bug reports, and minor inquiries. For broader questions and development-related discussions, use GitHub Discussions.
License
oneAPI Threading Building Blocks is licensed under Apache License, Version 2.0. By its terms, contributions submitted to the project are also done under that license.
* All names and brands may be claimed as the property of others.
Top Related Projects
oneAPI Threading Building Blocks (oneTBB)
This repo hosts the source for the DirectX Shader Compiler which is based on LLVM/Clang.
The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot