如何使用英特尔 TBB 并发无序列图
how to use intel tbb concurrent unordered map
以下是我用来开始学习如何使用Intel TBB
中的concurrent
容器的代码。
代码只是尝试填充tbb::concurrent_unordered_map
。
我已经使用以下命令在 Ubuntu 上安装了Intel TBB
: sudo apt-get install libtbb-dev
但是,当我将代码编译为: g++ -std=c++11 -fopenmp -ltbb concur_hash.cpp
#include <iostream>
#include <vector>
#include <omp.h>
#include "tbb/concurrent_unordered_map.h"
int main() {
tbb::concurrent_unordered_map<int, int> ht;
std::vector<std::pair<int, int>> vec;
vec.push_back({1,1});
vec.push_back({1,9});
vec.push_back({2,1});
vec.push_back({2,2});
vec.push_back({2,7});
vec.push_back({3,0});
vec.push_back({3,0});
vec.push_back({3,0});
vec.push_back({3,0});
vec.push_back({3,10});
const int vec_size = vec.size();
#pragma omp parallel for
for (int i = 0; i < vec_size; ++i) {
auto it = ht.find(vec[i].first);
if (it != ht.end()) {
it->second += vec[i].second;
}
else { ht.insert(vec[i]); }
}
for (auto kv : ht) {
std::cout << "k: " << kv.first << "t v: " << kv.second << std::endl;
}
return 1;
}
它抛出以下错误,我无法理解。
`/tmp/cckL17EZ.o: In function `tbb::tbb_allocator<tbb::interface5::internal::flist_iterator<tbb::interface5::internal::split_ordered_list<std::pair<int const, int>, tbb::tbb_allocator<std::pair<int const, int> > >, std::pair<int const, int> > >::deallocate(tbb::interface5::internal::flist_iterator<tbb::interface5::internal::split_ordered_list<std::pair<int const, int>, tbb::tbb_allocator<std::pair<int const, int> > >, std::pair<int const, int> >*, unsigned long)':
concur_hash.cpp:(.text._ZN3tbb13tbb_allocatorINS_10interface58internal14flist_iteratorINS2_18split_ordered_listISt4pairIKiiENS0_IS7_EEEES7_EEE10deallocateEPSA_m[_ZN3tbb13tbb_allocatorINS_10interface58internal14flist_iteratorINS2_18split_ordered_listISt4pairIKiiENS0_IS7_EEEES7_EEE10deallocateEPSA_m]+0x1c): undefined reference to `tbb::internal::deallocate_via_handler_v3(void*)'
/tmp/cckL17EZ.o: In function `tbb::tbb_allocator<tbb::interface5::internal::split_ordered_list<std::pair<int const, int>, tbb::tbb_allocator<std::pair<int const, int> > >::node>::deallocate(tbb::interface5::internal::split_ordered_list<std::pair<int const, int>, tbb::tbb_allocator<std::pair<int const, int> > >::node*, unsigned long)':
concur_hash.cpp:(.text._ZN3tbb13tbb_allocatorINS_10interface58internal18split_ordered_listISt4pairIKiiENS0_IS6_EEE4nodeEE10deallocateEPS9_m[_ZN3tbb13tbb_allocatorINS_10interface58internal18split_ordered_listISt4pairIKiiENS0_IS6_EEE4nodeEE10deallocateEPS9_m]+0x1c): undefined reference to `tbb::internal::deallocate_via_handler_v3(void*)'
/tmp/cckL17EZ.o: In function `tbb::tbb_allocator<tbb::interface5::internal::split_ordered_list<std::pair<int const, int>, tbb::tbb_allocator<std::pair<int const, int> > >::node>::allocate(unsigned long, void const*)':
concur_hash.cpp:(.text._ZN3tbb13tbb_allocatorINS_10interface58internal18split_ordered_listISt4pairIKiiENS0_IS6_EEE4nodeEE8allocateEmPKv[_ZN3tbb13tbb_allocatorINS_10interface58internal18split_ordered_listISt4pairIKiiENS0_IS6_EEE4nodeEE8allocateEmPKv]+0x29): undefined reference to `tbb::internal::allocate_via_handler_v3(unsigned long)'
/tmp/cckL17EZ.o: In function `tbb::tbb_allocator<tbb::interface5::internal::flist_iterator<tbb::interface5::internal::split_ordered_list<std::pair<int const, int>, tbb::tbb_allocator<std::pair<int const, int> > >, std::pair<int const, int> > >::allocate(unsigned long, void const*)':
concur_hash.cpp:(.text._ZN3tbb13tbb_allocatorINS_10interface58internal14flist_iteratorINS2_18split_ordered_listISt4pairIKiiENS0_IS7_EEEES7_EEE8allocateEmPKv[_ZN3tbb13tbb_allocatorINS_10interface58internal14flist_iteratorINS2_18split_ordered_listISt4pairIKiiENS0_IS7_EEEES7_EEE8allocateEmPKv]+0x20): undefined reference to `tbb::internal::allocate_via_handler_v3(unsigned long)'
collect2: error: ld returned 1 exit status`
尝试g++ -std=c++11 -fopenmp concur_hash.cpp -ltbb
相关文章:
- 控制允许动态运行c++的并发操作数
- 递归无序映射
- c++找不到具有相同哈希的无序集合元素
- 节俭并发:未解决的外部问题
- 正在将无序映射设置为无序映射的值
- 智能指针作为无序映射键,并通过引用进行比较
- 如何使用set实现无序数据结构?
- 如何写向量的无序向量集,即unordered_set<向量<向量<int>>集合?
- 如何禁用 CPU 的无序执行
- 并发/多线程:是否可以以这种方式生成相同的输出?
- 用于在并发环境中访问 MMIO 的软件模式
- C++中的并发哈希表
- 提升 asio 并发计时器取消问题与链
- 从C++无序集合中高效提取元素
- C++具有基元类型的并发队列
- 打印无序映射的第二个元素,即集合
- 使用简单两相锁定的并发程序
- 当我将其插入无序地图时,矢量的容量为 0
- 由并发无序映射查找线程调用的函数是否安全?
- 从boost无序到tbb并发哈希映射的转换