- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm using Intel Parallel Studio SP1 within Visual Studio 2008 and cannot get the compiler (v. 11.1.071 [IA-32]) to recognize the lambda expression within a TBB parallel_for. Using several different documentation resources, I've settled on the following code (for matrix multiplication):
Any advice on what I'm doing wrong or what might be missing?
--clay
parallel_for(blocked_range (0, m, 1),
[=](const blocked_range & r){ // use lambda facility of TBB 3.0
for (size_t i = r.begin(); i < r.end(); i++)
for (int j = 0; j < n; j++){
C=0;
for (int k = 0; k < p; k++)
C += A*B;
}
}, auto_partitioner());
I keep getting a compiler error ".\\MMmult.cpp(36): error: expected an expression" pointing to the open square bracket of the lambda. I've tried without the '=' and putting the lambda in a separate declaration (as was pointed out in an earlier forum post). All with the same negative results.Any advice on what I'm doing wrong or what might be missing?
--clay
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Did you turn it on?
/Qstd=c++0x, or go to the appropriate compiler configuration page to enable the C++0x extensions.
/Qstd=c++0x, or go to the appropriate compiler configuration page to enable the C++0x extensions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
p.s., While TBB from version 2.2 forward has had support for selected parallel constructs that take advantage of lambda expressions, lambdas are really an attribute of the compiler.
p.p.s TBB 3.0 uses auto_partitioner as the default argument, so you could drop the autopartitioner argument for brevity and clarity.
p.p.p.s You might want to consider reference sematics for the arrays referenced inside the lambda expression, rather than using the copy semantics ("[=]") used in the example: I think you want to use the arrays in place, shared among the threads rather than having each threadmake their own private copy.
p.p.s TBB 3.0 uses auto_partitioner as the default argument, so you could drop the autopartitioner argument for brevity and clarity.
p.p.p.s You might want to consider reference sematics for the arrays referenced inside the lambda expression, rather than using the copy semantics ("[=]") used in the example: I think you want to use the arrays in place, shared among the threads rather than having each threadmake their own private copy.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting Robert Reed (Intel)
Did you turn it on?
/Qstd=c++0x, or go to the appropriate compiler configuration page to enable the C++0x extensions.
/Qstd=c++0x, or go to the appropriate compiler configuration page to enable the C++0x extensions.
Aha, that was the missing piece. Thank you, Robert.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Not being a C++ programmer and not having read anything about the syntax or semantics of lambda's, I was just copying examples from other codes.
I've used the '[&]' notation. Is this the reference semantics? The execution seem faster with the ampersand instead of the equal sign.
I've used the '[&]' notation. Is this the reference semantics? The execution seem faster with the ampersand instead of the equal sign.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, use of & in the context specification sets the default linkage for symbols found in the lambda expression that are defined in the enclosing scope to reference semantics: the variable visible in the expression will be a reference to the actual variable rather than a copy to be used within the lambda construction. If the arrays were big enough or the computation run long enough, you should notice a performance boost by avoiding copying the arrays with each invocation. And if you actually cared about the results of your matrix multiply, you might notice using [=] thatthey're allwrong! ;-)
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