c++ - TBB parallel_for compile error -


i want use tbb parallel_for had code testing

#include <tbb/parallel_for.h> #include <tbb/blocked_range.h> #include <tbb/tbb.h>  std::vector<std::tuple<std::string, unsigned int, std::string>> commands; auto n = commands.size(); tbb::parallel_for(0, n, [&](int i) {     const auto &tuple = commands[i]; } ); 

my compile line is:

g++ -std=c++11 -wall -wextra -g -og textminingapp.cpp -ltbb -o textminingapp 

and compiler error is:

textminingapp.cpp: in function ‘int main(int, char**)’: textminingapp.cpp:184:7: error: no matching function call ‘parallel_for(int, long unsigned int&, main(int, char**)::<lambda(int)>)’      } );        ^ in file included textminingapp.cpp:15:0: /usr/include/tbb/parallel_for.h:185:6: note: candidate: template<class range, class body> void tbb::parallel_for(const range&, const body&)  void parallel_for( const range&        ^ 

do have idea solve this?

the problem of code 0 of type int, while n of type std::size_t. there's mismatch, , need conversion. solution follows:

tbb::parallel_for(static_cast<std::size_t>(0), n, [&](std::size_t i)) {     // other code     } 

another solution use tbb::blocked_range<t> specify range, i.e. overload tbb::parallel_for.

tbb::parallel_for(tbb::blocked_range<std::size_t>(0, n),     [&](const tbb::blocked_range<std::size_t> &range) {         (auto = range.begin(); != range.end(); ++i)             const auto &tuple = commands[i];     } ); 

obviously, first solution more concise. however, second 1 more flexible. because first one, can specify loop body, while second one, can more outside loop body.


Comments

Popular posts from this blog

Sass watch command compiles .scss files before full sftp upload -

filehandler - java open files not cleaned, even when the process is killed -

gridview - Yii2 DataPorivider $totalSum for a column -