1

我正在尝试使用工具 tbb::parallel_for 通过 TBB 库并行化我的代码。我使用 Mac OS 计算机,我下载并安装了带有 Homebrew 的 Tbb。

Tbb 位于 Macintosh HD ▸ opt ▸ intel ▸ compilers_and_libraries_2020.1.216 ▸ mac ▸ tbb ▸ include。

当我尝试编译时出现以下错误:

  "tbb::interface5::internal::task_base::destroy(tbb::task&)", referenced from:
      tbb::flow::interface10::graph::~graph() in interface_stokes.cpp.o
  "tbb::interface7::internal::task_arena_base::internal_terminate()", referenced from:
      tbb::interface7::task_arena::terminate() in interface_stokes.cpp.o
  "tbb::interface7::internal::task_arena_base::internal_initialize()", referenced from:
      tbb::interface7::task_arena::initialize() in interface_stokes.cpp.o
  "tbb::task_group_context::init()", referenced from:
      tbb::task_group_context::task_group_context(tbb::internal::string_index) in interface_stokes.cpp.o
  "tbb::task_group_context::reset()", referenced from:
      tbb::flow::interface10::graph::wait_for_all() in interface_stokes.cpp.o
  "tbb::task_group_context::~task_group_context()", referenced from:
      tbb::flow::interface10::graph::~graph() in interface_stokes.cpp.o
      tbb::interface9::internal::start_for<tbb::blocked_range<unsigned long>, tbb::internal::parallel_for_body<main::$_0, unsigned long>, tbb::auto_partitioner const>::run(tbb::blocked_range<unsigned long> const&, tbb::internal::parallel_for_body<main::$_0, unsigned long> const&, tbb::auto_partitioner const&) in interface_stokes.cpp.o
  "tbb::task::note_affinity(unsigned short)", referenced from:
      vtable for tbb::interface9::internal::flag_task in interface_stokes.cpp.o
  "tbb::internal::throw_exception_v4(tbb::internal::exception_id)", referenced from:
      tbb::internal::throw_exception(tbb::internal::exception_id) in interface_stokes.cpp.o
  "tbb::internal::get_initial_auto_partitioner_divisor()", referenced from:
      tbb::interface9::internal::adaptive_mode<tbb::interface9::internal::auto_partition_type>::adaptive_mode() in interface_stokes.cpp.o
  "tbb::interface7::internal::task_arena_base::internal_execute(tbb::interface7::internal::delegate_base&) const", referenced from:
      void tbb::interface7::task_arena::execute_impl<void, tbb::flow::interface10::graph::wait_functor const>(tbb::flow::interface10::graph::wait_functor const&) in interface_stokes.cpp.o
  "tbb::task_group_context::is_group_execution_cancelled() const", referenced from:
      tbb::flow::interface10::graph::wait_for_all() in interface_stokes.cpp.o
      tbb::task::is_cancelled() const in interface_stokes.cpp.o
  "tbb::internal::allocate_child_proxy::allocate(unsigned long) const", referenced from:
      tbb::interface9::internal::allocate_sibling(tbb::task*, unsigned long) in interface_stokes.cpp.o
  "tbb::internal::allocate_continuation_proxy::free(tbb::task&) const", referenced from:
      operator delete(void*, tbb::internal::allocate_continuation_proxy const&) in interface_stokes.cpp.o
  "tbb::internal::allocate_continuation_proxy::allocate(unsigned long) const", referenced from:
      operator new(unsigned long, tbb::internal::allocate_continuation_proxy const&) in interface_stokes.cpp.o
  "tbb::internal::allocate_root_with_context_proxy::free(tbb::task&) const", referenced from:
      operator delete(void*, tbb::internal::allocate_root_with_context_proxy const&) in interface_stokes.cpp.o
  "tbb::internal::allocate_root_with_context_proxy::allocate(unsigned long) const", referenced from:
      operator new(unsigned long, tbb::internal::allocate_root_with_context_proxy const&) in interface_stokes.cpp.o
  "typeinfo for tbb::task", referenced from:
      typeinfo for tbb::interface9::internal::start_for<tbb::blocked_range<unsigned long>, tbb::internal::parallel_for_body<main::$_0, unsigned long>, tbb::auto_partitioner const> in interface_stokes.cpp.o
      typeinfo for tbb::interface9::internal::flag_task in interface_stokes.cpp.o
  "vtable for tbb::task", referenced from:
      tbb::task::task() in interface_stokes.cpp.o
  NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [apps/interface_stokes/interface_stokes] Error 1
make[1]: *** [apps/interface_stokes/CMakeFiles/interface_stokes.dir/all] Error 2
make: *** [all] Error 2

为了编译我的工作(保存在与 TBB 不同的文件夹中),我使用了 Cmakelists,我在其中添加了:

#Additional modules path for cmake
set (CMAKE_MODULE_PATH
     ${CMAKE_MODULE_PATH}
     ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

include(safeguards)

set(CMAKE_CXX_FLAGS_DEBUG "-std=c++14 -g -fpermissive -fsanitize=address")
set(CMAKE_CXX_FLAGS_RELEASE "-std=c++14 -O3 -mavx -g -fpermissive")
set(CMAKE_CXX_FLAGS_RELEASEASSERT "-std=c++14 -O3 -mavx -g -fpermissive")



find_package(TBB)
if (TBB_FOUND)
  include_directories(${TBB_INCLUDE_DIRS})
  set(LINK_LIBS ${LINK_LIBS} ${TBB_LIBRARIES})
  set(HAVE_INTEL_TBB TRUE)
endif()



include_directories("${PROJECT_BINARY_DIR}")
include_directories("${PROJECT_SOURCE_DIR}")

include_directories(src)
include_directories(contrib)
add_subdirectory(apps)
add_subdirectory(tests)
add_subdirectory(output)

在我的程序中,还有一个名为 cmake 的文件夹,其中有一些文件 .cmake,实际上我不知道它们的用途。

我从来没有研究过这个主题,我正在编写一个已经构建好的代码。我猜这个错误是由于我的代码和 Tbb 库的链接错误造成的。有人知道如何解决吗?非常感谢你,斯特凡诺

4

0 回答 0