首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >编译时TBB错误

编译时TBB错误
EN

Stack Overflow用户
提问于 2016-10-19 18:22:21
回答 1查看 304关注 0票数 0

我有下面的代码试图执行

代码语言:javascript
复制
#include <iostream>
#include <cstring>
#include "tbb/tbb.h"

using namespace std;
using namespace tbb;

class Accumulate{
    float& arr;
    float* src;

    public:
    Accumulate(float& _arr, float* _src)
    :arr(_arr), src(_src){}
    void operator() (int i) const{
        arr += src[i];
    }

};

int main(int argc, const char * argv[]) {
    float arr[4] = {1,3,9,27};
    float sum = 0;
    parallel_for(0, 4, Accumulate(sum, arr));
    cout<< sum << endl;  
}

我试图使用parllel_for来计算和,这需要tbb库。我下载了源文件tbb目录并将其粘贴到我的xcode项目目录中。

当我试图编译上述代码时,我似乎得到了以下错误'tbb/internal/_flow_graph_types_impl.h‘文件未找到

我不知道我错过了什么,请告诉我

EN

回答 1

Stack Overflow用户

发布于 2016-10-19 21:23:43

我可以在TBB:impl.h中看到这个文件。

请确保您安装的TBB没有损坏。

sum上的程序中有一个数据竞赛,您可以使用lambda代替显式函子:

代码语言:javascript
复制
int main(int argc, const char * argv[]) {
    float arr[4] = {1,3,9,27};
    atomic<float> sum = 0; // fixing data-race. Still, it's not recommended way
    parallel_for(0, 4, [&](int i){
        sum += arr[i];
    });
    cout<< sum << endl;  
}

也请参阅tbb::parallel_reduce,以便使代码正确、干净和高效。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40138885

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档