开发者

Reasons for Parallel Extensions working slowly

开发者 https://www.devze.com 2023-01-01 14:12 出处:网络
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 bec

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.

  1. 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.
  2. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号