TBB parallel_for Release模式报错:侵入式列表节点重复加入列表
TBB Release模式运行断言失败问题排查
环境信息
- RedHat 8.8(VERSION_ID="8.8"),g++版本8.5.0-18(20210514 Red Hat)
- Ubuntu 22.04.1 LTS,g++版本11.3.0
- 通过vcpkg安装TBB库,原程序在Windows 10(Visual Studio)下编译运行完全正常
最小可复现代码
CMakeLists.txt
cmake_minimum_required(VERSION 3.9) if (CMAKE_BUILD_TYPE STREQUAL "Debug") set(CMAKE_CXX_FLAGS_DEBUG "-g -O0") set(CMAKE_BUILD_TYPE Debug) else() set(CMAKE_CXX_FLAGS "-Wall -mtune=native -march=native -g") set(CMAKE_CXX_FLAGS_RELEASE "-O3 -fno-math-errno -fno-signed-zeros -fno-trapping-math-freciprocal-math -fno-rounding-math -fno-signaling-nans -fexcess-precision=fast") endif() project(Example LANGUAGES CXX VERSION 0.9) set(CMAKE_CXX_STANDARD 17) set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) set(CMAKE_CXX_VISIBILITY_PRESET hidden) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) add_executable(example example.cpp ) find_package(TBB CONFIG REQUIRED) target_link_libraries(example TBB::tbb TBB::tbbmalloc )
vcpkg.json
{ "name": "vt", "version-string": "", "dependencies": [ "tbb" ], "builtin-baseline": "36fb23307e10cc6ffcec566c46c4bb3f567c82c6" }
example.cpp
#include <vector> #include "tbb/blocked_range.h" #include "tbb/parallel_for.h" int main() { std::vector<uint32_t> vec(100); for (size_t i = 0; i < vec.size(); ++i){ vec[i] = i; } tbb::parallel_for(tbb::blocked_range<size_t>(0, vec.size()), [&](tbb::blocked_range<size_t> r) { for (size_t i = r.begin(); i < r.end(); ++i) { vec[i] = vec[i]+1; } }); return 0; }
问题现象
程序在Debug模式下编译运行正常,但Release模式编译通过后运行触发断言失败:
Assertion node(val).my_prev_node == &node(val) && node(val).my_next_node == &node(val) failed (located in the push_front function, line in file: 135) Detailed description: Object with intrusive list node can be part of only one intrusive list simultaneously Aborted (core dumped)
Release模式构建命令:
mkdir build cd build cmake -DCMAKE_TOOLCHAIN_FILE=~/vcpkg/scripts/buildsystems/vcpkg.cmake .. cmake --build .
Debug模式仅需在cmake配置时添加-DCMAKE_BUILD_TYPE=Debug
已尝试的无效解决方法
- 移除vcpkg.json中的
builtin-baseline配置 - 删除
CMAKE_CXX_FLAGS_RELEASE的所有优化选项 - 移除
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)配置 - 移除
set(CMAKE_CXX_VISIBILITY_PRESET hidden)配置
内容的提问来源于stack exchange,提问作者Chris Gnam
相关产品推荐
相关产品推荐

