Strange Behaviour Using Scala Parallel Collections and setParallelism -
I recently found out about parallel collection in Scala 2.9 and was excited to see that the degree of equality can be determined with the help of collection. Parallel.ForkJoinTasks.defaultForkJoinPool.setParallelism
Although when I tried to make an experiment of adding two vectors of size one million each, I used the
- with parallel parallelism to set up the archive Will get faster as 64 sequential (shown in the above results).
- Increasing similarities set to increase performance in a non-linear way. I have the least hope for monotonic behavior (if I want to increase parallelism then the display should not be degraded)
Can anyone explain why this is happening < Pre>
object examplePar app {val Rnd = new random () val numSims = 1 val x = for (j & lt; - 1 to 1000000) returns Rnd.nextDouble () for Val y = (j & Lt; - 1 to 1000000) yield Rnd.nextDouble () Val parInt = list (1,2,4,8,16,32,64,128,256) Average of the top: double = 0.0 on currTime: long = 0 (J & lt; - parInt) {collection.parallel.ForkJoinTasks.defaultForkJoinPool SetParallelism (j) for average = 0.0 (for & lt; - for 1 numSims) {currTime = System.currentTimeMillis () (x zip y) .par.map (x => x._1 + x._2) Average + = (System.currentTimeMillis () - currTime)} println (+ j.toString + "=" + (average / numSims) .toString + "MS" "set for time to execute with average parity") } CurrTime = System.currentTimeMillis () (x zip y) .map (x => gt; x._1 + x._2) println ("time to execute using sequential" + (SystemCurrenttime milliseconds) - cruel Time). Storey NG + "MS")}
Scala 2.9.1 and a four-core processor Running example using
to execute parallelism with the average time set to 1 = 1047.0ms with average parallelism set to time 2 = 594.0ms average Time to execute with parallelism set to time 4 = 672.0ms to execute with average parallelism Time set to time 8 = 343.0ms Average execution time with equal parallelism set to 16 = 375.0ms Time to execute the time set to 32 = 391.0ms with the average parity of time to execute the time set to 64 = Average time to execute with equality equal to 406.0ms = set equals with 813.0ms = 813.0ms Time to implement set up to 256 = 469.0ms time to use sequential = 406ms
Although these results are for one run, they are formally set to run on more runs Go
parallelism Does not come free. In order to split this problem into smaller parts, additional chakras are needed, arranges everything, and synchronizes the result.
You can ask it to call all your friends, so you can go there
In case of your test, you can add two pairs , Which is a trivial exercise and takes so little time that overhead than parallel is more than just working in one thread.
Then, equality tells all your friends to help carry 3 suitcases. It will take half an day to get rid of you, while you can complete yourself in minutes.
To get some benefit from parallelization, it is necessary to complicate your work so that over the excess land. Try to do some expensive calculations, for example, formulas associated with a mixture of 5-10 trigonometric and logarithmic functions.
Comments
Post a Comment