I barely knew how to use the function in parallel. The next line of code calculates the square value of the index and puts it in an array (called squares) at that index. The parallel_for function is available in Visual Studio 2010 as part of the Concurrency namespace under the heading.
parallel_for(static_cast<size_t>(0), count,
[&squares](size_t n) { squares[n] = (n+1)*(n+1); });
You can see that it uses the lambda expression to calculate the squares in parallel, and this code works and compiles correctly. However, the lambda expression clogs the parallel_for function with code. I was thinking of simply defining a lambda expression inside a function object, for example:
function<void(size_t)> Squares =
[&squares](size_t n) { squares[n] = (n+1)*(n+1); };
My question is: how can I use this function (squares) in the parallel_for function? Am I writing the Squares function incorrectly or is it just a parallel_for paradigm for using a lambda expression? You can go further and recommend other parallel libraries to me besides Microsoft, but I would still like to know the answer to my question.
sj755 source
share