【问题标题】:Intel Threading Building Blocks poor performance英特尔线程构建模块性能不佳
【发布时间】:2015-02-11 12:48:37
【问题描述】:

我对 tbb 与 OpenMp 与单线程进行了非常简单的并行 for 循环评估。虽然 omp 几乎可以线性扩展,但 tbb 在 100% 负载的 4x 核心系统上运行速度快了大约 1.7 倍。 我将 W7 ia32 与 VS2010 i5-2500 一起使用。 代码:

const int size = 100000;
tbb::concurrent_vector<double> x(size);
long long t1 = GetTimeMs();
#if 1
tbb::parallel_for(0, size, 1, [&](int i) {
    double& xx = x[i];
    xx += i;
    for (int j = 0; j < size; j++) {
        xx += 3.0 * j * j + 2.0 * j + 1.0;
    }
});
#elif 0 
#pragma omp parallel for
for (int i = 0; i < size; i++) {
    double& xx = x[i];
    xx += i;
    for (int j = 0; j < size; j++) {                
        xx += 3.0 * j * j + 2.0 * j + 1.0;
    }
}
#else   
for (int i = 0; i < size; i++) {
    double& xx = x[i];
    xx += i;
    for (int j = 0; j < size; j++) {
        xx += 3.0 * j * j + 2.0 * j + 1.0;
    }
}
#endif
long long t2 = GetTimeMs() - t1;
printf("%lld ms\n", t2);

对于 single、omp 和 tbb,执行时间为 14.4、3.7、8.1。

【问题讨论】:

  • 它可能与块大小有关。我不知道 TBB,但看起来您使用的块大小为 1。OpenMP 默认使用 N/nthreads 之类的块。
  • 刚刚在 24 线程的 Linux 上进行了检查。 TBB 还好,比 OpenMP (22.8, 1.01, 0.99) 还要快一点
  • 你是在发布模式下编译吗?
  • 同样是在 windows 上,4 个 HT 线程和 gcc4.9.2 (16.5, 8.7, 8.7)
  • 请澄清on 4x core system with 100% load。此测试是 100% 负载,还是在您尝试通过测试执行额外计算时它已经忙于一些工作?

标签: c++ multithreading openmp multicore tbb


【解决方案1】:

谢谢大家的回答。 我自己检查了 Linux,它在那里运行良好。 好像是wintel平台的bug,我会报告给他们的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多