我在Ubuntu 20.04上使用OnETBB遇到了难以正确使用。当我想使用std :: excution :: par with std :: for_each使用CLI G ++和CMAKE时,就会发生问题。我有GCC 9.4.0。
这是我关注的过程:
test.cpp:
#include <iostream>
#include <vector>
#include <algorithm>
#include <execution>
int main(){
std::vector<int> vec = {1, 2, 3, 4, 5, 10, 20, 4 };
std::sort(std::execution::seq, vec.begin(), vec.end()); // sequential
std::sort(std::execution::par, vec.begin(), vec.end()); // parallel
return 0;
}
-
我尝试了以下命令:
g ++ -std = c ++ 17 -o test test.cpp -ltbb
这不起作用并给出许多错误。
-
我尝试了命令行,如说明此处:
g ++ -o -o test test.cpp $(pkg -config - libs -cflags tbb)
它给出以下错误:
错误:'std ::执行'尚未声明
指向行STD ::排序行。
-
我尝试了以下内容(基于此处)cmake文件,没有运气:
cmake_minimum_required(版本3.22)
项目(测试)
SET(CMAKE_CXX_STANDARD 20)
列表(附录cmake_module_path“/home/home/username/oneapi/tbb/最新/lib/cmake/tbb”)
#set(cmake_module_path“/home/home/username/oneapi/tbb/最新/lib/cmake/tbb”)#this也不起作用
add_executable(test test.cpp)
find_package(需要TBB)
target_link_libraries($ {project_name} tbb)
-
有趣的是,给出的示例在这里都在起作用。我可以构建并运行它们(除了MKL示例除外)。这些示例都没有 #include&lt; eccution&gt;
and std :: excution :: par
在它们中很艰难,据我所知。
-
在一个onetbb示例之一(例如fibonacci)中,如果我仅在示例源代码中包括&lt; execution&gt;
,则不会在上面的第五和第6个选项中给出错误。但是,当我想在代码中使用 std :: execution :: par
时,它不会编译。因此,当 std :: excution :: PAR
发挥作用时,示例不起作用。
-
可以使用 apt
安装的旧版本的tbb版本,不会给出此错误。
任何帮助都将受到赞赏。
I am having trouble properly using oneTBB on my Ubuntu 20.04. The problem occurs when I want to use std::execution::par with std::for_each for both using CLI g++ and cmake. I have gcc 9.4.0.
This is the procedure I follow:
test.cpp:
#include <iostream>
#include <vector>
#include <algorithm>
#include <execution>
int main(){
std::vector<int> vec = {1, 2, 3, 4, 5, 10, 20, 4 };
std::sort(std::execution::seq, vec.begin(), vec.end()); // sequential
std::sort(std::execution::par, vec.begin(), vec.end()); // parallel
return 0;
}
-
I tried the following command :
g++ -std=c++17 -o test test.cpp -ltbb
this does not work and give many errors.
-
I tried the command line as explained here:
g++ -o test test.cpp $(pkg-config --libs --cflags tbb)
it gives the following error:
error: ‘std::execution’ has not been declared
pointing to the line std::sort lines.
-
I tried the following (based on here) cmake file with no luck:
cmake_minimum_required(VERSION 3.22)
project(test)
set(CMAKE_CXX_STANDARD 20)
list(APPEND CMAKE_MODULE_PATH "/home/username/oneapi/tbb/latest/lib/cmake/tbb")
#set(CMAKE_MODULE_PATH "/home/username/oneapi/tbb/latest/lib/cmake/tbb") #this did not work either
add_executable(test test.cpp)
find_package(TBB REQUIRED)
target_link_libraries(${PROJECT_NAME} tbb)
-
Interestingly, the examples given here are all working. I can build and run them all (except the MKL examples). None of these examples have #include <execution>
and std::execution::par
in them tough, as far as I can see.
-
In one of the oneTBB examples (e.g. fibonacci), if I only include <execution>
to the example source code, it does not give error with the 5th and 6th option above. But when I want to use std::execution::par
in the code, it does not compile. So examples are not working when std::execution::par
comes into play.
-
Older version of TBB that can be installed using apt
, does not give this error.
Any help is appreciated.
发布评论
评论(1)
Detailed explanation in this thread