<div><br></div>I am guessing that it is slowdown caused by GC needing to co-ordinate with blocked threads. That requires lots of re-scheduling to happen in the kernel.<div>This is a hard problem I think, but also increasingly important as virtualization becomes more important and the number of schedulable cores unknown.</div>
<div><br></div><div>Alexander<br><div><br><div class="gmail_quote">On 7 October 2011 12:31, Oliver Batchelor <span dir="ltr"><<a href="mailto:saulzar@gmail.com">saulzar@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
I'm not sure if this is at all related, but if I run a small Repa program with more threads than I have cores/CPUs then it gets drastically slower, I have a dual core laptop - and -N2 makes my small program take approximately 0.6 of the time. Increasing to -N4 and we're running about 2x the time, -N8 and it's taking 20x or more. I guess this is probably more down to the design of Repa rather than GHC itself? <div>
<br></div><div><font color="#888888">Oliver<br><br></font><div class="gmail_quote"><div><div></div><div class="h5">On Sat, Oct 8, 2011 at 1:21 AM, Tom Thorne <span dir="ltr"><<a href="mailto:thomas.thorne21@gmail.com" target="_blank">thomas.thorne21@gmail.com</a>></span> wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div></div><div class="h5">
I have made a dummy program that seems to exhibit the same GC slowdown behavior, minus the segmentation faults. Compiling with -threaded and running with -N12 I get very bad performance (3x slower than -N1), running with -N12 -qg it runs approximately 3 times faster than -N1. I don't know if I should submit this as a bug or not? I'd certainly like to know why this is happening!<div>
<br></div><div><div><div><font face="'courier new', monospace">import Numeric.LinearAlgebra</font></div><div><font face="'courier new', monospace">import Numeric.GSL.Special.Gamma</font></div>
<div><font face="'courier new', monospace">import Control.Parallel.Strategies</font></div><div><font face="'courier new', monospace">import Control.Monad</font></div>
<div><font face="'courier new', monospace">import Data.IORef</font></div><div><font face="'courier new', monospace">import Data.Random</font></div><div><font face="'courier new', monospace">import Data.Random.Source.PureMT</font></div>
<div><font face="'courier new', monospace">import Debug.Trace</font></div><div><font face="'courier new', monospace">--</font></div><div><font face="'courier new', monospace"><br>
</font></div><div><font face="'courier new', monospace">subsets s n = (subsets_stream s) !! n</font></div><div><font face="'courier new', monospace"><br></font></div>
<div><font face="'courier new', monospace">subsets_stream [] = [[]] : repeat []</font></div><div><font face="'courier new', monospace">subsets_stream (x:xs) = </font></div>
<div><font face="'courier new', monospace"><span style="white-space:pre-wrap">        </span>let r = subsets_stream xs</font></div><div><font face="'courier new', monospace"><span style="white-space:pre-wrap">        </span> s = map (map (x:)) r</font></div>
<div><font face="'courier new', monospace"><span style="white-space:pre-wrap">        </span>in [[]] : zipWith (++) s (tail r)</font></div><div><font face="'courier new', monospace"><br>
</font></div><div><font face="'courier new', monospace">testfun :: Matrix Double -> Int -> [Int] -> Double</font></div><div><font face="'courier new', monospace">testfun x k cs = lngamma (det (c+u))</font></div>
<div><font face="'courier new', monospace"><span style="white-space:pre-wrap">        </span>where</font></div><div><font face="'courier new', monospace"><span style="white-space:pre-wrap">                </span>(m,c) = meanCov xx</font></div>
<div><font face="'courier new', monospace"><span style="white-space:pre-wrap">                </span>m' = fromRows [m] </font></div><div><font face="'courier new', monospace"><span style="white-space:pre-wrap">                </span>u = (trans m') <> m'</font></div>
<div><font face="'courier new', monospace"><span style="white-space:pre-wrap">                </span>xx = fromColumns ( [(toColumns x)!!i] ++ [(toColumns x)!!j] ++ [(toColumns x)!!k] ) </font></div>
<div><font face="'courier new', monospace"><span style="white-space:pre-wrap">                </span>i = cs !! 0</font></div><div><font face="'courier new', monospace"><span style="white-space:pre-wrap">                </span>j = cs !! 1</font></div>
<div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace">test :: Matrix Double -> Int -> Double</font></div>
<div><font face="'courier new', monospace">test x i = sum p</font></div><div><font face="'courier new', monospace"><span style="white-space:pre-wrap">        </span>where</font></div>
<div><font face="'courier new', monospace"><span style="white-space:pre-wrap">                </span>p = parMap (rdeepseq) (testfun x (i+1)) (subsets [0..i] 2)</font></div><div><font face="'courier new', monospace"><br>
</font></div><div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace">ranMatrix :: Int -> RVar (Matrix Double)</font></div>
<div><font face="'courier new', monospace">ranMatrix n = do</font></div><div><font face="'courier new', monospace"><span style="white-space:pre-wrap">        </span>xs <- mapM (\_ -> mapM (\_ -> uniform 0 1.0) [1..n]) [1..n]</font></div>
<div><font face="'courier new', monospace"><span style="white-space:pre-wrap">        </span>return (fromLists xs)</font></div><div><font face="'courier new', monospace"><br>
</font></div><div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace">loop :: Int -> Double -> Int -> RVar Double</font></div>
<div><font face="'courier new', monospace">loop n s i = traceShow i $ do</font></div><div><font face="'courier new', monospace"><span style="white-space:pre-wrap">        </span>x <- ranMatrix n<span style="white-space:pre-wrap">        </span></font></div>
<div><font face="'courier new', monospace"><span style="white-space:pre-wrap">        </span>let r = sum $ parMap (rdeepseq) (test x) [2..(n-2)]</font></div><div><font face="'courier new', monospace"><span style="white-space:pre-wrap">        </span>return (r+s)</font></div>
<div><font face="'courier new', monospace"><br></font></div><div><font face="'courier new', monospace">main = do</font></div><div><font face="'courier new', monospace"><span style="white-space:pre-wrap">        </span>let n = 100</font></div>
<div><font face="'courier new', monospace"><span style="white-space:pre-wrap">        </span>let iter = 5</font></div><div><font face="'courier new', monospace"><span style="white-space:pre-wrap">        </span>rng <- newPureMT</font></div>
<div><font face="'courier new', monospace"><span style="white-space:pre-wrap">        </span>rngr <- newIORef rng</font></div><div><font face="'courier new', monospace"><span style="white-space:pre-wrap">        </span>p <- runRVar (foldM (loop n) 0.0 [1..iter]) rngr</font></div>
<div><font face="'courier new', monospace"><span style="white-space:pre-wrap">        </span>print p</font></div></div><div><br></div><div>I have also found that the segmentation faults in my code disappear if I switch from Control.Parallel to Control.Monad.Par, which is quite strange. I get slightly better performance with Control.Parallel when it completes without a seg. fault, and the frequency with which it does so seems to depend on the number of sparks that are being created.</div>
<div><div></div><div>
<div><br><div class="gmail_quote">On Thu, Oct 6, 2011 at 1:56 PM, Tom Thorne <span dir="ltr"><<a href="mailto:thomas.thorne21@gmail.com" target="_blank">thomas.thorne21@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I'm trying to narrow it down so that I can submit a meaningful bug report, and it seems to be something to do with switching off parallel GC using -qg, whilst also passing -Nx.<div><br></div><div>Are there any known issues with this that people are aware of? At the moment I am using the latest haskell platform release on arch.</div>
<div><br></div><div>I'd like to give 7.2 a try in case that fixes it, but I'm using rather a lot of libraries (hmatrix, fclabels, random fu) and I don't know how to install them for multiple ghc versions</div>
<div><div></div><div>
<div><br><div class="gmail_quote">On Wed, Oct 5, 2011 at 10:43 PM, Johan Tibell <span dir="ltr"><<a href="mailto:johan.tibell@gmail.com" target="_blank">johan.tibell@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="gmail_quote"><div>On Wed, Oct 5, 2011 at 2:37 PM, Tom Thorne <span dir="ltr"><<a href="mailto:thomas.thorne21@gmail.com" target="_blank">thomas.thorne21@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex">
The only problem is that now I am getting random occasional segmentation faults that I was not been getting before, and once got a message saying:<div><font face="'courier new', monospace">Main: schedule: re-entered unsafely</font></div>
<div><font face="'courier new', monospace">Perhaps a 'foreign import unsafe' should be 'safe'?</font></div><div>I think this may be something to do with creating a lot of sparks though, since this occurs whether I have the parallel GC on or not.</div>
</blockquote></div><div><br>Unless you (or some library you're using) is doing what the error message says then you should file a GHC bug here:<br><br><a href="http://hackage.haskell.org/trac/ghc/" target="_blank">http://hackage.haskell.org/trac/ghc/</a><br>
<font color="#888888">
<br>-- Johan<br> <br></font></div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div></div></div></div>
<br></div></div><div class="im">_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></div></blockquote></div><br></div>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br></div></div>