- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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;
}
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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)
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
"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)
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you.
Just a small modification to make it work.
void process(const tbb::blocked_range<:VECTOR>::iterator>& r) const;

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page