<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Byzantine Reality</title>
	<atom:link href="http://shatterednirvana.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://shatterednirvana.wordpress.com</link>
	<description>Looking at Byzantine failures in everything around us.</description>
	<lastBuildDate>Wed, 01 Apr 2009 06:15:44 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='shatterednirvana.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/0fc16bf8feae1012b56e330b1698230e?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Byzantine Reality</title>
		<link>http://shatterednirvana.wordpress.com</link>
	</image>
			<item>
		<title>State of the Cell</title>
		<link>http://shatterednirvana.wordpress.com/2007/12/23/state-of-the-cell/</link>
		<comments>http://shatterednirvana.wordpress.com/2007/12/23/state-of-the-cell/#comments</comments>
		<pubDate>Sun, 23 Dec 2007 02:45:29 +0000</pubDate>
		<dc:creator>shatterednirvana</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Cell]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[RapidMind]]></category>
		<category><![CDATA[School]]></category>
		<category><![CDATA[UCSB Projects]]></category>

		<guid isPermaLink="false">http://shatterednirvana.wordpress.com/2007/12/23/state-of-the-cell/</guid>
		<description><![CDATA[Originally posted at http://cs.ucsb.edu/~cgb/stateOfTheCell.html, and thus, looks much better there.
The Cell Broadband Engine Architecture (which we shall refer to as simply the Cell architecture) was designed as a compromise between the general-purpose but slower CPU and the specific-purpose and faster GPU. It is a heterogeneous architecture: it contains processing units that specialize in different tasks. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shatterednirvana.wordpress.com&blog=389350&post=48&subd=shatterednirvana&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><b>Originally posted at <a href="http://cs.ucsb.edu/~cgb/stateOfTheCell.html">http://cs.ucsb.edu/~cgb/stateOfTheCell.html</a>, and thus, looks much better there.</b></p>
<p>The Cell Broadband Engine Architecture (which we shall refer to as simply the Cell architecture) was designed as a compromise between the general-purpose but slower CPU and the specific-purpose and faster GPU. It is a heterogeneous architecture: it contains processing units that specialize in different tasks. However, critics (and even some fans) of the Cell architecture claim that it is incredibly difficult to produce good, fast code on it. Having spent the last quarter working with the Cell architecture, we agree with this sentiment. But why?</p>
<p><span id="more-48"></span></p>
<p>Our paper, <a href='http://shatterednirvana.files.wordpress.com/2007/12/stateofthecell.pdf' title='stateofthecell.pdf'>&#8216;Lack of Abstraction Considered Harmful&#8217;</a>, provides a review of work on Cell as well, work we have done on Cell, and an analysis of this issue. This web page serves as a summary of that paper.</p>
<p>Page Layout</p>
<li> <a href="#intro">Introduction</a></li>
<li> <a href="#algorithms">Algorithms and Technologies Used</a></li>
<li> <a href="#design">Design Process</a></li>
<li> <a href="#results">Results</a></li>
<li> <a href="#cellReview">Pros and Cons of Cell</a></li>
<h4><a title="intro" name="intro"></a>Introduction</h4>
<p>In order to test how easy it is to program fast code on the Cell architecture, we implement two different algorithms: the Hadamard product and matrix multiplication. We implement these algorithms on our Cell system at Fred Chong&#8217;s Architecture Lab (the Archlab). Our Cell system is a PlayStation 3 with Yellow Dog Linux 5 and the Cell SDK 2.0.</p>
<h4><a title="algorithms" name="algorithms"></a>Algorithms and Technologies Used</h4>
<h4>Yellow Dog Linux 5 and Cell SDK 2.0</h4>
<p>Detailed instructions exist for <a href="http://www.ibm.com/developerworks/library/pa-linuxps3-1/">installing Yellow Dog Linux 5 and Cell SDK 2.0 on the PlayStation 3</a>, as well as for Fedora Core 7 and Cell SDK 3.0 on the IBM Blade Servers, but none exist for getting the new Cell SDK 3.0 on the PlayStation 3 <a href="#update">(Update)</a>. The company that supports Yellow Dog Linux, <a href="http://www.terrasoftsolutions.com/">Terra Soft</a>, offers the SDK with support, but for $4000, it is far out of our availability. Furthermore, although the SDK can be downloaded for free and used on other Linux boxes as a cross-compiling system, we were unable to get it to work on Gentoo Linux or Debian Linux. They seem to specifically require Fedora Core, which we did not have access to. Since these newer SDKs contain the optimized IBM XL C Compiler (IBM cross-compiler for C), we used the versions of gcc for the PPE and SPEs.</p>
<h4>RapidMind</h4>
<p><a href="http://www.rapidmind.net/">RapidMind</a> is a metaprogramming language for C++ that allows the programmer to take their existing C++ code and port it to the Cell architecture (or the GPU architecture) with seemingly little work involved. The programmer annotates the parts of their code where parallelization can be performed, and the RapidMind framework converts this code to &#8220;optimized&#8221; C++ code. The speed of the resulting code varies vastly on the skill of the programmer, as we will show.</p>
<h4>Cell Broadband Engine Architecture</h4>
<p>We defer a detailed analysis of the Cell architecture to its <a href="http://en.wikipedia.org/wiki/Cell_%28microprocessor%29">Wikipedia article</a> and to the <a href="presentations/cellPresentation.pdf">presentation</a> we gave at UC Santa Barbara on contributions to the IBM cross compiler, as the novel architecture has been discussed extensively in the various papers we have reviewed this quarter.</p>
<h4>Hadamard product and Matrix Multiplication Algorithms</h4>
<p>Both of these algorithms are relatively simple as far as computer science goes. Although matrix multiplication will be familiar to computer scientists, the <a href="http://en.wikipedia.org/wiki/Hadamard_product">Hadamard product</a> may not be. It takes two matrices and produces a new matrix of the same dimensions, with each element being the product of the two elements given as input.</p>
<h4><a title="design" name="design"></a>Design Process</h4>
<p>For our comparisons we use three renditions of the Hadamard product algorithm and three renditions of the matrix multiplication algorithm. For the Hadamard product, we have constructed one version that only runs on the PPE, a version that uses the PPE and four SPEs, and a final version that uses RapidMind. We only use four of the six SPEs since the matrices we are multiplying are square and thus it is easier to split up into four blocks instead of six. For the matrix multiplication algorithm, we use one version that only runs on the PPE. We also wrote a version that uses RapidMind, but is a more naive version compared to the optimized RapidMind version distributed by RapidMind. The code for the optimized RapidMind version can be found at their website, while the versions we have implemented are available here.</p>
<h4><a title="results" name="results"></a>Results</h4>
<p>For the six algorithms we have run on Cell, we see the following performance:</p>
<p><a href="http://shatterednirvana.files.wordpress.com/2007/12/hadamard.png" title="hadamard.png"><img src="http://shatterednirvana.files.wordpress.com/2007/12/hadamard.thumbnail.png" alt="hadamard.png" /></a></p>
<p><a href="http://shatterednirvana.files.wordpress.com/2007/12/matrixmultiply.png" title="matrixmultiply.png"><img src="http://shatterednirvana.files.wordpress.com/2007/12/matrixmultiply.thumbnail.png" alt="matrixmultiply.png" /></a></p>
<p>We see that in both cases, our PPE only code runs faster than our naive RapidMind implementation by three orders of magnitude (a factor of 1000 difference). This scales up exponentially with the number of rows in the matrices (since the y-axis is on a log scale), and we also see that the optimized RapidMind and our PPE / 4 SPE programs scale up much better. Unfortunately, both compilers / frameworks were difficult to work with (although in different ways). We were unable to send more than 16 KB of data to the SPEs, so as a result we have no data for the Hadamard product with more than 16 KB of data. Next, we discuss the difficulties and successes we have with Cell&#8217;s gcc / spu-gcc and RapidMind.</p>
<h4><a title="cellReview" name="cellReview"></a>Pros and Cons of Cell&#8217;s gcc / spu-gcc</h4>
<p><b>Pros: </b></p>
<li>Super-fine level granularity over the architecture assures the best performance out of the architecture. Some of the papers we&#8217;ve seen this quarter have shown the amazing speedups Cell can achieve. If you don&#8217;t mind spending the extra time to really work out your algorithm, its speed will certainly end up first-class.</li>
<li>Can program in assembly or C as needed. Certainly most of you will prefer C, but to get the fastest programs, the masochist in you will want to write this program in assembly. Take my advice though: don&#8217;t do it. We&#8217;ve argued that Cell needs more abstraction, so don&#8217;t go with less by programming in assembly. But if you really wanted to, at least you could.</li>
<li>Being able to use I/O (esp. printf) inside of the SPEs kicks ass. It&#8217;s much slower but gives the bad debugger some extra data to work with. Contrast this with CUDA (see Multigrid on CUDA), where you are not allowed to hit the screen&#8217;s I/O at all and have to save outputs in variables that the CPU can print out later.</li>
<p><b>Cons: </b></p>
<li>Having to manage mandatory factors such as memory alignment and data transfer is obscenely difficult. It literally should be a crime to make the programmer do this. There&#8217;s no reason the compiler can&#8217;t, especially given the fact that all other compilers seem to do this.</li>
<li>Having to manage optional factors such as branch prediction is ridiculous. Just like before, there&#8217;s no reason that the compiler can&#8217;t look at my loops and guess what&#8217;s needed next most of the time. This goes double considering the fact that branches are predicted not-taken ALWAYS. Come on! Programmers write code expecting it to get used! We don&#8217;t write branches knowing they&#8217;ll never get used! Even guessing always taken would be better than always guessing not-taken.</li>
<li>Inconsistency between data types on the PPE and SPEs. I know, they have a different instruction set and are optimized for different things, blah blah blah. But I should be able to define a vector of a certain type and have that code work on the PPE or SPEs, even if it gets translated differently or performs differently. I shouldn&#8217;t have to memorize the different types of vectors for the PPE and SPEs just to get some use out of them.</li>
<h4>Pros and Cons of RapidMind</h4>
<p><b>Pros: </b></p>
<li>Since RapidMind is built on top of C++, it is very simple to reuse small programs with the framework.</li>
<li>RapidMind abstracts the difficult-to-deal-with hardware away from the programmer. This is surely RapidMind&#8217;s greatest strength, as the lack of abstraction hurts the programmer&#8217;s productivity more than anything else we saw.</li>
<li>RapidMind is free for academic use! It&#8217;s easy to set up and has good documentation, so if you&#8217;re an academic type and have a PS3, go check it out!</li>
<p><b>Cons: </b></p>
<li>Resolving compiler issues is virtually impossible. See the screenshot from using RapidMind on the GPU in the <a href="http://shatterednirvana.wordpress.com/2007/12/20/multigrid-methods-with-cuda/">Multigrid Methods on CUDA</a> project to see more about that.</li>
<li>You need to be an expert at RapidMind to write fast RapidMind code. We constructed our program by following the recommendations at the developer&#8217;s site, but our final code for matrix multiplication was far different from the RapidMind team&#8217;s. They give many ways to solve problems but no &#8220;best practices&#8221;, leaving us with an algorithm that is substantially slower than theirs.</li>
<li>Some RapidMind variable types do not work as expected. RapidMind&#8217;s boolean type cannot be used alone in conditional statements, and having to refactor code that uses that eats a lot of time and readability out of the program.</li>
<h4>Conclusion</h4>
<p>We have seen on Cell that it is currently difficult to write fast code, and difficult to write any code at all. This goes double for developing with gcc and spu-gcc. In order for Cell to be a viable language, tools will need to be developed that abstract away the various parts of the hardware we&#8217;ve encountered difficulties with (memory alignment, sending data to SPEs, etc). Doing so would not have been out of reach for the Cell developers, yet it appears they wanted the potential to get the maximum performance out of the hardware. Unfortunately,  this decision makes it brutually difficult for the average programmer to get any real programming done. It also makes the programs dependent on the specifics of this version of the architecture. To illustrate this point: what do you have to change in your algorithm if a new Cell chip is designed with 10 SPEs and 512 KB local store instead of the current layout (8 SPEs and 256 KB local store). You could probably keep the same performance as before easily, but to get the most out of the architecture, you need to refactor your entire program. Why not let the compiler / scheduler / whatever do this for you? Computers were meant to make our lives easier, remember? I guess I finally see what the big deal about Ruby is, with <a href="http://www.artima.com/intv/ruby4.html">Matsumoto&#8217;s &#8220;crazy&#8221; idea:</a></p>
<p>&#8220;Often people, especially computer engineers, focus on the machines. They think, &#8216;By doing this, the machine will run faster. By doing this, the machine will run more effectively. By doing this, the machine will something something something.&#8217; They are focusing on machines. But in fact we need to focus on humans, on how humans care about doing programming or operating the application of the machines. We are the masters. They are the slaves.&#8221;</p>
<p>Hope is not lost for Cell. In fact, its quite the opposite. The potential for Cell is astounding. We just need to start harnessing that power the right way. Software complexity is already increasing on its own. We shouldn&#8217;t be making it even more complex. Here&#8217;s a more concise <a href="http://www.codinghorror.com/blog/archives/000082.html">article</a> that covers the same issue.</p>
<p>Chris Bunch</p>
<p><a title="update" name="update"></a><b>Update 12/22/07</b>: So it turns out there are a <a href="http://gnuradio.org/trac/wiki/PS3FC7Install">couple</a> <a href="http://www.ibm.com/developerworks/forums/thread.jspa?threadID=187296&amp;tstart=0">guides</a> for installing Fedora Core 7 on the PS3. I&#8217;m gonna try them out next week and see how they go.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/shatterednirvana.wordpress.com/48/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/shatterednirvana.wordpress.com/48/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shatterednirvana.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shatterednirvana.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shatterednirvana.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shatterednirvana.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shatterednirvana.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shatterednirvana.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shatterednirvana.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shatterednirvana.wordpress.com/48/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shatterednirvana.wordpress.com/48/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shatterednirvana.wordpress.com/48/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shatterednirvana.wordpress.com&blog=389350&post=48&subd=shatterednirvana&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://shatterednirvana.wordpress.com/2007/12/23/state-of-the-cell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d3a0edc111d09d96513f737960c67a29?s=96&#38;d=identicon" medium="image">
			<media:title type="html">shatterednirvana</media:title>
		</media:content>

		<media:content url="http://shatterednirvana.files.wordpress.com/2007/12/hadamard.thumbnail.png" medium="image">
			<media:title type="html">hadamard.png</media:title>
		</media:content>

		<media:content url="http://shatterednirvana.files.wordpress.com/2007/12/matrixmultiply.thumbnail.png" medium="image">
			<media:title type="html">matrixmultiply.png</media:title>
		</media:content>
	</item>
		<item>
		<title>Multigrid Methods with CUDA</title>
		<link>http://shatterednirvana.wordpress.com/2007/12/20/multigrid-methods-with-cuda/</link>
		<comments>http://shatterednirvana.wordpress.com/2007/12/20/multigrid-methods-with-cuda/#comments</comments>
		<pubDate>Thu, 20 Dec 2007 23:29:02 +0000</pubDate>
		<dc:creator>shatterednirvana</dc:creator>
				<category><![CDATA[CUDA]]></category>
		<category><![CDATA[Physics]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[RapidMind]]></category>
		<category><![CDATA[School]]></category>
		<category><![CDATA[UCSB Projects]]></category>

		<guid isPermaLink="false">http://shatterednirvana.wordpress.com/2007/12/20/multigrid-methods-with-cuda/</guid>
		<description><![CDATA[Originally posted at http://cs.ucsb.edu/~cgb/multigridCUDA.html, and thus, looks much better there.
Over the last quarter I have been investigating how to implement a multigrid algorithm with CUDA, a new language aimed at making General Purpose Computation on GPUs (GPGPU) easier. This web page documents this experience.

Page Layout
Introduction
Algorithms and Technologies Used
Design Process
Results
Pros and Cons of CUDA
Introduction
It is not [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shatterednirvana.wordpress.com&blog=389350&post=37&subd=shatterednirvana&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><strong>Originally posted at <a href="http://cs.ucsb.edu/~cgb/multigridCUDA.html">http://cs.ucsb.edu/~cgb/multigridCUDA.html</a>, and thus, looks much better there.</strong></p>
<p>Over the last quarter I have been investigating how to implement a multigrid algorithm with CUDA, a new language aimed at making <a href="http://www.gpgpu.org/">General Purpose Computation on GPUs (GPGPU)</a> easier. This web page documents this experience.</p>
<p><span id="more-37"></span></p>
<p>Page Layout</p>
<li><a href="#intro">Introduction</a></li>
<li><a href="#algorithms">Algorithms and Technologies Used</a></li>
<li><a href="#design">Design Process</a></li>
<li><a href="#results">Results</a></li>
<li><a href="#cudaReview">Pros and Cons of CUDA</a></li>
<h4><a title="intro" name="intro"></a>Introduction</h4>
<p>It is not always possible to solve a partial differential equation (PDE). In fact, exact solutions are not known for most PDEs. With the advent of computers, however, we can obtain good approximations to these solutions. One class of methods that are used to solve PDEs are the Multigrid Methods. Compared to other types of methods used to solve PDEs, they require less iterations and thus are generally faster. For this project, we have elected to solve a common PDE, the heat equation in three-dimensions, given by the following equation:</p>
<p><a href="http://en.wikipedia.org/wiki/Heat_equation"><img src="http://shatterednirvana.files.wordpress.com/2007/12/generalheateqn.png" border="0" alt="generalheateqn.png" /></a></p>
<p>Implementing multigrid methods is not a new problem. Therefore, we choose to implement them on a new platform, the Graphics Processor Unit (GPU). This has become possible only recently with the advent of GPGPU languages such as <a href="http://developer.nvidia.com/object/cuda.html">NVIDIA&#8217;s CUDA (Compute Unified Device Architecture)</a> and <a href="http://sourceforge.net/projects/amdctm/">ATI&#8217;s CTM (Close To Metal)</a>, amongst others. Since we already have an NVIDIA GeForce 8800 in our lab, which is CUDA-capable, we used CUDA to implement this project.</p>
<h4><a title="algorithms" name="algorithms"></a>Algorithms and Technologies Used</h4>
<p><strong>CUDA</strong></p>
<p>CUDA is a C-like language that allows programmers to &#8220;easily&#8221; port their code for use on the GPU. The language is mostly a super-set of the C language, allowing the programmer to flag which methods are run on the GPU and where variables are stored on the GPU. Although it is presented as a high-level language, low-level parts of the architecture are exposed to the user. As is the case with C, the programmer can allocate memory and de-allocate it (via cudaMalloc and cudaFree), but the programmer can choose specifically on the GPU where they want to put it. The following figure is from the CUDA documentation, showing the various memory locations available to the user:</p>
<p><a href="http://developer.download.nvidia.com/compute/cuda/1_1/NVIDIA_CUDA_Programming_Guide_1.1.pdf"></p>
<p><img src="http://shatterednirvana.files.wordpress.com/2007/12/hwmodel.png" border="0" alt="hwmodel.png" /></p>
<p></a></p>
<p>Here, we can see that we can allocate memory in the graphics card&#8217;s shared memory, constant cache, texture cache, and device memory. Although the device memory is the slowest to access, it has the most space and allows us to not have to worry about cache coherence in the shared memory. Thus, we use the device memory. A critique of the CUDA language is given in the &#8220;Pros and Cons of CUDA&#8221; section.</p>
<p><strong>Multigrid Methods</strong></p>
<p>Typical methods used to solve PDEs represent the simulated area as a three-dimensional grid (or matrix). Therefore, it is easy to represent on a computer. Furthermore, we can represent the heat equation as solving a linear system of equations. The general and specific representations are as follows:</p>
<p><a href="http://en.wikipedia.org/wiki/Heat_equation"></p>
<p><img src="http://shatterednirvana.files.wordpress.com/2007/12/linearsyseqn.png" border="0" alt="linearsyseqn.png" /></p>
<p></a></p>
<p><a href="http://en.wikipedia.org/wiki/Heat_equation"></p>
<p><img src="http://shatterednirvana.files.wordpress.com/2007/12/specificheateqn.png" alt="specificheateqn.png" /></p>
<p></a></p>
<p>For our implementation, k is 1, A is the <a href="http://en.wikipedia.org/wiki/Laplace_operator">Laplace operator</a>, x is u, and b is Ut. Three simple methods exist for solving this system of equations: The Jacobi Method, the Gauss-Seidel Method, and the Red-Black Gauss-Seidel Method. Our explanation for choosing the Red-Black Gauss-Seidel Method is given later, since this section focuses on Multigrid Methods in general.</p>
<p>As was previously stated, regular methods use one grid and solve it using any of the aforementioned methods. Multigrid methods differ in the sense that they solve many smaller grids and use those as approximations to the solution of the full size grid. This is necessary because solving only one large grid does not give the fine-grained accuracy that solving the smaller grids does. Furthermore, solving many small grids once and the large grid a small number of times is computationally faster than solving the large grid many times. The methods needed to implement this will be described in the design section.</p>
<p><strong>Red-Black Gauss-Seidel Method</strong></p>
<p>The simple methods used to solve a linear system of equations are the Jacobi Method, the Gauss-Seidel Method, and the Red-Black Gauss-Seidel Method. As shown in <a href="http://portal.acm.org/citation.cfm?coll=GUIDE&amp;dl=GUIDE&amp;id=347185">A Multigrid Tutorial</a>, the Red-Black Gauss-Seidel method converges the fastest out of these three methods (requires the least number of iterations). An added benefit specific to CUDA is that this method is easily parallelizable. In the standard Gauss-Seidel method, grid points must be updated one at a time. Although this works fine for serial computation, it is a poor choice for the parallel case. For Red-Black Gauss-Seidel, the odd points are all updated in parallel, and then the even points are all updated in parallel. The computation used to update each point is given by the average of that point&#8217;s neighbors.</p>
<h4><a title="design" name="design"></a>Design Process</h4>
<p>This being my first academic project since reading <a href="http://cc2e.com/">Code Complete</a>, I decided to develop a prototype first. My C++ prototype simulates a 2D grid situation. It was mainly used to get a feel for the methods needed for the CUDA version, and as a result, is incomplete. It ended up mapping over to CUDA well, as follows:</p>
<table border="1">
<tbody>
<tr>
<td>C++ Method Name</td>
<td>CUDA Method Name</td>
<td>Purpose</td>
</tr>
<tr>
<td>Constructor</td>
<td>Initialize / MG_CUDA_AllocateMem</td>
<td>Creates a grid. The C++ version needs a grid size; the CUDA version creates all the subgrids from the given size to a preset limit. Each subgrid is half the size of the previous grid.</td>
</tr>
<tr>
<td>Destructor</td>
<td>Close / MG_CUDA_Free</td>
<td>Frees the memory a grid has allocated. The CUDA version uses cudaFree to release all the memory it has been given via cudaMalloc.</td>
</tr>
<tr>
<td>setupInitialConditions</td>
<td>HeatToggle</td>
<td>The grid is initialized to 0 degrees at all points by the constructor. The C++ version of this method sets all points in the first row to be 100 degrees, and the CUDA version sets the innermost area of the cube to be 200 degrees. This is done so that we will be able to see the heat flow throughout the geometry.</td>
</tr>
<tr>
<td>restrictGrid</td>
<td>MG_CUDA_RestrictGrid / MG_CUDA_RKernel</td>
<td>Creates a new grid half the size of the original grid. The C++ version copies down the points from the bigger grid to the smaller one, while the CUDA version sets each point to be the weighted average of the points around it.</td>
</tr>
<tr>
<td>interpolateGrid</td>
<td>MG_CUDA_InterpolateGrid / MG_CUDA_IKernel</td>
<td>Creates a new grid twice the size of the original grid. Both versions sets each point to be the weighted average of the points around it.</td>
</tr>
<tr>
<td>solveGrid</td>
<td>MG_CUDA_SolveGrid / MG_CUDA_SGKernel</td>
<td>Both versions solve the given grid by using the Red-Black Gauss-Seidel Method. The odd numbered points are updated to be a weighted average of the points around them, and the process is repeated for the even numbered points. The C++ version does this until 50 iterations are done, while the CUDA version does 1 iteration.</td>
</tr>
<tr>
<td>computeResidual</td>
<td>MG_CUDA_ComputeResidual / MG_CUDA_CRKernel</td>
<td>Takes the difference between each point in two grids and returns a new grid containing this difference.</td>
</tr>
<tr>
<td>applyCorrection</td>
<td>MG_CUDA_ApplyCorrection / MG_CUDA_ACKernel</td>
<td>Adds in each point in a grid to the given grid and returns a new grid.</td>
</tr>
<tr>
<td>printGrid</td>
<td>{none}</td>
<td>Used for debugging purposes only while the visualization scheme was being developed.</td>
</tr>
<tr>
<td>main</td>
<td>Simulate</td>
<td>Performs one iteration of our multigrid solver, which consists of restricting the grids with data from the previous iteration, solving the smaller grids, and solving the largest grid.</td>
</tr>
</tbody>
</table>
<p>The code for the multigrid prototype can be downloaded <a href="code/cs290i/multigridPrototype.zip">here</a>.</p>
<h4><a title="results" name="results"></a>Results</h4>
<p>For the sake of timing purposes, we consider each execution of the &#8216;Simulate&#8217; method to be one step, and we time how many steps can be performed per second. We test this for both the CUDA and C multigrid implementations for grids of size 16 x 16 x 16 through 256 x 256 x 256. We attempted to go larger (to 512), but the CPU&#8217;s memory allocation function (malloc) failed and could not allocate us the 512 MB of memory we needed for each of the four arrays we manipulate on the CPU (note the 512 MB matching up with the grid size 512 is coincidental). That being said, the speedup we achieve is given as follows:</p>
<p><a title="results.png" href="http://shatterednirvana.files.wordpress.com/2007/12/results.png"><img src="http://shatterednirvana.files.wordpress.com/2007/12/results.thumbnail.png" alt="results.png" /></a></p>
<p>For the purposes of this experiment, the % difference is also the speedup between the CUDA and C versions of the multigrid method.</p>
<p><img src="http://shatterednirvana.files.wordpress.com/2007/12/data.png" alt="data.png" /></p>
<p>What is interesting to note is that the CPU version is actually faster on the grid of dimension 64, and that the GPU is not notably faster as we have seen in other CUDA GPU applications. The reason for this is two-fold. First, we were unable to resolve issues we were having getting the Red-Black Gauss-Seidel method to work on our largest grid, so it had to be done on the CPU, and the integer modulo operator we use to get the even and odd points for Red-Black Gauss-Seidel works very fast on the CPU and very slow on the GPU. Furthermore, the grid was stored as a one dimensional array in memory, and to recover the three dimensional array structure, each point had to perform a swizzling method, which also involved using integer modulo operations. Add in the fact that we do this 16 million times per step (once per point on the grid, so 16 million is for the 256 grid) and you see why our speedup was not as good as it could have been. A low resolution video of our CUDA multigrid implementation has been recorded along with a high-resolution screen capture. Both are provided here in that order:</p>
<p><a href="http://cs.ucsb.edu/~cgb/videos/multigrid.mov"></p>
<p><img src="http://shatterednirvana.files.wordpress.com/2007/12/preview64.thumbnail.png" alt="Multigrid Preview Pic" /></p>
<p></a></p>
<p><a title="Multigrid Preview Pic" href="http://shatterednirvana.files.wordpress.com/2007/12/preview64.png"><img src="http://shatterednirvana.files.wordpress.com/2007/12/preview64.thumbnail.png" alt="Multigrid Preview Pic" /></a></p>
<p>Unfortunately, the video recording software we used does not record the high-frame rates of our program very well and thus lags much more than the actual version does. Furthermore, our version is more brilliant in terms of color as the screenshot on the right reveals. We use the a simple 3D rotation technique based on which axes the user is manipulating for rotating the cube, and we provide mouse combinations to allow the user to zoom in and out of the cube and translate themselves in space about the cube. These features are all documented in the above video. As we have refactored Brent Oster&#8217;s C code to produce our CUDA version, we have kept the interaction mechanisms he has implemented intact. We have added functionality to switch rendering on and off to be able to accurately measure how many steps are computed per second, as the rendering negatively impacts it.</p>
<p>On December 14, 2007, this material was presented to our &#8216;GPGPU and 3D User Interfaces&#8217; class. A PDF of the presentation can be found <a href="http://cs.ucsb.edu/~cgb/presentations/multigridWithCUDA.pdf">here</a>. I&#8217;m currently working on putting the code up. The code used for this project consists of three files: NC_Multigrid.cpp, NC_Multigrid.h, NanoCAD2.cpp, and the CUDA source code, Multigridcu.cu. They can be found at the location &#8220;Projects/NanoCAD2/Modules/&#8221;, with the exception of the driver file, which is at &#8220;Projects/NanoCAD2/NanoCAD2.cpp&#8221;.</p>
<h4><a title="cudaReview" name="cudaReview"></a>Pros and Cons of CUDA</h4>
<p>CUDA provides a novel way for the programmer to use the graphics hardware to its fullest. It is both a high and low level language, but because it is a relatively new language, it is not without its downsides.</p>
<p><strong>Pros:</strong></p>
<li><strong>CUDA abstracts as much of the hardware away as you want it to.</strong> Although to really get the best performance you need to dive under the hood and program for the exact hardware you&#8217;re on, you can still get a decent speedup without worrying about it too much. The future of parallel programming languages will rely on their ease of use and how much they can abstract away from the programmer.</li>
<li><strong>CUDA is an important step forward in parallel computing.</strong> The design choices made by the CUDA team will shape how future languages deal with heterogeneous processing systems (here a CPU and a GPU).</li>
<li><strong>It&#8217;s really cool to launch 16 million threads and have them do something actually useful.</strong> Using less than 10 threads at a time in undergraduate classes gives you the impression that you can do everything you&#8217;d ever want to with just 1 or 2 threads. But it&#8217;s something else to launch a thread for each point in your grid, and if you have a 256 x 256 x 256 grid, launching 16 million threads really gives computing a whole different spin.</li>
<li><strong>There is a lot of potential behind CUDA.</strong> Making supercomputing available to the general public will make it much easier to teach new programmers about how to program parallel machines. There&#8217;s also lots of work to be done resolving the downsides of CUDA, which are:</li>
<p><strong>Cons:</strong></p>
<li><strong>Developing in CUDA on Windows with Visual Studio 2005, the supported environment of CUDA, is a nightmare.</strong> Getting started with CUDA was definitely the hardest part of this entire project. It took me no less than two weeks to make a new project and work with it. That being said, I&#8217;m no newcomer to Windows (used it almost my whole life) and Visual Studio 2005 (used it to develop C# applications). However, CUDA is something entirely different. There is a <a href="http://forums.nvidia.com/index.php?showtopic=30273">&#8220;custom build rule&#8221;</a> for CUDA that take a lot of the work out of setting up Visual Studio for use with CUDA, but even after following the directions on using it, it still wouldn&#8217;t work. Even taking the sample projects that came with CUDA and trying to refactor them only worked for a short while, although this may have had to do with&#8230;</li>
<li><strong>Remote Desktop Connection&#8217;s interaction with Windows makes it unusable.</strong> I know, this isn&#8217;t a CUDA problem, as RDC isn&#8217;t supported by CUDA, but there&#8217;s no reason it should be any different from using Visual Studio with other languages. RDC didn&#8217;t seem to consistently convert my <a href="http://en.wikipedia.org/wiki/Newline">newlines</a> on Mac (Line Feed) to Windows (Carriage Return + Line Feed), so Visual Studio thought my code was only one line long. It didn&#8217;t stop the code from working, but it&#8217;s incredibly annoying to have to deal with those error messages about having a problem somewhere on your one line of code and having the compiler point at the beginning of your code as the problem. However, since the same code works fine with the right newlines, I&#8217;d be inclined to say the CUDA compiler (nvcc) doesn&#8217;t seem to like the mix of Line Feeds and Carriage Returns that RDC is putting in there. So I had to ditch RDC and sit in front of the computer I was developing on (as I was having issues getting VNC to work). I was having problems getting emulation mode to work, even after copying all the emulation mode flags the compiler needs, so I had to use the regular mode. That&#8217;s not a problem, however,  until you see what happens when you use too many blocks in regular mode:</li>
<p><img src="http://shatterednirvana.files.wordpress.com/2007/12/theusual.jpeg" alt="theusual.jpeg" /></p>
<p>This wouldn&#8217;t be so bad except for the fact that this happens almost every time something goes wrong, not just with the blocks. In the last four hours of programming in CUDA, this has happened to me FIVE times. Future implementations of CUDA NEED to fix this for CUDA to become even close to viable as a good programming language. My computer shouldn&#8217;t die just because I used memory that I allocated and set to zero but forgot to copy the host&#8217;s version of to. That leads into the next issue&#8230;</p>
<li><strong>CUDA inconsistently throws errors / crashes.</strong> Usually after I see the blue screen of death, I tweak the code and try to compile it, only to see one of thse two screens:</li>
<p><img src="http://shatterednirvana.files.wordpress.com/2007/12/linker.png" alt="linker.png" /></p>
<p><img src="http://shatterednirvana.files.wordpress.com/2007/12/unexpected.png" alt="unexpected.png" /></p>
<p>Trying to recompile the code gives no errors and the code runs fine. So what&#8217;s the deal? I can&#8217;t even get the blue screen of death consistently! Sometimes Visual Studio gives me a cudaError_enum, sometimes the computer locks up, and sometimes it gives me the blue screen. Why can&#8217;t it just be consistent, and consistently the first result?</p>
<li><strong>GPU methods cannot call GPU methods, and consequently, recursion is not allowed.</strong> This is an unfortunate side-effect, and has caused the GPGPU teams to reimplement all the well-known recursive functions (e.g., quick sort) iteratively or find iterative algorithms that suit their purposes better (e.g., bitonic merge sort for the GPU). At this time, it is unclear whether this issue is CUDA-specific or specific to the GPU architecture.</li>
<li><strong>The documentation, while long, fails to mention important macros you can call to improve the quality of your code.</strong> If you read the documentation alone, you&#8217;d have no idea there was a macro you could wrap your cudaMalloc and cudaFree calls around to make sure they succeeded or your program died. It&#8217;s only two extra macro to document, and perhaps two of the most useful macros in CUDA. I can&#8217;t tell you for sure, because I&#8217;ve only read the documentation&#8230;</li>
<li><strong>CUDA will bring out your worst software engineering skills.</strong> This could be the greatest offender, depending on your programming skills. Structs aren&#8217;t allowed as of CUDA 1.0, forcing the programmer to write methods that pass a huge amount of data around. My typical method needed to throw around 6 or 7 variables when one or two well built structs would have been fine. Furthermore, without structs or objects (since it&#8217;s C and not C++), you&#8217;ll find yourself violating the <a href="http://www.artima.com/intv/dry.html">DRY (Don&#8217;t Repeat Yourself) principle</a> constantly. If you&#8217;re not familiar with the DRY principle, you may think this isn&#8217;t a big deal, as you&#8217;re just repeating yourself. But this makes your code harder to maintain, even for just you who knows the code, and with CUDA being a new language, there&#8217;s no reason not to have a construct that packages up data. Perhaps it has to do with the architecture like recursion did&#8230;</li>
<h4>Conclusion</h4>
<p>Whew! What a long review! It&#8217;s been a great quarter full of new opportunities, and thanks to all for letting me use what I&#8217;ve needed to get this done. Special thanks go out to Tobias Hollerer and Brent Oster for use of the hardware and software, respectively, that was used or refactored in some way for this project. CUDA has the potential to go far for sure, but there&#8217;s definitely some huge kinks it needs to work out before it&#8217;s ready for the general public.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/shatterednirvana.wordpress.com/37/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/shatterednirvana.wordpress.com/37/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shatterednirvana.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shatterednirvana.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shatterednirvana.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shatterednirvana.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shatterednirvana.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shatterednirvana.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shatterednirvana.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shatterednirvana.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shatterednirvana.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shatterednirvana.wordpress.com/37/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shatterednirvana.wordpress.com&blog=389350&post=37&subd=shatterednirvana&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://shatterednirvana.wordpress.com/2007/12/20/multigrid-methods-with-cuda/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
<enclosure url="http://cs.ucsb.edu/~cgb/videos/multigrid.mov" length="18937058" type="video/quicktime" />
	
		<media:content url="http://1.gravatar.com/avatar/d3a0edc111d09d96513f737960c67a29?s=96&#38;d=identicon" medium="image">
			<media:title type="html">shatterednirvana</media:title>
		</media:content>

		<media:content url="http://shatterednirvana.files.wordpress.com/2007/12/generalheateqn.png" medium="image">
			<media:title type="html">generalheateqn.png</media:title>
		</media:content>

		<media:content url="http://shatterednirvana.files.wordpress.com/2007/12/hwmodel.png" medium="image">
			<media:title type="html">hwmodel.png</media:title>
		</media:content>

		<media:content url="http://shatterednirvana.files.wordpress.com/2007/12/linearsyseqn.png" medium="image">
			<media:title type="html">linearsyseqn.png</media:title>
		</media:content>

		<media:content url="http://shatterednirvana.files.wordpress.com/2007/12/specificheateqn.png" medium="image">
			<media:title type="html">specificheateqn.png</media:title>
		</media:content>

		<media:content url="http://shatterednirvana.files.wordpress.com/2007/12/results.thumbnail.png" medium="image">
			<media:title type="html">results.png</media:title>
		</media:content>

		<media:content url="http://shatterednirvana.files.wordpress.com/2007/12/data.png" medium="image">
			<media:title type="html">data.png</media:title>
		</media:content>

		<media:content url="http://shatterednirvana.files.wordpress.com/2007/12/preview64.thumbnail.png" medium="image">
			<media:title type="html">Multigrid Preview Pic</media:title>
		</media:content>

		<media:content url="http://shatterednirvana.files.wordpress.com/2007/12/preview64.thumbnail.png" medium="image">
			<media:title type="html">Multigrid Preview Pic</media:title>
		</media:content>

		<media:content url="http://shatterednirvana.files.wordpress.com/2007/12/theusual.jpeg" medium="image">
			<media:title type="html">theusual.jpeg</media:title>
		</media:content>

		<media:content url="http://shatterednirvana.files.wordpress.com/2007/12/linker.png" medium="image">
			<media:title type="html">linker.png</media:title>
		</media:content>

		<media:content url="http://shatterednirvana.files.wordpress.com/2007/12/unexpected.png" medium="image">
			<media:title type="html">unexpected.png</media:title>
		</media:content>
	</item>
		<item>
		<title>Yay!</title>
		<link>http://shatterednirvana.wordpress.com/2007/12/20/yay/</link>
		<comments>http://shatterednirvana.wordpress.com/2007/12/20/yay/#comments</comments>
		<pubDate>Thu, 20 Dec 2007 23:06:16 +0000</pubDate>
		<dc:creator>shatterednirvana</dc:creator>
				<category><![CDATA[School]]></category>

		<guid isPermaLink="false">http://shatterednirvana.wordpress.com/2007/12/20/yay/</guid>
		<description><![CDATA[Grades are in!
GPGPU and 3D User Interfaces: A
Parallel Architectures: A+
Directed Research: S
Cognitive Science Seminar: S
I don&#8217;t know what an S means (satisfactory?), but the first quarter rocked! I&#8217;ll put up versions of my work here soon!
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shatterednirvana.wordpress.com&blog=389350&post=36&subd=shatterednirvana&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Grades are in!</p>
<p>GPGPU and 3D User Interfaces: A</p>
<p>Parallel Architectures: A+</p>
<p>Directed Research: S</p>
<p>Cognitive Science Seminar: S</p>
<p>I don&#8217;t know what an S means (satisfactory?), but the first quarter rocked! I&#8217;ll put up versions of my work here soon!</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/shatterednirvana.wordpress.com/36/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/shatterednirvana.wordpress.com/36/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shatterednirvana.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shatterednirvana.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shatterednirvana.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shatterednirvana.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shatterednirvana.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shatterednirvana.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shatterednirvana.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shatterednirvana.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shatterednirvana.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shatterednirvana.wordpress.com/36/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shatterednirvana.wordpress.com&blog=389350&post=36&subd=shatterednirvana&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://shatterednirvana.wordpress.com/2007/12/20/yay/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d3a0edc111d09d96513f737960c67a29?s=96&#38;d=identicon" medium="image">
			<media:title type="html">shatterednirvana</media:title>
		</media:content>
	</item>
		<item>
		<title>No Place For Democracy</title>
		<link>http://shatterednirvana.wordpress.com/2007/11/23/no-place-for-democracy/</link>
		<comments>http://shatterednirvana.wordpress.com/2007/11/23/no-place-for-democracy/#comments</comments>
		<pubDate>Fri, 23 Nov 2007 11:08:52 +0000</pubDate>
		<dc:creator>shatterednirvana</dc:creator>
				<category><![CDATA[Battlefield Control]]></category>
		<category><![CDATA[Eve]]></category>
		<category><![CDATA[Metal Gear]]></category>
		<category><![CDATA[Philosophy]]></category>
		<category><![CDATA[Politics]]></category>

		<guid isPermaLink="false">http://shatterednirvana.wordpress.com/2007/11/23/no-place-for-democracy/</guid>
		<description><![CDATA[&#8220;There will one day spring from the brain of science a machine or force so fearful in its potentialities, so absolutely terrifying, that even man, the fighter, who will dare torture and death in order to inflict torture and death, will be appalled, and so abandon war forever.&#8221;
 &#8211; Thomas A. Edison

Would it be unethical [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shatterednirvana.wordpress.com&blog=389350&post=33&subd=shatterednirvana&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>&#8220;There will one day spring from the brain of science a machine or force so fearful in its potentialities, so absolutely terrifying, that even man, the fighter, who will dare torture and death in order to inflict torture and death, will be appalled, and so abandon war forever.&#8221;<br />
 &#8211; <a href="http://www.quotedb.com/quotes/1397">Thomas A. Edison</a><br />
<span id="more-33"></span><br />
Would it be unethical to make this Weapon? How many lives would we save by making a Weapon that would constantly check Man&#8217;s dark side and keep us away from war? Yet to make something so brutal, so malicious, it inherently feels so wrong, doesn&#8217;t it? But let&#8217;s look at it a little bit closer, shall we?</p>
<p>The question is not whether or not this is feasible. The advances we have made in the last fifty years are so numerous it would be frivolous to argue otherwise. The relevant questions are (1) what this machine / force would be and (2) what this would do to humanity.</p>
<p>To follow on with Edison&#8217;s quote, I do not believe this terrifying force would be a simple weapon (like a gun). For it to be something that truly scares humanity, it must act on its own. If the weapon if so brutal, it can simply not be used and alternatives can be invented. Thus it must have its own mind. Two examples immediately come to mind (of similar nature): The Patriots (of Metal Gear Solid) and Helios (of Deus Ex).</p>
<p><strong>Disclaimer: Some of the material on the Patriots may change when Metal Gear Solid 4 is released, and on Helios when Deus Ex 3 is released.</strong></p>
<p>Both are artificial intelligences that aim to help humanity, acting as benevolent dictators to some extent. The Patriots control content (in their words, they create context) and claim to keep humanity from destroying themselves. They are much less forceful than Helios is; they do not try to stop war, but keep it at a level they consider to be &#8220;healthy&#8221; given the state of the world. Helios, on the other hand, appears to have no objection doing whatever is necessary to keep humanity &#8220;under control&#8221;. It controls the Internet and everything even remotely electrical and is well aware of what it believes it has to do to save humanity from itself.</p>
<p>Neither of these &#8220;beings&#8221; have taken this role for selfish reasons: they both aim to protect humanity from itself. They both see humanity as a curious baby with a fork near a light socket, seemingly desperate to kill itself. They act as if they are our parents, <a href="http://junkerhq.net/MGS2/index.html">talking down to us</a> and <a href="http://en.wikipedia.org/wiki/Major_Deus_Ex_characters#Helios">taking away our toys</a> (in Helios&#8217; case, stripping power from all the government buildings) as if we are children.</p>
<p>This is not to repeat what I have said earlier about the Patriots&#8217; rant on how humanity cannot take care of itself and needs a guardian. This is to expand on it and bring it into context. Our civilization is not a point right now where true democracy can work. In fact, a benevolent dictatorship is exactly what is needed to save this world from itself. As American citizens, we have come to the point where on the whole, we don&#8217;t really care about what happens in other countries or really what happens here. It&#8217;s an analogy to the South Park episode where the two candidates for South Park&#8217;s mascot are a Giant Douche and a Turd Sandwich: you&#8217;ve got different options, but when it comes down to picking a viable choice, it&#8217;s going to suck.</p>
<p>This is also not to say we should all be involved in politics. Trying to be moderately involved in politics has given me an incredible frustration that I would not wish on other people, and to those that have chosen this for their lives, you are either very brave or very stupid. I hope it is the former.</p>
<p>In a civilization where more Americans care about American Idol than America, it is not fair to have a democracy. It is not fair for me or you to be judged by our peers when our peers care about what will be for dinner or what will be on TV tonight than our fates. And I surely can&#8217;t blame them (too much that is). We certainly do need to pay more attention to the world around us, and stop being scared of every stupid little terrorist thread that turns out to be a hoax, but there is a lot going on in the world. Too much for one person to take in.</p>
<p>That&#8217;s why our benevolent dictatorship cannot be run by a human in the strictest sense of the word. It must be by something that can process data at a much faster rate we can but still has the heart or decision-making skills to guide us forward as a race. The Patriots and Helios surely are selfish beings concerned with their survival, but they certainly care more for our survival than we ever did. And they have the means and the motive to save us.</p>
<p>But if they take a strict approach and become, as Edison says, a force that will be so appalling that man will abandon war forever, what will we become? If we stop being something so core to our existence, we certainly will no longer be human. Knowing the power of these beings and their all-pervasive nature, would we be reduced to beings afraid of our supposed savior(s) until the end of our days? Or would they know better and prevent us from thinking these things? For our sakes, I hope they would.</p>
<p>Perhaps the best approach in this dangerous line of thought is to do as we always try to do when we have two competing ideas: combine them. Perhaps when we are all somewhat augmented / computerized we will have the brainpower and the ability to make these decisions for ourselves in a truly democratic fashion. But as we go along the away, we must not forget that always, there is only a plank between one and Perdition:</p>
<p>“He who fights with monsters might take care lest he thereby become a monster. And if you gaze for long into an abyss, the abyss gazes also into you.”<br />
- <a href="http://thinkexist.com/quotes/friedrich_nietzsche/3.html">Friedrich Nietzsche</a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/shatterednirvana.wordpress.com/33/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/shatterednirvana.wordpress.com/33/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shatterednirvana.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shatterednirvana.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shatterednirvana.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shatterednirvana.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shatterednirvana.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shatterednirvana.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shatterednirvana.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shatterednirvana.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shatterednirvana.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shatterednirvana.wordpress.com/33/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shatterednirvana.wordpress.com&blog=389350&post=33&subd=shatterednirvana&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://shatterednirvana.wordpress.com/2007/11/23/no-place-for-democracy/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d3a0edc111d09d96513f737960c67a29?s=96&#38;d=identicon" medium="image">
			<media:title type="html">shatterednirvana</media:title>
		</media:content>
	</item>
		<item>
		<title>My Favorite Error Message Ever</title>
		<link>http://shatterednirvana.wordpress.com/2007/11/02/my-favorite-error-message-ever/</link>
		<comments>http://shatterednirvana.wordpress.com/2007/11/02/my-favorite-error-message-ever/#comments</comments>
		<pubDate>Fri, 02 Nov 2007 07:25:06 +0000</pubDate>
		<dc:creator>shatterednirvana</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Cell]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[RapidMind]]></category>

		<guid isPermaLink="false">http://shatterednirvana.wordpress.com/2007/11/02/my-favorite-error-message-ever/</guid>
		<description><![CDATA[While running a Poisson Equation Finite Difference approximation algorithm (whew, a mouthful there!) today on Cell, I got the greatest error message ever:
[cgb@cell pfd]$ ./withRapidMind
terminate called after throwing an instance of &#8216;rapidmind::Exception&#8217;
what():  The type &#8216;double&#8217; is not supported by the Cell backend.
Aborted
What the hell indeed. Much thanks to the RapidMind guys for an awesome [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shatterednirvana.wordpress.com&blog=389350&post=31&subd=shatterednirvana&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>While running a Poisson Equation Finite Difference approximation algorithm (whew, a mouthful there!) today on Cell, I got the greatest error message ever:</p>
<p>[cgb@cell pfd]$ ./withRapidMind<br />
terminate called after throwing an instance of &#8216;rapidmind::Exception&#8217;<br />
what():  The type &#8216;double&#8217; is not supported by the Cell backend.<br />
Aborted</p>
<p>What the hell indeed. Much thanks to the RapidMind guys for an awesome function called &#8220;what&#8221; and not supporting the double type (although I&#8217;m sure there&#8217;s a long explanation about that I haven&#8217;t found yet).</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/shatterednirvana.wordpress.com/31/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/shatterednirvana.wordpress.com/31/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shatterednirvana.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shatterednirvana.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shatterednirvana.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shatterednirvana.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shatterednirvana.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shatterednirvana.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shatterednirvana.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shatterednirvana.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shatterednirvana.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shatterednirvana.wordpress.com/31/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shatterednirvana.wordpress.com&blog=389350&post=31&subd=shatterednirvana&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://shatterednirvana.wordpress.com/2007/11/02/my-favorite-error-message-ever/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d3a0edc111d09d96513f737960c67a29?s=96&#38;d=identicon" medium="image">
			<media:title type="html">shatterednirvana</media:title>
		</media:content>
	</item>
		<item>
		<title>Setting up Linux on the Cell (Part 2)</title>
		<link>http://shatterednirvana.wordpress.com/2007/11/01/setting-up-linux-on-the-cell-part-2/</link>
		<comments>http://shatterednirvana.wordpress.com/2007/11/01/setting-up-linux-on-the-cell-part-2/#comments</comments>
		<pubDate>Thu, 01 Nov 2007 05:15:18 +0000</pubDate>
		<dc:creator>shatterednirvana</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Cell]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ranting]]></category>
		<category><![CDATA[RapidMind]]></category>

		<guid isPermaLink="false">http://shatterednirvana.wordpress.com/2007/11/01/setting-up-linux-on-the-cell-part-2/</guid>
		<description><![CDATA[So&#8230;Yellow Dog Linux doesn&#8217;t like SDK 2.1 very much. Turns out I must have done something wrong while trying to install it because it only wants to work on Fedora and I fucked up my ability to compile code for the SPEs and PPE while doing so. So I reinstalled Yellow Dog and this time, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shatterednirvana.wordpress.com&blog=389350&post=29&subd=shatterednirvana&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>So&#8230;Yellow Dog Linux doesn&#8217;t like SDK 2.1 very much. Turns out I must have done something wrong while trying to install it because it only wants to work on Fedora and I fucked up my ability to compile code for the SPEs and PPE while doing so. So I reinstalled Yellow Dog and this time, followed the very simple explanation at the RapidMind website which said just to install the libspe2 rpm and not mess around with anything else. It worked great, but let&#8217;s step back a second here.<br />
<span id="more-29"></span><br />
SDK 2.1 (and I presume the new SDK 3.0) install a Cell Simulator on your machine. What the hell is the point of that? Why is it installing a Cell Simulator on my Cell? Yes, this works fine if you&#8217;re on a Fedora box that you want to develop code for Cell on that isn&#8217;t a Cell box. But if I want to develop on my Cell with the new SDK, don&#8217;t make me go get another box that isn&#8217;t a Cell to go do it! To quote what I&#8217;ve been hearing a lot lately, &#8220;What were they thinking?&#8221; The IBM official instructions say I can do this on a Cell box, but what the hell is the problem here!<br />
/rant</p>
<p>So reinstalling Yellow Dog and RapidMind by their instructions works fine. But I do have a couple gripes which may just be standard Linux issues that I never realized until now for some reason:</p>
<ul>If I sudo up to root, then I should be able to do anything that root could do if root logged in! But I can&#8217;t! I can&#8217;t boot into the ps3 game OS, I can&#8217;t even add groups! What the hell! Completely ridiculous.</ul>
<ul>(Not a Linux problem) X/Gnome looks like shit on my monitor. Holy crap I never realized how bad the analog connections on the PS3 look until I fired up X. If you have the choice and can get a digital connection and a monitor that suports HDCP, buy it. I&#8217;ll put up a screenshot of how miserable this looks sooner or later.</ul>
<p>I&#8217;m sure there are other things, and I&#8217;ll put them up as I remember them. Asides from those little gripes, the environment is actually very nice. Here&#8217;s a nice how-to that helped me out a bit: <a href="http://www.cellperformance.com/articles/2006/11/crosscompiling_for_ps3_linux.html">CellPerformance.Com</a>. I&#8217;d link directly to the RapidMind page too, but you have to login for that (although it is free to sign up).</p>
<p>Anywho, we&#8217;re gonna benchmark the Cell versus a slightly-faster-than-average PC and do some other cool stuff with that. Check back later for how that turns out.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/shatterednirvana.wordpress.com/29/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/shatterednirvana.wordpress.com/29/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shatterednirvana.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shatterednirvana.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shatterednirvana.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shatterednirvana.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shatterednirvana.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shatterednirvana.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shatterednirvana.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shatterednirvana.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shatterednirvana.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shatterednirvana.wordpress.com/29/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shatterednirvana.wordpress.com&blog=389350&post=29&subd=shatterednirvana&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://shatterednirvana.wordpress.com/2007/11/01/setting-up-linux-on-the-cell-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d3a0edc111d09d96513f737960c67a29?s=96&#38;d=identicon" medium="image">
			<media:title type="html">shatterednirvana</media:title>
		</media:content>
	</item>
		<item>
		<title>Setting up Linux on the Cell (Part 1)</title>
		<link>http://shatterednirvana.wordpress.com/2007/10/30/setting-up-linux-on-the-cell/</link>
		<comments>http://shatterednirvana.wordpress.com/2007/10/30/setting-up-linux-on-the-cell/#comments</comments>
		<pubDate>Tue, 30 Oct 2007 07:24:35 +0000</pubDate>
		<dc:creator>shatterednirvana</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Cell]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[RapidMind]]></category>

		<guid isPermaLink="false">http://shatterednirvana.wordpress.com/2007/10/30/setting-up-linux-on-the-cell/</guid>
		<description><![CDATA[So we got a PS3 for research in the lab the other day and we got to set up Linux on it. It&#8217;s actually pretty painless, although if you can, get a monitor that supports DVI and supports HDCP so you can get the digital connection. We only have analog in the lab so it [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shatterednirvana.wordpress.com&blog=389350&post=28&subd=shatterednirvana&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>So we got a PS3 for research in the lab the other day and we got to set up Linux on it. It&#8217;s actually pretty painless, although if you can, get a monitor that supports DVI and supports HDCP so you can get the digital connection. We only have analog in the lab so it looks like crap. Seriously though, it looks like feces and I have to use SSH to get anything done. That being said, here&#8217;s how to do it:<br />
<span id="more-28"></span><br />
This actually isn&#8217;t a how-to or anything. We just followed the directions at the <a href="http://www.ibm.com/developerworks/library/pa-linuxps3-1/">IBM website</a> and it was all set up. I actually wanted to set up <a href="http://rapidmind.net/">RapidMind</a> to fiddle with parallelizing applications in an &#8220;easier&#8221; fashion (check back later to see if it actually was easier) and needed to set up libspe2. Libspe1 comes with Cell, but to set up libspe2, you&#8217;ll need to install the Cell SDK 2.1 (2.0 comes with Cell and the IBM link above, use <a href="http://www.alphaworks.ibm.com/tech/cellsw/download">this link</a> for 2.1). I&#8217;m installing it right now, but if it doesn&#8217;t work, I&#8217;ll let you know, and if it gets really bad, it will become a how-to. Either way, I&#8217;m looking at using Cell for multigrid method solving and visualization, or maybe something unrelated, but I&#8217;ll let you know.</p>
<p><strong>UPDATE (10/30/07):</strong> Turns out installing SDK 2.1 went terrible. More on this later.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/shatterednirvana.wordpress.com/28/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/shatterednirvana.wordpress.com/28/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shatterednirvana.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shatterednirvana.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shatterednirvana.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shatterednirvana.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shatterednirvana.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shatterednirvana.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shatterednirvana.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shatterednirvana.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shatterednirvana.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shatterednirvana.wordpress.com/28/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shatterednirvana.wordpress.com&blog=389350&post=28&subd=shatterednirvana&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://shatterednirvana.wordpress.com/2007/10/30/setting-up-linux-on-the-cell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d3a0edc111d09d96513f737960c67a29?s=96&#38;d=identicon" medium="image">
			<media:title type="html">shatterednirvana</media:title>
		</media:content>
	</item>
		<item>
		<title>&#8220;Portable&#8221; Package Management is Bullshit {Mostly}</title>
		<link>http://shatterednirvana.wordpress.com/2007/10/25/portable-package-management-is-bullshit-mostly/</link>
		<comments>http://shatterednirvana.wordpress.com/2007/10/25/portable-package-management-is-bullshit-mostly/#comments</comments>
		<pubDate>Thu, 25 Oct 2007 10:38:34 +0000</pubDate>
		<dc:creator>shatterednirvana</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ranting]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://shatterednirvana.wordpress.com/2007/10/25/portable-package-management-is-bullshit-mostly/</guid>
		<description><![CDATA[I don&#8217;t always want to code in Java. In fact, I&#8217;ve recently wanted to not program in Java and get a feel for everything else that&#8217;s neat and nifty and blah blah blah. But Java spoiled me. I got used to having my libraries distributed with my package, and having it work on other systems [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shatterednirvana.wordpress.com&blog=389350&post=27&subd=shatterednirvana&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I don&#8217;t always want to code in Java. In fact, I&#8217;ve recently wanted to not program in Java and get a feel for everything else that&#8217;s neat and nifty and blah blah blah. But Java spoiled me. I got used to having my libraries distributed with my package, and having it work on other systems pretty easily. So imagine the fun times I had trying to get MySQL and SMTP support working in other languages&#8230;<br />
<span id="more-27"></span><br />
So all I need to do is read in a file, parse some e-mail addresses and names out of it, make accounts in MySQL, and send the users e-mails using SMTP. Doesn&#8217;t sound too tricky, and in fact, this sounds like something Perl would be great for. But the fact of the matter is that it took goddamn forever to figure out how to install the MySQL package with CPAN (the Perl package manager), and I couldn&#8217;t even get the SMTP package working on the server I needed it on (although it works fine on my local box). That&#8217;s completely ridiculous. I can&#8217;t get MySQL and SMTP support in Perl for Linux. Standard, vanilla Linux.</p>
<p>So I tried it in Ruby. I really wanted to do it in Ruby. The new Netbeans beta supports Ruby development (a whole &#8216;nother blog post on that may be coming soon&#8230;), and it got me really excited about Ruby. Unfortunately, that whole predicament went even worse, and the error messages that either of these give you will make sure that you&#8217;re not fixing these problems on your own.</p>
<p>I&#8217;m not asking for a quantum computer simulator that works on all systems. Ironically enough, that is available here (<a href="http://jquantum.sourceforge.net/jQuantumApplet.html">jQuantum</a>) for all systems and it looks very interesting on first glance. What I am saying is that MySQL and SMTP are not new players in their fields, and in fact are very well-established in their fields. These things need to work on all platforms in their languages, especially on the common Linux distributions.</p>
<p>For anyone who cared long enough to get here, I ended up with a Perl script that parses the file and does the MySQL stuff, and produces a file of e-mail addresses that a bash script takes in and e-mails out using sendmail (that script was readily on hand). Better luck next time. Sigh.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/shatterednirvana.wordpress.com/27/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/shatterednirvana.wordpress.com/27/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shatterednirvana.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shatterednirvana.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shatterednirvana.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shatterednirvana.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shatterednirvana.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shatterednirvana.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shatterednirvana.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shatterednirvana.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shatterednirvana.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shatterednirvana.wordpress.com/27/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shatterednirvana.wordpress.com&blog=389350&post=27&subd=shatterednirvana&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://shatterednirvana.wordpress.com/2007/10/25/portable-package-management-is-bullshit-mostly/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d3a0edc111d09d96513f737960c67a29?s=96&#38;d=identicon" medium="image">
			<media:title type="html">shatterednirvana</media:title>
		</media:content>
	</item>
		<item>
		<title>Bloom Filters</title>
		<link>http://shatterednirvana.wordpress.com/2007/09/21/bloom-filters/</link>
		<comments>http://shatterednirvana.wordpress.com/2007/09/21/bloom-filters/#comments</comments>
		<pubDate>Fri, 21 Sep 2007 04:24:44 +0000</pubDate>
		<dc:creator>shatterednirvana</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://shatterednirvana.wordpress.com/2007/09/21/bloom-filters/</guid>
		<description><![CDATA[I&#8217;ve been getting more into my programming roots lately, and after I read this CodeKata, I decided to give it a try. The idea is to write a Bloom Filter, fiddle with the parameters that make it what it is, and test its performance. That being said, let&#8217;s look at it.

The way I understood the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shatterednirvana.wordpress.com&blog=389350&post=26&subd=shatterednirvana&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;ve been getting more into my programming roots lately, and after I read this <a href="http://codekata.pragprog.com/2007/01/kata_five_bloom.html">CodeKata</a>, I decided to give it a try. The idea is to write a Bloom Filter, fiddle with the parameters that make it what it is, and test its performance. That being said, let&#8217;s look at it.<br />
<span id="more-26"></span><br />
The way I understood the Bloom Filter is as follows: get a large list (here, the UNIX dictionary, located at /usr/share/dict/words for Mac OS X users), perform some kind of mapping function, keep some subset of the result, and store that in an array. It doesn&#8217;t matter if multiple words in the dictionary map to the same result, but you will see a small percentage of words NOT in the dictionary match up and appear to be in the dictionary (a false positive). This summary is pretty much the same as what is said in the previous link, so let&#8217;s get to something original here.</p>
<p>The Perl script below takes in each word from the dictionary file, gets the MD5 hex value associated with it, and keeps the first 6 characters of it. The &#8220;6&#8243; can be changed to whatever you like, but lowering it will increase the number of false positives and increasing it will reduce the savings in file size you&#8217;re getting from using the Bloom Filter in the first place.</p>
<p>We then (as the Kata post above recommends) generate random 5 character words and see if they match up in our Bloom Filtered Array. If so, we make sure that we didn&#8217;t accidentally generate a real word. My Perl script is set to do this 10000 times, taking on average 10 minutes.</p>
<p>I ran this script 3 times, getting 159 false positives the first time, 145 the second, and 141 the third time. This averages to 147 false positives when checking 10000 random words, yielding a 1.47% error rate. That&#8217;s pretty good, if I don&#8217;t say so myself. The savings in file size is not too shabby as well. The dictionary file is 2.49MB, while the Bloom Filtered Array is 1.64 MB (a 34% reduction in size). This may not look too great, but on bigger data sets, a 1.47% error rate may be justifiable in exchange for cutting your data set&#8217;s size down by a third. Below is my code if you wish to try it out (requires a *NIX of some sort):</p>
<blockquote><p> #!/usr/bin/perl<br />
use strict;<br />
use warnings;<br />
use Digest::MD5 qw(md5 md5_hex md5_base64);</p>
<p># Chris Bunch<br />
# Bloom Filter implemented along these guidelines:<br />
# http://codekata.pragprog.com/2007/01/kata_five_bloom.html<br />
# Creates an array and for each word in /usr/dict/words<br />
# MD5&#8217;s the word and places the first n bits of it in the array</p>
<p># Do not create array if -nocreate is seen</p>
<p># Create array, size = wc -l /usr/share/dict/words</p>
<p>my $arraySize = `wc -l /usr/share/dict/words`;<br />
my @wordList = `cat /usr/share/dict/words`;<br />
my @bloomFilter;</p>
<p># Length of words in the Bloom Filter</p>
<p>my $md5Length = 6;</p>
<p># For each line of /usr/share/dict/words</p>
<p>foreach my $thisWord (@wordList) {</p>
<p># MD5 this word, save the first n bits</p>
<p>chomp ($thisWord);<br />
my $hash = md5_hex($thisWord);<br />
my $substring = substr($hash, 0, $md5Length);</p>
<p># Place it into the array at this place</p>
<p>push(@bloomFilter, $substring);<br />
}</p>
<p>my $i = 0;<br />
my @letters = qw(a b c d e f g h i j k l m n o p q r s t u v w x y z);</p>
<p>while ($i &lt; 10000) {<br />
my $searchWord = $letters[int(rand(@letters))] . $letters[int(rand(@letters))] . $letters[int(rand(@letters))] . $letters[int(rand(@letters))] . $letters[int(rand(@letters))];</p>
<p># map the word to the first n bits of its MD5</p>
<p>my $hashedWord = md5_hex($searchWord);<br />
my $substring = substr($hashedWord, 0, $md5Length);</p>
<p># look it up in the array</p>
<p>my $found = &#8220;false&#8221;;<br />
foreach my $thisWord (@bloomFilter) {</p>
<p>if ($substring eq $thisWord) {<br />
$found = &#8220;true&#8221;;<br />
}<br />
}</p>
<p># if present, print present, otherwise, print not present</p>
<p>if ($found eq &#8220;true&#8221;) {<br />
my @grepResults = `grep $searchWord /usr/share/dict/words`;<br />
foreach my $result (@grepResults) {<br />
chomp ($result);<br />
if ($result eq $searchWord) {<br />
$found = &#8220;false&#8221;;<br />
}<br />
}</p>
<p>if ($found eq &#8220;true&#8221;) {<br />
print &#8220;\n$searchWord was found&#8221;;<br />
}</p>
<p>}<br />
else {</p>
<p>}</p>
<p>$i++;<br />
}</p></blockquote>
<p>As always, if you see something miserably wrong with the code or have any comments, feel free to drop me a line.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/shatterednirvana.wordpress.com/26/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/shatterednirvana.wordpress.com/26/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shatterednirvana.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shatterednirvana.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shatterednirvana.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shatterednirvana.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shatterednirvana.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shatterednirvana.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shatterednirvana.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shatterednirvana.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shatterednirvana.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shatterednirvana.wordpress.com/26/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shatterednirvana.wordpress.com&blog=389350&post=26&subd=shatterednirvana&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://shatterednirvana.wordpress.com/2007/09/21/bloom-filters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d3a0edc111d09d96513f737960c67a29?s=96&#38;d=identicon" medium="image">
			<media:title type="html">shatterednirvana</media:title>
		</media:content>
	</item>
		<item>
		<title>It&#8217;s Everyone&#8217;s Fault</title>
		<link>http://shatterednirvana.wordpress.com/2007/09/18/its-everyones-fault/</link>
		<comments>http://shatterednirvana.wordpress.com/2007/09/18/its-everyones-fault/#comments</comments>
		<pubDate>Tue, 18 Sep 2007 05:29:45 +0000</pubDate>
		<dc:creator>shatterednirvana</dc:creator>
				<category><![CDATA[OCaml]]></category>
		<category><![CDATA[Ranting]]></category>

		<guid isPermaLink="false">http://shatterednirvana.wordpress.com/2007/09/18/its-everyones-fault/</guid>
		<description><![CDATA[&#8230;and no one&#8217;s. We have an infrastructure that is ridiculously difficult to maintain and even more difficult to make &#8220;simple&#8221; changes to. It&#8217;s often come up as to whose fault it is that it ended up this way. But it&#8217;s my opinion that it&#8217;s all of our faults, and at the same time, none of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shatterednirvana.wordpress.com&blog=389350&post=25&subd=shatterednirvana&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>&#8230;and no one&#8217;s. We have an infrastructure that is ridiculously difficult to maintain and even more difficult to make &#8220;simple&#8221; changes to. It&#8217;s often come up as to whose fault it is that it ended up this way. But it&#8217;s my opinion that it&#8217;s all of our faults, and at the same time, none of our faults.<br />
<span id="more-25"></span><br />
I don&#8217;t blame the original developers for their choice of language (OCaml). As in my &#8216;About&#8217; page, I don&#8217;t think the choice of language particularly damns us. However, I believe that a very small number of critical mistakes were made that have resulted in the current state of affairs. I was not in employment when the development was made, so I do not have insight to their working conditions or their rebuttals to the following list. I can only speak for what I have seen, and I make this short list knowing it is incomplete and biased. In no particular order:</p>
<ul>The documentation is incomplete and inconsistent. We have placed most of it on a central server, but the organization of it does not easily lend itself to be found. I had to dive through all the folders to find documentation that until now, I didn&#8217;t even know existed or had seen before long ago. Furthermore, it lacks the documentation needed for several key infrastructure services such as our identity management daemon (RMWD).</ul>
<ul>The knowledge transfer process was definitely lacking. This is the main part that I believe is everyone&#8217;s fault and no one&#8217;s. It&#8217;s like that feeling you get when you&#8217;re supposed to hang out with your friends and they don&#8217;t call you that day, but you don&#8217;t call them either. Neither the leaving developers nor the management made the knowledge transfer a priority, but we didn&#8217;t know the gravity of the situation. But then again, how could we have? It&#8217;s no excuse for sure, it&#8217;s just my rebuttal.</ul>
<p>I suppose I could go on, but I think that pretty much covers it. Of course, please give me your input on this, especially if you feel differently.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/shatterednirvana.wordpress.com/25/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/shatterednirvana.wordpress.com/25/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shatterednirvana.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shatterednirvana.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shatterednirvana.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shatterednirvana.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shatterednirvana.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shatterednirvana.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shatterednirvana.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shatterednirvana.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shatterednirvana.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shatterednirvana.wordpress.com/25/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shatterednirvana.wordpress.com&blog=389350&post=25&subd=shatterednirvana&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://shatterednirvana.wordpress.com/2007/09/18/its-everyones-fault/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/d3a0edc111d09d96513f737960c67a29?s=96&#38;d=identicon" medium="image">
			<media:title type="html">shatterednirvana</media:title>
		</media:content>
	</item>
	</channel>
</rss>