<?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>Suraj</title>
	<atom:link href="http://www.surajshrestha.com.np/feed" rel="self" type="application/rss+xml" />
	<link>http://www.surajshrestha.com.np</link>
	<description>a technological experience</description>
	<lastBuildDate>Tue, 15 Sep 2009 14:25:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Use EditPad Pro to check your Regular Expressions</title>
		<link>http://www.surajshrestha.com.np/software/use-editpad-pro-to-check-your-regular-expressions.html</link>
		<comments>http://www.surajshrestha.com.np/software/use-editpad-pro-to-check-your-regular-expressions.html#comments</comments>
		<pubDate>Tue, 15 Sep 2009 14:07:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[EditPad Pro]]></category>
		<category><![CDATA[Regular Expression]]></category>
		<category><![CDATA[Software Tools]]></category>

		<guid isPermaLink="false">http://www.surajshrestha.com.np/?p=235</guid>
		<description><![CDATA[If you are into PHP or other programming languages, you may need to write regular expressions very often. It may be tedious to run the whole program to check whether the regular expression you wrote is correct or not. So, if you have some sample string where you can find your desired regular expression match, [...]]]></description>
			<content:encoded><![CDATA[<p>If you are into PHP or other programming languages, you may need to write regular expressions very often. It may be tedious to run the whole program to check whether the regular expression you wrote is correct or not. So, if you have some sample string where you can find your desired regular expression match, <strong>EditPad Pro</strong> can be a very handy tool to check your regular expressions. Only you need to write or pase your search string ( where to find regex match) and your regular expression and search for Regular Expression match if any in given search string. You can also click on &#8220;Highlight&#8221; button and see if regular expression that you are writing matches any substring in search string at real time.</p>
<p>The screen shot is shown below. Evaluation version is free.</p>
<div style="text-align: left;">The regular expression mentioned in the picture searches for the url link from &lt;a&gt; tags.</div>
<div style="text-align: left;">There is also another tool from same vendor called RegexMagic, but it may not be much handy as you have to learn how to use  that tool.</div>
<div id="d-ta" style="text-align: left;"><a href="http://docs.google.com/File?id=dhmdxngb_68zps5jmf3_b" target="_blank"><br />
</a><a href="http://farm3.static.flickr.com/2560/3922383295_00e7d859fd_b.jpg"><img class="alignleft" title="EditPad Pro Snap" src="http://farm3.static.flickr.com/2560/3922383295_00e7d859fd_b.jpg" alt="" width="666" height="532" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.surajshrestha.com.np/software/use-editpad-pro-to-check-your-regular-expressions.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Memoized version of Fibonacci number calculation using only one variable in Java</title>
		<link>http://www.surajshrestha.com.np/algorithm/memoized-version-of-fibonacci-number-calculation-using-only-one-variable.html</link>
		<comments>http://www.surajshrestha.com.np/algorithm/memoized-version-of-fibonacci-number-calculation-using-only-one-variable.html#comments</comments>
		<pubDate>Wed, 05 Aug 2009 04:01:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Brute Force]]></category>
		<category><![CDATA[Fibonacci]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Memoization]]></category>
		<category><![CDATA[Recursive]]></category>

		<guid isPermaLink="false">http://www.surajshrestha.com.np/uncategorized/memoized-version-of-fibonacci-number-calculation-using-only-one-variable.html</guid>
		<description><![CDATA[Fibonacci number can be calculated using different techniques. Most common recursive technique is brute force where we calculate Fibonacci number by repeatedly calling the method of numbers less by one and less by two. In this technique, we do not care the fact the previous Fibonacci number may have been calculated. However, in Memoized technique, [...]]]></description>
			<content:encoded><![CDATA[<p>Fibonacci number can be calculated using different techniques. Most common recursive technique is brute force where we calculate Fibonacci number by repeatedly calling the method of numbers less by one and less by two. In this technique, we do not care the fact the previous Fibonacci number may have been calculated. However, in Memoized technique, we store the results in some array or variable and calculate new values from old calculated values. Source codes for brute force technique, memorized with array and memoized with one variable are given below.</p>
<p>1) Source code for<strong> Brute force technique</strong></p>
<p>public class Fibonacci { </p>
<p>&#160;&#160;&#160; int recursiveCalls= 0;   <br />&#160;&#160;&#160; </p>
<p>&#160;&#160;&#160; public int fib(int n){   <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; recursiveCalls++;    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; if( n==0 || n==1){    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return 1;    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; else{    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return fib(n-2) + fib(n-1);    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160; }    <br />&#160;&#160;&#160; public static void main(String[] args) {    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; Fibonacci f = new Fibonacci();    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println(&quot;Fib (30): &quot; + f.fib(30));    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println(&quot;Counter: &quot; + f.recursiveCalls);    <br />&#160;&#160;&#160; }    <br />}</p>
<p>2) Source code for <strong>Memoized technique using Table Array</strong></p>
<p>public class Fibonacci {   <br />&#160;&#160;&#160; int recursiveCalls= 0 ;    <br />&#160;&#160;&#160; int memoizedFib(int n){&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; int f[]= new int[n+1];    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; return recursiveFib(f,n);    <br />&#160;&#160;&#160; }    <br />&#160;&#160;&#160; int recursiveFib(int f[], int n){    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; recursiveCalls++;    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; if ( n==0 || n==1)    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; f[n] = 1;    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; else{    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (f[n-1] == 0)    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; recursiveFib(f, n-1);    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (f[n-2] == 0)    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; recursiveFib(f, n-2);    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; f[n] = f[n-2] + f[n-1];    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; return f[n];    <br />&#160;&#160;&#160; }    <br />}</p>
<p>&#160;</p>
<p>3) Source code for <strong>Memoized technique using one variable</strong></p>
<p>public class Fibonacci { </p>
<p>&#160;&#160;&#160; int recursiveCalls = 0;   <br />&#160;&#160;&#160; int a=0;    <br />&#160;&#160;&#160; int fib(int n){    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; recursiveCalls ++;    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (n==1){    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; a = 1;    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return 0 + a;    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; else{    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; int b = fib(n-1);    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; int c = a + b;    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; a = b;    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return c;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; }    <br />&#160;&#160;&#160; }    <br /> }</p>
<p>&#160;</p>
<p>The number of recursive Calls made for calculation of Fibonacci of 30 is 2692537 in Brute force technique where as it is 30 in memoized techniques</p>
]]></content:encoded>
			<wfw:commentRss>http://www.surajshrestha.com.np/algorithm/memoized-version-of-fibonacci-number-calculation-using-only-one-variable.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Algorithm to calculate height of a binary tree</title>
		<link>http://www.surajshrestha.com.np/algorithm/algorithm-to-calculate-height-of-a-binary-tree.html</link>
		<comments>http://www.surajshrestha.com.np/algorithm/algorithm-to-calculate-height-of-a-binary-tree.html#comments</comments>
		<pubDate>Mon, 03 Aug 2009 22:33:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Algorithm]]></category>
		<category><![CDATA[Binary Tree]]></category>
		<category><![CDATA[Data structure]]></category>
		<category><![CDATA[Recursive]]></category>

		<guid isPermaLink="false">http://www.surajshrestha.com.np/?p=216</guid>
		<description><![CDATA[Binary tree is a data structure of tree shape in which each node can have either 2 or 0 children(s). Height of a tree is the maximum depth of nodes of the tree. Here is the algorithm to that returns the height of the tree. It should be called by passing position of root node [...]]]></description>
			<content:encoded><![CDATA[<p>Binary tree is a data structure of tree shape in which each node can have either 2 or 0 children(s). Height of a tree is the maximum depth of nodes of the tree. Here is the algorithm to that returns the height of the tree. It should be called by passing position of root node of tree as argument.</p>
<blockquote>
<pre><em><span style="color: #000000;">Algorithm getHeight(pos)</span></em></pre>
<pre><em><span style="color: #000000;">     Input position pos of the node whose height is to be found out</span></em></pre>
<pre><em><span style="color: #000000;">     If (isInternal(pos))</span></em></pre>
<pre><em><span style="color: #000000;">             X = getHeight(leftchild(pos))</span></em></pre>
<pre><em><span style="color: #000000;">             Y = getHeight(rightchild(pos))</span></em></pre>
<pre><em><span style="color: #000000;">             Return greater(X,Y) + 1</span></em></pre>
<pre><em><span style="color: #000000;"> Return 0</span></em></pre>
</blockquote>
<p>The method names used above are</p>
<p><strong>isInternal(pos) </strong>- Returns true if the position pos is internal</p>
<p><strong>leftchild(pos)</strong> &#8211; Returns the position of the left child of the pos</p>
<p><strong>rightchild(pos)</strong> &#8211; Returns the position of the right child of the pos</p>
<p><strong>geater(X,Y)</strong> &#8211; Returns greater of X and Y.</p>
<p>At each node, the recursive algorithm will accumulate height of left and right sub tree and pass it to parent by adding 1 to the greater one. However, if the node is external it will simply return 0 to parent. This is how the algorithm works.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.surajshrestha.com.np/algorithm/algorithm-to-calculate-height-of-a-binary-tree.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Error while restoring SQL Server 2000 database backup onto 2008 database.</title>
		<link>http://www.surajshrestha.com.np/sql-server/error-while-restoring-sql-server-2000-database-backup-onto-2008-database.html</link>
		<comments>http://www.surajshrestha.com.np/sql-server/error-while-restoring-sql-server-2000-database-backup-onto-2008-database.html#comments</comments>
		<pubDate>Sun, 19 Jul 2009 18:03:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Database Restore]]></category>
		<category><![CDATA[SQL Server 2000]]></category>
		<category><![CDATA[SQL Server 2008]]></category>

		<guid isPermaLink="false">http://www.surajshrestha.com.np/?p=211</guid>
		<description><![CDATA[Normally, you cannot restore SQL Server 2000 database backup onto SQL Server 2008 database. This may be due to different collation technique or some other properties. If you try to restore 2000 database backup to 2008 database, you usually get the following error.
&#8220;System.Data.SqlClient.SqlError : The backup set  holds a backup of a database other than [...]]]></description>
			<content:encoded><![CDATA[<p>Normally, you cannot restore SQL Server 2000 database backup onto SQL Server 2008 database. This may be due to different collation technique or some other properties. If you try to restore 2000 database backup to 2008 database, you usually get the following error.</p>
<p><em>&#8220;System.Data.SqlClient.SqlError : The backup set  holds a backup of a database other than the existing &#8216;&lt;database name&gt;&#8217; database. (Microsoft.SqlServer.Smo)&#8221;</em></p>
<p>The snapshot of error is shown below.</p>
<p style="text-align: center;"><a href="http://www.flickr.com/photos/40035183@N05/3736031102/"><img class="aligncenter" title="SQL Server 2008 Restore Problem" src="http://farm3.static.flickr.com/2486/3736031102_a9854553bf_b.jpg" alt="" width="614" height="346" /></a></p>
<p>To avoid this error, you will have to restore backup (2000) as new database in SQL Server 2008 from SQL Server 2008 Management Studio. For this, Go to Object Browser of management studio. Then Right click the &#8216;Databases&#8217;, select &#8216;Restore Database&#8217;. Give a new name for the database that is going to be created. Then, select the backup file and restore. This will add a new database created from backup with the name you just typed in. If the name already exists, it will try to overwrite and backup will fail.</p>
<p>However, there are other many techniques to migrate database from SQL Server 2000 to SQL Server 2008.</p>
<p>1) Detach and Attach &#8211; You can detach database files from SQL Server 2000 and attach them to SQL Server 2008. However, detach and attach is not recommended method by experts due to chance of breaking data integrity.</p>
<p>2) Copy Database Wizard &#8211; It helps to copy database from selected source to destination easily.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.surajshrestha.com.np/sql-server/error-while-restoring-sql-server-2000-database-backup-onto-2008-database.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Publish your emails to a blog automatically</title>
		<link>http://www.surajshrestha.com.np/blogging/publish-your-emails-to-a-blog-automatically.html</link>
		<comments>http://www.surajshrestha.com.np/blogging/publish-your-emails-to-a-blog-automatically.html#comments</comments>
		<pubDate>Sat, 27 Jun 2009 03:39:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Blogging]]></category>
		<category><![CDATA[Blogger.com]]></category>
		<category><![CDATA[GMail]]></category>

		<guid isPermaLink="false">http://www.surajshrestha.com.np/?p=206</guid>
		<description><![CDATA[If your emails are not so confidential and you donot want to waste time logging into email account and read email by clicking next button, here is a tweak. You can create a new blog from blogger.com, set a unique email posting address at blog&#8217;s setting and forward your email to that address. The steps involved [...]]]></description>
			<content:encoded><![CDATA[<p>If your emails are not so confidential and you donot want to waste time logging into email account and read email by clicking next button, here is a tweak. You can create a new blog from blogger.com, set a unique email posting address at blog&#8217;s setting and forward your email to that address. The steps involved are described below.</p>
<p>Create a blog at Blogger.com (or any other blogging site).</p>
<p>Go to Settings -&gt;Email &amp; Mobile.</p>
<p>Create an Email Posting Address in Posting Options and click &#8216;Save Settings&#8217;. This email address is unique and should be used only to post to your blog.</p>
<p>Now, go to your Gmail (or other email) account setting.</p>
<p>Go to Forwarding and POP/IMAP.</p>
<p>Select option &#8220;Forward a copy of incoming mail to&#8221; and type the Email Posting Address (unique address that you created from blog settings above)</p>
<p>Then select appropriate option (either delete or archieve gmail&#8217;s email copy or do nothing).</p>
<p>Then you are done.</p>
<p>You can also subscribe to some newsletters, fun stuffs so that, they get automatically posted to your blog.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.surajshrestha.com.np/blogging/publish-your-emails-to-a-blog-automatically.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Configure Eclipse to show Content help (intellisense) in Java</title>
		<link>http://www.surajshrestha.com.np/java/configure-eclipse-to-show-content-help-intellisense-in-java.html</link>
		<comments>http://www.surajshrestha.com.np/java/configure-eclipse-to-show-content-help-intellisense-in-java.html#comments</comments>
		<pubDate>Fri, 26 Jun 2009 13:34:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Content Assist]]></category>
		<category><![CDATA[Eclipse]]></category>

		<guid isPermaLink="false">http://www.surajshrestha.com.np/?p=202</guid>
		<description><![CDATA[If you are running Eclipse for first time for Java, you may not get content assitant help while pressing Ctrl+Space saying &#8220;No Default Proposals&#8221;. To get Content Assist Help (like Intellisense in Microsoft Visual Studio), you have to configure it at first.
In Eclipse IDE, go to Windows -&#62; Preferences. A new window opens.
In left pane, [...]]]></description>
			<content:encoded><![CDATA[<p>If you are running Eclipse for first time for Java, you may not get content assitant help while pressing Ctrl+Space saying &#8220;No Default Proposals&#8221;. To get Content Assist Help (like Intellisense in Microsoft Visual Studio), you have to configure it at first.</p>
<p>In Eclipse IDE, go to Windows -&gt; Preferences. A new window opens.</p>
<p>In left pane, click Java -&gt; Editor -&gt; Content Assit -&gt; Advanced.</p>
<p>Now, in right pane top box, you can select Proposals to be shown in Default Proposal of Content Assist.</p>
<p>Finally, Click Ok to save the configuration and you are done.</p>
<p><img class="aligncenter" title="Content Assist Configuration in Eclipse" src="http://farm4.static.flickr.com/3379/3662786718_37e9c82f5b.jpg?v=0" alt="" width="480" height="500" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.surajshrestha.com.np/java/configure-eclipse-to-show-content-help-intellisense-in-java.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Parallel Rank sort using Java Thread</title>
		<link>http://www.surajshrestha.com.np/java/parallel-rank-sort-using-java-thread.html</link>
		<comments>http://www.surajshrestha.com.np/java/parallel-rank-sort-using-java-thread.html#comments</comments>
		<pubDate>Wed, 24 Jun 2009 21:32:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Java Thread]]></category>
		<category><![CDATA[Parallel Rank Sort]]></category>
		<category><![CDATA[Rank Sort]]></category>

		<guid isPermaLink="false">http://www.surajshrestha.com.np/?p=194</guid>
		<description><![CDATA[In this post, I have included code that uses Java Threads to calculate ranks of numbers in list[] array and put then in respective position (determined by rank) in finallist[] array. It is a relaxed algorithm as none of the threads created interact with each other.
import java.util.Random; /* library file to generate random number */
public [...]]]></description>
			<content:encoded><![CDATA[<p>In this post, I have included code that uses Java Threads to calculate ranks of numbers in list[] array and put then in respective position (determined by rank) in finallist[] array. It is a relaxed algorithm as none of the threads created interact with each other.</p>
<p><strong>import</strong> java.util.Random; /* library file to generate random number */</p>
<p><strong>public</strong> <strong>class</strong> ParallelRankSort {</p>
<p>      <strong>int</strong>[] list = <strong>new</strong> <strong>int</strong>[10]; </p>
<p>      <strong>int</strong> finallist[] = <strong>new</strong> <strong>int</strong>[10];</p>
<p>      <strong>final</strong> <strong>int</strong> n = 10;     </p>
<p>      <strong>public</strong> <strong>void</strong> initialize(){</p>
<p>            Random r = <strong>new</strong> Random(10);           </p>
<p>            <strong>for</strong>(<strong>int</strong> i=0; i&lt;n; i++){</p>
<p>                  list[n-1-i] =r.nextInt(50);</p>
<p>            }          </p>
<p>      }</p>
<p>      <strong>public</strong> <strong>void</strong> runThreads(){</p>
<p>            Thread t[] = <strong>new</strong> Thread[n];       </p>
<p>            <strong>for</strong>(<strong>int</strong> i=0; i&lt;n; i++){</p>
<p>                  FindRank f = <strong>new</strong> FindRank(list[i],list,finallist);</p>
<p>                  t[i] = <strong>new</strong> Thread(f);</p>
<p>                  t[i].start();</p>
<p>            }</p>
<p>            <strong>for</strong>(<strong>int</strong> i=0; i&lt;n; i++){</p>
<p>                  <strong>try</strong> {</p>
<p>                        t[i].join();</p>
<p>                  } <strong>catch</strong> (InterruptedException e) {                   </p>
<p>                        e.printStackTrace();</p>
<p>                  }</p>
<p>            }</p>
<p> </p>
<p>      }</p>
<p>     </p>
<p>      <strong>public</strong> <strong>void</strong> displayOutput(){</p>
<p>            //initial data</p>
<p>            System.<em>out</em>.println(&#8221;Initial data&#8221;);</p>
<p>            <strong>for</strong>(<strong>int</strong> i=0; i&lt;n; i++){</p>
<p>                  System.<em>out</em>.println(&#8221;list[" + i + "] = &#8221; + list[i]);</p>
<p>            }           </p>
<p>            System.<em>out</em>.println(&#8221;After sorting&#8221;);</p>
<p>            System.<em>out</em>.println(&#8221;");</p>
<p>            <strong>for</strong>(<strong>int</strong> i=0; i&lt;n; i++){</p>
<p>                  System.<em>out</em>.println(&#8221;finalList[" + i + "] = &#8221; + finallist[i]);</p>
<p>            }</p>
<p>      }</p>
<p>      <strong>public</strong> <strong>static</strong> <strong>void</strong> main(String[] args){</p>
<p>            ParallelRankSort p = <strong>new</strong> ParallelRankSort();</p>
<p>            p.initialize();</p>
<p>            p.runThreads();</p>
<p>            p.displayOutput();</p>
<p>      }</p>
<p> </p>
<p>}</p>
<p> //Runnable classes to be run by threads created above</p>
<p><strong>class</strong> FindRank <strong>implements</strong> Runnable{</p>
<p>      <strong>int</strong> data;</p>
<p>      <strong>int</strong> list[];</p>
<p>      <strong>int</strong> finallist[];</p>
<p>      FindRank(<strong>int</strong> data, <strong>int</strong>[] list, <strong>int</strong> finallist[]){</p>
<p>            <strong>this</strong>.data = data;</p>
<p>            <strong>this</strong>.list = list;</p>
<p>            <strong>this</strong>.finallist = finallist;</p>
<p>      }</p>
<p> </p>
<p>      <strong>public</strong> <strong>void</strong> run(){</p>
<p>            <strong>int</strong> count =0 ;</p>
<p>            <strong>for</strong>(<strong>int</strong> i=0; i&lt;list.length; i++){</p>
<p>                  <strong>if</strong>(list[i]&lt;data){</p>
<p>                        count++;</p>
<p>                  }</p>
<p>            }</p>
<p>            finallist[count] = data;</p>
<p>      }</p>
<p>}</p>
<p><strong>The output obtained is shown below.</strong></p>
<div><span style="font-size: x-small;"></span></div>
<p> </p>
<p><span style="font-size: x-small;"></p>
<p align="left">Initial data</p>
<p align="left">list[0] = 14</p>
<p align="left">list[1] = 31</p>
<p align="left">list[2] = 38</p>
<p align="left">list[3] = 47</p>
<p align="left">list[4] = 6</p>
<p align="left">list[5] = 46</p>
<p align="left">list[6] = 40</p>
<p align="left">list[7] = 43</p>
<p align="left">list[8] = 30</p>
<p align="left">list[9] = 13</p>
<p align="left">After sorting</p>
<p align="left"> </p>
<p align="left">finalList[0] = 6</p>
<p align="left">finalList[1] = 13</p>
<p align="left">finalList[2] = 14</p>
<p align="left">finalList[3] = 30</p>
<p align="left">finalList[4] = 31</p>
<p align="left">finalList[5] = 38</p>
<p align="left">finalList[6] = 40</p>
<p align="left">finalList[7] = 43</p>
<p align="left">finalList[8] = 46</p>
<p>finalList[9] = 47</p>
<p> </p>
<p></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.surajshrestha.com.np/java/parallel-rank-sort-using-java-thread.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to setup visual studio to run parallel programs using openmp in visual C++?</title>
		<link>http://www.surajshrestha.com.np/microsoft-visual-studio/visual-c/how-to-setup-visual-studio-to-run-parallel-programs-using-openmp-in-visual-c.html</link>
		<comments>http://www.surajshrestha.com.np/microsoft-visual-studio/visual-c/how-to-setup-visual-studio-to-run-parallel-programs-using-openmp-in-visual-c.html#comments</comments>
		<pubDate>Wed, 17 Jun 2009 22:31:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Visual C++]]></category>
		<category><![CDATA[OpenMP]]></category>

		<guid isPermaLink="false">http://www.surajshrestha.com.np/?p=191</guid>
		<description><![CDATA[If you write a program to be run in parallel in multiple cores of a computer or multi-computer, then you should setup a configuration in visual studio before it actually runs in multiple cores (or computer).
Here are the steps.
1. Go to Project -&#62;&#8221;Project Name&#8221; Properties.
2. Go to Configuration Properties.
3. Go to C/C++ -&#62; Language
4. In the [...]]]></description>
			<content:encoded><![CDATA[<p>If you write a program to be run in parallel in multiple cores of a computer or multi-computer, then you should setup a configuration in visual studio before it actually runs in multiple cores (or computer).</p>
<p>Here are the steps.</p>
<p>1. Go to Project -&gt;&#8221;Project Name&#8221; Properties.</p>
<p>2. Go to Configuration Properties.</p>
<p>3. Go to C/C++ -&gt; Language</p>
<p>4. In the right window, look for OpenMP Support and set its value to <strong>Yes</strong> and you are done.</p>
<p>After this configuration, you will actually be able to run the program in parallel.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.surajshrestha.com.np/microsoft-visual-studio/visual-c/how-to-setup-visual-studio-to-run-parallel-programs-using-openmp-in-visual-c.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A simple parallel program using OpenMp in Microsoft Visual C++</title>
		<link>http://www.surajshrestha.com.np/parallel-programming/a-simple-parallel-program-using-openmp-in-microsoft-visual-c.html</link>
		<comments>http://www.surajshrestha.com.np/parallel-programming/a-simple-parallel-program-using-openmp-in-microsoft-visual-c.html#comments</comments>
		<pubDate>Mon, 15 Jun 2009 13:06:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Parallel Programming]]></category>
		<category><![CDATA[iostream]]></category>
		<category><![CDATA[MS Visual Studio]]></category>
		<category><![CDATA[omp]]></category>
		<category><![CDATA[OpenMP]]></category>

		<guid isPermaLink="false">http://www.surajshrestha.com.np/?p=184</guid>
		<description><![CDATA[Here is the code of a program that creates 10 parallel threads and computes the square root of 10 integers of &#8216;number&#8217; array and places in &#8216;root&#8217; array.
omp_set_num_threads(p) sets the number of threads to be created to p.
The following statement creates p (set by omp_set_num_threads) parallel processes and assigns n/p iterations to each process in [...]]]></description>
			<content:encoded><![CDATA[<p>Here is the code of a program that creates 10 parallel threads and computes the square root of 10 integers of &#8216;number&#8217; array and places in &#8216;root&#8217; array.</p>
<p><span style="FONT-SIZE: x-small">omp_set_num_threads(p) sets the number of threads to be created to p.</span></p>
<p><span style="FONT-SIZE: x-small">The following statement creates p (set by omp_set_num_threads) parallel processes and assigns n/p iterations to each process in serial order. So, first n/p interations will be done by first process.</span></p>
<p><span style="FONT-SIZE: x-small"><span style="COLOR: #0000ff; FONT-SIZE: x-small"><span style="COLOR: #0000ff; FONT-SIZE: x-small">#pragma</span></span><span style="FONT-SIZE: x-small"> omp parallel </span><span style="COLOR: #0000ff; FONT-SIZE: x-small"><span style="COLOR: #0000ff; FONT-SIZE: x-small">for</span></span></span></p>
<p style="TEXT-ALIGN: justify"><span style="COLOR: #0000ff; FONT-SIZE: x-small"><span style="COLOR: #0000ff; FONT-SIZE: x-small">for</span></span><span style="FONT-SIZE: x-small">(i=0; i&lt;n; i++)</span></p>
<p style="TEXT-ALIGN: justify"><span style="FONT-SIZE: x-small">{</span></p>
<p style="TEXT-ALIGN: justify">     root[i] = sqrt(numbers[i]);</p>
<p style="TEXT-ALIGN: justify">}</p>
<p style="TEXT-ALIGN: justify">The complete code is given below.</p>
<p><span style="font-size: x-small;"><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;"> </span></span></span></p>
<p><span style="font-size: x-small;"><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">#include</span></span><span style="color: #000000; font-size: x-small;"> </span><span style="color: #a31515; font-size: x-small;"><span style="color: #a31515; font-size: x-small;">&#8220;stdafx.h&#8221;</span></span></span></p>
<p><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">#include</span></span><span style="color: #000000; font-size: x-small;"> </span><span style="color: #a31515; font-size: x-small;"><span style="color: #a31515; font-size: x-small;">&lt;omp.h&gt;</span></span></p>
<p><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">#include</span></span><span style="color: #000000; font-size: x-small;"> </span><span style="color: #a31515; font-size: x-small;"><span style="color: #a31515; font-size: x-small;">&lt;math.h&gt;</span></span></p>
<p><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">#include</span></span><span style="color: #000000; font-size: x-small;"> </span><span style="color: #a31515; font-size: x-small;"><span style="color: #a31515; font-size: x-small;">&lt;iostream&gt;</span></span></p>
<p><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">#include</span></span><span style="color: #000000; font-size: x-small;"> </span><span style="color: #a31515; font-size: x-small;"><span style="color: #a31515; font-size: x-small;">&lt;stdio.h&gt;</span></span></p>
<p><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">#include</span></span><span style="color: #000000; font-size: x-small;"> </span><span style="color: #a31515; font-size: x-small;"><span style="color: #a31515; font-size: x-small;">&lt;conio.h&gt;</span></span></p>
<p><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">#define</span></span><span style="font-size: x-small;"><span style="color: #000000;"> n 10</span></span></p>
<p><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">using</span></span><span style="color: #000000; font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">namespace</span></span><span style="color: #000000; font-size: x-small;"> std; </span><span style="color: #008000; font-size: x-small;"><span style="color: #008000; font-size: x-small;">/*used for cout*/</span></span></p>
<p><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">int</span></span><span style="font-size: x-small;"><span style="color: #000000;"> main()</span></span></p>
<p><span style="font-size: x-small;">{</span></p>
<p><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">int</span></span><span style="font-size: x-small;"> i;</span></p>
<p><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">float</span></span><span style="font-size: x-small;"> numbers[n], root[n];</span></p>
<p><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">for</span></span><span style="font-size: x-small;">(i=0; i&lt;n; i++)</span></p>
<p><span style="font-size: x-small;">{</span></p>
<p>numbers[i] = (i+1);</p>
<p>}</p>
<p><span style="font-size: x-small;">omp_set_num_threads(n); </span><span style="color: #008000; font-size: x-small;"><span style="color: #008000; font-size: x-small;">/*creates n parallel threads*/</span></span></p>
<p><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">#pragma</span></span><span style="font-size: x-small;"> omp parallel </span><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">for</span></span><span style="font-size: x-small;"> </span><span style="color: #008000; font-size: x-small;"><span style="color: #008000; font-size: x-small;">/*runs the statement following in parallel*/</span></span></p>
<p><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">for</span></span><span style="font-size: x-small;">(i=0; i&lt;n; i++)</span></p>
<p><span style="font-size: x-small;">{</span></p>
<p>root[i] = sqrt(numbers[i]);</p>
<p>}</p>
<p><span style="color: #0000ff; font-size: x-small;"><span style="color: #0000ff; font-size: x-small;">for</span></span><span style="font-size: x-small;">(i=0; i&lt;n; i++)</span></p>
<p><span style="font-size: x-small;">{</span></p>
<p><span style="font-size: x-small;">cout&lt;&lt;numbers[i]&lt;&lt;</span><span style="color: #a31515; font-size: x-small;"><span style="color: #a31515; font-size: x-small;">&#8221; &#8220;</span></span><span style="font-size: x-small;">&lt;&lt;root[i]&lt;&lt;endl;</span></p>
<p><span style="font-size: x-small;">}</span></p>
<p><span style="font-size: x-small;">getch(); </span><span style="color: #008000; font-size: x-small;"><span style="color: #008000; font-size: x-small;">/*just to pause the output */</span></span></p>
<p><span style="font-size: x-small;">}</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.surajshrestha.com.np/parallel-programming/a-simple-parallel-program-using-openmp-in-microsoft-visual-c.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Difference between Response.Redirect() and Server.Transfer() in ASP.Net</title>
		<link>http://www.surajshrestha.com.np/web-application/difference-between-responseredirect-and-servertransfer-in-aspnet.html</link>
		<comments>http://www.surajshrestha.com.np/web-application/difference-between-responseredirect-and-servertransfer-in-aspnet.html#comments</comments>
		<pubDate>Sat, 09 May 2009 04:32:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Web Application]]></category>
		<category><![CDATA[Fiddler]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[HTTP Request and Respond]]></category>
		<category><![CDATA[Packet Sniffer]]></category>

		<guid isPermaLink="false">http://www.surajshrestha.com.np/?p=156</guid>
		<description><![CDATA[Response.Redirect() and Server.Transfer() both bring the contents from new location (specified as parameter) in web server to the client (browser). However, there are some key differences between these two commands. ]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span lang="EN-US"><span style="font-family: Calibri; font-size: small;">Response.Redirect() and Server.Transfer() both bring the contents from new location (specified as parameter) in web server to the client (browser). However, there are some key differences between these two commands. The main difference is that, Redirect() forces the browser to redirect to new location whereas Transfer() makes server to transfer to new location. The point here is, who does the work, it is either client or server. I am going to deal the difference in terms of the HTTP Request generated and HTTP Response received.</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span lang="EN-US"><span style="font-family: Calibri; font-size: small;">Steps involved in Response.Redirect()</span></span></p>
<p class="MsoListParagraphCxSpFirst" style="text-indent: -0.25in; margin: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;" lang="EN-US"><span style="mso-list: Ignore;"><span style="font-family: Calibri; font-size: small;">1.</span><span style="font: 7pt &quot;Times New Roman&quot;;">       </span></span></span><span lang="EN-US"><span style="font-size: small;"><span style="font-family: Calibri;"><span style="mso-spacerun: yes;"> </span>Client (browser) sends a POST or GET request to the web server with details of new web location to be redirected.</span></span></span></p>
<p class="MsoListParagraphCxSpLast" style="text-indent: -0.25in; margin: 0in 0in 10pt 0.5in; mso-list: l0 level1 lfo1;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;" lang="EN-US"><span style="mso-list: Ignore;"><span style="font-family: Calibri; font-size: small;">2.</span><span style="font: 7pt &quot;Times New Roman&quot;;">       </span></span></span><span lang="EN-US"><span style="font-family: Calibri; font-size: small;">Server checks the new location and if the location is found, it will respond back with 302 Found message. The response message format is like shown below. The message is catched by packet sniffing software called fiddler2.</span></span></p>
<p class="MsoNoSpacing" style="margin: 0in 0in 0pt 1in;"><span style="font-size: 9pt;" lang="EN-US"><span style="font-family: Calibri;">HTTP/1.1 302 Found</span></span></p>
<p class="MsoNoSpacing" style="margin: 0in 0in 0pt 1in;"><span style="font-size: 9pt;" lang="EN-US"><span style="font-family: Calibri;">Server: ASP.NET Development Server/9.0.0.0</span></span></p>
<p class="MsoNoSpacing" style="margin: 0in 0in 0pt 1in;"><span style="font-size: 9pt;" lang="EN-US"><span style="font-family: Calibri;">Date: Fri, 08 May 2009 13:49:28 GMT</span></span></p>
<p class="MsoNoSpacing" style="margin: 0in 0in 0pt 1in;"><span style="font-size: 9pt;" lang="EN-US"><span style="font-family: Calibri;">X-AspNet-Version: 2.0.50727</span></span></p>
<p class="MsoNoSpacing" style="margin: 0in 0in 0pt 1in;"><span style="font-size: 9pt;" lang="EN-US"><span style="font-family: Calibri;">Location: /StateDemoApp/StatusPage.aspx</span></span></p>
<p class="MsoNoSpacing" style="margin: 0in 0in 0pt 1in;"><span style="font-size: 9pt;" lang="EN-US"><span style="font-family: Calibri;">Set-Cookie: tempCookie=6; path=/</span></span></p>
<p class="MsoNoSpacing" style="margin: 0in 0in 0pt 1in;"><span style="font-size: 9pt;" lang="EN-US"><span style="font-family: Calibri;">Set-Cookie: permCookie=0; expires=Fri, 08-May-2009 13:51:28 GMT; path=/</span></span></p>
<p class="MsoNoSpacing" style="margin: 0in 0in 0pt 1in;"><span style="font-size: 9pt;" lang="EN-US"><span style="font-family: Calibri;">Cache-Control: private</span></span></p>
<p class="MsoNoSpacing" style="margin: 0in 0in 0pt 1in;"><span style="font-size: 9pt;" lang="EN-US"><span style="font-family: Calibri;">Content-Type: text/html; charset=utf-8</span></span></p>
<p class="MsoNoSpacing" style="margin: 0in 0in 0pt 1in;"><span style="font-size: 9pt;" lang="EN-US"><span style="font-family: Calibri;">Content-Length: 150</span></span></p>
<p class="MsoNoSpacing" style="margin: 0in 0in 0pt 1in;"><span style="font-size: 9pt;" lang="EN-US"><span style="font-family: Calibri;">Connection: Close</span></span></p>
<p class="MsoNoSpacing" style="margin: 0in 0in 0pt 1in;"><span style="font-size: 9pt;" lang="EN-US"><span style="font-family: Calibri;"> </span></span></p>
<p class="MsoNoSpacing" style="margin: 0in 0in 0pt 1in;"><span style="font-size: 9pt;" lang="EN-US"><span style="font-family: Calibri;">&lt;html&gt;&lt;head&gt;&lt;title&gt;Object moved&lt;/title&gt;&lt;/head&gt;&lt;body&gt;</span></span></p>
<p class="MsoNoSpacing" style="margin: 0in 0in 0pt 1in;"><span style="font-size: 9pt;" lang="EN-US"><span style="font-family: Calibri;">&lt;h2&gt;Object moved to &lt;a href=&#8221;%2fStateDemoApp%2fStatusPage.aspx&#8221;&gt;here&lt;/a&gt;.&lt;/h2&gt;</span></span></p>
<p class="MsoNoSpacing" style="margin: 0in 0in 0pt 1in;"><span style="font-size: 9pt;" lang="EN-US"><span style="font-family: Calibri;">&lt;/body&gt;&lt;/html&gt;</span></span></p>
<p class="MsoListParagraphCxSpFirst" style="text-indent: -0.25in; margin: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;" lang="EN-US"><span style="mso-list: Ignore;"><span style="font-family: Calibri; font-size: small;">3.</span><span style="font: 7pt &quot;Times New Roman&quot;;">       </span></span></span><span lang="EN-US"><span style="font-family: Calibri; font-size: small;">The client knows that this message is not for display and it is ok to redirect to new location.</span></span></p>
<p class="MsoListParagraphCxSpMiddle" style="text-indent: -0.25in; margin: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;" lang="EN-US"><span style="mso-list: Ignore;"><span style="font-family: Calibri; font-size: small;">4.</span><span style="font: 7pt &quot;Times New Roman&quot;;">       </span></span></span><span lang="EN-US"><span style="font-family: Calibri; font-size: small;">Then, client generates a new GET HTTP Request, requesting contents from new location.</span></span></p>
<p class="MsoListParagraphCxSpLast" style="text-indent: -0.25in; margin: 0in 0in 10pt 0.5in; mso-list: l0 level1 lfo1;"><span style="mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin;" lang="EN-US"><span style="mso-list: Ignore;"><span style="font-family: Calibri; font-size: small;">5.</span><span style="font: 7pt &quot;Times New Roman&quot;;">       </span></span></span><span lang="EN-US"><span style="font-family: Calibri; font-size: small;">The server then serves it as a brand new request. It does not remember the client as it is follow up of previous Response.Redirect(). In fact, no need to remember.</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span lang="EN-US"><span style="font-family: Calibri; font-size: small;">So, in Response.Redirect(), two round trips to the server are involved. In Response.Redirect(), we cannot pass on the form variable. Also, we cannot preserve those variables for reuse. In this method, the control is completely transferred to new page. However, the execution of current page can still be continued.</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span lang="EN-US"><span style="font-family: Calibri; font-size: small;">In Server.Tranfer() method, the transfer is done by server. In involves only one round trip to server. The server finds out the new location and if it ok, it serves the content. The new content from new location is served as the part of the originating application, i.e. the URL address remains same and not changed to new address unlike in Redirect() method. So, this method has got one major disadvantage that, if somebody wants to bookmark the new address, he or she will not be able to do so, as only one address is visible in address bar.</span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.surajshrestha.com.np/web-application/difference-between-responseredirect-and-servertransfer-in-aspnet.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- www.000webhost.com Analytics Code -->
<script type="text/javascript" src="http://analytics.hosting24.com/count.php"></script>
<noscript><a href="http://www.hosting24.com/"><img src="http://analytics.hosting24.com/count.php" alt="web hosting" /></a></noscript>
<!-- End Of Code -->
