<?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&#039;s blog &#187; Parallel Programming</title>
	<atom:link href="http://www.surajshrestha.com.np/category/parallel-programming/feed" rel="self" type="application/rss+xml" />
	<link>http://www.surajshrestha.com.np</link>
	<description>imagination more important than knowledge</description>
	<lastBuildDate>Sun, 08 Aug 2010 23:20:16 +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>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>
	</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 Analytics Code -->
