[Haskell-cafe] [GHC 7.8.4] IO Monad leak space?

Baojun Wang wangbj at gmail.com
Fri Jul 3 16:06:45 UTC 2015


Full source code:

https://github.com/wangbj/haskell/blob/master/lcmsum.hs

I build the program with:

ghc -O2 --make -rtsopts -prof -auto-all lcmsum

and run it with:

echo -ne '5\n100\n1000\n10000\n100000\n1000000\n'  | ./lcmsum +RTS -sstderr
-p

I've tried use

``let !ret = (v1+(fromIntegral i) * (fromIntegral v)) in r'' instead,
however it didn't make any difference per profiling. (both Array are
Unboxed).

Thanks
baojun

On Fri, Jul 3, 2015 at 2:50 AM Tom Ellis <
tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk> wrote:

> On Fri, Jul 03, 2015 at 08:18:55AM +0000, Baojun Wang wrote:
> > Consider below function:
> >
> > f3 :: UArray Int Int -> IOUArray Int Int64 -> Int -> IO ()
> > f3 u r i = let !v = u ! i
> >             in go (f31 v) i i
> >   where f31 v j = readArray r j >>= \v1 ->
> >           writeArray r j (v1 + (fromIntegral i) * (fromIntegral v))
> >         f31 :: Int -> Int -> IO ()
> >         go g k s = when (k <= maxn) (
> >           g k >> go g (s+k) s )
> >
> > When call f3:
> >
> >   loopM_ (f3 uu res) 1 1 1000000
>
> Could you provide complete working code (including definitions of uu and
> res) and I will have a go at diagnosing.  (My first guess is that you need
> to force (v1 + (fromIntegral i) * (fromIntegral v)).)
>
> Tom
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150703/683f81b7/attachment.html>


More information about the Haskell-Cafe mailing list