我正在实现tbb的并发哈希映射,以将其性能与一组其他并发哈希表进行比较.
然而,我从中获得的性能是可怕的,我无法相信它与其他并发哈希表相比是那么慢
这是我的实现:
class TBB: public TestDs{
typedef tbb::concurrent_hash_map<int,int, HashCompare<int> > hash_t;
private:
hash_t _ds;
public:
TBB(const Configuration& config) : _ds(config.initial_count) {
}
bool containsKey(int key) {
hash_t::accessor a;
if(_ds.find(a,key)){
return true;
}
else
return false;
}
int get(int key) {
hash_t::accessor a;
if(_ds.find(a,key)){
return (int)(a->second);
}
else
return 0;
}
int put(int key, int value) {
return _ds.insert( std::make_pair(key, value) );
}
int remove(int key) {
return _ds.erase(key);
}
int size() {
return _ds.size();
}
const char* name() { …Run Code Online (Sandbox Code Playgroud) 我最近下载了TBB41_20130613(此时Windows的当前版本),我注意到有文件夹vc11和vc11_uibin/lib文件夹.据我所知,两者都有相同的库(文件名相同),但它们显然是不同的二进制文件(不同的文件大小).我没有在文档中找到任何参考,也没有通过Google找到两者之间的区别.
这两者有什么区别?我什么时候应该使用另一个,还是我必须同时引用它们?
使用tbb并行三个嵌套独立循环的最佳方法是什么?
for(int i=0; i<100; i++){
for(int j=0; j<100; j++){
for(int k=0; k<100; k++){
printf("Hello World \n");
}
}
}
Run Code Online (Sandbox Code Playgroud) 我需要一个快速的线程间通信机制,用于将work(void*)从TBB任务传递给正在运行/阻塞操作的多个worker.目前我正在考虑使用pipe()+ libevent.英特尔线程构建模块是否有更快,更优雅的替代方案?
我们正在考虑使用哪个并行框架C/C++.我们有一些非常特殊的条件,并不是100%肯定,例如TBB可以添加"更多"的东西.
N运行的线程和一个同步的工作队列(使用pthread互斥锁).int).重复此过程直到队列为空.
那么,现在,我想知道像TBB(线程构建块)这样的框架是否可以从算法的角度为这种特殊场景提供更多?(所以,内部......)
我试图使用tbb多线程现有的递归算法.单线程版本使用尾调用递归,从结构上看,它看起来像这样:
void my_func() {
my_recusive_func (0);
}
bool doSomeWork (int i, int& a, int& b, int& c) {
// do some work
}
void my_recusive_func (int i) {
int a, b, c;
bool notDone = doSomeWork (i, a, b, c);
if (notDone) {
my_recusive_func (a);
my_recusive_func (b);
my_recusive_func (c);
}
}
Run Code Online (Sandbox Code Playgroud)
我是tbb新手所以我的第一次尝试使用了parallel_invoke函数:
void my_recusive_func (int i) {
int a, b, c;
bool notDone = doSomeWork (i, a, b, c);
if (notDone) {
tbb::parallel_invoke (
[a]{my_recusive_func (a);},
[b]{my_recusive_func (b);},
[c]{my_recusive_func (c);}); …Run Code Online (Sandbox Code Playgroud) 我的理解是,如果我只使用一个线程,tbb::concurrent_unordered_multimap应该表现得像std::unordered_multimap.但是,在此示例中,它不会:
#include "tbb/concurrent_unordered_map.h"
#include <iostream>
#include <unordered_map>
struct myhash {
size_t operator()(const int& a) const {
return 1;
}
};
int main() {
tbb::concurrent_unordered_multimap<int, int, myhash> tbbidx;
std::unordered_multimap<int, int, myhash> stdidx;
for(int i = 0; i < 100; ++i) {
tbbidx.insert(std::make_pair(i % 10, i));
stdidx.insert(std::make_pair(i % 10, i));
}
std::cout << "tbb size " << tbbidx.size() << std::endl;
std::cout << "tbb count " << tbbidx.count(0) << std::endl;
std::cout << "std size " << stdidx.size() << std::endl; …Run Code Online (Sandbox Code Playgroud) 我不擅长数据结构,所以这可能是一个非常愚蠢的问题.我正在寻找一种方法来实现队列+映射的混合行为.
我目前正在www.threadingbuildingblocks.org中使用tbb::concurrent_bounded_queue(记录在英特尔开发人员专区)的多线程单一生产者单一消费者流程.队列具有市场数据报价对象,并且流程的生产者方面实际上是高度时间敏感的,因此我需要的是一个键入市场数据标识符的队列,例如USDCAD,EURUSD.价值指向(通过)我收到的此密钥的最新市场数据报价.unique_ptr
所以,让我们说我的队列有5个元素用于5个唯一标识符,突然我们得到队列中第3个位置的标识符的更新市场数据报价,然后我只存储最新的值并丢弃我以前的值.所以,基本上我只是将我的unique_ptr移动到这个密钥的新市场数据报价.
它就像是相似concurrent_bounded_queue<pair<string, unique_ptr<Quote>>>但却被锁定在该对的第一个元素上.
我不确定这是否已经在第三方库中可用(可能是tbb本身),或者如果它是标准数据结构则称它是什么.
我非常感谢对此提供任何帮助或指导.
谢谢.
在英特尔线程构建块框架中,如何确保所有线程不忙于等待其他线程完成。
例如考虑以下代码,
#include <tbb/tbb.h>
#include <vector>
#include <cstdlib>
#include <future>
#include <iostream>
std::future<bool> run_something(std::function<bool(bool)> func, bool b) {
auto task = std::make_shared<std::packaged_task<bool()> >(std::bind(func, b));
std::future<bool> res = task->get_future();
tbb::task_group g;
g.run([task]() { (*task)(); });
return res;
};
int main() {
tbb::parallel_for(0, 100, 1, [=](size_t i) {
g.run([] () {
std::cout << "A" << std::endl;
run_something([] (bool b) { return b; }, true).get();
});
});
return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)
这里main函数作为任务产生,因为 TBB 库使用的线程池中有线程。然后,当run_something函数中第二次调用产生更多任务时,TBB 调度程序发现没有可用的线程并且只是死锁。也就是说,我看到该打印语句在 4 超线程机器上执行了 4 次,在 8 …
我们已经使用 TBB 多年了,我发现在升级时,我们现在被带到了 oneAPI TBB 页面。oneAPI TBB是否会取代传统TBB?两个版本都得到维护还是独立的 TBB 现已弃用?
尝试确定要迁移到哪个。在我看来,oneAPI TBB 取代了 TBB,因为 TBB 页面自去年以来就没有更新过,但我无法轻易判断。
同样让我困惑的是,在 include 目录中,同时存在 tbb/tbb.h 和 oneapi/tbb/tbb.h ,并且两者都有相同的文件。它们相同吗?我不知道该用哪个。
tbb ×10
c++ ×9
c++11 ×2
hashmap ×2
c ×1
concurrency ×1
deadlock ×1
gcc ×1
intel-oneapi ×1
recursion ×1