Intel tbb parallel_for: pass class member function with parameters?

試著忘記壹切 提交于 2019-12-06 09:16:28

Look at this example.

They create a class and suply the class with a all the parameters needed. In that class is also a operator() which does an oppertion on the data. The parallel_for is then called with a instance of that class.

parallel_for(blocked_range<int>(0, nElements, 100), ArraySummer( p_A, p_B, p_SUM_TBB ) ); 
//The class is arraysummer

How you could do it :

class ClassTACaller
{
   int* m_parameter;
   ClassT* m_Tinstance

public:

   ClassTACaller(ClassT* tinstance, int* param):m_parameter(param), m_Tinstance(tinstance){}
   void operator() ( const blocked_range<int>& r ) const 
   {
      m_Tinstance->A(r, param);
   }
};

parallel_for(blocked_range<int>(0, nElements, 100), ClassTACaller(&classTinstance, &x));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!