views:

36

answers:

1

I am trying to make my calculating application faster by using Parallel Extensions. 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

A: 

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.

Cobusve
In short, I have a list of objects and try to calculate some properties' values for each object. Objects are isolated, there are no common variables to compute. There is a static class for storing constants but its fields are not mutable.Intel Core i7 is used for calculation. All cores are 90-100% busy. But it works slower then single-thread calculation with one core busy.
darja
I assume that the calculations are pretty basic then. The overhead of allocating resources for each thread is thus exceeding the value you are getting from executing in parallel.How many objects do you have in your list?A classic way to fix this is to reduce the overhead of creating a large number of threads to an optimal value. Your I7 may e.g. have 8 cores, so you could do the division of work yourself.
Cobusve
Try this: 1. Make a method that calculates the properties on a list of objects instead of a single one. 2. Write some code which divides your set of objects into 8 lists. 3. Now use the Parallel extensions to kick of 8 parallel processes, each performing the calculation on a list.If you profile this you can accurately gauge the additional effort required to break the data set into 8 lists as well as the overhead of iterating each list.If this overhead is less than the performance gains of using all cores then this will improve your performance, else you are just adding effort (time)
Cobusve