Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: Performance of parallel mergesort (Antoine Latter)
2. Re: Performance of parallel mergesort (Antoine Latter)
3. Re: Einstein's Problem (Daniel Fischer)
4. Performance of parallel mergesort (Jon Harrop)
5. Re: Einstein's Problem (Patrick LeBoutillier)
6. Re: Performance of parallel mergesort (Antoine Latter)
7. Re: Einstein's Problem (Daniel Fischer)
----------------------------------------------------------------------
Message: 1
Date: Thu, 24 Dec 2009 00:22:00 +0000
From: Antoine Latter <[email protected]>
Subject: Re: [Haskell-beginners] Performance of parallel mergesort
To: Jon Harrop <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
On Thu, Dec 24, 2009 at 12:16 AM, Antoine Latter <[email protected]> wrote:
> Hi Jon,
>
> You're more likely to get a useful response over on the
> glasgow-haskell-users mailing list, as it looks like this is a GHC
> specific bug: http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
>
> Running this at -N6 doesn't want to complete for me, so I'm not sure
> if it would segfault. I'm on a 64-bit Intel Mac OS X using GHC 6.12,
> dual core.
>
> With such a small example as this your best bet would be to file a bug report:
>
> http://hackage.haskell.org/trac/ghc/
>
> You'll need to use the login guest/guest to file a new ticket.
>
> Antoine
>
Here's a paste-bin link for the code in question:
http://hpaste.org/fastcgi/hpaste.fcgi/view?id=14871#a14871
> On Wed, Dec 23, 2009 at 9:14 PM, Jon Harrop <[email protected]> wrote:
>>
>> I took the parallel merge sort described here:
>>
>> Â http://martin.sulzmann.googlepages.com/AMP-Spring2008-intro.pdf
>>
>> and added a simple test:
>>
>> main :: IO ()
>> main = do
>> Â Â putStrLn $ show $ sum $ mergesort $ [sin x | x <- [1.0 .. 1000000.0]]
>>
>> Compiled it with GHC 6.8.2 from Debian testing and ran it with various
>> +RTS -N<n> arguments to measure its performance and obtained the following
>> results on an 8 core:
>>
>> $ ghc --make -O2 -threaded mergesort.hs -o mergesort
>> [1 of 1] Compiling Main       ( mergesort.hs, mergesort.o )
>> Linking mergesort ...
>> $ time ./mergesort +RTS -N1
>> -0.117109518058233
>>
>> real   0m9.723s
>> user   0m9.461s
>> sys   0m0.232s
>> $ time ./mergesort +RTS -N2
>> -0.117109518058233
>>
>> real   0m13.574s
>> user   0m15.225s
>> sys   0m0.140s
>> $ time ./mergesort +RTS -N3
>> -0.117109518058233
>>
>> real   0m13.185s
>> user   0m15.529s
>> sys   0m0.184s
>> $ time ./mergesort +RTS -N4
>> -0.117109518058233
>>
>> real   0m13.251s
>> user   0m15.829s
>> sys   0m0.336s
>> $ time ./mergesort +RTS -N5
>> -0.117109518058233
>>
>> real   0m13.093s
>> user   0m16.929s
>> sys   0m0.164s
>> $ time ./mergesort +RTS -N6
>> Segmentation fault
>>
>> real   0m5.711s
>> user   0m7.408s
>> sys   0m0.136s
>>
>> That segfault must be due to a bug in GHC so I thought perhaps a newer
>> version
>> of GHC might fix the segfault but I installed GHC 6.10.4 from Sid and now I
>> get:
>>
>> $ ghc --make -O2 -threaded mergesort.hs -o mergesort
>> Binary: Int64 truncated to fit in 32 bit Int
>> ghc: panic! (the 'impossible' happened)
>> Â (GHC version 6.10.4 for i386-unknown-linux):
>> Â Â Â Â Prelude.chr: bad argument
>>
>> Please report this as a GHC bug: Â http://www.haskell.org/ghc/reportabug
>>
>> I'll try the haskell-platform package next. Are these known problems?
>>
>> --
>> Dr Jon Harrop, Flying Frog Consultancy Ltd.
>> http://www.ffconsultancy.com/?e
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>
------------------------------
Message: 2
Date: Thu, 24 Dec 2009 00:23:06 +0000
From: Antoine Latter <[email protected]>
Subject: Re: [Haskell-beginners] Performance of parallel mergesort
To: Jon Harrop <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
On Thu, Dec 24, 2009 at 12:22 AM, Antoine Latter <[email protected]> wrote:
> On Thu, Dec 24, 2009 at 12:16 AM, Antoine Latter <[email protected]> wrote:
>> Hi Jon,
>>
>> You're more likely to get a useful response over on the
>> glasgow-haskell-users mailing list, as it looks like this is a GHC
>> specific bug: http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
>>
>> Running this at -N6 doesn't want to complete for me, so I'm not sure
>> if it would segfault. I'm on a 64-bit Intel Mac OS X using GHC 6.12,
>> dual core.
>>
>> With such a small example as this your best bet would be to file a bug
>> report:
>>
>> http://hackage.haskell.org/trac/ghc/
>>
>> You'll need to use the login guest/guest to file a new ticket.
>>
>> Antoine
>>
>
> Here's a paste-bin link for the code in question:
> http://hpaste.org/fastcgi/hpaste.fcgi/view?id=14871#a14871
>
-N6 finally completed. I'm using GHC 6.12 on Inter, dual-core
mac-book. I'm not sure how comparable my setup is to what you tried.
Antoine
------------------------------
Message: 3
Date: Thu, 24 Dec 2009 01:34:52 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Einstein's Problem
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Am Mittwoch 23 Dezember 2009 20:46:51 schrieb Patrick LeBoutillier:
> Hi all,
>
> I've been working hard at trying to solve Einstein's problem
> (http://www.davar.net/MATH/PROBLEMS/EINSTEIN.HTM) if an efficient
> manner using Haskell.
>
> I have posted my solution here: http://haskell.pastebin.com/m3ff1973a
>
> This exercise has been a real eye opener for me, especially for
> learning to work with the Maybe and List monads.
>
> I'm looking for suggestions for making the "test" function nicer. In
> order to make my solution fast, I generate my test cases
> incrementally,
> thereby elimating most of the cases early on. However the function
> looks funny (deeply nested).
Instead of
if checkStreet s then ... else [], use Control.Monad.guard:
test = do
ds <- drinkPerms
ns <- nationPerms
let s = Street $ makeHouses ds ns [] [] []
guard (checkStreet s)
ss <- smokePerms
...
>
> I'm also open to any comments about making better use of the different
> Haskell idioms.
There is a function permutations in Data.List, you can use that instead of
writing your
own (except if you want the permutations in a different order).
xxxPerms = permutationsOf [toEnum 0 .. toEnum 4] :: [[XXX]] isn't particularly
nice,
better give the first and last constructor of each type or define
allPerms :: (Enum a, Bounded a) => [[a]]
allPerms = permutationsOf [minBound .. maxBound]
and derive also Bounded for your types.
nationPerms = filter rule1 $ permutationsOf [toEnum 0 .. toEnum 4] :: [[Nation]]
where rule1 ns = (ns !! 0) == Norway
is very inefficient, make that
nationPerms = map (Norway:) $ permutationsOf [England .. Denmark]
(yes, it's not so terrible for only five items, still it made me wince).
Similar for drinkPerms.
checkCond (f,c) h = fmap (== c) (f h)
~>
checkCond (f,c) = fmap (== c) . f
>
>
> Thanks a lot,
>
> Patrick
------------------------------
Message: 4
Date: Thu, 24 Dec 2009 02:24:19 +0000
From: Jon Harrop <[email protected]>
Subject: [Haskell-beginners] Performance of parallel mergesort
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
For some reason all traffic from this beginners list stopped reaching me after
the 13th of December.
Thanks for the response, Antoine. I've tried to install more recent versions
of GHC (6.10 and 6.12) but I cannot get either of them to work at all.
GHC 6.8 generates code that segfaults and the GHC 6.10 from Debian testing
cannot compile anything for me. So I thought I'd try GHC 6.12. That isn't in
any repo so I decided to build it from source. I uninstalled all other GHCs
to give it a fresh start. The GHC page says "Stop, install the Haskell
Platform" but the Haskell Platform says you must install GHC first, so I've
got a nice circular dependency right from the start!
So I tried installing GHC 6.12 from source but that requires GHC to be
installed. So I installed GHC 6.8 (the one that segfaults) using apt again
from Debian. That seems to have built a GHC 6.12 that I can run from the
command line but it cannot compile that program because it doesn't have
parallel stuff. So I thought I'd install the Haskell Platform.
Unfortunately, the Haskell Platform configure script gives the nonsensical
error that I must "upgrade" from GHC 6.12 down to GHC 6.10. I was getting
pretty run down by this point so I just told it to sod off using
the --enable-unsupported-ghc-version command line option. The Haskell
Platform's configure script then completed but building it failed with:
[21 of 21] Compiling Graphics.UI.GLUT ( Graphics/UI/GLUT.hs,
dist/build/Graphics/UI/GLUT.p_o )
Registering GLUT-2.1.1.2...
Setup: GLUT-2.1.1.2: dependency
"OpenGL-2.2.1.1-182b091280ce0de861295bc592bae77c" doesn't exist (use --force
to override)
Error:
Building the GLUT-2.1.1.2 package failed
make: *** [build.stamp] Error 2
I have glut and use it all the time from OCaml without a hitch so I've no idea
what the problem is here.
Oh well, I just discovered that installing GHC 6.12 has at least fixed GHC
6.10 so it can now compile and run that mergesort. Oh FFS, spoke too soon:
$ time ./mergesort +RTS -N8
Stack space overflow: current size 8388608 bytes.
Use `+RTS -Ksize' to increase it.
real 0m38.801s
user 4m0.851s
sys 0m1.308s
--
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e
------------------------------
Message: 5
Date: Wed, 23 Dec 2009 21:30:54 -0500
From: Patrick LeBoutillier <[email protected]>
Subject: Re: [Haskell-beginners] Einstein's Problem
To: Daniel Fischer <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Daniel,
> Instead of
>
> if checkStreet s then ... else [], use Control.Monad.guard:
>
> test = do
> ds <- drinkPerms
> ns <- nationPerms
> let s = Street $ makeHouses ds ns [] [] []
> guard (checkStreet s)
> ss <- smokePerms
> ...
Excellent. That really cleans it up!
>>
>> I'm also open to any comments about making better use of the different
>> Haskell idioms.
>
> There is a function permutations in Data.List, you can use that instead of
> writing your
> own (except if you want the permutations in a different order).
> xxxPerms = permutationsOf [toEnum 0 .. toEnum 4] :: [[XXX]] isn't
> particularly nice,
> better give the first and last constructor of each type or define
> allPerms :: (Enum a, Bounded a) => [[a]]
> allPerms = permutationsOf [minBound .. maxBound]
> and derive also Bounded for your types.
Great! I tried to do something a bit like that using typeclasses, but
I got lost along the way.. :(
I love how allPerms generates the correct permutations using type inference!
> nationPerms = filter rule1 $ permutationsOf [toEnum 0 .. toEnum 4] ::
> [[Nation]]
> where rule1 ns = (ns !! 0) == Norway
>
> is very inefficient, make that
> nationPerms = map (Norway:) $ permutationsOf [England .. Denmark]
> (yes, it's not so terrible for only five items, still it made me wince).
> Similar for drinkPerms.
How do you do it with drinkPerms? The constant element is in the
middle (with Nations
it seems easier since it's the first one).
> checkCond (f,c) h = fmap (== c) (f h)
> ~>
> checkCond (f,c) = fmap (== c) . f
Ok. Hopefully someday these patterns will be obvious...
Thanks a lot,
Patrick
--
=====================
Patrick LeBoutillier
Rosemère, Québec, Canada
------------------------------
Message: 6
Date: Thu, 24 Dec 2009 02:55:33 +0000
From: Antoine Latter <[email protected]>
Subject: Re: [Haskell-beginners] Performance of parallel mergesort
To: Jon Harrop <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
On Thu, Dec 24, 2009 at 2:24 AM, Jon Harrop <[email protected]> wrote:
>
> For some reason all traffic from this beginners list stopped reaching me after
> the 13th of December.
>
> Thanks for the response, Antoine. I've tried to install more recent versions
> of GHC (6.10 and 6.12) but I cannot get either of them to work at all.
>
> GHC 6.8 generates code that segfaults and the GHC 6.10 from Debian testing
> cannot compile anything for me. So I thought I'd try GHC 6.12. That isn't in
> any repo so I decided to build it from source. I uninstalled all other GHCs
> to give it a fresh start. The GHC page says "Stop, install the Haskell
> Platform" but the Haskell Platform says you must install GHC first, so I've
> got a nice circular dependency right from the start!
>
> So I tried installing GHC 6.12 from source but that requires GHC to be
> installed. So I installed GHC 6.8 (the one that segfaults) using apt again
> from Debian. That seems to have built a GHC 6.12 that I can run from the
> command line but it cannot compile that program because it doesn't have
> parallel stuff. So I thought I'd install the Haskell Platform.
>
The Haskell Platform is currently the recommended way to go, but it
won't be up on GHC 6.12 until some time in the new year (I don't know
their timelines).
For me, I didn't have a working GHC 6.12 setup until this morning. The
compiler is ready, but we're still working on moving the libraries
over to the new major version.
Maybe compiling your own 6.10.4 would be the best choice until the
next platform release.
If you're willing to dive in, the version of cabal-install that works
for GHC 6.12.1 is out now, but it does require some boot-strapping to
get going, as GHC no longer ships libraries that aren't required to
build GHC.
But back to the GHC panic, it might be worth posting that error to the
GHC-users list I mentioned earlier.
Antoine
------------------------------
Message: 7
Date: Thu, 24 Dec 2009 04:09:26 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Einstein's Problem
To: Patrick LeBoutillier <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Am Donnerstag 24 Dezember 2009 03:30:54 schrieb Patrick LeBoutillier:
> How do you do it with drinkPerms? The constant element is in the
> middle (with Nations
> it seems easier since it's the first one).
insertAt :: Int -> a -> [a] -> [a]
insertAt k x xs = case splitAt k xs of
(front,back) -> front ++ x:back
drinkPerms = map (insertAt 2 Milk) $ permutations [Coffee, Tea, Water, Beer]
Another possibility to have x inserted at a fixed position in all permutations
of xs is to
use
do (fs,bs) <- picks k xs
pf <- permutations fs
pb <- permutations bs
return (pf ++ x:pb)
which has the advantage that the permutations of the front are shared (if the
back is
longer than the front, it might be better to swap lines 2 and 3 to share the
permutations
of the back) and avoids the many splits.
picks :: Int -> [a] -> [([a],[a])]
picks k xs
| k == 0 = [([],xs)]
| k == l = [(xs,[])]
| k > l = []
| otherwise = pickHelper l k xs
where
l = length xs
pickHelper s t yys@(y:ys)
| s == t = [(yys,[])]
| otherwise = [(y:zs,ws) | (zs,ws) <- pickHelper (s-1) (t-1) ys]
++ [(zs,y:ws) | (zs,ws) <- pickHelper (s-1) t ys]
It's by far not as nice as keeping the first element fixed, but you can easily
keep more
than one position fixed. And when you have a couple more items, this approach
is
enormously faster than filtering.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20091223/b0ef4b6b/attachment.html
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 18, Issue 23
*****************************************