<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>geek thoughts &#187; haskell</title>
	<atom:link href="http://www.mlesniak.com/category/haskell/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mlesniak.com</link>
	<description></description>
	<lastBuildDate>Wed, 12 May 2010 09:04:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Ubuntu 64 Bit and GHCs Garbage Collector</title>
		<link>http://www.mlesniak.com/2010/03/02/ubuntu-64-bit-and-ghcs-garbage-collector/</link>
		<comments>http://www.mlesniak.com/2010/03/02/ubuntu-64-bit-and-ghcs-garbage-collector/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 07:38:19 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[ghc]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[solutions]]></category>

		<guid isPermaLink="false">http://www.mlesniak.com/?p=646</guid>
		<description><![CDATA[Hi, Update: I tested a kernel 2.6.31-12 (from kernel.org) and had the same (if not even worse) behaviour as with 2.6.31-19. So, I apologize. It has nothing to do with Ubuntu per se, but probably with the linux-kernel; that makes me wonder if I haven&#8217;t done something faulty: that behaviour should have attracted the attention [...]]]></description>
			<content:encoded><![CDATA[<p>Hi,</p>
<p><em><strong>Update</strong>: I tested a kernel 2.6.31-12 (from kernel.org) and had the same (if not even worse) behaviour as with 2.6.31-19. So, I apologize. It has nothing to do with Ubuntu per se, but probably with the linux-kernel; that makes me wonder if I haven&#8217;t done something faulty: that behaviour should have attracted the attention of some other Haskell developers in the meantime, but I couldn&#8217;t find any information on it. So, take in mind that the following could be incorrect&#8230;</em></p>
<p>finding this strange behaviour had cost me a lot of hours (see also my <a href="http://www.haskell.org/pipermail/haskell-cafe/2010-March/073938.html">post</a> on the haskell-cafe mailing list), because honestly, who do you blame if your parallel programm behaves strangely:</p>
<ol>
<li>yourself</li>
<li>the compiler</li>
<li>the special patches of your OS vendor to your linux kernel</li>
</ol>
<p>Since the probabilities of an error in 2. are quite low (at lot of people use GHC and its parallelization techniques) and &#8212; at least I thought that &#8212; those in 3. are low, too (some of those people from 1. should be using my OS with GHC for parallel development), I chose 1. Hence, I spent a lot of time trying to find synchronisation and performance problems in my code, which in fact, weren&#8217;t there!</p>
<p>The current setup of a standard Ubuntu 9.10 (64 bit) is a vanilla kernel (2.6.31-19-generic) , used with GHC 6.12.1. Look at this small and seemingly innocent program</p>
<pre lang="haskell'">-- File Pi.hs
-- you need the numbers package from hackage.
module Main where
import Data.Number.CReal
import System.Environment
import GHC.Conc

main = do
    digits &lt;- (read . head) `fmap` getArgs :: IO Int
    showCReal (fromEnum digits) pi `pseq` return ()
</pre>
<p>that you can compile with</p>
<pre>ghc -- make -O2 -threaded Pi.hs -o pi
</pre>
<p>Benchmarking with</p>
<pre>for i in `seq 1 5`;do time pi 5000 +RTS -N1;done
for i in `seq 1 5`;do time pi 5000 +RTS -N2;done</pre>
<p>I received the following exemplary runtimes for the vanilla ubuntu kernel.</p>
<p><br class="spacer_" /></p>
<p><a href="http://www.mlesniak.com/wp-content/uploads/2010/03/bad.png"><img class="aligncenter size-full wp-image-648" title="bad" src="http://www.mlesniak.com/wp-content/uploads/2010/03/bad.png" alt="" width="354" height="310" /></a></p>
<p>And this is the threadscope profile of a particular bad run:</p>
<p><img class="aligncenter size-full wp-image-650" title="thread" src="http://www.mlesniak.com/wp-content/uploads/2010/03/thread.png" alt="" width="583" height="247" /><br />
 As you can see, nearly all time is spend in the Garbage Collector, doing&#8230;things, GCs do&#8230;</p>
<p>I then compiled my own kernel2.633 from kernel.org and received these results:</p>
<p><a href="http://www.mlesniak.com/wp-content/uploads/2010/03/good.png"><img class="aligncenter size-full wp-image-649" title="good" src="http://www.mlesniak.com/wp-content/uploads/2010/03/good.png" alt="" width="354" height="310" /></a></p>
<p><strong>Conclusion:</strong> At least for me and my parallel programs (and even some innocent toy programs like Pi.hs) does the standard Ubuntu 64bit kernel harm parallel performance (especially that of the GC) a lot.</p>
<p>I find this highly surprising:</p>
<ul>
<li>Ubuntu is a widely used distribution</li>
<li> 64 bit versions are also becoming quite common</li>
<li>in my perception Haskell developers use parallelism a lot</li>
</ul>
<p><strong>Question. </strong>Either the intersection of these properties is quite small or my measurements have some serious flaw. I&#8217;d be glad if someone could disprove my results (and give me the opportunity to learn a bit) or support my measurements.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mlesniak.com/2010/03/02/ubuntu-64-bit-and-ghcs-garbage-collector/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Visualizing rising iteration depth in a voltage diffusion model</title>
		<link>http://www.mlesniak.com/2010/01/08/visualizing-rising-iteration-depth-in-a-voltage-diffusion-model/</link>
		<comments>http://www.mlesniak.com/2010/01/08/visualizing-rising-iteration-depth-in-a-voltage-diffusion-model/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 14:38:03 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[haskell]]></category>
		<category><![CDATA[pastha]]></category>

		<guid isPermaLink="false">http://www.mlesniak.com/?p=640</guid>
		<description><![CDATA[Using my PASTHA library (more follows soon) to parallelize stencil calculations I wrote a few wrapper scripts for gnuplot and gifsicle to visualize the voltage diffusion for a metal plane for rising iteration depths:]]></description>
			<content:encoded><![CDATA[<p>Using my PASTHA library (more follows soon) to parallelize stencil calculations I wrote a few wrapper scripts for gnuplot and gifsicle to visualize the voltage diffusion for a metal plane for rising iteration depths:<a href="http://www.mlesniak.com/wp-content/uploads/2010/01/anim.gif"><img class="aligncenter size-full wp-image-643" title="anim" src="http://www.mlesniak.com/wp-content/uploads/2010/01/anim.gif" alt="" width="400" height="300" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mlesniak.com/2010/01/08/visualizing-rising-iteration-depth-in-a-voltage-diffusion-model/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Started hacking on GHC capabilities</title>
		<link>http://www.mlesniak.com/2009/12/11/started-hacking-on-ghc-capabilities/</link>
		<comments>http://www.mlesniak.com/2009/12/11/started-hacking-on-ghc-capabilities/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 19:57:40 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[capabilities]]></category>
		<category><![CDATA[haskell]]></category>

		<guid isPermaLink="false">http://www.mlesniak.com/?p=589</guid>
		<description><![CDATA[Today I&#8217;ve started the small personal hacking project of implementing dynamic capatiblities in GHC&#8216;s parallel runtime system; I&#8217;ll blog about my efforts, problems and solutions and would be grateful for any hints, comments or pointers for more documentation. I began by talking with Simon Marlow and discussing the idea. He said that it&#8217;s a least worthwhile [...]]]></description>
			<content:encoded><![CDATA[<p>Today I&#8217;ve started the small personal hacking project of implementing dynamic capatiblities in <a href="http://haskell.org/ghc/">GHC</a>&#8216;s parallel runtime system; I&#8217;ll blog about my efforts, problems and solutions and would be grateful for any hints, comments or pointers for more documentation. I began by talking with <a href="http://www.haskell.org/~simonmar/">Simon Marlow</a> and discussing the idea. He said that it&#8217;s a least worthwhile to try implementing it.</p>
<p>Currently I</p>
<ul>
<li>made an account (mlesniak) on the <a href="http://hackage.haskell.org/trac/ghc/">GHC&#8217;s developers wiki</a>.</li>
<li> opened a ticket (<a href="http://hackage.haskell.org/trac/ghc/ticket/3729">No. #3729</a>) as a task, describing my idea: <em>&#8220;Currently the number of capabilities can only be set at the start of a program using -N. At least for benchmarking and playing with semi-implicit code (any other real-world scenarious?) if would be nice to change the number of capabilities at runtime.&#8221; </em>
<p><em><span style="font-style: normal;"><strong>Current questions:</strong></span><br />
 </em></p>
<ul>
<li>There is no person assigned on this task, should I assign myself?</li>
<li>It&#8217;s the only project without a particular difficulty (Diffuclty: None); should I set one or is this set by one of the &#8220;important&#8221; maintainers?</li>
</ul>
</li>
<li>downloaded the source for GHC HEAD, according to <a href="http://hackage.haskell.org/trac/ghc/wiki/GettingStarted">Getting Started</a></li>
<li>was able to compile it on my 2.4 GHz Dualcore with 4 GB memory using the <a href="http://hackage.haskell.org/trac/ghc/wiki/Building">Building Guide</a>. It took about 40 minutes for a full compile (yikes!)</li>
<li>took a first look into ghc/rts/ <a href="http://www.mlesniak.com/wp-content/uploads/2009/12/Capability.c">Capability.c</a> and <a href="http://www.mlesniak.com/wp-content/uploads/2009/12/Capability.h">Capability.h</a>. This looks quite complicated and I probably have to understand a lot of the underlying system before I can even think about trying to modify this part of the RTS itself. Hopefully, the <a href="http://hackage.haskell.org/trac/ghc/wiki/Commentary">GHC Commentary</a> will help.</li>
</ul>
<p>Why do I do this? Firstly, I really like to solve problems and learn new things on the way. Secondly, I was always interested in the underlying parallel runtime system of GHC but without a concrete task motivating myself to understand this huge system was difficult. Thirdly, I hope that by learning part of the system I&#8217;m able to implement some of my (currently quite vague) ideas on dynamic adaptiblity of parallel runtime systems.</p>
<p>I will keep the interwebs updated, but do not expect too much soon, since I do this primary in my free time. Any hints, questions, remarks, (de-)motivating comments?</p>
<p><em> </em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mlesniak.com/2009/12/11/started-hacking-on-ghc-capabilities/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GHC 6.12 RC1 and Ubuntu 9.10 (Karmic Koala)</title>
		<link>http://www.mlesniak.com/2009/12/01/ghc-6-12-rc1-and-ubuntu-9-10-karmic-koala/</link>
		<comments>http://www.mlesniak.com/2009/12/01/ghc-6-12-rc1-and-ubuntu-9-10-karmic-koala/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 09:53:57 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[ghc]]></category>
		<category><![CDATA[haskell]]></category>

		<guid isPermaLink="false">http://www.mlesniak.com/?p=605</guid>
		<description><![CDATA[I&#8217;m excited about GHC 6.12 and hope it is released soon. Currently I have some problems with Ubuntu 9.10 and its Linux kernel 2.6.31-14. It seems that GHC 6.12 will solve (some) of my problems. For the examplary unoptimized code -- Compile with ghc-6.10.4 -O2 -threaded --make Example.hs -o example module Main where import GHC.Conc [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m excited about GHC 6.12 and hope it is released soon. Currently I have some <a href="http://www.mail-archive.com/haskell-cafe@haskell.org/msg67148.html">problems</a> with Ubuntu 9.10 and its Linux kernel 2.6.31-14. It seems that GHC 6.12 will solve (some) of my problems.</p>
<p>For the examplary unoptimized code</p>

<div class="wp_codebox"><table><tr id="p6052"><td class="code" id="p605code2"><pre class="haskell" style="font-family:monospace;"><span style="color: #5d478b; font-style: italic;">-- Compile with ghc-6.10.4 -O2 -threaded --make Example.hs -o example</span>
<span style="color: #06c; font-weight: bold;">module</span> Main <span style="color: #06c; font-weight: bold;">where</span>
<span style="color: #06c; font-weight: bold;">import</span> GHC<span style="color: #339933; font-weight: bold;">.</span>Conc
<span style="color: #06c; font-weight: bold;">import</span> Control<span style="color: #339933; font-weight: bold;">.</span>Concurrent
<span style="color: #06c; font-weight: bold;">import</span> Control<span style="color: #339933; font-weight: bold;">.</span><a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Monad"><span style="color: #cccc00; font-weight: bold;">Monad</span></a>
<span style="color: #06c; font-weight: bold;">import</span> System<span style="color: #339933; font-weight: bold;">.</span>Environment
<span style="color: #06c; font-weight: bold;">import</span> Data<span style="color: #339933; font-weight: bold;">.</span>List
<span style="color: #5d478b; font-style: italic;">------------------------------------------------------------</span>
main <span style="color: #339933; font-weight: bold;">::</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:IO"><span style="color: #cccc00; font-weight: bold;">IO</span></a> <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span>
main <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
    args <span style="color: #339933; font-weight: bold;">&lt;-</span> getArgs
    <span style="color: #06c; font-weight: bold;">let</span> threads <span style="color: #339933; font-weight: bold;">=</span> numCapabilities    <span style="color: #5d478b; font-style: italic;">-- threads determined by -N...</span>
        taskDur <span style="color: #339933; font-weight: bold;">=</span> <span style="color: red;">1000000</span>            <span style="color: #5d478b; font-style: italic;">-- big enough magic number</span>
        taskNum <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span><a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:read"><span style="font-weight: bold;">read</span></a> <span style="color: #339933; font-weight: bold;">.</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:head"><span style="font-weight: bold;">head</span></a><span style="color: green;">&#41;</span> args <span style="color: #5d478b; font-style: italic;">-- Number of tasks is 1st parameter</span>
&nbsp;
    queue    <span style="color: #339933; font-weight: bold;">&lt;-</span> newChan
    finished <span style="color: #339933; font-weight: bold;">&lt;-</span> newChan
    writeList2Chan queue <span style="color: green;">&#40;</span>replicate taskNum taskDur<span style="color: green;">&#41;</span>
    replicateM<span style="color: #339933; font-weight: bold;">_</span> threads <span style="color: green;">&#40;</span>forkIO <span style="color: green;">&#40;</span>thread queue finished<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span>
    replicateM<span style="color: #339933; font-weight: bold;">_</span> taskNum <span style="color: green;">&#40;</span>readChan finished<span style="color: green;">&#41;</span>
<span style="color: #5d478b; font-style: italic;">------------------------------------------------------------</span>
thread <span style="color: #339933; font-weight: bold;">::</span> Chan <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Int"><span style="color: #cccc00; font-weight: bold;">Int</span></a> <span style="color: #339933; font-weight: bold;">-</span>&amp;gt; Chan <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:Int"><span style="color: #cccc00; font-weight: bold;">Int</span></a> <span style="color: #339933; font-weight: bold;">-</span>&amp;gt; <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#t:IO"><span style="color: #cccc00; font-weight: bold;">IO</span></a> <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span>
thread queue finished <span style="color: #339933; font-weight: bold;">=</span>
    forever <span style="color: #339933; font-weight: bold;">$</span> <span style="color: #06c; font-weight: bold;">do</span>
        task <span style="color: #339933; font-weight: bold;">&lt;-</span> readChan queue
        workFor task
        writeChan finished <span style="color: red;">1</span>
  <span style="color: #06c; font-weight: bold;">where</span> workFor n <span style="color: #339933; font-weight: bold;">=</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:foldl"><span style="font-weight: bold;">foldl</span></a>' <span style="color: green;">&#40;</span>\a b <span style="color: #339933; font-weight: bold;">-&gt;</span> a <span style="color: #339933; font-weight: bold;">+</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:sqrt"><span style="font-weight: bold;">sqrt</span></a> <span style="color: green;">&#40;</span><span style="color: red;">2</span><span style="color: #339933; font-weight: bold;">^</span>b<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span> <span style="color: red;">1</span> <span style="color: green;">&#91;</span><span style="color: red;">1</span><span style="color: #339933; font-weight: bold;">..</span>n<span style="color: green;">&#93;</span> `pseq`
           <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:return"><span style="font-weight: bold;">return</span></a> <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span></pre></td></tr></table></div>

<p>we get the following runtimes on my Dualcore Notebook:</p>
<pre>$ time e-6.12 +RTS -N1 -RTS 16

real	0m43.994s
user	0m43.630s
sys	0m0.040s
$ time e-6.12 +RTS -N2 -RTS 16

real	0m25.987s
user	0m48.790s
sys	0m0.230s
$ time e-6.10 +RTS -N1 -RTS 16

real	0m45.883s
user	0m44.500s
sys	0m0.400s
$ time e-6.10 +RTS -N2 -RTS 16

real	0m38.930s
user	0m46.040s
sys	0m0.490s
</pre>
<p>As you can see, e-6.12 (the version compiled with ghc-6.12-20091010) delivers a good speedup whereas ghc-6.10 does not use my two cores very much. This makes testing, benchmarking and developing my parallel Haskell code currently quite difficult.</p>
<p><br class="spacer_" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.mlesniak.com/2009/12/01/ghc-6-12-rc1-and-ubuntu-9-10-karmic-koala/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
