<?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>Yet Another [À Compléter] &#187; soc</title>
	<atom:link href="http://blog.neteril.org/tag/soc/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.neteril.org</link>
	<description>Random thoughts of Jérémie Laval</description>
	<lastBuildDate>Wed, 24 Aug 2011 17:43:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Funny parallelism</title>
		<link>http://blog.neteril.org/2008/07/26/funny-parallelism/</link>
		<comments>http://blog.neteril.org/2008/07/26/funny-parallelism/#comments</comments>
		<pubDate>Sat, 26 Jul 2008 19:33:31 +0000</pubDate>
		<dc:creator>Jérémie Laval</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[Google Summer of Code 2008]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mono]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[parallelfx]]></category>
		<category><![CDATA[soc]]></category>
		<category><![CDATA[sudoku]]></category>

		<guid isPermaLink="false">http://garuma.wordpress.com/?p=259</guid>
		<description><![CDATA[For those who have some free leisure time this weekend and would like to explore a bit ParallelFx in a didactic manner I ported to Linux a Sudoku game coming from ParallelFx CTP samples which optionally uses ParallelFx to generate Sudoku grids. For screenshot fans that&#8217;s how it looks like : You can enable the [...]]]></description>
			<content:encoded><![CDATA[<p>For those who have some free leisure time this weekend and would like to explore a bit ParallelFx in a didactic manner I ported to Linux <a href="http://netherilshade.free.fr/mono/parallelfx/ParallelFx-Sudoku.tar.gz">a Sudoku game</a> coming from ParallelFx CTP samples which optionally uses ParallelFx to generate Sudoku grids.</p>
<p>For screenshot fans that&#8217;s how it looks like :</p>
<div id="attachment_260" class="wp-caption aligncenter" style="width: 310px"><a href="http://garuma.files.wordpress.com/2008/07/capture-microsoft-sudoku-expert.png"><img src="http://garuma.files.wordpress.com/2008/07/capture-microsoft-sudoku-expert.png?w=300" alt="Sudoku main interface" width="300" height="177" class="size-medium wp-image-260" /></a><p class="wp-caption-text">Sudoku main interface</p></div>
<p>You can enable the use of ParallelFx via the two options &laquo;&nbsp;Use multiple processors to generate puzzles&nbsp;&raquo; and &laquo;&nbsp;Use speculative puzzle generation&nbsp;&raquo; found in the Game settings box :</p>
<div id="attachment_261" class="wp-caption aligncenter" style="width: 310px"><a href="http://garuma.files.wordpress.com/2008/07/capture-game-settings.png"><img src="http://garuma.files.wordpress.com/2008/07/capture-game-settings.png?w=300" alt="Game settings window" width="300" height="201" class="size-medium wp-image-261" /></a><p class="wp-caption-text">Game settings window</p></div>
<p>The first one uses Parallel.For instead of a standard for to generate grids and the other allows the background generation of further grids using Future.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.neteril.org/2008/07/26/funny-parallelism/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>LINQ Raytracer but with a P twist</title>
		<link>http://blog.neteril.org/2008/07/25/linq-raytracer-but-with-a-p-twist/</link>
		<comments>http://blog.neteril.org/2008/07/25/linq-raytracer-but-with-a-p-twist/#comments</comments>
		<pubDate>Fri, 25 Jul 2008 09:56:29 +0000</pubDate>
		<dc:creator>Jérémie Laval</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[Google Summer of Code 2008]]></category>
		<category><![CDATA[Mono]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[linq]]></category>
		<category><![CDATA[lukeh]]></category>
		<category><![CDATA[plinq]]></category>
		<category><![CDATA[raytracer]]></category>
		<category><![CDATA[soc]]></category>

		<guid isPermaLink="false">http://garuma.wordpress.com/?p=246</guid>
		<description><![CDATA[Following Marek&#8217;s annoucement about Mono&#8217;s compiler getting full C# 3.0 support and his proof-of-concept which none other than Luke Hoban LINQ-ified Ray tracer, I&#8217;m happy to say that by using Mono&#8217;s PLINQ and with as little modifications as this : &#8230; the code runs approximately 1,5x faster on my dual-core computer. Actually it&#8217;s rather good [...]]]></description>
			<content:encoded><![CDATA[<p>Following Marek&#8217;s <a href="http://mareksafar.blogspot.com/2008/07/mono-c-compiler-gets-full-c-30-support.html">annoucement</a> about Mono&#8217;s compiler getting full C# 3.0 support and his proof-of-concept which none other than Luke Hoban <a href="http://blogs.msdn.com/lukeh/archive/2007/10/01/taking-linq-to-objects-to-extremes-a-fully-linqified-raytracer.aspx">LINQ-ified Ray tracer</a>, I&#8217;m happy to say that by using Mono&#8217;s PLINQ and with as little modifications as this :</p>
<pre class="brush: csharp; title: ; notranslate">--- linq-sequential.cs	2008-07-25 11:38:53.000000000 +0200
+++ plinq-parallel.cs	2008-07-25 11:39:04.000000000 +0200
@@ -1,9 +1,9 @@
-internal void RenderSequential(Scene scene)
+internal void RenderParallel(Scene scene)
 {
     int[] rgb = new int[screenWidth * screenHeight];

     var pixelsQuery =
-        from y in Enumerable.Range(0, screenHeight)
+        from y in ParallelEnumerable.Range(0, screenHeight)
         let recenterY = -(y - (screenHeight / 2.0)) / (2.0 * screenHeight)
         select from x in Enumerable.Range(0, screenWidth)
                let recenterX = (x - (screenWidth / 2.0)) / (2.0 * screenWidth)
@@ -65,14 +65,14 @@
                select new { X = x, Y = y, Color = traceRay(new TraceRayArgs(ray, scene, 0)) };

     int rowsProcessed = 0;
-    foreach (var row in pixelsQuery)
+    pixelsQuery.ForAll(row =&gt;
     {
         foreach (var pixel in row)
         {
             rgb[pixel.X + (pixel.Y * screenWidth)] = pixel.Color.ToInt32();
         }
-        rowsProcessed++;
-        if (rowsProcessed % rowsPerUpdate == 0 ||
-            rowsProcessed &gt;= screenHeight) updateImageHandler(rgb);
-    }
+        int processed = Interlocked.Increment(ref rowsProcessed);
+        if (processed % rowsPerUpdate == 0 ||
+            processed &gt;= screenHeight) updateImageHandler(rgb);
+    });
 }</pre>
<p>&#8230; the code runs approximately 1,5x faster on my dual-core computer. Actually it&#8217;s rather good although there is still room for improvement (OrderBy fallbacks to the traditional LINQ operator for instance). The Ray tracer here is particularly well suited to parallelization because calling MoveNext() involves a good deal of computation with no-constant time as it depends on how much reflection there is, that&#8217;s why the processing feels slower on the bottom of the picture.</p>
<p>Following are two screencasts of both sequential and parallel version of the Ray Tracer found in Microsoft ParallelFx CTP samples :</p>
<p align="center">
<a href='http://blog.neteril.org/2008/07/25/linq-raytracer-but-with-a-p-twist/raytracer-linq/' title='raytracer-linq'><img width="150" height="150" src="http://blog.neteril.org/wp-content/uploads/2008/07/raytracer-linq-150x150.gif" class="attachment-thumbnail" alt="Sequential version" title="raytracer-linq" /></a>
<a href='http://blog.neteril.org/2008/07/25/linq-raytracer-but-with-a-p-twist/raytracer-plinq/' title='raytracer-plinq'><img width="150" height="150" src="http://blog.neteril.org/wp-content/uploads/2008/07/raytracer-plinq-150x150.gif" class="attachment-thumbnail" alt="Parallel version" title="raytracer-plinq" /></a>
</p>
<p>Actually colors are much more good-looking than this, but since GIF format supports 256 colors at most the output is a little fuzzy.</p>
<p>Now off to some multi-threading debug.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.neteril.org/2008/07/25/linq-raytracer-but-with-a-p-twist/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Current PLinq : mixed results</title>
		<link>http://blog.neteril.org/2008/07/22/current-plinq-mixed-results/</link>
		<comments>http://blog.neteril.org/2008/07/22/current-plinq-mixed-results/#comments</comments>
		<pubDate>Tue, 22 Jul 2008 20:12:08 +0000</pubDate>
		<dc:creator>Jérémie Laval</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[Google Summer of Code 2008]]></category>
		<category><![CDATA[Mono]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[linq]]></category>
		<category><![CDATA[parallelfx]]></category>
		<category><![CDATA[plinq]]></category>
		<category><![CDATA[soc]]></category>

		<guid isPermaLink="false">http://garuma.wordpress.com/?p=220</guid>
		<description><![CDATA[As described in the roadmap, PLinq implementation work has started a week ago. Some good bits are already there like what I consider to be the 3 most important operators (because most of the others can be expressed using these ones) : Select, Where and Aggregate. Following is a discussion on the specificities of PLinq, [...]]]></description>
			<content:encoded><![CDATA[<p>As described in the roadmap, PLinq implementation work has started a week ago. Some good bits are already there like what I consider to be the 3 most important operators (because most of the others can be expressed using these ones) : <code>Select</code>, <code>Where</code> and <code>Aggregate</code>. Following is a discussion on the specificities of PLinq, difficulties they raise and, at the end, some examples/benchmarks.</p>
<p>A thing to be distinguished in PLinq contrary to standard Linq is the way data is processed. With Linq you can pretty much assume that data is processed in order. For example in Mono, <code>Select</code> is implemented like this internally :</p>
<pre class="brush: csharp; title: ; notranslate">static IEnumerable CreateSelectIterator (IEnumerable source, Func selector)
{
	foreach (var element in source)
		yield return selector (element);
}</pre>
<p>So if the <code>IEnumerable</code>&#8216;s iterator is built to return data in order (like most standard collections in .NET) this order will be kept. More importantly, some Linq&#8217;s operators would lose their purpose if data wasn&#8217;t kept in order. Operators such as <code>ElementAt</code>, <code>Skip</code>, <code>First</code> are dependent on indexing and thus can&#8217;t work reliably on scrambled data.</p>
<p>Now the problem is that PLinq doesn&#8217;t follow this intuitive ordering property and that for a simple reason : performances. Indeed, just like <code>Parallel.For</code> split the domain to parallelize work, PLinq&#8217;s queries are run on workers which just take randomly data from the source enumerable and return them back without reordering them (or, put in another way, ordered by which took the less processing time). By doing things like this we can yield optimum performances. On the other hand, most applications rely somehow on data ordering, be it implicitly or with operators like <code>OrderBy</code>, which mean we can&#8217;t just ignore that aspect of Linq.</p>
<p>The current way PLinq allows this ordering part is to have two separate extension methods for turning <code>IEnumerable</code> into <code>IParallelEnumerable</code>. The first, <code>AsParallel()</code>, allows the engine to process the data as it wants, so a developer can&#8217;t expect in which order its initial data will be given back to him. The second one, <code>AsOrdered()</code>, enforces strict order preservation at each step of the processing and, in fact, allows the class of operators I cited before to work as expected. However if ordering is explicitly turned on, either by <code>AsOrdered()</code> or <code>OrderBy</code> operator, the performance penalty can be important, killing the interest to parallelize queries in the first place (which is why it&#8217;s turned off by default).</p>
<p>At the moment only the first mode (unordered processing) is supported in Mono&#8217;s PLinq. Adding support for the other mode will be quite challenging with operators like <code>Where</code> because they tend to create gaps in the source enumerable, gaps which are very hard to track in a non-deterministic environment like ParallelFx. I still have no clear idea on how to handle this in Mono&#8217;s ParallelFx without too much locking  (if anyone has pointers go ahead <img src='http://blog.neteril.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  ) .</p>
<p>Finally to close this post on a lighter touch, I have some examples which works on current implementation. First of all simple query like this one :</p>
<pre class="brush: csharp; title: ; notranslate">ParallelEnumerable.Range(1, 2000)
	.Where(i =&gt; i % 10 == 0)
	.Select(i =&gt; i + 1)</pre>
<p>Yield around 1.5x performance improvement when run on my dual-core system. The actual precise number vary importantly on external things like how much data is queried, how long an operator takes to process one item, how selective are the predicates used &#8230;</p>
<p>A second example which yield very little improvement at the moment (an example of <a href="http://en.wikipedia.org/wiki/Amdahl%27s_law">why PLinq isn&#8217;t a panacea</a>) is this sort-of adaptive image blurrer. It takes a pixel and filter the others according to how much close their color are to the selected pixel&#8217;s one. If a pixel doesn&#8217;t comply to this predicate it gets blurred with a bloom-like effect :</p>
<p align="center"><a href="http://garuma.files.wordpress.com/2008/07/blurrer-final.png"><img src="http://garuma.files.wordpress.com/2008/07/blurrer-final.png?w=300" alt="" width="300" height="112" class="aligncenter size-medium wp-image-225" /></a><br />
<em>(In the screenshot blue and white colors are supposed to be more blurred and thus fade in the background)</em></p>
<p>The parallelized version of this program is actually slower by a little amount than its synchronous counterpart on Linux but a little quicker on Windows for about the same run-time of the synchronous version on both platforms.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.neteril.org/2008/07/22/current-plinq-mixed-results/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

