class ApplyFoo 
    { 
        float * const my_a; 
public: 
    void operator () (const blocked_range<size_t> & r) const 
        { 
            float * a = my_a; 
            for (size_t i = r.begin(); i != r.end(); ++ i) 
                Foo(a[i]); 
    } 

    ApplyFoo(float a[]) : my_a(a) {} 
}; 

int _tmain(int argc, _TCHAR* argv[]) 

    // 创建task scheduler 
    // task_scheduler_init支持一个参数,以指定使用的线程数 
    task_scheduler_init init; 
    float a[100]; 
    for (int i = 0; i < 100; i ++) 
        a[i] = (float)i; 
    // TBB会把数组分成若干的block 
    // 对block调用ApplyFoo这个functor 
    parallel_for(blocked_range<size_t>(0, 100), ApplyFoo(a)); 
    return 0; 

相关文章:

  • 2021-10-09
  • 2022-12-23
  • 2022-12-23
  • 2021-08-24
  • 2021-12-19
  • 2021-10-10
  • 2022-12-23
  • 2021-09-01
猜你喜欢
  • 2021-06-22
  • 2022-12-23
  • 2021-09-13
  • 2021-07-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案