Software Archive
Read-only legacy content
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
17060 Discussions

lambda for TBB parallel_for

Goran_N
Beginner
676 Views
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.
0 Kudos
2 Replies
JenniferJ
Moderator
676 Views
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.

[cpp]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);
}
[/cpp]

I'm using the Parallel Composer update2-revised.

Jennifer
0 Kudos
Goran_N
Beginner
676 Views
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.

[cpp]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);
}
[/cpp]

I'm using the Parallel Composer update2-revised.

Jennifer

0 Kudos
Reply