标签: tbb

并行执行比Serial更多的时间?

我正在研究TBB中的任务实现,并运行了Fibonacci系列的并行和连续计算代码.

守则是:

#include <iostream>
#include <list>
#include <tbb/task.h>
#include <tbb/task_group.h>
#include <stdlib.h>
#include "tbb/compat/thread"
#include "tbb/task_scheduler_init.h"
using namespace std;
using namespace tbb;

#define CutOff 2

long serialFib( long n ) {
if( n<2 )
return n;
else
return serialFib(n-1) + serialFib(n-2);
}


class FibTask: public task 
{
    public:
    const long n;
    long* const sum;

    FibTask( long n_, long* sum_ ) : n(n_), sum(sum_) {}

    task* execute() 
    {
        // cout<<"task id of thread is \t"<<this_thread::get_id()<<"FibTask(n)="<<n<<endl;  // Overrides virtual function task::execute    
                // …
Run Code Online (Sandbox Code Playgroud)

c++ linux tbb

1
推荐指数
1
解决办法
1302
查看次数

TBB流程图条件执行

可以动态地控制TBB流图中的执行路径,使用节点的输出作为条件变量来确定是否应该启动另一个节点?

c++ multithreading asynchronous tbb tbb-flow-graph

1
推荐指数
1
解决办法
1218
查看次数

在pthread,Intel TBB,openmp上哪个库更通用,更灵活?

我想用c ++学习多核编程,你能给我推荐一些笔记吗?而什么是之间的差异pthread,Intel TBB以及openmp?哪个库可以Intel CPU更有效地使用?谢谢.

multithreading multicore pthreads tbb openmp

1
推荐指数
1
解决办法
1075
查看次数

与 C++ 的 TBB 链接

我正在尝试在 HPCG 基准测试中使用 TBB 进行一些测试。但是到目前为止我还没有成功编译程序。我收到这样的错误:

src/ComputeSPMV_ref.o: In function `tbb::interface6::internal::start_for<tbb::blocked_range<int>, tbb::internal::parallel_for_body<ComputeSPMV_ref(SparseMatrix_STRUCT const&, Vector_STRUCT&, Vector_STRUCT&)::{lambda(int)#1}, int>, tbb::auto_partitioner const>::~start_for()':
ComputeSPMV_ref.cpp:(.text+0x3): undefined reference to `vtable for tbb::task'
src/ComputeSPMV_ref.o: In function `tbb::interface6::internal::start_for<tbb::blocked_range<int>, tbb::internal::parallel_for_body<ComputeSPMV_ref(SparseMatrix_STRUCT const&, Vector_STRUCT&, Vector_STRUCT&)::{lambda(int)#1}, int>, tbb::auto_partitioner const>::~start_for()':
ComputeSPMV_ref.cpp:(.text+0x23): undefined reference to `vtable for tbb::task'
src/ComputeSPMV_ref.o: In function `tbb::interface6::internal::start_for<tbb::blocked_range<int>, tbb::internal::parallel_for_body<ComputeSPMV_ref(SparseMatrix_STRUCT const&, Vector_STRUCT&, Vector_STRUCT&)::{lambda(int)#1}, int>, tbb::auto_partitioner const>::execute()':
ComputeSPMV_ref.cpp:(.text+0x182): undefined reference to `tbb::internal::allocate_continuation_proxy::allocate(unsigned long) const'
ComputeSPMV_ref.cpp:(.text+0x1ad): undefined reference to `tbb::internal::allocate_child_proxy::allocate(unsigned long) const'
ComputeSPMV_ref.cpp:(.text+0x26b): undefined reference to `tbb::internal::allocate_continuation_proxy::allocate(unsigned long) const'
ComputeSPMV_ref.cpp:(.text+0x296): undefined reference to `tbb::internal::allocate_child_proxy::allocate(unsigned long) const' …
Run Code Online (Sandbox Code Playgroud)

c++ tbb

1
推荐指数
1
解决办法
4248
查看次数

TBB parallel_for:为什么Body :: operator()参数不是const?

英特尔《 TBB开发人员参考》中的此页面列出了parallel_for模板参数的要求Body,其中包括:

void Body::operator()( Range& range ) const
Run Code Online (Sandbox Code Playgroud)

为什么将Range参数传递给operator()const?最好在有必要和/或有用的地方看一个例子。

c++ tbb

1
推荐指数
1
解决办法
166
查看次数

使用 task_group 的英特尔线程构建块性能不佳(新用户)

我最近对英特尔线程构建块感兴趣。我想利用tbb::task_group该类来管理线程池。

我的第一次尝试是构建一个测试,其中将向量复制到另一个向量中:我创建了第 n 个任务,每个任务负责复制向量的连续切片。

但是,性能会随着线程数的增加而降低。我对另一个线程池实现有相同的结果。使用 TBB 2018 更新 5 和 gcc 6.3 on debian strecth on a 8 i7 core box,我得到下图来复制 1'000'000 个元素的向量:

第 n 个真实用户

1 0.808s 0.807s

2 1.068s 2.105s

4 1.109 秒 4.282 秒

也许你们中的一些人会帮助我理解这个问题。这是代码:

#include<iostream>
#include<cstdlib>
#include<vector>
#include<algorithm>
#include "tbb/task_group.h"
#include "tbb/task_scheduler_init.h"

namespace mgis{
  using real = double;
  using size_type = size_t;
}

void my_copy(std::vector<mgis::real>& d,
         const std::vector<mgis::real>& s,
         const mgis::size_type b,
         const mgis::size_type e){
  const auto pb = s.begin()+b;
  const auto pe = …
Run Code Online (Sandbox Code Playgroud)

c++ tbb

1
推荐指数
1
解决办法
488
查看次数

使用 TBB 并行创建向量

我有一个vector<int> foo和一个函数float bar(int)。使用algorithms图书馆,我可以填充vector<float> quux

transform(foo.begin(), foo.end(), quux.begin(), bar);
Run Code Online (Sandbox Code Playgroud)

我的foo函数碰巧很慢,我希望使用 TBB 库跨多个线程并行处理此代码。我认为这将是一个理想的情况,因为所有操作都是独立的。但是,似乎没有parallel_transform算法。我在parallel_for算法中看到的每个示例都将数据放回到原始数组中,这是我无法做到的,因为我正在更改类型。

c++ parallel-processing tbb

1
推荐指数
1
解决办法
234
查看次数

如何在Ubuntu上安装TBB?

我从http://threadingbuildingblocks.org/ver.php?fid=174下载了tbb40_233oss_lin.tgz文件

我将"TBBROOT"变量设置为我的bash_proflie中的目录,然后解压缩tar文件并导航到bin文件夹并运行tbbvars.sh文件

我打字了

sh tbbvars.sh intel64
Run Code Online (Sandbox Code Playgroud)

我试图运行示例但它抱怨如图所示

count_strings.cpp:38:37: fatal error: tbb/concurrent_hash_map.h: No such file or directory
Run Code Online (Sandbox Code Playgroud)

我尝试手动设置库路径并输入

g++ file.cpp -o output -L/path/to/the/lib/-ltbb
Run Code Online (Sandbox Code Playgroud)

但它仍然抱怨.

如何在Ubuntu上编译示例代码?

提前致谢.

tbb

0
推荐指数
1
解决办法
6407
查看次数

具有TBB和IPP的Opencv

我已经构建了Opencv并启用了TBB.并使用"detectMultiscale"并编写了一个基本程序来检测面部.如果框架中有一个面,我无法找到处理时间的任何变化.另外我注意到如果一帧中没有脸(空),处理时间减少了两倍.

1)现在如何改善处理时间?

2)是否值得去英特尔IPP?什么可能是实际的好处?

任何人都可以给我一个建议吗?

更新:

我用opencv2.4.5做到了这一点.

更新2:

我在opencv社区发布了相同的问题,并获得了回复,因为TBB是从opencv2.4.5预先启用的,我们不需要重新构建opencv与TBB enbled?那是对的吗?

http://answers.opencv.org/question/14226/opencv-with-both-tbb-and-ipp/?answer=14231#post-id-14231

opencv image-processing tbb computer-vision face-detection

0
推荐指数
1
解决办法
3090
查看次数

什么是tbb中parallel_reduce的Reduce?

parallel_reduce 提供2个接口,lambdas的一个可以像上一个链接中显示的那样使用

#include "tbb/parallel_reduce.h"
#include "tbb/blocked_range.h"

using namespace tbb;

float ParallelSum( float array[], size_t n ) {
    return parallel_reduce( 
        blocked_range<float*>( array, array+n ), 
        0.f, 
        [](const blocked_range<float*>& r, float init)->float {
            for( float* a=r.begin(); a!=r.end(); ++a ) 
                init += *a;
            return init;
        },
        []( float x, float y )->float { // what this lambda does ?
            return x+y;
        }
    );                    
}
Run Code Online (Sandbox Code Playgroud)

第二个lambda符合const Reduction& reduction签名,我正在研究这个lambda试图改变身体或价值观,但它确实没有做任何事情(即使我把一个cout内部,没有任何事情发生),看起来它完全没有任何理由.

这是什么目的Reduction?与此有关0f?我得到的0f是一个用于检测可以跳过的值的谓词,但我仍然无法弄清楚lambda的作用...

c++ lambda multithreading tbb c++11

0
推荐指数
1
解决办法
1722
查看次数