<?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>PlanetMarshall</title>
	<atom:link href="http://www.planetmarshall.co.uk/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.planetmarshall.co.uk</link>
	<description>Andrew Marshall's blog.</description>
	<lastBuildDate>Thu, 11 Mar 2010 17:19:16 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>The Robin Hood Tax</title>
		<link>http://www.planetmarshall.co.uk/2010/03/the-robin-hood-tax/</link>
		<comments>http://www.planetmarshall.co.uk/2010/03/the-robin-hood-tax/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 16:12:55 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Opinion]]></category>

		<guid isPermaLink="false">http://www.planetmarshall.co.uk/?p=679</guid>
		<description><![CDATA[I haven&#8217;t posted an opinion piece before, and I may be opening myself up to a whole world of pain by starting with this one, but this idea has been gathering momentum around the internet for a while now and I wanted to respond to it with a little more elucidation than that afforded by [...]]]></description>
			<content:encoded><![CDATA[<p class="pm_first"><span>I</span> haven&#8217;t posted an opinion piece before, and I may be opening myself up to a whole world of pain by starting with this one, but this idea has been gathering momentum around the internet for a while now and I wanted to respond to it with a little more elucidation than that afforded by a tweet or a facebook flame war. For the record, I am not opposed to the <a title="The Robin Hood Tax" href="http://robinhoodtax.org.uk/" target="_blank">Robin Hood Tax</a> in the same way that I oppose Scientology or Jeremy Clarkson, but generally speaking it&#8217;s a good idea to be critical and to not take everything at face value.</p>
<blockquote><p>Disclaimer : this is an <em>opinion</em> piece. I trust that people are capable of using Google to research the facts, though if you&#8217;re planning on using Wikipedia I should mention that this article has nothing to do with the film starring Kevin Costner or any episodes of Star Trek.</p></blockquote>
<p><span id="more-679"></span></p>
<h3>The idea</h3>
<p>Tax &#8217;speculative banking transactions&#8217; at 0.05% to raise money for public services, and to fight global poverty and climate change. I am not economist enough to object to this on financial grounds, so I want to look at it from a purely ideological perspective.</p>
<h3>Is global poverty an economic, or political problem?</h3>
<p>The underlying assumption behind the campaign is that global poverty is an economic problem, one that can be solved largely by throwing money at it. Is that really the case? It seems to me that the underlying causes of poverty include poor education, sanitation, the prevalence of superstition, oppressive and unstable political regimes and tribal warfare. Some of the richest nations on earth have tried their hand at tackling these issues over the past century, although perhaps not altruistically, and had little in the way of success.</p>
<p>As of 2009, government support for banking institutions cost the UK taxpayer some £850bn, so it seems that the treasury has few problems in finding the cash when it&#8217;s required. The Robin Hood Tax proposes putting even more under their control, can our government institutions really be relied upon to manage it efficiently? Even if more money is earmarked for aid, how can we be sure that it will reach its intended destination? The BBC recently reported that a portion of the aid sent to ease the Ethiopian famine in the 1980s only ended up in the hands of  unscrupulous arms dealers.</p>
<h3>Avoidance of responsibility</h3>
<p>Charities need money, and on those grounds it would seem that the Tax would be a good idea. However, more than money, charities need volunteers willing to give up their time and their skills. Is there not the worry that by collectively handing responsibility for charitable giving over to the treasury, we wash our hands of the issues and carry on oblivious to the problems around us?</p>
<p>The underlying causes of global poverty and suffering in all their complexities will only be resolved by accepting, and not absolving ourselves of our responsibilities. What is needed is not increased taxation, but participation. If you are interested in volunteering opportunities in your area, see <a title="Volunteering opportunities in your area" href="http://www.do-it.org.uk/" target="_blank">http://www.do-it.org.uk/</a></p>
<h3>Scapegoating the financial services industry</h3>
<p>The banking industry needs to take its share of the responsibility for the financial crisis, but so do we all. Everyone rode on the crest of the credit wave over the past decade, taking &gt;100% mortgages, interest-free overdrafts, living on credit and accepting a lifestyle beyond our means.</p>
<p>Recently the government proposed a tax on bankers bonuses but to do such a thing constitutes a massive abuse of power. If the government wish to reduce the bonuses of bankers then they should use their influence as majority shareholders of the institutions that they have bailed out, surely to achieve the same thing through tax legislation is a conflict of interest? These individuals would be taxed not on the basis of what they earn but on what they do for a living. Many individuals receive salaries that the general public perceive to be grossly inflated, but I have yet to hear if the Robin Hood Tax would be extended to box office or football tickets.</p>
<h3>Celebrity endorsements</h3>
<p>This may seem a trivial objection, but I found the decision to promote this tax with a video featuring actors Bill Nighy ( 2 O levels ) and Robert Hardy ( BA in English from Oxford, so some education, at least ) incredibly patronising. David Attenborough, when asked of his opinion on global warming, used to refrain from making comments about it on the basis that he was a journalist, not a climatologist. It was only after seeing the magnitude of the effects for himself that he began to speak out. I wish more celebrities would follow his example and understand that, for better or worse, their fame gives them influence that far outstrips their knowledge of the subject. I dread to think of the number of Americans currently taking vaccination advice from Jim Carrey ( high school graduate ) and his wife Jenny McCarthy ( abandoned nursing college to pose for Playboy ). It&#8217;s unfortunate that the promoters of the Robin Hood Tax have decided to perpetuate the idea that actors are an authority on anything other than acting.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.planetmarshall.co.uk/2010/03/the-robin-hood-tax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Winter Camping</title>
		<link>http://www.planetmarshall.co.uk/2010/01/winter-camping/</link>
		<comments>http://www.planetmarshall.co.uk/2010/01/winter-camping/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 00:53:58 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Hiking]]></category>
		<category><![CDATA[Swimming]]></category>

		<guid isPermaLink="false">http://www.planetmarshall.co.uk/?p=513</guid>
		<description><![CDATA[Last week myself and a group of friends took a winter camping trip up to the Lake District. An odd decision, it could be argued, seen as the region has recently seen both some of its worst flooding and coldest winters in recent years.  Nonethless, equipped with ice axe, crampons and a generous supply of [...]]]></description>
			<content:encoded><![CDATA[
<a href="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/IMG_0310.JPG" title="Figured out the self timer" class="thickbox" rel="singlepic102" >
	<img class="ngg-singlepic ngg-left" src="http://www.planetmarshall.co.uk/wp-content/gallery/cache/102__120x_IMG_0310.JPG" alt="Figured out the self timer" title="Figured out the self timer" />
</a>

<p class="pm_first">Last week myself and a group of friends took a winter camping trip up to the <a title="The Lake District National Park" href="http://www.lakedistrict.gov.uk" target="_blank">Lake District</a>. An odd decision, it could be argued, seen as the region has recently seen both some of its worst flooding and coldest winters in recent years.  Nonethless, equipped with ice axe, crampons and a generous supply of Kendal Mint Cake we set out to climb Scafell.</p>
<p><span id="more-513"></span></p>
<h3 class="pm_first">Some of the things I learned</h3>
<ol>
<a href="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/IMG_0299.JPG" title="Not the north face of the Eiger" class="thickbox" rel="singlepic98" >
	<img class="ngg-singlepic ngg-right" src="http://www.planetmarshall.co.uk/wp-content/gallery/cache/98__120x_IMG_0299.JPG" alt="" title="" />
</a>
</p>
<li>Elephants, though clearly signposted, are not common in the lake district. I didn&#8217;t see a single one all weekend. Sheep, however, are plentiful.</li>
<li>It may be effective as a deterrent against the <a title="Ravenous Bugblatter Beast of Traal" href="http://www.bbc.co.uk/dna/h2g2/A387029" target="_blank">Ravenous Bugblatter Beast of Traal</a>, but a towel is no replacement for an insulating mattress.</li>
<li>Pop up tents, though useful on the beach, are less effective in torrential rain and gale force winds.</li>
<li>Retracing your steps back through the snow sounds easy, and it probably is for other people.</li>
<li>The <a title="The Wasdale Head Inn" href="http://www.wasdaleheadinn.co.uk/home.html">Wasdale Head Inn</a> serves an excellent selection of whiskeys, of which <a title="Wikipedia's entry on Lagavulin." href="http://en.wikipedia.org/wiki/Lagavulin_Single_Malt" target="_blank">Lagavulin </a>is the best. I should know, I tried all of them.</li>
<li>Swimming in Wastwater in January is almost exactly as cold as you&#8217;d expect.</li>
</ol>
<h3 class="pm_first">The Route</h3>
<p>The map below, which requires <a title="Microsoft Silverlight" href="http://www.microsoft.com/SILVERLIGHT/" target="_blank">Microsoft Silverlight</a>, was exported from my <a title="Garmin Forerunner 305" href="https://buy.garmin.com/shop/shop.do?cID=142&amp;pID=349" target="_blank">GPS wristwatch</a> and shows the route we took up Scafell before visibility made further progress a bit risky, and so we retraced our steps back through the snow. Or at least tried to before our steps mysteriously disappeared. There is also a <a title="Photosynth of Scafell" href="http://photosynth.net/view.aspx?cid=4b895bbc-3e41-4957-a35f-b3fab7155bfc" target="_blank">Photosynth </a>from part of our route available.</p>
<p><div class="pm_header"><a onclick="pm_toggleCodeBlock(this,'4b995fbf5a3e8')">&#x25bc;</a> Silverlight Application</div><div id="4b995fbf5a3e8" style="display:" class="silverlightControlHost"><object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="520" height="350"><param name="source" value="http://www.planetmarshall.co.uk/silverlight/osmap.xap"/><param name="background" value="#212121" /><!--<param name="minRuntimeVersion" value="2.0.31005.0" />--><param name="enableHtmlAccess" value="true" /><a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;"><img src="http://storage.timheuer.com/sl4wp-ph.png" alt="Install Microsoft Silverlight" style="border-style: none; width:520px; height:350px"/></a></object><iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe></div><br /></p>
<h3>Swimming in Wastwater</h3>
<p>Although as an amateur triathlete I&#8217;ve done many open water swims, I&#8217;ve never done one in winter and never without a wetsuit. So, in an attempt to kill both birds with one stone I decided to go for a swim in Wastwater in January. I lasted about two minutes. I&#8217;m no <a title="Ice Swimmer Lewis Gordon Pugh" href="http://www.lewispugh.com/" target="_blank">Lewis Gordon Pugh</a>. It was cold, but it really wasn&#8217;t as bad as you might think.  The water was beautifully clear but unfortunately sharp rocks do not a beach make.</p>
<h3>Gallery</h3>

<div class="ngg-galleryoverview" id="ngg-gallery-9">


	
	<!-- Thumbnails -->
		
	<div id="ngg-image-83" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/IMG_0247.JPG" title="Dave and Lizzy on the way to the campsite
" class="thickbox" rel="set_9" >
				<img title="Dave and Lizzy on the way to the campsite" alt="Dave and Lizzy on the way to the campsite" src="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/thumbs/thumbs_IMG_0247.JPG" width="64" height="48" />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-84" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/IMG_0248.JPG" title="Jamie by Wastwater" class="thickbox" rel="set_9" >
				<img title="Jamie by Wastwater" alt="Jamie by Wastwater" src="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/thumbs/thumbs_IMG_0248.JPG" width="64" height="48" />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-85" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/IMG_0253.JPG" title="View from the campsite" class="thickbox" rel="set_9" >
				<img title="View from the campsite" alt="View from the campsite" src="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/thumbs/thumbs_IMG_0253.JPG" width="64" height="48" />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-109" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/IMG_0333.JPG" title="The campsite" class="thickbox" rel="set_9" >
				<img title="The campsite" alt="The campsite" src="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/thumbs/thumbs_IMG_0333.JPG" width="64" height="48" />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-86" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/IMG_0260.JPG" title="The Wasdale Head Inn" class="thickbox" rel="set_9" >
				<img title="The Wasdale Head Inn" alt="The Wasdale Head Inn" src="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/thumbs/thumbs_IMG_0260.JPG" width="64" height="48" />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-87" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/IMG_0261.JPG" title="Before the morning's walk" class="thickbox" rel="set_9" >
				<img title="Before the morning's walk" alt="Before the morning's walk" src="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/thumbs/thumbs_IMG_0261.JPG" width="64" height="48" />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-88" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/IMG_0264.JPG" title="Some water" class="thickbox" rel="set_9" >
				<img title="Some water" alt="Some water" src="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/thumbs/thumbs_IMG_0264.JPG" width="64" height="48" />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-89" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/IMG_0271.JPG" title="On the way up Scafell..." class="thickbox" rel="set_9" >
				<img title="On the way up Scafell..." alt="On the way up Scafell..." src="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/thumbs/thumbs_IMG_0271.JPG" width="64" height="48" />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-90" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/IMG_0274.JPG" title="...still on the way up Scafell" class="thickbox" rel="set_9" >
				<img title="...still on the way up Scafell" alt="...still on the way up Scafell" src="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/thumbs/thumbs_IMG_0274.JPG" width="64" height="48" />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-91" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/IMG_0275.JPG" title="A look back over Wastwater" class="thickbox" rel="set_9" >
				<img title="A look back over Wastwater" alt="A look back over Wastwater" src="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/thumbs/thumbs_IMG_0275.JPG" width="64" height="48" />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-92" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/IMG_0278.JPG" title="First glimpses of snow up Scafell" class="thickbox" rel="set_9" >
				<img title="First glimpses of snow up Scafell" alt="First glimpses of snow up Scafell" src="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/thumbs/thumbs_IMG_0278.JPG" width="64" height="48" />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-93" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/IMG_0288.JPG" title="Starting to get serious" class="thickbox" rel="set_9" >
				<img title="Starting to get serious" alt="Starting to get serious" src="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/thumbs/thumbs_IMG_0288.JPG" width="64" height="48" />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-94" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/IMG_0293.JPG" title="Touching the void" class="thickbox" rel="set_9" >
				<img title="Touching the void" alt="Touching the void" src="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/thumbs/thumbs_IMG_0293.JPG" width="64" height="48" />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-95" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/IMG_0294.JPG" title=" " class="thickbox" rel="set_9" >
				<img title=" " alt=" " src="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/thumbs/thumbs_IMG_0294.JPG" width="64" height="48" />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-96" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/IMG_0295.JPG" title=" " class="thickbox" rel="set_9" >
				<img title=" " alt=" " src="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/thumbs/thumbs_IMG_0295.JPG" width="64" height="48" />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-97" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/IMG_0298.JPG" title="England, believe it or not." class="thickbox" rel="set_9" >
				<img title="England, believe it or not." alt="England, believe it or not." src="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/thumbs/thumbs_IMG_0298.JPG" width="64" height="48" />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-98" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/IMG_0299.JPG" title="Not the north face of the Eiger" class="thickbox" rel="set_9" >
				<img title=" " alt=" " src="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/thumbs/thumbs_IMG_0299.JPG" width="64" height="48" />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-99" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/IMG_0300.JPG" title=" " class="thickbox" rel="set_9" >
				<img title=" " alt=" " src="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/thumbs/thumbs_IMG_0300.JPG" width="64" height="48" />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-100" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/IMG_0303.JPG" title=" " class="thickbox" rel="set_9" >
				<img title=" " alt=" " src="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/thumbs/thumbs_IMG_0303.JPG" width="64" height="48" />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-101" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/IMG_0305.JPG" title="Getting to grips with the self timer." class="thickbox" rel="set_9" >
				<img title="Getting to grips with the self timer." alt="Getting to grips with the self timer." src="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/thumbs/thumbs_IMG_0305.JPG" width="64" height="48" />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-102" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/IMG_0310.JPG" title="Figured out the self timer" class="thickbox" rel="set_9" >
				<img title="Figured out the self timer" alt="Figured out the self timer" src="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/thumbs/thumbs_IMG_0310.JPG" width="64" height="48" />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-103" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/IMG_0314.JPG" title="Stopping, briefly, for lunch." class="thickbox" rel="set_9" >
				<img title="Stopping, briefly, for lunch." alt="Stopping, briefly, for lunch." src="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/thumbs/thumbs_IMG_0314.JPG" width="64" height="48" />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-104" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/IMG_0316.JPG" title="Axe and cake" class="thickbox" rel="set_9" >
				<img title="Axe and cake" alt="Axe and cake" src="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/thumbs/thumbs_IMG_0316.JPG" width="64" height="48" />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-106" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/IMG_0322.JPG" title="On the way down." class="thickbox" rel="set_9" >
				<img title="On the way down." alt="On the way down." src="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/thumbs/thumbs_IMG_0322.JPG" width="64" height="48" />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-105" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/IMG_0318.JPG" title="Andy looking down over Wasdale" class="thickbox" rel="set_9" >
				<img title="Andy looking down over Wasdale" alt="Andy looking down over Wasdale" src="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/thumbs/thumbs_IMG_0318.JPG" width="64" height="48" />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-115" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/img_0320.jpg" title="Dave surveys his domain" class="thickbox" rel="set_9" >
				<img title="Dave surveys his domain" alt="Dave surveys his domain" src="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/thumbs/thumbs_img_0320.jpg" width="64" height="48" />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-107" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/IMG_0327.JPG" title="A night heron." class="thickbox" rel="set_9" >
				<img title="A night heron." alt="A night heron." src="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/thumbs/thumbs_IMG_0327.JPG" width="64" height="48" />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-108" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/IMG_0329.JPG" title="Lakes wildlife" class="thickbox" rel="set_9" >
				<img title="Lakes wildlife" alt="Lakes wildlife" src="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/thumbs/thumbs_IMG_0329.JPG" width="64" height="48" />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-111" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/IMG_0342.JPG" title="Wastwater" class="thickbox" rel="set_9" >
				<img title="Wastwater" alt="Wastwater" src="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/thumbs/thumbs_IMG_0342.JPG" width="64" height="48" />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-113" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/IMG_0345.JPG" title="Walking by Wastwater." class="thickbox" rel="set_9" >
				<img title="Walking by Wastwater." alt="Walking by Wastwater." src="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/thumbs/thumbs_IMG_0345.JPG" width="64" height="48" />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-79" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/DSC_0278.JPG" title="Preparing for a swim in Wastwater" class="thickbox" rel="set_9" >
				<img title="Preparing for a swim in Wastwater" alt="Preparing for a swim in Wastwater" src="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/thumbs/thumbs_DSC_0278.JPG" width="64" height="42" />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-80" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/DSC_0279_1.JPG" title="Wastwater in winter" class="thickbox" rel="set_9" >
				<img title="Wastwater in winter" alt="Wastwater in winter" src="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/thumbs/thumbs_DSC_0279_1.JPG" width="64" height="52" />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-81" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/DSC_0283.JPG" title="Wading in Wastwater" class="thickbox" rel="set_9" >
				<img title="Wading in Wastwater" alt="Wading in Wastwater" src="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/thumbs/thumbs_DSC_0283.JPG" width="64" height="42" />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-82" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/DSC_0284.JPG" title="Swimming in Wastwater" class="thickbox" rel="set_9" >
				<img title="Swimming in Wastwater" alt="Swimming in Wastwater" src="http://www.planetmarshall.co.uk/wp-content/gallery/winter_camp/thumbs/thumbs_DSC_0284.JPG" width="64" height="42" />
			</a>
		</div>
	</div>
	 	 	
	<!-- Pagination -->
 	<div class="ngg-clear">&nbsp;</div> 	
</div>


]]></content:encoded>
			<wfw:commentRss>http://www.planetmarshall.co.uk/2010/01/winter-camping/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Silverlight and CUDA interop</title>
		<link>http://www.planetmarshall.co.uk/2010/01/silverlight-and-cuda-interop/</link>
		<comments>http://www.planetmarshall.co.uk/2010/01/silverlight-and-cuda-interop/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 02:11:58 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[CUDA]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://www.planetmarshall.co.uk/?p=389</guid>
		<description><![CDATA[Update &#8211; source code now available
Microsoft have recently released a beta of Silverlight 4, which has limited support for native interoperation using COM. Potentially, this example could be applied to any number of native interop scenarios, however for this example I have chosen to use Nvidia&#8217;s CUDA technology.
Disclaimer : This is an example of what [...]]]></description>
			<content:encoded><![CDATA[
<a href="http://www.planetmarshall.co.uk/wp-content/gallery/cuda-interop/mandrill.jpg" title="" class="thickbox" rel="singlepic78" >
	<img class="ngg-singlepic ngg-right" src="http://www.planetmarshall.co.uk/wp-content/gallery/cache/78__x96_mandrill.jpg" alt="mandrill" title="mandrill" />
</a>
<br />
<em>Update &#8211; <a href="#source">source code</a> now available</em></p>
<p class="pm_first">Microsoft have recently released a beta of Silverlight 4, which has limited support for native interoperation using COM. Potentially, this example could be applied to any number of native interop scenarios, however for this example I have chosen to use Nvidia&#8217;s CUDA technology.</p>
<blockquote><p>Disclaimer : This is an example of what can be done, not necessarily, and in all likelihood, an example of how it should be done.</p></blockquote>
<h3>About CUDA</h3>
<p>Up until around 2001 PC graphics cards, though powerful, implemented a fixed function pipeline that limited use to whatever was exposed by the APIs, usually Direct3D or OpenGL. The addition of a programmable pixel pipeline led to the use of graphics cards for more general computation tasks; at first using shaders directly, followed by higher level GPU specific programming languages, such as Brook, SH, and later NVidia&#8217;s CUDA. Most of this work was, and is, documented by the <a title="GPGPU" href="http://gpgpu.org/" target="_blank">GPGPU</a> group. <a href="http://www.nvidia.com/object/cuda_home.html#" target="_blank">NVIDIA&#8217;s website</a> shows CUDA being used in a wide variety of applications but in practice it is best employed in so called &#8220;<a title="Wikipedia : Embarrassingly Parallel" href="http://en.wikipedia.org/wiki/Embarrassingly_parallel" target="_blank">embarassingly parallel</a>&#8221; problems.<br />
<span id="more-389"></span></p>
<h3>The demonstration application</h3>
<p>The demo below shows a Silverlight 4 beta application, which implements a recursive gaussian filter. Note that this is not the same algorithm provided by the sample in the CUDA SDK, but a more efficient method, which is described in detail in <a href="#young">[1]</a> for those interested. The main advantage of a filter implemented in this way is that the computation time is independent of the width of the filter.<br />
To enable CUDA interop, you&#8217;ll need a CUDA compatible graphics card. Then do the following,</p>
<ol>
<li>Install the MFC COM application (link below). The installer should register the application with COM automatically.</li>
<li>Right click on the Silverlight App and install it for running outside of the browser. The CUDA option should now be available from the Combo box.</li>
</ol>
<p>Source code : <a title="Download source code" name="source" href="http://planetmarshall.co.uk/silverlight/cuda_interop/SilverlightCudaInteropDemo.zip">SilverlightCudaInteropDemo.zip</a><br />
<a title="Install CUDA Server application" href="http://planetmarshall.co.uk/silverlight/cuda_interop/InstallCudaServer.msi">Install MFC COM Application (5.5 Mb)</a><br />
<div class="pm_header"><a onclick="pm_toggleCodeBlock(this,'4b995fbf90b2b')">&#x25bc;</a> Silverlight Application</div><div id="4b995fbf90b2b" style="display:" class="silverlightControlHost"><object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="520" height="580"><param name="source" value="http://www.planetmarshall.co.uk/silverlight/cuda_interop/SlCudaInteropDemo.xap"/><param name="background" value="#212121" /><!--<param name="minRuntimeVersion" value="2.0.31005.0" />--><param name="enableHtmlAccess" value="true" /><a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;"><img src="http://storage.timheuer.com/sl4wp-ph.png" alt="Install Microsoft Silverlight" style="border-style: none; width:520px; height:580px"/></a></object><iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe></div><br />
<h3>The native component</h3>
<p>The native component takes the form of a COM Automation server, implemented as a client side MFC application.</p>
<blockquote><p>Note: Make sure you run Visual Studio with Administrator privileges, otherwise registering the automation server with COM will fail.</p></blockquote>
<p>MFC and Automation are beyond the scope of this article, but the basic process I followed was thus</p>
<ol>
<li>Create an MFC Dialog application using the Wizard. Make sure to enable Automation support</li>
<li>Add a method to the autmation interface using the add Method wizard from the Class View</li>
<li>Add a dual interface using this <a title="TN065: Dual-Interface Support for OLE Automation Servers" href="http://msdn.microsoft.com/en-us/library/4h56szat%28VS.100%29.aspx" target="_blank">Technical Note</a> from MSDN.</li>
<li>If you get link errors, make sure to include the output of MIDL in the application class ( the one that contains OnInitInstance). I couldn&#8217;t find any reference to this step, but it&#8217;s how the samples work.</li>
<li>Make sure that the run time library options passed to nvcc and msvc match, ie they should all use a DLL or Static linking, not a mixture of both</li>
<li>If you get stuck, take a look at the <a title="MFC Samples" href="http://msdn.microsoft.com/en-us/library/482ck6x8%28VS.100%29.aspx" target="_blank">MFC Samples</a>, particularly <a title="ACDUAL Sample: Adds Dual Interfaces to an Automation Application" href="http://msdn.microsoft.com/en-us/library/xfx55tf8%28VS.100%29.aspx" target="_blank">acdual</a>.</li>
</ol>
<p>when you pass a native array through COM Automation, it is converted to a <a title="Array Manipulation Functions from MSDN" href="http://msdn.microsoft.com/en-us/library/ms221145%28VS.100%29.aspx" target="_blank"><code>SAFEARRAY</code></a> on the native side. Note that I couldn&#8217;t find any documentation on this, I discovered it through experience. The code snippets below show sending and receiving array data between Silverlight and the MFC application.</p>

<div class="wp_syntax">
<div class="wp_header"><a onclick="pm_toggleCodeBlock(this,'4b995fbf95e37')">&#x25ba;</a> Listing : Calling COM from Silverlight</div><div id="4b995fbf95e37" style="display:none;" class="code"><div class="csharp pm_syntax"><span class="kw4">dynamic</span> cuda <span class="sy0">=</span> ComAutomationFactory.<span class="me1">CreateObject</span><span class="br0">&#40;</span><span class="st0">&quot;CudaServer.Application&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="kw4">float</span><span class="br0">&#91;</span><span class="br0">&#93;</span> data <span class="sy0">=</span> <span class="kw3">new</span> <span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="br0">&#123;</span>1.0f, 3.14f <span class="br0">&#125;</span><span class="sy0">;</span><br />
<span class="kw4">dynamic</span> retData <span class="sy0">=</span> cuda.<span class="me1">Process</span><span class="br0">&#40;</span> data <span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="co1">// retData is a managed float array</span></div></div></div>


<div class="wp_syntax">
<div class="wp_header"><a onclick="pm_toggleCodeBlock(this,'4b995fbf98956')">&#x25ba;</a> Listing : Returning data to Silverlight from MFC via COM</div><div id="4b995fbf98956" style="display:none;" class="code"><div class="cpp pm_syntax">VARIANT CCudaServer<span class="sy4">::</span><span class="me2">Process</span><span class="br0">&#40;</span>VARIANT <span class="sy3">&amp;</span>amp<span class="sy4">;</span>data<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; SAFEARRAY <span class="sy2">*</span>pSrcData <span class="sy1">=</span> &nbsp;data.<span class="me1">parray</span><span class="sy4">;</span><br />
<br />
&nbsp; <span class="co1">// this will copy the safe array into the variant</span><br />
&nbsp; CComVariant var<span class="br0">&#40;</span>pSrcData<span class="br0">&#41;</span><span class="sy4">;</span><br />
<br />
&nbsp; <span class="co1">// when we return the VARIANT containing the SAFEARRAY</span><br />
&nbsp; <span class="co1">// it will be marshaled to Silverlight as a managed array</span><br />
&nbsp; VARIANT retVal<span class="sy4">;</span><br />
&nbsp; VariantInit<span class="br0">&#40;</span> <span class="sy3">&amp;</span>amp<span class="sy4">;</span>retVal <span class="br0">&#41;</span><span class="sy4">;</span><br />
&nbsp; var.<span class="me1">Detach</span><span class="br0">&#40;</span> <span class="sy3">&amp;</span>amp<span class="sy4">;</span>retVal <span class="br0">&#41;</span><span class="sy4">;</span><br />
&nbsp; retVal.<span class="me1">vt</span> <span class="sy1">=</span> VT_ARRAY <span class="sy3">|</span> VT_R4<span class="sy4">;</span><br />
&nbsp; <span class="kw1">return</span> retVal<span class="sy4">;</span><br />
<span class="br0">&#125;</span></div></div></div>

<h3>Using MEF to implement the application</h3>
<p>The <a title="Managed Extensibility Framework at Codeplex" href="http://www.codeplex.com/MEF" target="_blank">Managed Extensibility Framework</a> is an extensible plugin framework for .NET applications and Silverlight. I have used it to dynamically discover implementations of <code>IProcessorProvider</code> based on the permissions available to the Silverlight application. The figure below shows the component structure of the application.</p>

<!-- collapsible header -->

<div class="pm_header"><a onclick="pm_toggleCodeBlock(this,'4b995fbf94d11')">&#x25ba;</a> Figure : Component diagram for demo application</div>
<div id="4b995fbf94d11" style="display:none;">
<a href="http://www.planetmarshall.co.uk/wp-content/gallery/cuda-interop/slcuda_component.png" title="Component diagram for demo application" class="thickbox" rel="singlepic77" >
	<img class="ngg-singlepic" src="http://www.planetmarshall.co.uk/wp-content/gallery/cache/77__475x_slcuda_component.png" alt="slcuda_component" title="slcuda_component" />
</a>
</div>

<h3>Performance notes</h3>
<h4>Silverlight</h4>
<p>Unlike the <a title="My Reaction-Diffusion simulator" href="http://www.planetmarshall.co.uk/index.php/2009/03/reaction-diffusion-models/">Reaction Diffusion simulation</a>, for this application I have chosen to use Silverlight&#8217;s <a title="WirteableBitmap in Silverlight 3, from MSDN" href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap%28VS.95%29.aspx" target="_blank"><code>WriteableBitmap</code></a>, introduced in Silverlight 3, rather than <a title="Joe Stegman's PNG Encoder for Silverlight" href="http://blogs.msdn.com/jstegman/archive/2008/04/21/dynamic-image-generation-in-silverlight.aspx" target="_blank">dynamic PNG encoding</a>. This revealed an interesting performance issue when using a typical double loop to iterate over the pixels. Initial timings revealed that the vast majority of the time was spent in updating the <code>WriteableBitmap</code> rather than actually performing the image processing. The initial update loop used the <code>PixelWidth</code> and <code>PixelHeight</code> properties to bound the loop counters, taking about 200ms to iterate over the loop.</p>

<div class="wp_syntax">
<div class="wp_header"><a onclick="pm_toggleCodeBlock(this,'4b995fbf9c553')">&#x25ba;</a> Listing : Updating bitmap using property accessors</div><div id="4b995fbf9c553" style="display:none;" class="code"><div class="csharp pm_syntax"><span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw4">int</span> j <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span> j <span class="sy0">&amp;</span>lt<span class="sy0">;</span> bmp.<span class="me1">PixelHeight</span><span class="sy0">;</span> <span class="sy0">++</span>j<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; <span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw4">int</span> i <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span> i <span class="sy0">&amp;</span>lt<span class="sy0">;</span> bmp.<span class="me1">PixelWidth</span><span class="sy0">;</span> <span class="sy0">++</span>i<span class="br0">&#41;</span><br />
&nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp;<span class="co1">// update pixels</span><br />
&nbsp; &nbsp;<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div></div></div>

<p>By caching the bitmap properties in local variables, the timing was reduced to ~5ms. Needless to say I was shocked by how much of a difference such a seemingly trivial change made.</p>

<div class="wp_syntax">
<div class="wp_header"><a onclick="pm_toggleCodeBlock(this,'4b995fbf9ee9f')">&#x25ba;</a> Listing : Updating bitmap with cached variables</div><div id="4b995fbf9ee9f" style="display:none;" class="code"><div class="csharp pm_syntax"><span class="kw4">int</span> pxWidth <span class="sy0">=</span>  bmp.<span class="me1">PixelWidth</span><span class="sy0">;</span><br />
<span class="kw4">int</span> pxHeight <span class="sy0">=</span> bmp.<span class="me1">PixelHeight</span><span class="sy0">;</span><br />
<span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw4">int</span> j <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span> j <span class="sy0">&amp;</span>lt<span class="sy0">;</span> pxHeight<span class="sy0">;</span> <span class="sy0">++</span>j<span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; <span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw4">int</span> i <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span> i <span class="sy0">&amp;</span>lt<span class="sy0">;</span> pxWidth<span class="sy0">;</span> <span class="sy0">++</span>i<span class="br0">&#41;</span><br />
&nbsp; <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp;<span class="co1">// update pixels</span><br />
&nbsp; &nbsp;<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div></div></div>

<h4>OLE Automation</h4>
<p>The guidelines for building performant automation code is much the same as that for other unmanaged interop scenarios in .NET : avoid chatty interfaces. Note that this is exactly what I have not done here. In fact, the time it takes CUDA to perform the image processing is dwarfed by the time it takes to marshal the data between Silverlight and COM. This can be mitigated somewhat by splitting the blur call into two operations, one to load the image, which is called only upon initialization, and one to perform the blur.</p>
<h4>CUDA</h4>
<p>CUDA operations are extremely sensitive to data alignment and the order in which threads access data. Kernels should be written in such a way that threads access adjacent data elements, meaning that the row major access pattern familiar to C and C# developers would produce suboptimal performance ( sometimes by as much as an order of magnitude ). Instead, array accesses should be performed in a manner more reminiscent of FORTRAN. In addition, 2D arrays should be padded out so that threads access data elements that are correctly aligned ( see the CUDA documentation for the correct alignment values ). A full exposition of performance optimization for CUDA is really beyond the scope of this article, there are many examples in the <a title="Learn More about CUDA - NVIDIA" href="http://www.nvidia.com/object/cuda_education.html" target="_blank">NVIDIA documentation</a> although the terminology can be somewhat opaque. One of the clearest explanations I have found is this <a title="Supercomputing 2007 CUDA Tutorial" href="http://gpgpu.org/sc2007" target="_blank">presentation </a>from Mark Harris at Supercomputing 2007.</p>

<div class="wp_syntax">
<div class="wp_header"><a onclick="pm_toggleCodeBlock(this,'4b995fbfa1743')">&#x25ba;</a> Listing : Row major access pattern</div><div id="4b995fbfa1743" style="display:none;" class="code"><div class="cuda pm_syntax"><span class="kw2">__global__</span> <span class="kw4">void</span> kernel<span class="br0">&#40;</span> <span class="kw4">float</span> <span class="sy0">*</span>destData<span class="sy0">,</span> <span class="kw4">float</span> <span class="sy0">*</span>srcData<span class="sy0">,</span> <span class="kw4">int</span> stride<span class="sy0">,</span> <span class="kw4">int</span> height <span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; <span class="co1">// suboptimal access pattern</span><br />
&nbsp; <span class="kw4">int</span> rowStart <span class="sy0">=</span> <span class="br0">&#40;</span><span class="kw3">blockDim</span>.<span class="me1">x</span><span class="sy0">*</span><span class="kw3">blockIdx</span>.<span class="me1">x</span><span class="sy0">+</span><span class="kw3">threadIdx</span>.<span class="me1">x</span><span class="br0">&#41;</span><span class="sy0">*</span>stride<span class="sy0">;</span><br />
&nbsp; <span class="kw1">for</span> <span class="br0">&#40;</span> <span class="kw4">int</span> i <span class="sy0">=</span> rowStart<span class="sy0">;</span> i <span class="sy0">&amp;</span>lt<span class="sy0">;</span> rowStart<span class="sy0">+</span>stride<span class="sy0">;</span> <span class="sy0">++</span>i <span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; destData<span class="br0">&#91;</span>idx<span class="br0">&#93;</span> <span class="sy0">=</span> srcData<span class="br0">&#91;</span>idx<span class="br0">&#93;</span><span class="sy0">;</span><br />
&nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div></div></div>


<div class="wp_syntax">
<div class="wp_header"><a onclick="pm_toggleCodeBlock(this,'4b995fbfa324a')">&#x25ba;</a> Listing : Column major access patern</div><div id="4b995fbfa324a" style="display:none;" class="code"><div class="cuda pm_syntax"><span class="kw2">__global__</span> <span class="kw4">void</span> kernel<span class="br0">&#40;</span> <span class="kw4">float</span> <span class="sy0">*</span>destData<span class="sy0">,</span> <span class="kw4">float</span> <span class="sy0">*</span>srcData<span class="sy0">,</span> <span class="kw4">int</span> stride<span class="sy0">,</span> <span class="kw4">int</span> height <span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; <span class="co1">// optimal access pattern, each thread accesses adjacent elements</span><br />
&nbsp; <span class="kw4">int</span> colStart <span class="sy0">=</span> <span class="kw3">blockDim</span>.<span class="me1">x</span><span class="sy0">*</span><span class="kw3">blockIdx</span>.<span class="me1">x</span><span class="sy0">+</span><span class="kw3">threadIdx</span>.<span class="me1">x</span><span class="sy0">;</span><br />
&nbsp; <span class="co1">// this case, 16*sizeof(float)= 64 bytes</span><br />
&nbsp; <span class="kw1">for</span> <span class="br0">&#40;</span> <span class="kw4">int</span> i <span class="sy0">=</span> colStart <span class="sy0">;</span> i <span class="sy0">&amp;</span>lt<span class="sy0">;</span> colStart<span class="sy0">+</span><span class="br0">&#40;</span>stride<span class="sy0">*</span>height<span class="br0">&#41;</span><span class="sy0">;</span> i<span class="sy0">+=</span>stride <span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; destData<span class="br0">&#91;</span>i<span class="br0">&#93;</span> <span class="sy0">=</span> srcData<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="sy0">;</span><br />
&nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div></div></div>

<h3>References</h3>
<ol>
<li><span class="p1"><a name="young"></a>Young, I.T. &amp; van Vliet,L.J, 1995. <a title="Recursive Implementation of the Gaussian Filter" href="http://www.sciencedirect.com/science?_ob=ArticleURL&amp;_udi=B6V18-3YS90HC-D&amp;_user=10&amp;_coverDate=06%2F30%2F1995&amp;_rdoc=2&amp;_fmt=high&amp;_orig=browse&amp;_srch=doc-info%28%23toc%235668%231995%23999559997%23172292%23FLP%23display%23Volume%29&amp;_cdi=5668&amp;_sort=d&amp;_docanchor=&amp;_ct=11&amp;_acct=C000050221&amp;_version=1&amp;_urlVersion=0&amp;_userid=10&amp;md5=cdfad44c178fc20739d26562c5f26e04" target="_blank">Recursive implementation of the Gaussian filter</a>. <em>Signal Processing</em>, 44, pp.139-151. </span></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.planetmarshall.co.uk/2010/01/silverlight-and-cuda-interop/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Searching MSDN Using Google</title>
		<link>http://www.planetmarshall.co.uk/2009/11/searching-msdn-using-google/</link>
		<comments>http://www.planetmarshall.co.uk/2009/11/searching-msdn-using-google/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 15:40:29 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.planetmarshall.co.uk/?p=382</guid>
		<description><![CDATA[I sometimes find it useful to search MSDN directly using Google, so I wrote a search plugin using OpenSearch to make this easier. Firefox should discover the search plugin automatically &#8211; it should appear in the search drop down at the top right. Otherwise, you can just install the plugin directly. For more details, see [...]]]></description>
			<content:encoded><![CDATA[<p class="pm_first"><span>I</span> sometimes find it useful to search MSDN directly using Google, so I wrote a search plugin using OpenSearch to make this easier. Firefox should discover the search plugin automatically &#8211; it should appear in the search drop down at the top right. Otherwise, you can just <a href="javascript:window.external.AddSearchProvider('http://www.planetmarshall.co.uk/code/google_msdn.xml')">install</a> the plugin directly. For more details, see <a href="https://developer.mozilla.org/en/Creating_OpenSearch_plugins_for_Firefox" target="_new">Creating OpenSearch plugins for Firefox.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.planetmarshall.co.uk/2009/11/searching-msdn-using-google/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Piano Recordings &#8211; Upright Piano</title>
		<link>http://www.planetmarshall.co.uk/2009/08/piano-recordings-upright-piano/</link>
		<comments>http://www.planetmarshall.co.uk/2009/08/piano-recordings-upright-piano/#comments</comments>
		<pubDate>Sun, 02 Aug 2009 23:41:45 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Music]]></category>
		<category><![CDATA[Piano]]></category>

		<guid isPermaLink="false">http://www.planetmarshall.co.uk/?p=333</guid>
		<description><![CDATA[This is the second in a series of attempts to do some piano recordings, a project which started out of a desire to conquer stagefright on the rare occasions that I perform in public. Increasingly I have been investigating the process in more depth, making use of Cubase and various recording techniques. The result of [...]]]></description>
			<content:encoded><![CDATA[
<a href="http://www.planetmarshall.co.uk/wp-content/gallery/music/grand.jpg" title="Piano recital at the Leys School in Cambridge. The piano is a Steinway model O." class="thickbox" rel="singlepic73" >
	<img class="ngg-singlepic ngg-left" src="http://www.planetmarshall.co.uk/wp-content/gallery/cache/73__x80_grand.jpg" alt="Not an upright piano. A Steinway model O, in fact." title="Not an upright piano. A Steinway model O, in fact." />
</a>

<p class="pm_first">This is the second in a series of attempts to do some piano recordings, a project which started out of a desire to conquer stagefright on the rare occasions that I perform in public. Increasingly I have been investigating the process in more depth, making use of Cubase and various recording techniques. The result of these investigations is this recording of Sergei Rachmaninoff&#8217;s Prelude in D Major, which I performed at a recital in June. This represents probably the best recording I can achieve given my upright piano and limited knowledge of recording techniques. The audio player requires <a href="http://silverlight.net" target="_new">Silverlight</a>, I have also provided a link to an mp3 file.</p>
<p><span id="more-333"></span></p>
<p><a href="http://www.planetmarshall.co.uk/music/Rach_Op23_4.mp3" target="_new">Prelude in D Major, Op3 No 4 by Sergei Rachmaninoff</a></p>
<p><div class="pm_header"><a onclick="pm_toggleCodeBlock(this,'4b995fbfacbba')">&#x25bc;</a> Silverlight Application</div><div id="4b995fbfacbba" style="display:" class="silverlightControlHost"><object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="400" height="60"><param name="source" value="http://www.planetmarshall.co.uk/silverlight/AudioPlayer.xap"/><param name="background" value="#212121" /><!--<param name="minRuntimeVersion" value="2.0.31005.0" />--><param name="enableHtmlAccess" value="true" /><a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;"><img src="http://storage.timheuer.com/sl4wp-ph.png" alt="Install Microsoft Silverlight" style="border-style: none; width:400px; height:60px"/></a></object><iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe></div><br /></p>
<h3>Setup</h3>
<p>
<a href="http://www.planetmarshall.co.uk/wp-content/gallery/music/upright_setup.jpg" title="Recording setup, ably assisted by Rowley the cat." class="thickbox" rel="singlepic74" >
	<img class="ngg-singlepic ngg-right" src="http://www.planetmarshall.co.uk/wp-content/gallery/cache/74__x150_upright_setup.jpg" alt="Upright piano and cat." title="Upright piano and cat." />
</a>
 This <a href="http://www.soundonsound.com/sos/jan08/articles/pianorecording_0108.htm" target="_new">article</a> from Sound on Sound describes a number of piano recording methods, including several for upright piano. The simple fact is that an upright piano is not a suitable instrument for recording, however by following some of the advice in the article I think i have probably got the best I can from the instrument and the equipment available. The picture on the right shows the setup, which is as follows</p>
<ul>
<li>Kawai upright piano</li>
<li>Alesis IO|2 stereo interface</li>
<li>Pair AKG Perceptron 150 microphones in crossed stereo configuration</li>
<li>Laptop computer running Cubase LE ( supplied with the Alesis hardware )</li>
</ul>
<p>Most of the kit is quite portable, so at some point I hope to repeat the experiment with a grand piano and compare the results.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.planetmarshall.co.uk/2009/08/piano-recordings-upright-piano/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using Merged ResourceDictionaries in Silverlight Themes</title>
		<link>http://www.planetmarshall.co.uk/2009/07/using-merged-resourcedictionaries-in-silverlight-themes/</link>
		<comments>http://www.planetmarshall.co.uk/2009/07/using-merged-resourcedictionaries-in-silverlight-themes/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 02:16:59 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://www.planetmarshall.co.uk/?p=303</guid>
		<description><![CDATA[Silverlight 3.0 moved its featureset closer to that of WPF by adding support for merged Resource Dictionaries and Style Inheritance. Without these features, developing custom templates and styles for Silverlight controls can become a bit of a copy-and-paste nightmare. Since I have used the implicit theming feature built into the Silverlight Toolkit to make my [...]]]></description>
			<content:encoded><![CDATA[<p class="pm_first"><span>S</span>ilverlight 3.0 moved its featureset closer to that of WPF by adding support for merged <a href="http://msdn.microsoft.com/en-us/library/cc903952%28VS.95%29.aspx" target="_new">Resource Dictionaries</a> and <a href="http://msdn.microsoft.com/en-us/library/system.windows.style.basedon%28VS.95%29.aspx" target="_new">Style Inheritance</a>. Without these features, developing custom templates and styles for Silverlight controls can become a bit of a copy-and-paste nightmare. Since I have used the implicit theming feature built into the <a href="http://www.codeplex.com/Silverlight" target="_new">Silverlight Toolkit</a> to make my Silverlight controls fit into the overall look and feel of this site, I was hoping that these features would enable me to refactor my themes developed for Silverlight 2.0 to be a bit less unwieldy.</p>
<p><span id="more-303"></span></p>
<h3>Silverlight toolkit themes do not support merged dictionaries</h3>
<p>Unfortunately, merged dictionaries are not supported by the Silverlight Toolkit&#8217;s Themes feature &#8211; at least not as it stands. For example, the following XAML and accompanying class causes a <code>XamlParseException</code> if you try to use it.</p>

<div class="wp_syntax">
<div class="wp_header"><a onclick="pm_toggleCodeBlock(this,'4b995fbfc8ff5')">&#x25ba;</a> Listing : </div><div id="4b995fbfc8ff5" style="display:none;" class="code"><div class="xml pm_syntax"><span class="sc3"><span class="re1">&lt;ResourceDictionary<span class="re2">&gt;</span></span></span><br />
&nbsp;<span class="sc3"><span class="re1">&lt;ResourceDictionary.MergedDictionaries<span class="re2">&gt;</span></span></span><br />
&nbsp; <span class="sc3"><span class="re1">&lt;ResourceDictionary</span> <span class="re0">Source</span>=<span class="st0">&quot;/MergedTheme;component/Styles/Button.xaml&quot;</span><span class="re2">/&gt;</span></span><br />
&nbsp;<span class="sc3"><span class="re1">&lt;ResourceDictionary.MergedDictionaries<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/ResourceDictionary<span class="re2">&gt;</span></span></span></div></div></div>


<div class="wp_syntax">
<div class="wp_header"><a onclick="pm_toggleCodeBlock(this,'4b995fbfc9d71')">&#x25ba;</a> Listing : </div><div id="4b995fbfc9d71" style="display:none;" class="code"><div class="csharp pm_syntax"><span class="kw1">public</span> <span class="kw4">class</span> MergedTheme <span class="sy0">:</span> Theme <span class="br0">&#123;</span><br />
&nbsp;<span class="kw1">public</span> MergedTheme<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">:</span> <br />
&nbsp; <span class="kw1">base</span><span class="br0">&#40;</span><span class="kw3">typeof</span><span class="br0">&#40;</span>MergedTheme<span class="br0">&#41;</span>.<span class="me1">Assembly</span>, <span class="st0">&quot;MergedTheme.Theme.xaml&quot;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; DefaultStyleKey <span class="sy0">=</span> <span class="kw3">typeof</span><span class="br0">&#40;</span>MergedTheme<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp;<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div></div></div>

<p>All is not lost however, since full source code is provided for the Silverlight Toolkit, so it becomes a straightforward matter to track down the problem and supply a patch. </p>
<h3>Writing a test to reproduce the problem</h3>
<p>Since the toolkit comes with an accompanying test suite, we proceed in textbook <a href="http://en.wikipedia.org/wiki/Test-driven_development" target="_new">TDD</a> fashion by first writing a test that exercises the issue. We can reuse some of the existing code to do this, adding a resource dictionary containing a merged dictionary reference and adding the following test to the <code>ImplicitStyleManagerTest</code> class</p>

<div class="wp_syntax">
<div class="wp_header"><a onclick="pm_toggleCodeBlock(this,'4b995fbfcc36e')">&#x25ba;</a> Listing : </div><div id="4b995fbfcc36e" style="display:none;" class="code"><div class="csharp pm_syntax"><span class="co1">/// &lt;summary&gt;</span><br />
<span class="co1">/// Test that styles contained in a &nbsp;merged dictionary can be successfully applied</span><br />
<span class="co1">/// &lt;/summary&gt;</span><br />
<span class="br0">&#91;</span>TestMethod<span class="br0">&#93;</span><br />
<span class="br0">&#91;</span>Asynchronous<span class="br0">&#93;</span><br />
<span class="br0">&#91;</span>Description<span class="br0">&#40;</span><span class="st0">&quot;Test that a dictionary contining merged dictionaries can be successfully loaded.&quot;</span><span class="br0">&#41;</span><span class="br0">&#93;</span><br />
<span class="kw1">public</span> <span class="kw1">void</span> TestResourceDictionaryWithMergedDictionaries<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp;Uri uri <span class="sy0">=</span> <span class="kw3">new</span> Uri<span class="br0">&#40;</span><span class="st0">&quot;System.Windows.Controls.Testing.Theming;<br />
&nbsp; component/ImplicitStyleManager/MergedResourceDictionary.xaml&quot;</span>, UriKind.<span class="me1">Relative</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp;TestAuto<span class="br0">&#40;</span> <span class="br0">&#40;</span>stackPanel<span class="br0">&#41;</span> <span class="sy0">=&gt;</span> <span class="br0">&#123;</span><br />
&nbsp; SetResourceDictionaryUri<span class="br0">&#40;</span>stackPanel, uri<span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; ImplicitStyleManager.<span class="me1">SetApplyMode</span><span class="br0">&#40;</span>stackPanel, ImplicitStylesApplyMode.<span class="kw1">Auto</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; <span class="br0">&#125;</span>, Colors.<span class="me1">Blue</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
<span class="br0">&#125;</span></div></div></div>

<p>The test fails as we would expect.</p>

<!-- collapsible header -->

<div class="pm_header"><a onclick="pm_toggleCodeBlock(this,'4b995fbfc69c6')">&#x25ba;</a> Figure : The test written to exercise the bug fails as expected.</div>
<div id="4b995fbfc69c6" style="display:none;">
<a href="http://www.planetmarshall.co.uk/wp-content/gallery/sltoolkit/testfail.png" title="The test written to exercise the bug fails as expected." class="thickbox" rel="singlepic70" >
	<img class="ngg-singlepic" src="http://www.planetmarshall.co.uk/wp-content/gallery/cache/70__x_testfail.png" alt="Failing unit test" title="Failing unit test" />
</a>
</div>

<h3>Fix the code to make the test pass</h3>
<p>The Theme class works by transforming the<code> ResourceDictionary</code> xaml into a <code>ContentControl</code>. A quick glance at the xaml generated by this process in the Visual Studio debugger shows why an exception is being raised.</p>

<div class="wp_syntax">
<div class="wp_header"><a onclick="pm_toggleCodeBlock(this,'4b995fbfcf354')">&#x25ba;</a> Listing : </div><div id="4b995fbfcf354" style="display:none;" class="code"><div class="xml pm_syntax"><span class="sc3"><span class="re1">&lt;ContentControl<span class="re2">&gt;</span></span></span><br />
&nbsp;<span class="sc3"><span class="re1">&lt;ContentControl.Resources<span class="re2">&gt;</span></span></span><br />
&nbsp; <span class="sc3"><span class="re1">&lt;ResourceDictionary.MergedDictionaries<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp;<span class="sc3"><span class="re1">&lt;ResourceDictionary</span> <span class="re0">Source</span>=<span class="st0">&quot;[...]/ResourceDictionaryForMerge.xaml&quot;</span> <span class="re2">/&gt;</span></span> <br />
&nbsp; <span class="sc3"><span class="re1">&lt;/ResourceDictionary.MergedDictionaries<span class="re2">&gt;</span></span></span><br />
&nbsp;<span class="sc3"><span class="re1">&lt;/ContentControl.Resources<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/ContentControl<span class="re2">&gt;</span></span></span></div></div></div>

<p>The <code>ResourceDictionary.MergedDictionaries</code> element is missing its parent <code>ResourceDictionary</code> element, so we add a couple of lines of code to ResourceParser.ParseElement to detect the element and wrap it in a <code>ResourceDictionary</code>, using LINQ to XML.</p>

<div class="wp_syntax">
<div class="wp_header"><a onclick="pm_toggleCodeBlock(this,'4b995fbfd030b')">&#x25ba;</a> Listing : </div><div id="4b995fbfd030b" style="display:none;" class="code"><div class="csharp pm_syntax"><span class="kw1">private</span> <span class="kw1">static</span> <span class="kw1">void</span> ParseElement<span class="br0">&#40;</span>XmlReader reader, XmlWriter writer, <span class="kw4">bool</span> checkTypes<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp;<span class="kw1">if</span> <span class="br0">&#40;</span>reader.<span class="me1">Depth</span> <span class="sy0">==</span> <span class="nu0">0</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>...<span class="br0">&#125;</span><br />
&nbsp;<span class="kw1">else</span> <span class="br0">&#123;</span><br />
&nbsp; <span class="co1">// handle merged dictionaries by wrapping them in a ResourceDictionary element</span><br />
&nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>reader.<span class="me1">Name</span> <span class="sy0">==</span> <span class="st0">&quot;ResourceDictionary.MergedDictionaries&quot;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp;XElement parent <span class="sy0">=</span> <span class="kw3">new</span> XElement<span class="br0">&#40;</span><span class="st0">&quot;ResourceDictionary&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp;parent.<span class="me1">Add</span><span class="br0">&#40;</span>XElement.<span class="me1">ReadFrom</span><span class="br0">&#40;</span>reader<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; &nbsp;writer.<span class="me1">WriteRaw</span><span class="br0">&#40;</span>parent.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span><br />
&nbsp; <span class="br0">&#125;</span><br />
&nbsp; <span class="kw1">else</span> <span class="br0">&#123;</span> ... <span class="br0">&#125;</span><br />
&nbsp;<span class="br0">&#125;</span> &nbsp; <br />
<span class="br0">&#125;</span></div></div></div>

<p>Having made the change, we rerun the test.</p>

<!-- collapsible header -->

<div class="pm_header"><a onclick="pm_toggleCodeBlock(this,'4b995fbfc7a9c')">&#x25ba;</a> Figure : How I love the green bar</div>
<div id="4b995fbfc7a9c" style="display:none;">
<a href="http://www.planetmarshall.co.uk/wp-content/gallery/sltoolkit/testpass.png" title="How I love the green bar" class="thickbox" rel="singlepic71" >
	<img class="ngg-singlepic" src="http://www.planetmarshall.co.uk/wp-content/gallery/cache/71__x_testpass.png" alt="How I love the green bar" title="How I love the green bar" />
</a>
</div>

<p>As we would hope, our custom theme now works as expected and we also have a unit test that ensures the bug does not reoccur. Note the Xaml code above, in that the Resource Dictionary is referenced using <a href="http://msdn.microsoft.com/en-us/library/aa970069.aspx" target="_new">Pack Uri</a> syntax. This is because <code>Button.xaml</code> is compiled as a Resource, rather than Content, since the latter doesn&#8217;t appear to work reliably and can result in obfuscated error messages such as <i>XamlParseException: attribute &#8220;Button.xaml&#8221; value out of range.</i></p>

<!-- collapsible header -->

<div class="pm_header"><a onclick="pm_toggleCodeBlock(this,'4b995fbfc8a7f')">&#x25ba;</a> Figure : The button on the right gets its theme from a merged ResourceDictionary</div>
<div id="4b995fbfc8a7f" style="display:none;">
<a href="http://www.planetmarshall.co.uk/wp-content/gallery/sltoolkit/themed.png" title="The button on the right gets its theme from a merged ResourceDictionary" class="thickbox" rel="singlepic72" >
	<img class="ngg-singlepic" src="http://www.planetmarshall.co.uk/wp-content/gallery/cache/72__x_themed.png" alt="Themed controls" title="Themed controls" />
</a>
</div>

<p>I have submitted the patch for this fix to the toolkit site on Codeplex.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.planetmarshall.co.uk/2009/07/using-merged-resourcedictionaries-in-silverlight-themes/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Piano Recordings</title>
		<link>http://www.planetmarshall.co.uk/2009/04/piano-recordings/</link>
		<comments>http://www.planetmarshall.co.uk/2009/04/piano-recordings/#comments</comments>
		<pubDate>Sun, 19 Apr 2009 17:18:44 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Music]]></category>
		<category><![CDATA[Piano]]></category>

		<guid isPermaLink="false">http://www.planetmarshall.co.uk/?p=268</guid>
		<description><![CDATA[
Prelude in C&#x266f; Minor by Sergei Rachmaninoff.
In December I had my first piano recital in nearly two years, and so I started to look into various methods that performers use to conquer performance anxiety, something which causes me a lot of grief. Lately I&#8217;ve been hanging around with a number of friends involved in Cambridge&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p><br/><br />
<a href="http://www.planetmarshall.co.uk/music/Rach_Op3_2.mp3">Prelude in C&#x266f; Minor by Sergei Rachmaninoff.</a></p>
<p class="pm_first"><span>I</span>n December I had my first piano recital in nearly two years, and so I started to look into various methods that performers use to conquer performance anxiety, something which causes me a lot of grief. Lately I&#8217;ve been hanging around with a number of friends involved in Cambridge&#8217;s thriving local music scene, and so not willing to go the beta blockers route I started thinking about doing some recordings. This way not only do I get to hear what the audience hears but it also reproduces some of the pressure that comes with performing for an audience. The audiofile above is my first effort, a recording of Sergei Rachmaninoff&#8217;s Prelude in C&#x266f; Minor.</p>
<p><span id="more-268"></span></p>
<p>Ok, nobody&#8217;s ever going to sign me up for any recording contracts and there were a number of dodgy chords in that last section but I thought it was pretty good for a first effort. It was recorded in one take and I haven&#8217;t added anything else since the whole point of this exercise is as practice for a live performance.</p>
<h3>Kit</h3>
<p>
<a href="http://www.planetmarshall.co.uk/wp-content/gallery/music/io2_angle_lg.jpg" title="" class="thickbox" rel="singlepic27" >
	<img class="ngg-singlepic ngg-left" src="http://www.planetmarshall.co.uk/wp-content/gallery/cache/27__150x100_io2_angle_lg.jpg" alt="io2_angle_lg.jpg" title="io2_angle_lg.jpg" />
</a>
 I spent a little under £200 ( excluding the piano and the laptop ) on the recording kit, from <a href="http://www.dv247.com/" target="_new">Digital Village</a> in Cambridge. I used an <a target="_new" href="http://www.alesis.com/io2">Alesis IO|2</a> stereo mixer attached to a laptop running a cutdown version of <a href="http://www.steinberg.net/en/products/musicproduction/cubaseessential4_product.html" target="_new">Cubase</a> that came with the mixer, and a couple of cheap microphones stuffed down the piano cabinet and secured with parcel tape. The piano is a fairly largish Kawai upright.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.planetmarshall.co.uk/2009/04/piano-recordings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Implementation of the Reaction Diffusion Simulation</title>
		<link>http://www.planetmarshall.co.uk/2009/04/implentation-of-the-reaction-diffusion-simulation/</link>
		<comments>http://www.planetmarshall.co.uk/2009/04/implentation-of-the-reaction-diffusion-simulation/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 09:34:08 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://www.planetmarshall.co.uk/?p=111</guid>
		<description><![CDATA[Update &#8211; This post was written before the release of Silverlight 3.0b, which provides a number of enhancements relevant to this implementation, such as a WriteableBitmap and Pixel Shaders
Rendering
The first obstacle to implementing the RD simulation is that Silverlight 2.0 does not by default provide a means of generating dynamic images. WPF has a WriteableBitmap, [...]]]></description>
			<content:encoded><![CDATA[<p>
<a href="http://www.planetmarshall.co.uk/wp-content/gallery/reaction_diffusion/blood.png" title="" class="thickbox" rel="singlepic65" >
	<img class="ngg-singlepic ngg-left" src="http://www.planetmarshall.co.uk/wp-content/gallery/cache/65__x96_blood.png" alt="blood.png" title="blood.png" />
</a>
<em>Update &#8211; This post was written before the release of <a href="http://silverlight.net/getstarted/silverlight3/default.aspx" target="_new">Silverlight 3.0b</a>, which provides a number of enhancements relevant to this implementation, such as a WriteableBitmap and Pixel Shaders</em></p>
<h3>Rendering</h3>
<p>The first obstacle to implementing the <a href="http://www.planetmarshall.co.uk/index.php/2009/03/reaction-diffusion-models/">RD simulation</a> is that Silverlight 2.0 does not by default provide a means of generating dynamic images. WPF has a WriteableBitmap, but no equivalent exists in Silverlight. However, it does support PNG streams so we can dynamically update a bitmap by encoding it to PNG on the fly. For this I have used <a href="http://blogs.msdn.com/jstegman/default.aspx">Joe Stegman&#8217;s</a> <a href="http://blogs.msdn.com/jstegman/archive/2008/10/27/silverlight-2-sample-updates.aspx">PNGEncoder </a>class, which I have modified slightly to deal with RGB data and to reduce memory usage.<br />
<span id="more-111"></span></p>
<h3>Performance notes</h3>
<p>
<a href="http://www.planetmarshall.co.uk/wp-content/gallery/reaction_diffusion/waves.png" title="" class="thickbox" rel="singlepic69" >
	<img class="ngg-singlepic ngg-right" src="http://www.planetmarshall.co.uk/wp-content/gallery/cache/69__x96_waves.png" alt="waves.png" title="waves.png" />
</a>
Performance of the simulator is dominated by the time it takes to update the arrays containing the concentration values of the chemicals. Actual rendering time is negligible, even though the image has to be dynamically encoded to a PNG file in order for Silverlight to display it. There are two ways of implementing 2D arrays in Silverlight with C#, rectangular arrays or C style jagged arrays. If this were a desktop application, the most performant method would be to use rectangular arrays and unsafe access, however that option is not available to us in Silverlight so it turns out that, for safe access, jagged arrays are faster.</p>
<p>For example, originally the simulation step looked like this</p>

<div class="wp_syntax">
<div class="wp_header"><a onclick="pm_toggleCodeBlock(this,'4b995fbff348d')">&#x25ba;</a> Listing : Rectangular array implementation</div><div id="4b995fbff348d" style="display:none;" class="code"><div class="csharp pm_syntax"><span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw4">int</span> j <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span> j <span class="sy0">&amp;</span>lt<span class="sy0">;</span> H<span class="sy0">;</span> j<span class="sy0">++</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp;<span class="kw4">int</span> jm <span class="sy0">=</span> j <span class="sy0">!=</span> <span class="nu0">0</span> <span class="sy0">?</span> j <span class="sy0">-</span> <span class="nu0">1</span> <span class="sy0">:</span> H <span class="sy0">-</span> <span class="nu0">1</span><span class="sy0">;</span><br />
&nbsp;<span class="kw4">int</span> jp <span class="sy0">=</span> j <span class="sy0">!=</span> H <span class="sy0">-</span> <span class="nu0">1</span> <span class="sy0">?</span> j <span class="sy0">+</span> <span class="nu0">1</span> <span class="sy0">:</span> <span class="nu0">0</span><span class="sy0">;</span><br />
&nbsp;<span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw4">int</span> i <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span> i <span class="sy0">&amp;</span>lt<span class="sy0">;</span> W<span class="sy0">;</span> i<span class="sy0">++</span><span class="br0">&#41;</span><br />
&nbsp;<span class="br0">&#123;</span><br />
&nbsp; <span class="kw4">int</span> im <span class="sy0">=</span> i <span class="sy0">!=</span> <span class="nu0">0</span> <span class="sy0">?</span> i <span class="sy0">-</span> <span class="nu0">1</span> <span class="sy0">:</span> W <span class="sy0">-</span> <span class="nu0">1</span><span class="sy0">;</span><br />
&nbsp; <span class="kw4">int</span> ip <span class="sy0">=</span> i <span class="sy0">!=</span> W <span class="sy0">-</span> <span class="nu0">1</span> <span class="sy0">?</span> i <span class="sy0">+</span> <span class="nu0">1</span> <span class="sy0">:</span> <span class="nu0">0</span><span class="sy0">;</span><br />
&nbsp; <span class="kw4">double</span> d2u <span class="sy0">=</span> U<span class="br0">&#91;</span>j,im<span class="br0">&#93;</span><span class="sy0">+</span>U<span class="br0">&#91;</span>j,ip<span class="br0">&#93;</span><span class="sy0">+</span>U<span class="br0">&#91;</span>jm,i<span class="br0">&#93;</span><span class="sy0">+</span>U<span class="br0">&#91;</span>jp,i<span class="br0">&#93;</span><span class="sy0">-</span><span class="nu0">4</span><span class="sy0">*</span>U<span class="br0">&#91;</span>j,i<span class="br0">&#93;</span><span class="sy0">;</span><br />
&nbsp; <span class="kw4">double</span> d2v <span class="sy0">=</span> V<span class="br0">&#91;</span>j,im<span class="br0">&#93;</span><span class="sy0">+</span>V<span class="br0">&#91;</span>j,ip<span class="br0">&#93;</span><span class="sy0">+</span>V<span class="br0">&#91;</span>jm,i<span class="br0">&#93;</span><span class="sy0">+</span>V<span class="br0">&#91;</span>jp,i<span class="br0">&#93;</span><span class="sy0">-</span><span class="nu0">4</span><span class="sy0">*</span>V<span class="br0">&#91;</span>j,i<span class="br0">&#93;</span><span class="sy0">;</span><br />
&nbsp; <span class="kw4">double</span> uv2 <span class="sy0">=</span> U<span class="br0">&#91;</span>j,i<span class="br0">&#93;</span><span class="sy0">*</span>V<span class="br0">&#91;</span>j,i<span class="br0">&#93;</span><span class="sy0">*</span>V<span class="br0">&#91;</span>j,i<span class="br0">&#93;</span><span class="sy0">;</span><br />
&nbsp; Uu<span class="br0">&#91;</span>j,i<span class="br0">&#93;</span> <span class="sy0">=</span> du<span class="sy0">*</span>d2u<span class="sy0">-</span>uv2<span class="sy0">+</span>F<span class="sy0">+</span>U<span class="br0">&#91;</span>j,i<span class="br0">&#93;</span><span class="sy0">*</span>one_minus_F<span class="sy0">;</span><br />
&nbsp; Vv<span class="br0">&#91;</span>j,i<span class="br0">&#93;</span> <span class="sy0">=</span> dv<span class="sy0">*</span>d2v<span class="sy0">+</span>uv2<span class="sy0">+</span>V<span class="br0">&#91;</span>j,i<span class="br0">&#93;</span><span class="sy0">*</span>one_minus_F_minus_k<span class="sy0">;</span><br />
&nbsp;<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div></div></div>

<p>On my machine this took on the order of 600ms to perform 100 iterations. Using jagged arrays instead, we have the following</p>

<div class="wp_syntax">
<div class="wp_header"><a onclick="pm_toggleCodeBlock(this,'4b995fc0033db')">&#x25ba;</a> Listing : Jagged array implementation</div><div id="4b995fc0033db" style="display:none;" class="code"><div class="csharp pm_syntax"><span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw4">int</span> j <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span> j <span class="sy0">&amp;</span>lt<span class="sy0">;</span> H<span class="sy0">;</span> j<span class="sy0">++</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp;<span class="kw4">int</span> jm <span class="sy0">=</span> j <span class="sy0">!=</span> <span class="nu0">0</span> <span class="sy0">?</span> j <span class="sy0">-</span> <span class="nu0">1</span> <span class="sy0">:</span> H <span class="sy0">-</span> <span class="nu0">1</span><span class="sy0">;</span><br />
&nbsp;<span class="kw4">int</span> jp <span class="sy0">=</span> j <span class="sy0">!=</span> H <span class="sy0">-</span> <span class="nu0">1</span> <span class="sy0">?</span> j <span class="sy0">+</span> <span class="nu0">1</span> <span class="sy0">:</span> <span class="nu0">0</span><span class="sy0">;</span><br />
&nbsp;<span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw4">int</span> i <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span> i <span class="sy0">&amp;</span>lt<span class="sy0">;</span> W<span class="sy0">;</span> i<span class="sy0">++</span><span class="br0">&#41;</span><br />
&nbsp;<span class="br0">&#123;</span><br />
&nbsp; <span class="kw4">int</span> im <span class="sy0">=</span> i <span class="sy0">!=</span> <span class="nu0">0</span> <span class="sy0">?</span> i <span class="sy0">-</span> <span class="nu0">1</span> <span class="sy0">:</span> W <span class="sy0">-</span> <span class="nu0">1</span><span class="sy0">;</span><br />
&nbsp; <span class="kw4">int</span> ip <span class="sy0">=</span> i <span class="sy0">!=</span> W <span class="sy0">-</span> <span class="nu0">1</span> <span class="sy0">?</span> i <span class="sy0">+</span> <span class="nu0">1</span> <span class="sy0">:</span> <span class="nu0">0</span><span class="sy0">;</span><br />
&nbsp; <span class="kw4">double</span> d2u <span class="sy0">=</span> U<span class="br0">&#91;</span>j<span class="br0">&#93;</span><span class="br0">&#91;</span>im<span class="br0">&#93;</span><span class="sy0">+</span>U<span class="br0">&#91;</span>j<span class="br0">&#93;</span><span class="br0">&#91;</span>ip<span class="br0">&#93;</span><span class="sy0">+</span>U<span class="br0">&#91;</span>jm<span class="br0">&#93;</span><span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="sy0">+</span>U<span class="br0">&#91;</span>jp<span class="br0">&#93;</span><span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="sy0">-</span><span class="nu0">4</span><span class="sy0">*</span>U<span class="br0">&#91;</span>j<span class="br0">&#93;</span><span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="sy0">;</span><br />
&nbsp; <span class="kw4">double</span> d2v <span class="sy0">=</span> V<span class="br0">&#91;</span>j<span class="br0">&#93;</span><span class="br0">&#91;</span>im<span class="br0">&#93;</span><span class="sy0">+</span>V<span class="br0">&#91;</span>j<span class="br0">&#93;</span><span class="br0">&#91;</span>ip<span class="br0">&#93;</span><span class="sy0">+</span>V<span class="br0">&#91;</span>jm<span class="br0">&#93;</span><span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="sy0">+</span>V<span class="br0">&#91;</span>jp<span class="br0">&#93;</span><span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="sy0">-</span><span class="nu0">4</span><span class="sy0">*</span>V<span class="br0">&#91;</span>j<span class="br0">&#93;</span><span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="sy0">;</span><br />
&nbsp; <span class="kw4">double</span> uv2 <span class="sy0">=</span> U<span class="br0">&#91;</span>j<span class="br0">&#93;</span><span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="sy0">*</span>V<span class="br0">&#91;</span>j<span class="br0">&#93;</span><span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="sy0">*</span>V<span class="br0">&#91;</span>j<span class="br0">&#93;</span><span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="sy0">;</span><br />
&nbsp; Uu<span class="br0">&#91;</span>j<span class="br0">&#93;</span><span class="br0">&#91;</span>i<span class="br0">&#93;</span> <span class="sy0">=</span> du<span class="sy0">*</span>d2u<span class="sy0">-</span>uv2<span class="sy0">+</span> F<span class="sy0">+</span>U<span class="br0">&#91;</span>j<span class="br0">&#93;</span><span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="sy0">*</span>one_minus_F<span class="sy0">;</span><br />
&nbsp; Vv<span class="br0">&#91;</span>j<span class="br0">&#93;</span><span class="br0">&#91;</span>i<span class="br0">&#93;</span> <span class="sy0">=</span> dv<span class="sy0">*</span>d2v<span class="sy0">+</span>uv2<span class="sy0">+</span>V<span class="br0">&#91;</span>j<span class="br0">&#93;</span><span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="sy0">*</span>one_minus_F_minus_k<span class="sy0">;</span><br />
&nbsp;<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div></div></div>

<p>Just replacing the array type and making no other changes this now takes about 500ms, an improvement of about 13%. However, now that we are using jagged arrays we can do better and move the row accesses out of the inner loop.</p>

<div class="wp_syntax">
<div class="wp_header"><a onclick="pm_toggleCodeBlock(this,'4b995fc007839')">&#x25ba;</a> Listing : Jagged array with outer loop caching</div><div id="4b995fc007839" style="display:none;" class="code"><div class="csharp pm_syntax"><span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw4">int</span> j <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span> j <span class="sy0">&amp;</span>lt<span class="sy0">;</span> H<span class="sy0">;</span> j<span class="sy0">++</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp;<span class="kw4">int</span> jm <span class="sy0">=</span> j <span class="sy0">!=</span> <span class="nu0">0</span> <span class="sy0">?</span> j <span class="sy0">-</span> <span class="nu0">1</span> <span class="sy0">:</span> H <span class="sy0">-</span> <span class="nu0">1</span><span class="sy0">;</span><br />
&nbsp;<span class="kw4">int</span> jp <span class="sy0">=</span> j <span class="sy0">!=</span> H <span class="sy0">-</span> <span class="nu0">1</span> <span class="sy0">?</span> j <span class="sy0">+</span> <span class="nu0">1</span> <span class="sy0">:</span> <span class="nu0">0</span><span class="sy0">;</span><br />
&nbsp;<span class="kw4">var</span> u_m <span class="sy0">=</span> U<span class="br0">&#91;</span>jm<span class="br0">&#93;</span><span class="sy0">;</span><br />
&nbsp;<span class="kw4">var</span> u <span class="sy0">=</span> U<span class="br0">&#91;</span>j<span class="br0">&#93;</span><span class="sy0">;</span><br />
&nbsp;<span class="kw4">var</span> u_p <span class="sy0">=</span> U<span class="br0">&#91;</span>jp<span class="br0">&#93;</span><span class="sy0">;</span><br />
&nbsp;<span class="kw4">var</span> v_m <span class="sy0">=</span> V<span class="br0">&#91;</span>jm<span class="br0">&#93;</span><span class="sy0">;</span><br />
&nbsp;<span class="kw4">var</span> v <span class="sy0">=</span> V<span class="br0">&#91;</span>j<span class="br0">&#93;</span><span class="sy0">;</span><br />
&nbsp;<span class="kw4">var</span> v_p <span class="sy0">=</span> V<span class="br0">&#91;</span>jp<span class="br0">&#93;</span><span class="sy0">;</span><br />
&nbsp;<span class="kw4">var</span> uu <span class="sy0">=</span> Uu<span class="br0">&#91;</span>j<span class="br0">&#93;</span><span class="sy0">;</span><br />
&nbsp;<span class="kw4">var</span> vv <span class="sy0">=</span> Vv<span class="br0">&#91;</span>j<span class="br0">&#93;</span><span class="sy0">;</span><br />
&nbsp;<span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw4">int</span> i <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">;</span> i <span class="sy0">&amp;</span>lt<span class="sy0">;</span> W<span class="sy0">;</span> i<span class="sy0">++</span><span class="br0">&#41;</span><br />
&nbsp;<span class="br0">&#123;</span><br />
&nbsp; <span class="kw4">int</span> im <span class="sy0">=</span> i <span class="sy0">!=</span> <span class="nu0">0</span> <span class="sy0">?</span> i <span class="sy0">-</span> <span class="nu0">1</span> <span class="sy0">:</span> W <span class="sy0">-</span> <span class="nu0">1</span><span class="sy0">;</span><br />
&nbsp; <span class="kw4">int</span> ip <span class="sy0">=</span> i <span class="sy0">!=</span> W <span class="sy0">-</span> <span class="nu0">1</span> <span class="sy0">?</span> i <span class="sy0">+</span> <span class="nu0">1</span> <span class="sy0">:</span> <span class="nu0">0</span><span class="sy0">;</span><br />
&nbsp; <span class="kw4">double</span> d2u <span class="sy0">=</span> u<span class="br0">&#91;</span>im<span class="br0">&#93;</span><span class="sy0">+</span>u<span class="br0">&#91;</span>ip<span class="br0">&#93;</span><span class="sy0">+</span>u_m<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="sy0">+</span>u_p<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="sy0">-</span><span class="nu0">4</span><span class="sy0">*</span>u<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="sy0">;</span><br />
&nbsp; <span class="kw4">double</span> d2v <span class="sy0">=</span> v<span class="br0">&#91;</span>im<span class="br0">&#93;</span><span class="sy0">+</span>v<span class="br0">&#91;</span>ip<span class="br0">&#93;</span><span class="sy0">+</span>v_m<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="sy0">+</span>v_p<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="sy0">-</span><span class="nu0">4</span><span class="sy0">*</span>v<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="sy0">;</span><br />
&nbsp; <span class="kw4">double</span> uv2 <span class="sy0">=</span> u<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="sy0">*</span>v<span class="br0">&#91;</span>i<span class="br0">&#93;</span> <span class="sy0">*</span>v<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="sy0">;</span><br />
&nbsp; uu<span class="br0">&#91;</span>i<span class="br0">&#93;</span> <span class="sy0">=</span> du<span class="sy0">*</span>d2u<span class="sy0">-</span>uv2<span class="sy0">+</span>F<span class="sy0">+</span>u<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="sy0">*</span>one_minus_F<span class="sy0">;</span><br />
&nbsp; vv<span class="br0">&#91;</span>i<span class="br0">&#93;</span> <span class="sy0">=</span> dv<span class="sy0">*</span>d2v<span class="sy0">+</span>uv2<span class="sy0">+</span>v<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="sy0">*</span>one_minus_F_minus_k<span class="sy0">;</span><br />
&nbsp;<span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div></div></div>

<p>This brings the count down to about 330ms, an improvement of about 40% over the original implementation.</p>
<p>We&#8217;ve taken the sequential code about as far as we can go. The next step is to try to take advantage of muliple cores that may be available on the user&#8217;s machine.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.planetmarshall.co.uk/2009/04/implentation-of-the-reaction-diffusion-simulation/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>London Triathlon 2008</title>
		<link>http://www.planetmarshall.co.uk/2009/04/london-triathlon-2008/</link>
		<comments>http://www.planetmarshall.co.uk/2009/04/london-triathlon-2008/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 17:57:16 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Sport]]></category>
		<category><![CDATA[Triathlon]]></category>
		<category><![CDATA[Cycling]]></category>
		<category><![CDATA[Running]]></category>
		<category><![CDATA[Swimming]]></category>

		<guid isPermaLink="false">http://www.planetmarshall.co.uk/?p=220</guid>
		<description><![CDATA[Somewhat late, since I have had pictures on my facebook profile for months, but I thought I should add a post about my experiences at the London Triathlon in August 2008. This was the second of three major endurance events I completed in 2008, the others being the Blenheim Triathlon and the New York Marathon, [...]]]></description>
			<content:encoded><![CDATA[
<a href="http://www.planetmarshall.co.uk/wp-content/gallery/london/medal.jpg" title="" class="thickbox" rel="singlepic61" >
	<img class="ngg-singlepic ngg-right" src="http://www.planetmarshall.co.uk/wp-content/gallery/cache/61__x150_medal.jpg" alt="medal.jpg" title="medal.jpg" />
</a>

<p class="pm_first"><span>S</span>omewhat late, since I have had pictures on my facebook profile for months, but I thought I should add a post about my experiences at the London Triathlon in August 2008. This was the second of three major endurance events I completed in 2008, the others being the <a href="http://www.planetmarshall.co.uk/index.php/2008/07/blenheim_triathlon_2008/">Blenheim Triathlon</a> and the <a href="http://www.planetmarshall.co.uk/index.php/2008/11/new-york-city-marathon-2008/">New York Marathon</a>, in aid of <a href="http://www.epilepsyresearch.org.uk/" target="_new">Epilepsy Research UK</a>. I would like to thank everyone who generously sponsored me for those events, your donations have since been passed on to the charity and will be put towards improving the quality of life for eplieptics who suffer from more severe symptoms than my own.<br />
<span id="more-220"></span></p>
<h3>The Joy of Weekend Engineering Works</h3>
<p>The <a href="http://www.thelondontriathlon.co.uk/" target="_new">Mazda London Triathlon</a> was my first Olympic distance event, a 1500m swim, 40km cycle and 10k run. Since I had already had something of a dry run at Blenheim I knew largely what to expect during the race itself. this time however there were no generous family members around to provide transportation, so that was my responsibility, and I don&#8217;t drive. Unfortunately, National Express or whoever was running East Anglia&#8217;s railways that particular week had picked Sunday 10th August for engineering works between and Cambridge and Audley End. Audley End is a 15 mile cycle from Cambridge, quite a nice cycle on any other day, but one I could have done without on the day I&#8217;m supposed to competing in a Triathlon. If that weren&#8217;t bad enough, the first train to arrive broke down and I had to wait 45 minutes for the next one. The accumulation of delays reduced the 2 hour buffer with which I had left myself to prepare to about 30 minutes and seriously threatened my participation in the race.</p>
<h3>The Swim</h3>
<p>
<a href="http://www.planetmarshall.co.uk/wp-content/gallery/london/swim_1.jpg" title="" class="thickbox" rel="singlepic64" >
	<img class="ngg-singlepic ngg-left" src="http://www.planetmarshall.co.uk/wp-content/gallery/cache/64__x150_swim_1.jpg" alt="swim_1.jpg" title="swim_1.jpg" />
</a>
Had I not participated this article would have been rather pointless, so suffice to say all problems were resolved and I made it to the ExCel centre and into Prince Albert dock for the beginning of the swim. As at Blenheim I was surprised at the number of triathletes who hadn&#8217;t done any open water swimming preparation &#8211; I certainly would not have liked that to be my first experience of it. Probably the most depressing part is that the markers for the super sprint and sprint distances were still up, so my initial thought was along the lines of, Oh, its not that far. No wait, that&#8217;s for the 400m race, it must be the next one. No, that&#8217;s for the 750m race. The marker for the 1500m race was a blurry orange blob in the distance somewhere near Dover. 1500m, a distance I can cover in less than 5 minutes on foot, is a hell of a long way in open water. </p>
<p>The start of a triathlon is a rather chaotic affair, advice is often given for novices to stay near the back and it&#8217;s advice I would be inclined to take. The stronger swimmers can make the rest of us minnows feel a bit like a cat in a washing machine during the early stages. Incidentally, it was at this point that I lost my GPS, which now lies at the bottom of Prince Albert dock. Do not be tempted to take yours into the water, leave it for the cycle and the run. </p>
<h3>The Cycle</h3>
<p>
<a href="http://www.planetmarshall.co.uk/wp-content/gallery/london/bike_2.jpg" title="" class="thickbox" rel="singlepic57" >
	<img class="ngg-singlepic ngg-right" src="http://www.planetmarshall.co.uk/wp-content/gallery/cache/57__x150_bike_2.jpg" alt="bike_2.jpg" title="bike_2.jpg" />
</a>
Whoever organizes the Mazda events seems to be intent on making the transitions as painful as possible. In Blenheim there was a 400m uphill run out of the water, in London there is a flight of stairs after the swim, which left me barely able to breathe. Nonetheless, even without the GPS, the cycle is by a huge margin my favourite event and at that time was the only part of the triathlon where I feel I can really compete and not just hold my own. I still had my rather old fashioned road bike but I had finally invested in a set of SPD pedals and, having gone through the baptism of traffic light embarassments, was keen to see what improvement they might make.</p>
<p>There is a certain amount of Schadenfreude to be enjoyed when overtaking someone who clearly spent more on their bicycle than some people do on their cars, with an 8 year old road bike that originally cost less than £200 ( ok, it&#8217;s had a few upgrades since then ). Of course, this is just making up for the experience of being overtaken in the water by people twice my age doing breaststroke, so I cannot allow myself to feel too smug about it.</p>
<p>As I said, I didn&#8217;t have the GPS so couldn&#8217;t be too accurate about pace but I found someone who was just slightly above my standard and followed them around the route ( not too close though, drafting is illegal in most Triathlons, including this one ).</p>
<h3>The Run</h3>
<p>
<a href="http://www.planetmarshall.co.uk/wp-content/gallery/london/run_2.jpg" title="" class="thickbox" rel="singlepic63" >
	<img class="ngg-singlepic ngg-left" src="http://www.planetmarshall.co.uk/wp-content/gallery/cache/63__x150_run_2.jpg" alt="run_2.jpg" title="run_2.jpg" />
</a>
A word about T2 ( the cycle->run transition ) in the London race. The ExCel centre is huge, as anyone who&#8217;s ever been to a conference there will know. Transition to the 10k run involved running around most of the perimeter of the event hall, which, from a rough calculation, is about 400m. That&#8217;s just transition, and is not actually part of the run component but it is mitigated somewhat in that the actual run is slightly short of the standard 10km. This was the most difficult part of the race, as the leg muscles adapt to the difference between cycling and running and at one point I didn&#8217;t think I was actually going to make it out of the conference centre. It was painful, and involved no small amount of willpower to keep going.</p>
<p>Once that transition period is over though the previous disciplines are forgotten and it becomes all about the run. I am a better 10k runner than I was, but even at that time I was good enough to enjoy it particularly without the blistering heat we had enjoyed at <a href="http://www.planetmarshall.co.uk/index.php/2008/07/blenheim_triathlon_2008/">Blenheim</a> in June. The difficult part is that it is a 2 lap race, so there is a psychological impact when you come to the end of the first lap and see the runners ahead of you finishing, knowing that you still have 5,000m to run. At the end of the second lap, there is a punishing uphill ramp to the finishing straight and it was at this final point that I was overtaken by someone who had decided to do a sprint finish and I still regret not taking him on. Next time.</p>
<h3>Finish</h3>
<p>
<a href="http://www.planetmarshall.co.uk/wp-content/gallery/london/finish_1.jpg" title="" class="thickbox" rel="singlepic60" >
	<img class="ngg-singlepic ngg-right" src="http://www.planetmarshall.co.uk/wp-content/gallery/cache/60__x150_finish_1.jpg" alt="finish_1.jpg" title="finish_1.jpg" />
</a>
My final time was 2:56:01, which I think was pretty good for a first effort particularly given a rather poor swim time. A final thanks to fellow triathlete Mark Oxenham who saved me the grief of a train journey home by providing transportation, and to Suzy and Anna for coming down to offer moral support.</p>
<h3>Gallery</h3>

<div class="ngg-galleryoverview" id="ngg-gallery-6">


	
	<!-- Thumbnails -->
		
	<div id="ngg-image-56" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/london/bike_1.jpg" title=" " class="thickbox" rel="set_6" >
				<img title="bike_1.jpg" alt="bike_1.jpg" src="http://www.planetmarshall.co.uk/wp-content/gallery/london/thumbs/thumbs_bike_1.jpg"  />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-57" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/london/bike_2.jpg" title=" " class="thickbox" rel="set_6" >
				<img title="bike_2.jpg" alt="bike_2.jpg" src="http://www.planetmarshall.co.uk/wp-content/gallery/london/thumbs/thumbs_bike_2.jpg"  />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-58" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/london/bike_3.jpg" title=" " class="thickbox" rel="set_6" >
				<img title="bike_3.jpg" alt="bike_3.jpg" src="http://www.planetmarshall.co.uk/wp-content/gallery/london/thumbs/thumbs_bike_3.jpg"  />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-59" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/london/bike_4.jpg" title=" " class="thickbox" rel="set_6" >
				<img title="bike_4.jpg" alt="bike_4.jpg" src="http://www.planetmarshall.co.uk/wp-content/gallery/london/thumbs/thumbs_bike_4.jpg"  />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-60" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/london/finish_1.jpg" title=" " class="thickbox" rel="set_6" >
				<img title="finish_1.jpg" alt="finish_1.jpg" src="http://www.planetmarshall.co.uk/wp-content/gallery/london/thumbs/thumbs_finish_1.jpg"  />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-61" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/london/medal.jpg" title=" " class="thickbox" rel="set_6" >
				<img title="medal.jpg" alt="medal.jpg" src="http://www.planetmarshall.co.uk/wp-content/gallery/london/thumbs/thumbs_medal.jpg"  />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-62" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/london/run_1.jpg" title=" " class="thickbox" rel="set_6" >
				<img title="run_1.jpg" alt="run_1.jpg" src="http://www.planetmarshall.co.uk/wp-content/gallery/london/thumbs/thumbs_run_1.jpg"  />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-63" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/london/run_2.jpg" title=" " class="thickbox" rel="set_6" >
				<img title="run_2.jpg" alt="run_2.jpg" src="http://www.planetmarshall.co.uk/wp-content/gallery/london/thumbs/thumbs_run_2.jpg"  />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-64" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/london/swim_1.jpg" title=" " class="thickbox" rel="set_6" >
				<img title="swim_1.jpg" alt="swim_1.jpg" src="http://www.planetmarshall.co.uk/wp-content/gallery/london/thumbs/thumbs_swim_1.jpg"  />
			</a>
		</div>
	</div>
	 	 	
	<!-- Pagination -->
 	<div class="ngg-clear">&nbsp;</div> 	
</div>

]]></content:encoded>
			<wfw:commentRss>http://www.planetmarshall.co.uk/2009/04/london-triathlon-2008/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Reaction-Diffusion Models</title>
		<link>http://www.planetmarshall.co.uk/2009/03/reaction-diffusion-models/</link>
		<comments>http://www.planetmarshall.co.uk/2009/03/reaction-diffusion-models/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 00:27:03 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Differential Equations]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false">http://www.planetmarshall.co.uk/?p=124</guid>
		<description><![CDATA[One of Alan Turing&#8217;s many contributions to mathematics and science during the 20th century was his 1952 paper on &#8220;The Chemical Basis of Morphogenesis&#8221; in which he suggested that a simple model of coupled differential equations could account for pattern formation in natural processes such as those found on animal coats. Such models are known [...]]]></description>
			<content:encoded><![CDATA[
<a href="http://www.planetmarshall.co.uk/wp-content/gallery/reaction_diffusion/maze.png" title="" class="thickbox" rel="singlepic68" >
	<img class="ngg-singlepic ngg-right" src="http://www.planetmarshall.co.uk/wp-content/gallery/cache/68__x96_maze.png" alt="maze.png" title="maze.png" />
</a>

<p class="pm_first"><span>O</span>ne of <a target="_new" href="http://en.wikipedia.org/wiki/Alan_Turing">Alan Turing</a>&#8217;s many contributions to mathematics and science during the 20th century was his <a href="#1_turing">1952 paper</a> on &#8220;The Chemical Basis of Morphogenesis&#8221; in which he suggested that a simple model of coupled differential equations could account for pattern formation in natural processes such as those found on animal coats. Such models are known as Reaction-Diffusion models, and take the following general form<br />
<center><img src="http://www.planetmarshall.co.uk/wp-content/cache/tex_7a2bc8ea1910cfbd65cd8f6e0f9d93db.png" align="absmiddle" class="tex" alt="\frac{\partial}{\partial t}\mathbf{q}=\mathbf{D}\nabla^2\mathbf{q}+\mathbf{R}(\mathbf{q})" /></center></p>
<p><span id="more-124"></span></p>
<p>The equation describes how the concentration of each chemical components in q evolves as a function of the other components. I have chosen to illustrate the Gray-Scott model; the physical derivation of the reactant term is described in detail in <a href="#2_grayscott">[2]</a>, the addition of the diffusion term and the resultant behaviour in <a href="#3_pearson">[3]</a>. The model has two chemical components, U and V and is described as follows.<br />
<center><img src="http://www.planetmarshall.co.uk/wp-content/cache/tex_0ce40140abea7929669115d693d6b1ea.png" align="absmiddle" class="tex" alt="\begin{align*}<br />
\frac{\partial}{\partial t}U&#038;=D_u\nabla^2U-UV^2+F(1-U) \\<br />
\frac{\partial}{\partial t}V&#038;=D_v\nabla^2V+UV^2-(F+k)V<br />
\end{align*}" /></center></p>
<p>The model is what is knows as an activator-inhibitor model, in which one chemical acts to inhibit the growth of the other.</p>
<h3>Simulation</h3>
<p>The simulation is implemented with <a href="http://www.silverlight.net" target="_new">Silverlight 2.0</a>. For full details of the implementation see the separate <a href="http://www.planetmarshall.co.uk/index.php/2009/04/implentation-of-the-reaction-diffusion-simulation/">post</a>. For guidance in parameter selection, see <a href="#3_pearson">[3]</a>, or just select a preset and modify it. Note that the Png image generation feature currently requires the <a target="_new" href="http://www.mozilla.com/firefox/">Firefox</a> browser.</p>
<p><div class="pm_header"><a onclick="pm_toggleCodeBlock(this,'4b995fc038091')">&#x25ba;</a> Silverlight Application</div><div id="4b995fc038091" style="display:none" class="silverlightControlHost"><object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="450" height="300"><param name="source" value="http://www.planetmarshall.co.uk/silverlight/ReactionDiffusion.xap"/><param name="background" value="#212121" /><!--<param name="minRuntimeVersion" value="2.0.31005.0" />--><param name="enableHtmlAccess" value="true" /><a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;"><img src="http://storage.timheuer.com/sl4wp-ph.png" alt="Install Microsoft Silverlight" style="border-style: none; width:450px; height:300px"/></a></object><iframe style='visibility:hidden;height:0;width:0;border:0px'></iframe></div><br />
<h3>Gallery</h3>
<div class="ngg-galleryoverview" id="ngg-gallery-5">


	
	<!-- Thumbnails -->
		
	<div id="ngg-image-65" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/reaction_diffusion/blood.png" title=" " class="thickbox" rel="set_5" >
				<img title="blood.png" alt="blood.png" src="http://www.planetmarshall.co.uk/wp-content/gallery/reaction_diffusion/thumbs/thumbs_blood.png"  />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-66" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/reaction_diffusion/cells.png" title=" " class="thickbox" rel="set_5" >
				<img title="cells.png" alt="cells.png" src="http://www.planetmarshall.co.uk/wp-content/gallery/reaction_diffusion/thumbs/thumbs_cells.png"  />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-67" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/reaction_diffusion/clouds.png" title=" " class="thickbox" rel="set_5" >
				<img title="clouds.png" alt="clouds.png" src="http://www.planetmarshall.co.uk/wp-content/gallery/reaction_diffusion/thumbs/thumbs_clouds.png"  />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-68" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/reaction_diffusion/maze.png" title=" " class="thickbox" rel="set_5" >
				<img title="maze.png" alt="maze.png" src="http://www.planetmarshall.co.uk/wp-content/gallery/reaction_diffusion/thumbs/thumbs_maze.png"  />
			</a>
		</div>
	</div>
	 		
	<div id="ngg-image-69" class="ngg-gallery-thumbnail-box"  >
		<div class="ngg-gallery-thumbnail" >
			<a href="http://www.planetmarshall.co.uk/wp-content/gallery/reaction_diffusion/waves.png" title=" " class="thickbox" rel="set_5" >
				<img title="waves.png" alt="waves.png" src="http://www.planetmarshall.co.uk/wp-content/gallery/reaction_diffusion/thumbs/thumbs_waves.png"  />
			</a>
		</div>
	</div>
	 	 	
	<!-- Pagination -->
 	<div class="ngg-clear">&nbsp;</div> 	
</div>

<h3>References</h3>
<ol>
<li><a name="1_turing"></a>Turing,A.,1952. <a target="_new" href="http://www.dna.caltech.edu/courses/cs191/paperscs191/turing.pdf">The chemical basis of morphogenesis [pdf]</a>. <i>Philosophical Transactions of the Royal Society</i>, 237 pp.37-72
</li>
<li><a name="2_grayscott"></a>Gray,P. and Scott,S.K. 1985. <a href="http://www.jstor.org/stable/2881810" target="_new">Sustained Oscillations and Other Exotic Patterns of Behavior in Isothermal Reactions.</a> <i>Journal of Physical Chemistry</i>, 89 pp.22-32
</li>
<li><a name="3_pearson"></a>Pearson,J.,1993. <a href="http://www.jstor.org/stable/2881810" target="_new">Complex patterns in a simple system.</a> <i>Science</i>, 261(5118) pp.189-192
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.planetmarshall.co.uk/2009/03/reaction-diffusion-models/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
