[Haskell-cafe] Re: Parallel Pi
Simon Marlow
marlowsd at gmail.com
Thu Mar 18 17:44:55 EDT 2010
On 17/03/10 21:30, Daniel Fischer wrote:
> Am Mittwoch 17 März 2010 19:49:57 schrieb Artyom Kazak:
>> Hello!
>> I tried to implement the parallel Monte-Carlo method of computing Pi
>> number, using two cores:
> <move>
>>
>> But it uses only on core:
>>
> <snip>
>>
>> We see that our one spark is pruned. Why?
>>
>
> Well, the problem is that your tasks don't do any real work - yet.
> piMonte returns a thunk pretty immediately, that thunk is then evaluated by
> show, long after your chance for parallelism is gone. You must force the
> work to be done _in_ r1 and r2, then you get parallelism:
>
> Generation 0: 2627 collections, 2626 parallel, 0.14s, 0.12s elapsed
> Generation 1: 1 collections, 1 parallel, 0.00s, 0.00s elapsed
>
> Parallel GC work balance: 1.79 (429262 / 240225, ideal 2)
>
> MUT time (elapsed) GC time (elapsed)
> Task 0 (worker) : 0.00s ( 8.22s) 0.00s ( 0.00s)
> Task 1 (worker) : 8.16s ( 8.22s) 0.01s ( 0.01s)
> Task 2 (worker) : 8.00s ( 8.22s) 0.13s ( 0.11s)
> Task 3 (worker) : 0.00s ( 8.22s) 0.00s ( 0.00s)
>
> SPARKS: 1 (1 converted, 0 pruned)
>
> INIT time 0.00s ( 0.00s elapsed)
> MUT time 16.14s ( 8.22s elapsed)
> GC time 0.14s ( 0.12s elapsed)
> EXIT time 0.00s ( 0.00s elapsed)
> Total time 16.29s ( 8.34s elapsed)
>
> %GC time 0.9% (1.4% elapsed)
>
> Alloc rate 163,684,377 bytes per MUT second
>
> Productivity 99.1% of total user, 193.5% of total elapsed
>
> But alas, it is slower than the single-threaded calculation :(
>
> INIT time 0.00s ( 0.00s elapsed)
> MUT time 7.08s ( 7.10s elapsed)
> GC time 0.08s ( 0.08s elapsed)
> EXIT time 0.00s ( 0.00s elapsed)
> Total time 7.15s ( 7.18s elapsed)
It works for me (GHC 6.12.1):
SPARKS: 1 (1 converted, 0 pruned)
INIT time 0.00s ( 0.00s elapsed)
MUT time 9.05s ( 4.54s elapsed)
GC time 0.12s ( 0.09s elapsed)
EXIT time 0.00s ( 0.01s elapsed)
Total time 9.12s ( 4.63s elapsed)
wall-clock speedup of 1.93 on 2 cores.
What hardware are you using there? Have you tried changing any GC settings?
Cheers,
Simon
More information about the Haskell-Cafe
mailing list