intel onetbb ubuntu linux std :: excution :: par错误

发布于 2025-02-02 03:34:12 字数 2490 浏览 2 评论 0 原文

我在Ubuntu 20.04上使用OnETBB遇到了难以正确使用。当我想使用std :: excution :: par with std :: for_each使用CLI G ++和CMAKE时,就会发生问题。我有GCC 9.4.0。

这是我关注的过程:

  • 我已经使用英特尔网页上的Intel GUI安装了ONETBB(在这里)。

  • 我已经使用“ source vars.sh”设置环境,in/tbb/最新/et et(解释在这里)。

  • 我有一个示例代码:

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:

  • I have installed oneTBB using the Intel GUI from Intel's web page (here).

  • I have set the environment using "source vars.sh" in /tbb/latest/env (explained here ).

  • I have a sample code:

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

此岸叶落 2025-02-09 03:34:12

您在示例中使用了ONEDPL API,因此它本身无关。实际上,TBB只是可以与ONEDPL一起使用的后端之一 - 另一个是OpenMP。使用TBB后端,您可以遇到确实来自与TBB后端相关的问题不正确用法的错误,这是上述响应之一中所述的一个方面。借助Oneapi,我们从较旧的(与新的)“旧” TBB转到了新的ONETBB,也可以将其溢出到编译过程中。建议是首先将OnEdpl标头放入您的源代码(例如,在标准库标题之前) - 这应该足以自动调用正确的TBB后端。

我们已经有有关ONEDPL的文档,例如,请参阅

解决方案(您找到的)对您首次看到的错误的位置。

Detailed explanation in this thread

You are using oneDPL APIs in your example, so it is not about TBB per se. In fact, TBB is just one of the backends that can be used with oneDPL -- another one is OpenMP. With TBB backend, you can get into the errors that are indeed coming from the issues connected to TBB backend incorrect usage -- one aspect of that described in one of the responses above. With oneAPI, we switched to new oneTBB from older (and incompatible with new one) "old" TBB -- that also can spill out into the compilation process. The advice is to put oneDPL headers first into your source code (e.g., before standard library headers) -- that should be sufficient to automatically call correct TBB backend.

We already have documentation regarding oneDPL, e.g., please see

https://www.intel.com/content/www/us/en/develop/documentation/oneapi-dpcpp-library-guide/top.html

where the solution (found by you) to the errors you first seen.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文