Hi guys
i just want to ask. is there someone here who has experience using the parallel.for loop? can you give me an example or snippet of you work? and if you are too kind enough explain to me how it works...
Thank you very much
Imo
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Aug 31, 2012, 10:49 AM
On my dual core Pentium I3 laptop and on most occasions, the time taken to process the task (calculate 10 million square roots) using parallel processing is around 50% of that taken using sequential processing which, of course, is what you'd expect:
The overload of the Parallel.For method I'm using takes 3 arguments:
1. A starting value (inclusive).
2. An ending value (exclusive).
3. A lambda expression which calculates the root and stores it in the array.
As you probably know, some iterations will be allocated to a thread running on one core and the other iterations to a thread running on the other core. As only one thread can deal with a particular iteration, there's no chance of a collision when writing the result to the array and a lock is not therefore needed.