lambda for TBB parallel_for

lambda for TBB parallel_for

Is it possible to pass a lambda function into 'parallel_for' instead of Body object?
This is an example of what I would like to do:

auto procEachRowL = [this, &imageOut, &imWB](const tbb::blocked_range &r){
for (size_t i=r.begin(); i this->ProcessEachRow(i, imageOut, imWB); };

parallel_for(blocked_range(0, yMax, 1), procEachRowL); // Syntax error here

Thanks.

3 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Quoting - Goran N
auto procEachRowL = [this, &imageOut, &imWB](const tbb::blocked_range &r){
for (size_t i=r.begin(); ithis->ProcessEachRow(i, imageOut, imWB); };

parallel_for(blocked_range(0, yMax, 1), procEachRowL); // Syntax error here

Thanks.

I used NQ example and it works fine for me.

void solve() { 
	auto forPar_For = 
 [](const blocked_range &r){ 
      for (size_t i = r.begin(); i != r.end(); ++i) { 
      setQueen(new int[size], 0, (int)i); 
         }; 
      };

	parallel_for(blocked_range(0, size, 1), forPar_For);
}

I'm using the Parallel Composer update2-revised.

Jennifer

My syntax error was coming from:

parallel_for(blocked_range<int>...

instead of:

parallel_for(blocked_range<size_t>...

Now it works correctly. Thanks!

Quoting - Jennifer Jiang (Intel)

I used NQ example and it works fine for me.

void solve() { 
	auto forPar_For = 
 [](const blocked_range &r){ 
      for (size_t i = r.begin(); i != r.end(); ++i) { 
      setQueen(new int[size], 0, (int)i); 
         }; 
      };

	parallel_for(blocked_range(0, size, 1), forPar_For);
}

I'm using the Parallel Composer update2-revised.

Jennifer

Leave a Comment

Please sign in to add a comment. Not a member? Join today