parallel_for using boost bind

parallel_for using boost bind

Hi,I try to use boost::bind instead of lambda function as the compiler is not 4.7.got the following error. any way to solve it?test.cpp: In member function void list::parallel():test.cpp:27: error: no matching function for call to parallel_for(__gnu_cxx::__normal_iterator > >, __gnu_cxx::__normal_iterator > >, size_t, boost::_bi::bind_t, boost::_bi::list2, boost::arg<1> > >)using namespace std;struct Obj{ int32_t value;};class list{ std::vector objList;public: void process(Obj& obj) { //do something }; void parallel() { tbb::parallel_for(objList.begin(), objList.end(), size_t(1), boost::bind(&list::process, this, _1)); };};int main(int argc,char *argv[]){ return 1;}

6 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.

list::process() expects a reference to Obj, but the result of boost::bind() will get an iterator to Obj from tbb::parallel_for, so you'll have to dereference it first?

ok I try to modify it to accept iterator. However, no luck.test.cpp: In member function void list::parallel():test.cpp:52: error: no matching function for call to parallel_for(__gnu_cxx::__normal_iterator > >, __gnu_cxx::__normal_iterator > >, size_t, boost::_bi::bind_t > > >, boost::_bi::list2, boost::arg<1> > >)void process(std::vector::iterator obj) { //do something };

Best Reply

The first mistake is not related to bind:iterators are passed directly to the parallel_for. It accepts either numeric types or a Range-modelling type (e.g. blocked_range). The second, an iterator is not implicitly convertable to its reference_type which is expected in list::process.Please try the following:

void process(std::vector::iterator it)...tbb::parallel_for(tbb:blocked_range::iterator>(objList.begin(), objList.end()),boost::bind(&list::process, this, _1)

"The first mistake is not related to bind:iterators are passed directly
to the parallel_for. It accepts either numeric types or a
Range-modelling type (e.g. blocked_range)."
Ah, I hadn't looked at the implementation yet: there's some code that doesn't work with iterators, but maybe compiler diagnostics in the presence of SFINAE just doesn't drill through to that underlying reason even if there's no remaining specialisation?

So it might work with a Range and the revised process().

(Edited)

Thank you.Just a small modification to make it work.void process(const tbb::blocked_range::iterator>& r) const;

Connectez-vous pour laisser un commentaire.