<?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>Guy and his Traveling Macbook</title>
	<atom:link href="http://www.guysherman.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.guysherman.com</link>
	<description></description>
	<lastBuildDate>Thu, 22 Sep 2011 05:28:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Fun with Arduino!</title>
		<link>http://www.guysherman.com/2011/09/22/fun-with-arduino/</link>
		<comments>http://www.guysherman.com/2011/09/22/fun-with-arduino/#comments</comments>
		<pubDate>Thu, 22 Sep 2011 05:28:52 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.guysherman.com/?p=292</guid>
		<description><![CDATA[So a couple of days ago my Adafruit Experiment Kit for Arduino (ARDX) arrived, and today I spent some time playing with it. I went through the first couple of experiments but decided to go off the range a little with the second one. Instead of writing a whole bunch of code which goes through &#8230; </p><p><a class="more-link block-button" href="http://www.guysherman.com/2011/09/22/fun-with-arduino/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<p>So a couple of days ago my <a title="Adafruit Experimentation Kit for Arduino" href="http://www.adafruit.com/products/170" target="_blank">Adafruit Experiment Kit for Arduino (ARDX)</a> arrived, and today I spent some time playing with it.</p>
<p>I went through the first couple of experiments but decided to go off the range a little with the second one. Instead of writing a whole bunch of code which goes through and sets individual pins, I decided to try using the Port Registers to set a whole bunch of pins at once. So, what I decided to do was make an 8-bit binary display. I had to use some Bit Math to take the lower 6 bits of the number and put them onto one port register, and the upper two onto the other port register. Thanks to <a title="Cosine Kitty" href="http://arduino.cc/playground/Profiles/CosineKitty" target="_blank">Cosine Kitty</a> for the info on <a title="Port Registers" href="http://www.arduino.cc/playground/Code/BitMath#registers" target="_blank">Port Registers</a>.</p>
<p>Here&#8217;s a video of my first pass at the experiment, with scrolling LEDs.<br />
<iframe src="http://www.youtube.com/embed/2NBRtNDj3Zs" frameborder="0" width="560" height="315"></iframe></p>
<p>And here is the binary counter.<br />
<iframe src="http://www.youtube.com/embed/ZlyeH6TWnic" frameborder="0" width="560" height="315"></iframe></p>
<p>My next step will be to read bytes from the serial port and show them on the 8-bit display.</p>
<p>That&#8217;s all folks.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guysherman.com/2011/09/22/fun-with-arduino/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>No item should ever go un-processed</title>
		<link>http://www.guysherman.com/2011/09/16/no-item-should-ever-go-un-processed/</link>
		<comments>http://www.guysherman.com/2011/09/16/no-item-should-ever-go-un-processed/#comments</comments>
		<pubDate>Fri, 16 Sep 2011 04:31:39 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.guysherman.com/?p=286</guid>
		<description><![CDATA[I have recently been fixing a support incident with a system of ours which processes data in the form of CSV files emailed to an exchange mailbox. Occasionally the producer of these CSVs doesn&#8217;t form them correctly and the whole thing packs up; the item stays in the mailbox, and somebody has to go digging &#8230; </p><p><a class="more-link block-button" href="http://www.guysherman.com/2011/09/16/no-item-should-ever-go-un-processed/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<p>I have recently been fixing a support incident with a system of ours which processes data in the form of CSV files emailed to an exchange mailbox. Occasionally the producer of these CSVs doesn&#8217;t form them correctly and the whole thing packs up; the item stays in the mailbox, and somebody has to go digging to fix it, and get the whole thing up and running before the backlog of data to be processed gets rather large. This has brought to light two important points about data-processing in my mind:</p>
<ol>
<li>No item should ever go &#8220;un-processed&#8221; &#8211; if it fails to go down the normal handling path, it should go down an error handling path &#8211; either way it should leave the main queue.</li>
<li>There must always be a mechanism for a human to intervene, and correct (or choose to ignore) malformed data; this makes for nice error-handling path for point 1.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.guysherman.com/2011/09/16/no-item-should-ever-go-un-processed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My CV as an Infographic</title>
		<link>http://www.guysherman.com/2011/09/05/my-cv-as-an-infographic/</link>
		<comments>http://www.guysherman.com/2011/09/05/my-cv-as-an-infographic/#comments</comments>
		<pubDate>Mon, 05 Sep 2011 22:56:36 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[CV]]></category>

		<guid isPermaLink="false">http://www.guysherman.com/?p=281</guid>
		<description><![CDATA[I recently got an invite to a service called visualize.me, it takes data from your linked-in profile and turns it into a neat infographic. I&#8217;d like to see what the recruitment folks think. The link to my profile is below: http://vizualize.me/0S62S_ZXAT#]]></description>
			<content:encoded><![CDATA[<p>I recently got an invite to a service called <a title="Visualize.Me" href="http://vizualize.me/">visualize.me</a>, it takes data from your linked-in profile and turns it into a neat infographic. I&#8217;d like to see what the recruitment folks think. The link to my profile is below:</p>
<p><a title="http://vizualize.me/0S62S_ZXAT#" href="http://vizualize.me/0S62S_ZXAT#">http://vizualize.me/0S62S_ZXAT#</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.guysherman.com/2011/09/05/my-cv-as-an-infographic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>GreenScreen for Kinect</title>
		<link>http://www.guysherman.com/2011/07/24/greenscreen-for-kinect/</link>
		<comments>http://www.guysherman.com/2011/07/24/greenscreen-for-kinect/#comments</comments>
		<pubDate>Sun, 24 Jul 2011 04:55:45 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C Sharp]]></category>
		<category><![CDATA[Kinect]]></category>

		<guid isPermaLink="false">http://www.guysherman.com/?p=263</guid>
		<description><![CDATA[Since Microsoft released the official Kinect SDK for Windows I have been doing a tiny bit of mucking around with it. I am working on a poor-man&#8217;s &#8220;Green Screen&#8221; app which uses the Kinect&#8217;s skeleton tracking to mask out the background. I got the first stage of it working today. I&#8217;ll post more videos as the &#8230; </p><p><a class="more-link block-button" href="http://www.guysherman.com/2011/07/24/greenscreen-for-kinect/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<p>Since Microsoft released the <a title="Kinect SDK for Windows" href="http://research.microsoft.com/en-us/um/redmond/projects/kinectsdk/" target="_blank">official Kinect SDK for Windows</a> I have been doing a tiny bit of mucking around with it.</p>
<p>I am working on a poor-man&#8217;s &#8220;Green Screen&#8221; app which uses the Kinect&#8217;s skeleton tracking to mask out the background. I got the first stage of it working today.</p>
<p><iframe src="http://www.youtube.com/embed/fGvSs1RFCjQ?hl=en&amp;fs=1" frameborder="0" width="425" height="349"></iframe></p>
<p>I&#8217;ll post more videos as the software progresses.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guysherman.com/2011/07/24/greenscreen-for-kinect/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>To share or not to share&#8230;</title>
		<link>http://www.guysherman.com/2011/03/20/to-share-or-not-to-share/</link>
		<comments>http://www.guysherman.com/2011/03/20/to-share-or-not-to-share/#comments</comments>
		<pubDate>Sun, 20 Mar 2011 10:17:58 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Boost]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[DirectX]]></category>
		<category><![CDATA[flyweight]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://www.guysherman.com/?p=264</guid>
		<description><![CDATA[So, I&#8217;m gradually working towards making a simple fighting game, using my Kinect as the input sensor. I think initially it&#8217;ll be one person punching a punching bag, then two people competing, and then probably some sort of computer controlled AI which looks at your pose, and chooses the right pose/move accordingly (although since I &#8230; </p><p><a class="more-link block-button" href="http://www.guysherman.com/2011/03/20/to-share-or-not-to-share/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<p>So, I&#8217;m gradually working towards making a simple fighting game, using my Kinect as the input sensor. I think initially it&#8217;ll be one person punching a punching bag, then two people competing, and then probably some sort of computer controlled AI which looks at your pose, and chooses the right pose/move accordingly (although since I don&#8217;t really know how to fight, that will be interesting).</p>
<h2>The Experiment</h2>
<p>Anyhow, a few weeks ago I got a very rudimentary scripting host working, where I have my rendering infrastructure written in C++, and I have a mono .NET window displaying the output etc. Well I have since improved it to allow me to create entities on-screen in a (somewhat) adhoc manner (they&#8217;re all the same entity at the moment). In doing this I decided to do an experiment to discover what we all know is true: if you have more than one instance of the same model on screen, it better be the same vertices et al in memory. My Naive version loaded the model from disk, and packed it into my renderable format in memory each time the scrip requested an entity from the engine. I wanted to do 1000 entities, but the Naive approach crashed my computer at ~380, so for my performance comparisons I only went up to 200. My second approach uses <a title="Boost Flyweights" href="http://www.boost.org/doc/libs/1_46_1/libs/flyweight/doc/index.html">boost::flyweights</a> to share the model amongst all the entities that use it. I performance tested this one up to 200 as well, but as you can see below it gets up to 1000 dwarves on screen quite happily.</p>
<div id="attachment_265" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.guysherman.com/wp-content/uploads/2011/03/1000dwarves.png"><img class="size-medium wp-image-265" title="1000 Dwarves" src="http://www.guysherman.com/wp-content/uploads/2011/03/1000dwarves-300x224.png" alt="" width="300" height="224" /></a><p class="wp-caption-text">Snow-white couldn&#39;t cook for all these guys.</p></div>
<h2><span id="more-264"></span></h2>
<h2>The Results</h2>
<p>I&#8217;ve also attached a bunch of graphs of the comparison between the two approaches. Obviously, the approach using the flyweights was much better than the naive approach, but there are a few interesting features on the graphs. First up is the load-times. In the naive approach the curve starts out very steep for the 1, 2, 5 and 10 dwarf runs, and then peels of to some sort of linear amount function for the rest. It seems to me like it takes at least 10 reads of a file for my Windows/my hard disk to cache the file fully. You&#8217;ll also notice that there is a tiny amount of growth in the load-times for the flyweight approach, although I think this is down to the &#8220;.&#8221; that gets printed to the console for every constructed entity (printf and its higher-level cousins are SLOW).</p>
<div id="attachment_266" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.guysherman.com/wp-content/uploads/2011/03/loadtimes.png"><img class="size-medium wp-image-266" title="Load Times" src="http://www.guysherman.com/wp-content/uploads/2011/03/loadtimes-300x182.png" alt="" width="300" height="182" /></a><p class="wp-caption-text">Load times</p></div>
<p>Next is the memory graph. The thing that strikes me here is that the memory growth appears to slow for the naive approach, which I don&#8217;t quite understand. You can also see a delta between &#8220;max&#8221; memory, and &#8220;rendering&#8221; memory. This is because the importer library loads a copy of the file into its format, then I convert from its format into vertex and index arrays, and the create vertex/index buffers out of those, and then clean everything up so that only the buffers are left. &#8220;Max&#8221; memory, therefore is during the loading phase, and &#8220;Rendering&#8221; memory is once we&#8217;ve created the buffers and cleaned up the other stuff. Note that there&#8217;s no delta between these in the flyweight approach, and as we would expect, the memory usage is constant.</p>
<div id="attachment_267" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.guysherman.com/wp-content/uploads/2011/03/memory.png"><img class="size-medium wp-image-267" title="Memory Usage" src="http://www.guysherman.com/wp-content/uploads/2011/03/memory-300x181.png" alt="" width="300" height="181" /></a><p class="wp-caption-text">Memory Usage</p></div>
<p>Finally, a graph showing something that I have not made much any better yet, and that is the frame time. I didn&#8217;t really expect any improvement, but it seems that repeatedly setting the same vertex and index buffer is slightly faster (maybe ~15%) than setting different buffers each time (I guess that&#8217;s the GPU cache being nice, or maybe the driver being smart and not actually doing anything). I am hopeful that if I do GPU instancing it&#8217;ll make the rendering much faster because the only thing I&#8217;ll have to change per entity is the world matrix.</p>
<div id="attachment_268" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.guysherman.com/wp-content/uploads/2011/03/frametime.png"><img class="size-medium wp-image-268" title="Frame Time" src="http://www.guysherman.com/wp-content/uploads/2011/03/frametime-300x181.png" alt="" width="300" height="181" /></a><p class="wp-caption-text">Even the frame time was slightly improved</p></div>
<h2>A Problem</h2>
<p>I am a little uneasy with my current approach, using boost::flyweights, because the flyweight pattern assumes an immutable shared-object, and my design does the loading in two stages: the first loads from disk, and packs into my runtime format, the second actually creates the gpu-based resources. This is deliberate, partially because I don&#8217;t want to couple the disk-based loading code to my graphics API, and secondly because I want to go multi-threaded and perform the second stage in a prologue for each frame (ie, at the start of each frame the load-queue is processed, and recently loaded assets get turned into resources on the GPU). So, back to the problem: the flyweight supports get/casting to a const <em>value_type&amp;</em> (<em>value_type</em> is your type, ie GraphicsResource), but I can&#8217;t populate the buffers inside the object if it is a const, so I had to &#8220;cast away the constness&#8221;, which felt horrible and left me feeling empty inside.</p>
<h2>Conclusion</h2>
<p>As I always knew, sharing a single instance of resources like models is not just a good idea, it is vitally important. Boost::flyweight is a nice pattern and removes the need to write complicated factory and handle classes, but the fact that a cast from const to non-const is required to satisfy my design smells like a two-week old dead turtle washed up on the beach. So, sharing instances is definitely the way to go, boost::flyweight just might not be the vehicle to get me there.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guysherman.com/2011/03/20/to-share-or-not-to-share/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>All those things I&#8217;ve been talking about&#8230;</title>
		<link>http://www.guysherman.com/2011/03/04/all-those-things-ive-been-talking-about/</link>
		<comments>http://www.guysherman.com/2011/03/04/all-those-things-ive-been-talking-about/#comments</comments>
		<pubDate>Fri, 04 Mar 2011 06:14:55 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Mono]]></category>
		<category><![CDATA[SuperNova]]></category>

		<guid isPermaLink="false">http://www.guysherman.com/?p=258</guid>
		<description><![CDATA[Well, I finally got a really rough prototype going of some C# code making my sandbox engine create a renderer and attach it to a .NET window. Here&#8217;s a screenie&#8230;]]></description>
			<content:encoded><![CDATA[<p>Well, I finally got a really rough prototype going of some C# code making my sandbox engine create a renderer and attach it to a .NET window. Here&#8217;s a screenie&#8230;</p>
<div id="attachment_259" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.guysherman.com/wp-content/uploads/2011/03/SuperNovaEmbedded.png"><img src="http://www.guysherman.com/wp-content/uploads/2011/03/SuperNovaEmbedded-300x256.png" alt="A screenshot of the SuperNova engine using DirectX to draw into a .NET Windows Forms window" title="SuperNova with Mono Embedded" width="300" height="256" class="size-medium wp-image-259" /></a><p class="wp-caption-text">SuperNova drawing into a .NET window</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.guysherman.com/2011/03/04/all-those-things-ive-been-talking-about/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lambda expressions in C# &#8211; How useful are they really?</title>
		<link>http://www.guysherman.com/2011/01/27/lambda-expressions-in-c-how-useful-are-they-really/</link>
		<comments>http://www.guysherman.com/2011/01/27/lambda-expressions-in-c-how-useful-are-they-really/#comments</comments>
		<pubDate>Thu, 27 Jan 2011 21:43:38 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.guysherman.com/?p=256</guid>
		<description><![CDATA[I&#8217;m currently working on a project where we are using a technology called DDS (Data Distribution Service). DDS is a Publish/Subscribe technology for Inter-Process Communication. It is fast, and very flexible in terms of the Quality-of-Service that you want. Now, I have developed a framework around it so that various parts of our application need &#8230; </p><p><a class="more-link block-button" href="http://www.guysherman.com/2011/01/27/lambda-expressions-in-c-how-useful-are-they-really/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m currently working on a project where we are using a technology called DDS (Data Distribution Service). DDS is a Publish/Subscribe technology for Inter-Process Communication. It is fast, and very flexible in terms of the Quality-of-Service that you want. Now, I have developed a framework around it so that various parts of our application need only interact with a state class, and in fact they can register to be notified of changes to properties on these state classes. These state classes effectively register an interest in a particular Topic (the fundamental unit of data within DDS, a collection of repeated fields, a single occurrence of which is called a Sample). Now, when a class uses my framework to register an interest in a particular topic, it supplies an Action&lt;T&gt; which is used to process Samples of the Topic in question. In some cases I have passed a C# Lambda Expression in as the Action, but I find a key problem with these lambdas is that they are very hard to test (I&#8217;m pretty much doing TDD, not quite, but pretty much). I&#8217;m leaning towards the idea that if you can&#8217;t test it easily, it isn&#8217;t all that useful as language element. I&#8217;m interested to see what people think.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guysherman.com/2011/01/27/lambda-expressions-in-c-how-useful-are-they-really/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows Phone 7 game &#8220;Get Kicking&#8221; out now!</title>
		<link>http://www.guysherman.com/2010/12/02/windows-phone-7-game-get-kicking-out-now/</link>
		<comments>http://www.guysherman.com/2010/12/02/windows-phone-7-game-get-kicking-out-now/#comments</comments>
		<pubDate>Thu, 02 Dec 2010 08:40:07 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Windows Phone 7]]></category>

		<guid isPermaLink="false">http://www.guysherman.com/?p=252</guid>
		<description><![CDATA[My first Windows Phone 7 game &#8220;Get Kicking&#8221; is available now on the Windows Phone 7 Marketplace: http://social.zune.net/redirect?type=phoneApp&#38;id=72d6c3a5-a6f9-df11-9264-00237de2db9e]]></description>
			<content:encoded><![CDATA[<p>My first Windows Phone 7 game &#8220;Get Kicking&#8221; is available now on the Windows Phone 7 Marketplace: <a href="http://social.zune.net/redirect?type=phoneApp&amp;id=72d6c3a5-a6f9-df11-9264-00237de2db9e">http://social.zune.net/redirect?type=phoneApp&amp;id=72d6c3a5-a6f9-df11-9264-00237de2db9e</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.guysherman.com/2010/12/02/windows-phone-7-game-get-kicking-out-now/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows Phone 7 Challenge Entry is in&#8230;</title>
		<link>http://www.guysherman.com/2010/10/30/windows-phone-7-challenge-entry-is-in/</link>
		<comments>http://www.guysherman.com/2010/10/30/windows-phone-7-challenge-entry-is-in/#comments</comments>
		<pubDate>Sat, 30 Oct 2010 13:30:56 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.guysherman.com/?p=250</guid>
		<description><![CDATA[I&#8217;ve been working on an entry for the Windows Phone 7 Challenge the Microsoft NZ are running. The game is done (not withstanding a few minor tweaks), and the video has been uploaded to youtube. Check it out below:]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on an entry for the Windows Phone 7 Challenge the Microsoft NZ are running. The game is done (not withstanding a few minor tweaks), and the video has been uploaded to youtube. Check it out below:</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/UOrhLBeU11o?hl=en&amp;fs=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/UOrhLBeU11o?hl=en&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.guysherman.com/2010/10/30/windows-phone-7-challenge-entry-is-in/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.NET 4.0 and the Task Parallel Library (TPL)</title>
		<link>http://www.guysherman.com/2010/07/06/net-4-0-and-the-task-parallel-library-tpl/</link>
		<comments>http://www.guysherman.com/2010/07/06/net-4-0-and-the-task-parallel-library-tpl/#comments</comments>
		<pubDate>Tue, 06 Jul 2010 08:21:54 +0000</pubDate>
		<dc:creator>Guy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C Sharp]]></category>
		<category><![CDATA[Task Parallel Library]]></category>
		<category><![CDATA[TPL]]></category>

		<guid isPermaLink="false">http://www.guysherman.com/?p=237</guid>
		<description><![CDATA[I&#8217;ve been tasked with presenting a training session at work on the new concurrent programming features in the .NET Framework 4.0, so I&#8217;ve been playing around with a Mandelbrot set visualiser for which I have written three routines: a sequential routine, a (potentially) each line can be calculated in parallel, and a third where (potentially) &#8230; </p><p><a class="more-link block-button" href="http://www.guysherman.com/2010/07/06/net-4-0-and-the-task-parallel-library-tpl/">Continue reading &#187;</a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been tasked with presenting a training session at work on the new concurrent programming features in the .NET Framework 4.0, so I&#8217;ve been playing around with a Mandelbrot set visualiser for which I have written three routines: a sequential routine, a (potentially) each line can be calculated in parallel, and a third where (potentially) each pixel can be calculated in parallel. I say &#8220;potentially&#8221; because the resource manager underneath the TPL actually manages the threading for you. In essence, when using a technique like <em><strong>Parallel.For</strong></em> you create a lambda function for the loop body, any single iteration of which <em>could</em> be executed in parallel to any other iteration of the loop body, and the TPL takes care of scheduling these iterations across some magically optimized number of threads.</p>
<p>My sequential code is a nested for loop where the out loop iterates y and the inner loop iterates x. In the <em><strong>Parallel.For</strong></em> version of the visualiser I replace the outer loop with a <em><strong>Parallel.For</strong></em> like so:</p>
<pre>Parallel.For(0, parameters.imageHeight, y =&gt;
{
    double c_im = parameters.maxIm - y * parameters.imFactor;
    for (uint x = 0; x &lt; parameters.imageWidth; ++x)
    {
        mandelbrotPixel(bmd, (uint)y, c_im, x);
    }
});</pre>
<p>What this means is that the TPL will try to run as many iterations of the  body of the lambda function in parallel as is sensible.</p>
<p>So, onto the results. I ran the same program on my work machine (Core2 Duo, 4GB RAM, Vista 32) and my home machine (Core2 Quad, 2GB RAM, Windows 7 64), and got the following results:</p>
<pre>Test        |     Time (work)        | Time (home)
-------------------------------------------
Sequential  | 9.480s                 | 9.373s
Parallel.For| 4.540s                 | 2.451s
Nested P.F  | 4.300s                 | 2.403s</pre>
<p>As you can see, by simply running the code on a machine with two more cores, the runtime was halved.</p>
<p>In order to get the run-times large enough for changes in performance to be meaningful I made the application generate a 4096 by 4096 image.</p>
<p>Take a look at the source code here: <a href="http://www.guysherman.com/wp-content/uploads/2010/07/ParallelProgramming.zip">ParallelProgramming.zip</a>, it&#8217;s a Visual Studio 2010 solution, but the code is fairly straightforward.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guysherman.com/2010/07/06/net-4-0-and-the-task-parallel-library-tpl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

