1. 简介
OneTBB Benifits
- oneTBB enables you to specify logical paralleism 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.
Testing Approach
几种在并行开发中常见的问题:
- Interface correspondence to specification
- Memory errors
- Data race
- Race conditions and deadlocks
其中比较复杂的是:Race conditions 和 deadlocks。可以使用下面的测试方法:
- Unit tests that, however, have limited capability to catch such errors
- Integration tests. Multiple different functionalities are heavily combined to emulate user use cases that may trigger such errors based on prior knowledge and expertise.
- Stress testing with different possible combinations. It ensures that even rarely triggered error conditions are caught by testing.
2. 使用
安装
1
2
3
4
5
6
7
8
9
10
# Clone oneTBB repository
git clone https://github.com/oneapi-src/oneTBB.git
cd oneTBB
# Create binary directory for out-of-source build
mkdir build && cd build
# Configure: customize CMAKE_INSTALL_PREFIX and disable TBB_TEST to avoid tests build
# if you want to customize, you can config like that:
# cmake -DCMAKE_INSTALL_PREFIX=/tmp/my_installed_onetbb -DTBB_TEST=OFF ..
cmake .. && make -j$(nproc)
sudo make install
测试
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <tbb/tbb.h>
#include <cstdio>
using namespace tbb;
int main()
{
tick_count t0 = tick_count::now();
parallel_for(0, 100, 1, [](int i) {
printf("hello tbb %d \n", i);
} );
tick_count t1 = tick_count::now();
printf("use time %f \n", (t1-t0).seconds());
return 0;
}
CMakeLists.txt
1
2
3
4
5
6
cmake_minimum_required(VERSION 3.1)
project( TEST )
find_package( TBB REQUIRED)
add_executable( TEST_tbb test_tbb.cpp)
target_link_libraries( TEST_tbb TBB::tbb)
Results
3. 参考
https://oneapi-src.github.io/oneTBB/