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@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@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe