<?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>Blog of developer Mikkel Ovesen &#187; parallel</title>
	<atom:link href="http://blog.ovesens.net/tag/parallel/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ovesens.net</link>
	<description>My thoughts, stuff I need to remember or things I just want to share with the world</description>
	<lastBuildDate>Thu, 19 Jan 2012 11:55:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How will you parallelize your existing codebase? Try R.A.S.P</title>
		<link>http://blog.ovesens.net/2008/12/how-will-you-parallelize-your-existing-codebase-try-r-a-s-p/</link>
		<comments>http://blog.ovesens.net/2008/12/how-will-you-parallelize-your-existing-codebase-try-r-a-s-p/#comments</comments>
		<pubDate>Wed, 24 Dec 2008 19:08:00 +0000</pubDate>
		<dc:creator>Mikkel Ovesen</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[parallel]]></category>
		<category><![CDATA[thread]]></category>
		<category><![CDATA[threading]]></category>

		<guid isPermaLink="false">/post/2008/12/24/How-will-you-parallelize-your-existing-codebase-Try-RASP.aspx</guid>
		<description><![CDATA[Original post: http://www.atalasoft.com/cs/blogs/rickm/archive/2008/12/23/how-will-you-parallelize-your-existing-codebase-try-r-a-s-p.aspx &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;- How will you parallelize your existing codebase? Try R.A.S.P. There has been much talk of how we will be writing all of our new code with parallelization in mind.&#160; However, what of our existing code?&#160; It&#8217;s &#8230; <a href="http://blog.ovesens.net/2008/12/how-will-you-parallelize-your-existing-codebase-try-r-a-s-p/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>
Original post:
</p>
<p>
<a href="http://www.atalasoft.com/cs/blogs/rickm/archive/2008/12/23/how-will-you-parallelize-your-existing-codebase-try-r-a-s-p.aspx">http://www.atalasoft.com/cs/blogs/rickm/archive/2008/12/23/how-will-you-parallelize-your-existing-codebase-try-r-a-s-p.aspx</a>
</p>
<p>
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-
</p>
<h2>How will you parallelize your existing codebase? Try R.A.S.P.</h2>
<p>
There<br />
has been much talk of how we will be writing all of our new code with<br />
parallelization in mind.&nbsp; However, what of our existing code?&nbsp; It&rsquo;s<br />
unlikely that everyone will just suddenly dump decades of existing code<br />
and write everything from scratch.&nbsp; In this article I&rsquo;m going to<br />
provide a simple methodology for how we might deal with the ever<br />
building problem of parallelizing our existing mountains of code.&nbsp;<br />
Comments and contributions are welcome.
</p>
<p>
&nbsp;
</p>
<h3>Methodologies of the Past</h3>
<p>
From<br />
the STL to .NET, the frameworks we have constructed our applications<br />
around have been heavily dependent on the idea of an application having<br />
a single thread.&nbsp; Given that the foundation of what we have all been<br />
using for a very long time was constructed around this preconception,<br />
it&rsquo;s unreasonable to expect that much of our existing code will ever be<br />
fully parallel.&nbsp; Even those that wrote code on top of a thread safe<br />
framework may find that years of patches and and poor design decisions<br />
make ground up parallelization impossible.
</p>
<p>
If we set our<br />
expectations reasonably, we see that we should instead focus on<br />
leveraging parallelism to improve the performance of the slowest parts<br />
of our software.&nbsp; From this viewpoint, parallelization is an<br />
optimization problem.&nbsp; Like all optimization, the difficulty of<br />
parallelizing code will have much to do with the methodologies which<br />
were used to write it.&nbsp;&nbsp;
</p>
<p>
Of course, object-oriented code being written with modern <a href="http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod">S.O.L.I.D. principles</a><br />
and will be easier to parallelize than older procedural code.&nbsp; At the<br />
same time, a poorly organized codebase or poorly written code will<br />
always make change difficult and so also hard to parallelize.&nbsp; This is<br />
why well written code is worth the investment.&nbsp; We will see the<br />
investment paying off in spades for the companies who have bothered to<br />
care about code quality.&nbsp; Others who find they have spaghetti code<br />
under the hood will find they will need to deeply segregate and<br />
modularize before parallelization is possible.
</p>
<p>
&nbsp;
</p>
<h3>A Methodology for Revisiting the Past</h3>
<p>
In<br />
most cases it would be a poor choice to implement your own threading<br />
API.&nbsp; Efficient and easy to use parallelization APIs are coming to (or<br />
already part of) every commonly used language and framework.&nbsp; Most of<br />
these APIs are not only built on top of <a href="http://lacl.univ-paris12.fr/gava/PAPP2009/">years of research</a>,<br />
they also have been written and debugged by a large number of people<br />
with specific expertise.&nbsp; These APIs are a godsend because they will<br />
allow most developers to parallelize existing software with a minimum<br />
amount of pain.&nbsp; The parallelization of existing code bases will be<br />
much the same as any other kind of performance tuning.&nbsp;
</p>
<p>
The<br />
key will be using a profiler to identify places in the code that would<br />
be sped up by parallelization and leveraging these new APIs to take<br />
advantage of the available hardware.&nbsp; The exciting part is that this<br />
can be done with any existing profiler and many existing APIs.&nbsp; The<br />
unfortunate part is that because memory sharing is such a big issue,<br />
parallelization requires a degree of separation beyond other types of<br />
optimization and so is likely to require some amount of refactoring.
</p>
<p>
Not<br />
all types of performance problems are conducive to being solved by<br />
parallelization, careful evaluation of the problem at hand is<br />
required.&nbsp; Also, as with anything that requires significant code<br />
change, building a solid test fixture is key to introducing as few bugs<br />
as possible.&nbsp; By leveraging the ideas of <a href="http://prematureoptimization.org/blog/archives/26">avoiding premature optimization</a>, <a href="http://dotnet.sys-con.com/node/133775">pragmatic unit testing</a>, <a href="http://msdn.microsoft.com/en-us/magazine/cc163329.aspx">using existing APIs</a>, and <a href="http://www.ryanlowe.ca/blog/archives/001048_be_mindful_of_code_entropy.php">mindful refactoring</a> it will be possible to introduce parallelization into many already existing projects with a manageable amount of risk.
</p>
<p>
&nbsp;
</p>
<h3>What is RASP?</h3>
<p>
While not included in the acronym, the first step in any kind of optimization is <strong><a href="http://en.wikipedia.org/wiki/Performance_analysis">profiling</a></strong>.&nbsp;<br />
Before you can begin to parallelize your code, you must determine where<br />
the bottlenecks might be.&nbsp; A broadly defined list of parallelizable<br />
things to look for would be, to quote <a href="http://loufranco.com/blog/files/20-Days-of-Clojure-Day-12.html">Rich Hickey</a>,<br />
&ldquo;independent data/work, moderate-to-course-grained work units and/or<br />
complex coordination logic that would be simplified with threads&rdquo;.&nbsp; A<br />
couple quick examples of low hanging fruit to be on the lookout for<br />
would be slow iterative loops and blocking I/O.&nbsp; It is important to<br />
note that as a general guideline it would be wrong to parallelize<br />
anything if it would not significantly increase the speed of your<br />
software.
</p>
<p>
For each of the bottlenecks found while profiling, parallelization is best separated into four steps:
</p>
<table border="0" cellspacing="0" cellpadding="2">
<tbody>
<tr>
<td><strong>Review</strong>: </td>
<td>Review code to determine if it is a good candidate for parallelization.</td>
</tr>
<tr>
<td><strong>Anchor:</strong></td>
<td>Create a unit test fixture to ensure that the behavior of the to be parallelized code does not change.</td>
</tr>
<tr>
<td><strong>Separate</strong>: </td>
<td>Ensure that the to be parallelized code has no shared memory constraints, and if it does, factor them out if possible.</td>
</tr>
<tr>
<td><strong>Parallelize</strong>: </td>
<td>Minimally refactor for parallelization while leveraging an existing API to do the heavy lifting.</td>
</tr>
</tbody>
</table>
<p>
As<br />
the specifics of what each of these would entail depends greatly on<br />
exactly which platform and language is in use, I will not go into them<br />
deeply now.&nbsp; Overall, it&rsquo;s a simple methodology but I think both<br />
sufficient for the task at hand and broadly applicable.&nbsp;
</p>
<p>
&nbsp;
</p>
<h3>Conclusion </h3>
<p>
Review,<br />
Anchor, Separate, Parallelize.&nbsp; It&rsquo;s not intended to be a difficult<br />
concept but instead to provide a simple path to parallelization.&nbsp; I<br />
would be very interested in hearing about any opinions on what RASP<br />
might be missing or how it may be better clarified.&nbsp; While I didn&rsquo;t<br />
have time to discuss them deeply in this post, <a href="http://www.cs.uiuc.edu/homes/snir/PPP/">parallelization patterns</a><br />
are also a key concept in using RASP as if you can&rsquo;t easily identify<br />
what can be parallelized than it would be impossible to use any<br />
parallelization methodology.&nbsp; In the future I hope flush out RASP<br />
further as well as discuss parallelization patterns in depth.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ovesens.net/2008/12/how-will-you-parallelize-your-existing-codebase-try-r-a-s-p/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debugging memory leaks and Parallel LINQ</title>
		<link>http://blog.ovesens.net/2008/12/debugging-memory-leaks-and-parallel-linq/</link>
		<comments>http://blog.ovesens.net/2008/12/debugging-memory-leaks-and-parallel-linq/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 01:47:00 +0000</pubDate>
		<dc:creator>Mikkel Ovesen</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[debug]]></category>
		<category><![CDATA[memoryleaks]]></category>
		<category><![CDATA[parallel]]></category>
		<category><![CDATA[plinq]]></category>

		<guid isPermaLink="false">/post/2008/12/18/Debugging-memory-leaks-and-Parallel-LINQ.aspx</guid>
		<description><![CDATA[Link to good articles Debugging OutOfMemoryExceptions in managed code using Windbg http://blogs.msdn.com/amolravande/archive/2008/12/16/debugging-outofmemoryexceptions-in-managed-code-using-windbg.aspx &#160; Query Data with Parallel LINQ http://blogs.msdn.com/charlie/archive/2008/12/15/query-data-with-parallel-linq.aspx &#160;]]></description>
			<content:encoded><![CDATA[<h1>Link to good articles</h1>
<p>
Debugging OutOfMemoryExceptions in managed code using Windbg
</p>
<p>http://blogs.msdn.com/amolravande/archive/2008/12/16/debugging-outofmemoryexceptions-in-managed-code-using-windbg.aspx</p>
<p>
&nbsp;
</p>
<p>
Query Data with Parallel LINQ
</p>
<p>http://blogs.msdn.com/charlie/archive/2008/12/15/query-data-with-parallel-linq.aspx</p>
<p>
&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ovesens.net/2008/12/debugging-memory-leaks-and-parallel-linq/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Jeff Richter Video on Asynchronous Programming and his Power Threading Library</title>
		<link>http://blog.ovesens.net/2008/12/jeff-richter-video-on-asynchronous-programming-and-his-power-threading-library/</link>
		<comments>http://blog.ovesens.net/2008/12/jeff-richter-video-on-asynchronous-programming-and-his-power-threading-library/#comments</comments>
		<pubDate>Wed, 10 Dec 2008 17:26:00 +0000</pubDate>
		<dc:creator>Mikkel Ovesen</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[async]]></category>
		<category><![CDATA[parallel]]></category>
		<category><![CDATA[plinq]]></category>
		<category><![CDATA[thread]]></category>

		<guid isPermaLink="false">/post/2008/12/10/Jeff-Richter-Video-on-Asynchronous-Programming-and-his-Power-Threading-Library.aspx</guid>
		<description><![CDATA[Jeff Richter Video on Asynchronous Programming and his Power Threading Library: &#160;http://blogs.msdn.com/charlie/archive/2008/12/03/jeff-richter-video-on-asynchronous-programming-and-his-power-threading-library.aspx]]></description>
			<content:encoded><![CDATA[<h1>Jeff Richter Video on Asynchronous Programming and his Power Threading Library:</h1>
<p>
&nbsp;<a href="http://blogs.msdn.com/charlie/archive/2008/12/03/jeff-richter-video-on-asynchronous-programming-and-his-power-threading-library.aspx">http://blogs.msdn.com/charlie/archive/2008/12/03/jeff-richter-video-on-asynchronous-programming-and-his-power-threading-library.aspx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ovesens.net/2008/12/jeff-richter-video-on-asynchronous-programming-and-his-power-threading-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

