小编Tho*_*mas的帖子

使用 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
查看次数

标签 统计

c++ ×1

tbb ×1