I am trying to make my calculating application faster by using Parallel E开发者_C百科xtensions. I am new in it, so I have just replaced the main foreach loop with Parallel.ForEach. But calculating became more slow. What can be common reasons for decreasing performance of parallel extensions?
Thanks
You will only get improvement by running parallel if a number of conditions are met. Firstly why could you expect a speed increase?
Cases where you can expect performance increase are e.g.
- If you have sequential operations waiting on a resource, e.g. making TCP connections to a server and downloading data, this may be faster to do in parallel.
- If you have multiple processors/cores it may be faster to execute each task on a core instead of using 100% of one core and none of the others.
If you have one core and lots of small operations the extra work required for context switches and allocating the resources required to manage the parallel threads may outweigh the advantages.
If you describe your particular case we can try to speculate why it is slower in your example.
Actually the WikiPedia entry on Parallel Computing has some good information on this, see at http://en.wikipedia.org/wiki/Parallel_computing
You want to pay particular attention to Amdahl's law.
精彩评论