Community
cancel
Showing results for 
Search instead for 
Did you mean: 
dophine
Beginner
84 Views

parallel_for using boost bind

Jump to solution
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<:_BI::VALUE>, 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;
}
0 Kudos
1 Solution
Anton_M_Intel
Employee
84 Views
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<:VECTOR>::iterator>(objList.begin(), objList.end()),boost::bind(&list::process, this, _1)

View solution in original post

5 Replies
RafSchietekat
Black Belt
84 Views
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?
dophine
Beginner
84 Views
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<:_BI::VALUE>, boost::arg<1> > >)
void process(std::vector::iterator obj)
{
//do something
};
Anton_M_Intel
Employee
85 Views
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<:VECTOR>::iterator>(objList.begin(), objList.end()),boost::bind(&list::process, this, _1)

View solution in original post

RafSchietekat
Black Belt
84 Views
"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)
dophine
Beginner
84 Views
Thank you.
Just a small modification to make it work.
void process(const tbb::blocked_range<:VECTOR>::iterator>& r) const;
Reply