geopi Wiki Rss Feedhttp://code.msdn.microsoft.com/geopi/Wiki/View.aspx?title=Homegeopi Wiki Rss DescriptionUPDATED WIKI: Homehttp://code.msdn.microsoft.com/geopi/Wiki/View.aspx?title=Home&version=10<div class="wikidoc">
<h2>
<b>Using .NET4 Parallel Extensions - Geometric Approximation of PI</b>
</h2> <br /><ul>
<li>EXERCISE 1: CONFIGURE EVENT TRACING </li><li>EXERCISE 2: CALCULATE PI USING A SERIAL PROCEDURE </li><li>EXERCISE 3: CALCULATE PI USING A THREAD POOL </li><li>EXERCISE 4: CALCULATE PI USING TASK PARALLELIZATION</li>
</ul> <br /><h2>
<b>Try it Yourself!</b>
</h2><ul>
<li><a href="https://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=geopi" class="externalLink">Download the documentation and demonstration code. <span class="externalLinkIcon"></span></a></li><li><a href="http://channel9.msdn.com/tags/Parallel+Computing+Platform/" class="externalLink">See related video demonstrations at MSDN Channel9. <span class="externalLinkIcon"></span></a></li><li><a href="http://msdn.microsoft.com/en-us/concurrency/default.aspx" class="externalLink">Refer to the MSDN Concurrency Dev Center.<span class="externalLinkIcon"></span></a></li><li><a href="http://code.msdn.microsoft.com/Project/ProjectDirectory.aspx?ProjectSearchText=PCP" class="externalLink">See related Code Gallery projects. <span class="externalLinkIcon"></span></a></li>
</ul> <br /><img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=geopi&DownloadId=9402" alt="new_9guy_small.png" /><br />
</div>philpennSun, 14 Mar 2010 00:02:28 GMTUPDATED WIKI: Home 20100314AUPDATED WIKI: Homehttp://code.msdn.microsoft.com/geopi/Wiki/View.aspx?title=Home&version=9<div class="wikidoc">
<h2>
<b>Using .NET4 Parallel Extensions - Geometric Approximation of PI</b>
</h2> <br /><ul>
<li>EXERCISE 1: PARALLELIZE AN EXISTING ALGORITHM USING THE STATIC PARALLEL HELPER CLASS </li><ul>
<li>Task 1 – Parallelizing a Long Running Service </li>
</ul><li>EXERCISE 2: CREATE AND RUN PARALLELIZED TASKS</li><ul>
<li>Task 1 – Natively Running Parallelized Tasks </li><li>Task 2 – Using the Wait() and WaitAll() Methods </li><li>Task 3 – Using the IsCompleted Property </li><li>Task 4 – Using the ContinueWith() Method </li>
</ul><li>EXERCISE 3: USE THE GENERIC TASK CLASS TO CREATE AND RUN TASKS THAT RETURN A VALUE </li><ul>
<li>Task 1 – Capturing a Task’s Return Value </li>
</ul><li>EXERCISE 4: PARALLELIZE LINQ QUERIES USING PLINQ </li><ul>
<li>Task 1 – Using the ParallelEnumerable Class’ Static Methods to Parallelize LINQ </li><li>Task 2 – Using the ParallelEnumerable Class’ Extension Methods to Parallelize LINQ </li><li>Task 3 – Using AsParallel() With Query Comprehension Syntax</li>
</ul>
</ul> <br /><h2>
<b>Try it Yourself!</b>
</h2><ul>
<li><a href="https://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=geopi" class="externalLink">Download the documentation and demonstration code. <span class="externalLinkIcon"></span></a></li><li><a href="http://channel9.msdn.com/tags/Parallel+Computing+Platform/" class="externalLink">See related video demonstrations at MSDN Channel9. <span class="externalLinkIcon"></span></a></li><li><a href="http://msdn.microsoft.com/en-us/concurrency/default.aspx" class="externalLink">Refer to the MSDN Concurrency Dev Center.<span class="externalLinkIcon"></span></a></li><li><a href="http://code.msdn.microsoft.com/Project/ProjectDirectory.aspx?ProjectSearchText=PCP" class="externalLink">See related Code Gallery projects. <span class="externalLinkIcon"></span></a></li>
</ul> <br /><img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=geopi&DownloadId=9402" alt="new_9guy_small.png" /><br />
</div>philpennSat, 13 Mar 2010 23:16:57 GMTUPDATED WIKI: Home 20100313PUPDATED WIKI: Homehttp://code.msdn.microsoft.com/geopi/Wiki/View.aspx?title=Home&version=8<div class="wikidoc">
<h2>
<b>Using .NET4 Parallel Extensions - Geometric Approximation of PI</b>
</h2> <br /><ul>
<li>EXERCISE 1: PARALLELIZE AN EXISTING ALGORITHM USING THE STATIC PARALLEL HELPER CLASS </li><ul>
<li>Task 1 – Parallelizing a Long Running Service </li>
</ul><li>EXERCISE 2: CREATE AND RUN PARALLELIZED TASKS</li><ul>
<li>Task 1 – Natively Running Parallelized Tasks </li><li>Task 2 – Using the Wait() and WaitAll() Methods </li><li>Task 3 – Using the IsCompleted Property </li><li>Task 4 – Using the ContinueWith() Method </li>
</ul><li>EXERCISE 3: USE THE GENERIC TASK CLASS TO CREATE AND RUN TASKS THAT RETURN A VALUE </li><ul>
<li>Task 1 – Capturing a Task’s Return Value </li>
</ul><li>EXERCISE 4: PARALLELIZE LINQ QUERIES USING PLINQ </li><ul>
<li>Task 1 – Using the ParallelEnumerable Class’ Static Methods to Parallelize LINQ </li><li>Task 2 – Using the ParallelEnumerable Class’ Extension Methods to Parallelize LINQ </li><li>Task 3 – Using AsParallel() With Query Comprehension Syntax</li>
</ul>
</ul> <br /><h2>
<b>Try it Yourself!</b>
</h2><ul>
<li><a href="https://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=geopi" class="externalLink">Download the documentation and demonstration code. <span class="externalLinkIcon"></span></a></li><li><a href="http://channel9.msdn.com/tags/Parallel+Computing+Platform/" class="externalLink">See related video demonstrations at MSDN Channel9. <span class="externalLinkIcon"></span></a></li><li><a href="http://msdn.microsoft.com/en-us/concurrency/default.aspx" class="externalLink">Refer to the MSDN Concurrency Dev Center.<span class="externalLinkIcon"></span></a></li><li><a href="http://code.msdn.microsoft.com/Project/ProjectDirectory.aspx?ProjectSearchText=PCP" class="externalLink">See related Code Gallery projects. <span class="externalLinkIcon"></span></a></li>
</ul> <br /><span class="unresolved">Cannot resolve link: </span>[image:new_9guy_small.png]<br />
</div>philpennSat, 13 Mar 2010 23:16:23 GMTUPDATED WIKI: Home 20100313PUPDATED WIKI: Homehttp://code.msdn.microsoft.com/geopi/Wiki/View.aspx?title=Home&version=7<div class="wikidoc">
<b>Resource Page Description</b><br />This sample illustrates how to using .NET4 parallel extensions.
<br /> <br /><h2>
<b>Scenario</b>
</h2> <br />In the following set of exercises, you will implement an application that calculates Pi by using a geometric approximation. Initially, you will perform the calculation in a single-threaded manner; you will then change the code to divide the calculation into discrete operations and perform the calculation by using thread pool threads. Finally, you will change the code to use the Task Parallel Library to perform each operation as a parallel task. In the process, you will uncover some data synchronization issues that you must deal with.<br /> <br />The algorithm that you will implement calculates Pi based on some simple mathematics and statistical sampling.<br />If you draw a circle of radius r and then draw a square with sides that touch the circle, the sides of the square are 2 * r in length, as shown in Figure 1.<br /> <br /><img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=geopi&DownloadId=9234" alt="Figure 1" /><br /> <br /><b>Figure 1. Circle and bounding square.</b><br /> <br /> <br /> <br />The area of the square, S, is calculated as follows:<br /> <br />S = (2 * r) * (2 * r)<br />This can be rearranged as: <br /> <br />S = 4 * r * r<br /> <br />You can further rearrange to give:<br /> <br />r * r = S / 4<br /> <br />The area of the circle, C, is calculated as follows:<br /> <br />C = Pi * r * r<br /> <br />Substituting for r*r and rearranging gives:<br /> <br />Pi = 4 * C / S<br /> <br />To calculate Pi, you must determine the value of the ratio C / S. This is where statistical sampling helps.<br /> <br />To do this, generate a set of random points that lie inside the square, and count how many of these points also fall inside the circle. If you have generated a sufficiently large and random sample, the ratio of points that lie inside the circle to the points that lie inside the square (and also in the circle) approximates the ratio of the areas of the two shapes, C / S. All you have to do is count them.<br /> <br />How do you determine whether a point lies inside the circle? To help visualize the solution, draw the square on a piece of graph paper with the center of the square at the origin, which is point (0, 0). You can then generates pairs of values, or coordinates, that lie inside the range (-r, -r) to (+r, +r). You can determine whether any set of coordinates (x, y) lie inside the circle by applying Pythagoras’ theorem to calculate the distance (d) of these coordinates from the origin. You can compute d as the square root of ((x * x) + (y * y)). If d is less than or equal to r, the radius of the circle, the coordinates (x, y) specify a point inside the circle, as shown in Figure 2.<br /> <br /><img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=geopi&DownloadId=9235" alt="Figure 2" /><br /> <br /><b>Figure 2. Illustrating the distance of the point from the center of the circle.</b><br /> <br /> <br />You can simplify matters further by generating only coordinates that lie in the upper-right quadrant of the graph, so that you only have to generate pairs of random numbers between 0 and r. This is the approach that you will take in the exercises.<br />
</div>philpennSat, 27 Feb 2010 00:48:25 GMTUPDATED WIKI: Home 20100227AUPDATED WIKI: Homehttp://code.msdn.microsoft.com/geopi/Wiki/View.aspx?title=Home&version=6<div class="wikidoc">
<b>Resource Page Description</b><br />This sample illustrates how to using .NET4 parallel extensions.
<br /> <br /><h2>
<b>Scenario</b>
</h2> <br />In the following set of exercises, you will implement an application that calculates Pi by using a geometric approximation. Initially, you will perform the calculation in a single-threaded manner; you will then change the code to divide the calculation into discrete operations and perform the calculation by using thread pool threads. Finally, you will change the code to use the Task Parallel Library to perform each operation as a parallel task. In the process, you will uncover some data synchronization issues that you must deal with.<br /> <br />The algorithm that you will implement calculates Pi based on some simple mathematics and statistical sampling.<br />If you draw a circle of radius r and then draw a square with sides that touch the circle, the sides of the square are 2 * r in length, as shown in Figure 1.<br /> <br /><img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=geopi&DownloadId=9234" alt="Figure 1" /><br /> <br /><b>Figure 1. Circle and bounding square.</b><br /> <br /> <br /> <br />The area of the square, S, is calculated as follows:<br /> <br />S = (2 * r) * (2 * r)<br />This can be rearranged as: <br /> <br />S = 4 * r * r<br /> <br />You can further rearrange to give:<br /> <br />r * r = S / 4<br /> <br />The area of the circle, C, is calculated as follows:<br /> <br />C = Pi * r * r<br /> <br />Substituting for r*r and rearranging gives:<br /> <br />Pi = 4 * C / S<br /> <br />To calculate Pi, you must determine the value of the ratio C / S. This is where statistical sampling helps.<br /> <br />To do this, generate a set of random points that lie inside the square, and count how many of these points also fall inside the circle. If you have generated a sufficiently large and random sample, the ratio of points that lie inside the circle to the points that lie inside the square (and also in the circle) approximates the ratio of the areas of the two shapes, C / S. All you have to do is count them.<br /> <br />How do you determine whether a point lies inside the circle? To help visualize the solution, draw the square on a piece of graph paper with the center of the square at the origin, which is point (0, 0). You can then generates pairs of values, or coordinates, that lie inside the range (-r, -r) to (+r, +r). You can determine whether any set of coordinates (x, y) lie inside the circle by applying Pythagoras’ theorem to calculate the distance (d) of these coordinates from the origin. You can compute d as the square root of ((x * x) + (y * y)). If d is less than or equal to r, the radius of the circle, the coordinates (x, y) specify a point inside the circle, as shown in Figure 2.<br /> <br /><img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=geopi&DownloadId=9235" alt="Figure 2" /><br /> <br /><b>Figure 2 Illustrating the distance of the point from the center of the circle.</b><br />
</div>philpennSat, 27 Feb 2010 00:46:13 GMTUPDATED WIKI: Home 20100227AUPDATED WIKI: Homehttp://code.msdn.microsoft.com/geopi/Wiki/View.aspx?title=Home&version=5<div class="wikidoc">
<b>Resource Page Description</b><br />This sample illustrates how to using .NET4 parallel extensions.
<br /> <br /><h2>
<b>Scenario</b>
</h2> <br />In the following set of exercises, you will implement an application that calculates Pi by using a geometric approximation. Initially, you will perform the calculation in a single-threaded manner; you will then change the code to divide the calculation into discrete operations and perform the calculation by using thread pool threads. Finally, you will change the code to use the Task Parallel Library to perform each operation as a parallel task. In the process, you will uncover some data synchronization issues that you must deal with.<br /> <br />The algorithm that you will implement calculates Pi based on some simple mathematics and statistical sampling.<br />If you draw a circle of radius r and then draw a square with sides that touch the circle, the sides of the square are 2 * r in length, as shown in Figure 1.<br /> <br /><img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=geopi&DownloadId=9234" alt="Figure 1" /><br /> <br /><b>Figure 1. Circle and bounding square.</b><br /> <br /> <br /> <br />The area of the square, S, is calculated as follows:<br /> <br />S = (2 * r) * (2 * r)<br />This can be rearranged as: <br /> <br />S = 4 * r * r<br /> <br />You can further rearrange to give:<br /> <br />r * r = S / 4<br /> <br />The area of the circle, C, is calculated as follows:<br /> <br />C = Pi * r * r<br /> <br />Substituting for r*r and rearranging gives:<br /> <br />Pi = 4 * C / S<br /> <br />To calculate Pi, you must determine the value of the ratio C / S. This is where statistical sampling helps.<br /> <br />To do this, generate a set of random points that lie inside the square, and count how many of these points also fall inside the circle. If you have generated a sufficiently large and random sample, the ratio of points that lie inside the circle to the points that lie inside the square (and also in the circle) approximates the ratio of the areas of the two shapes, C / S. All you have to do is count them.<br /> <br />How do you determine whether a point lies inside the circle? To help visualize the solution, draw the square on a piece of graph paper with the center of the square at the origin, which is point (0, 0). You can then generates pairs of values, or coordinates, that lie inside the range (-r, -r) to (+r, +r). You can determine whether any set of coordinates (x, y) lie inside the circle by applying Pythagoras’ theorem to calculate the distance (d) of these coordinates from the origin. You can compute d as the square root of ((x * x) + (y * y)). If d is less than or equal to r, the radius of the circle, the coordinates (x, y) specify a point inside the circle, as shown in Figure 2.<br /> <br /><span class="unresolved">Cannot resolve link: </span>[image:Figure 2|Figure2.jpg]<br /> <br /><b>Figure 2 Illustrating the distance of the point from the center of the circle.</b><br />
</div>philpennSat, 27 Feb 2010 00:44:45 GMTUPDATED WIKI: Home 20100227AUPDATED WIKI: Homehttp://code.msdn.microsoft.com/geopi/Wiki/View.aspx?title=Home&version=4<div class="wikidoc">
<b>Resource Page Description</b><br />This sample illustrates how to using .NET4 parallel extensions.
<br /> <br /><h2>
<b>Scenario</b>
</h2> <br />In the following set of exercises, you will implement an application that calculates Pi by using a geometric approximation. Initially, you will perform the calculation in a single-threaded manner; you will then change the code to divide the calculation into discrete operations and perform the calculation by using thread pool threads. Finally, you will change the code to use the Task Parallel Library to perform each operation as a parallel task. In the process, you will uncover some data synchronization issues that you must deal with.<br /> <br />The algorithm that you will implement calculates Pi based on some simple mathematics and statistical sampling.<br />If you draw a circle of radius r and then draw a square with sides that touch the circle, the sides of the square are 2 * r in length, as shown in Figure 1.<br /> <br /><img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=geopi&DownloadId=9234" alt="Figure 1" /><br /> <br /><b>Figure 1. Circle and bounding square.</b><br /> <br /> <br /> <br />The area of the square, S, is calculated as follows:<br /> <br />S = (2 * r) * (2 * r)<br />This can be rearranged as: <br /> <br />S = 4 * r * r<br /> <br />You can further rearrange to give:<br /> <br />r * r = S / 4<br /> <br />The area of the circle, C, is calculated as follows:<br /> <br />C = Pi * r * r<br /> <br />Substituting for r*r and rearranging gives:<br /> <br />Pi = 4 * C / S<br /> <br />To calculate Pi, you must determine the value of the ratio C / S. This is where statistical sampling helps.<br /> <br />To do this, generate a set of random points that lie inside the square, and count how many of these points also fall inside the circle. If you have generated a sufficiently large and random sample, the ratio of points that lie inside the circle to the points that lie inside the square (and also in the circle) approximates the ratio of the areas of the two shapes, C / S. All you have to do is count them.<br /> <br />How do you determine whether a point lies inside the circle? To help visualize the solution, draw the square on a piece of graph paper with the center of the square at the origin, which is point (0, 0). You can then generates pairs of values, or coordinates, that lie inside the range (-r, -r) to (+r, +r). You can determine whether any set of coordinates (x, y) lie inside the circle by applying Pythagoras’ theorem to calculate the distance (d) of these coordinates from the origin. You can compute d as the square root of ((x * x) + (y * y)). If d is less than or equal to r, the radius of the circle, the coordinates (x, y) specify a point inside the circle, as shown in Figure 2.<br /> <br /><span class="unresolved">Cannot resolve link: </span>[image:Figure 2|Figure2.jpg]<br /> <br /><b>Figure 2 Illustrating the distance of the point from the center of the circle.</b><br />
</div>philpennSat, 27 Feb 2010 00:44:13 GMTUPDATED WIKI: Home 20100227AUPDATED WIKI: Homehttp://code.msdn.microsoft.com/geopi/Wiki/View.aspx?title=Home&version=3<div class="wikidoc">
<b>Resource Page Description</b><br />This sample illustrates how to using .NET4 parallel extensions.
<br /> <br /><h2>
<b>Scenario</b>
</h2> <br />In the following set of exercises, you will implement an application that calculates Pi by using a geometric approximation. Initially, you will perform the calculation in a single-threaded manner; you will then change the code to divide the calculation into discrete operations and perform the calculation by using thread pool threads. Finally, you will change the code to use the Task Parallel Library to perform each operation as a parallel task. In the process, you will uncover some data synchronization issues that you must deal with.<br /> <br />The algorithm that you will implement calculates Pi based on some simple mathematics and statistical sampling.<br />If you draw a circle of radius r and then draw a square with sides that touch the circle, the sides of the square are 2 * r in length, as shown in Figure 1.<br /> <br /><img src="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=geopi&DownloadId=9234" alt="Figure 1" /><br /> <br /><b>Figure 1. Circle and bounding square.</b><br />
</div>philpennSat, 27 Feb 2010 00:38:32 GMTUPDATED WIKI: Home 20100227AUPDATED WIKI: Homehttp://code.msdn.microsoft.com/geopi/Wiki/View.aspx?title=Home&version=2<div class="wikidoc">
<b>Resource Page Description</b><br />This sample illustrates how to using .NET4 parallel extensions.
<br /> <br /><h2>
<b>Scenario</b>
</h2> <br />In the following set of exercises, you will implement an application that calculates Pi by using a geometric approximation. Initially, you will perform the calculation in a single-threaded manner; you will then change the code to divide the calculation into discrete operations and perform the calculation by using thread pool threads. Finally, you will change the code to use the Task Parallel Library to perform each operation as a parallel task. In the process, you will uncover some data synchronization issues that you must deal with.<br /> <br />The algorithm that you will implement calculates Pi based on some simple mathematics and statistical sampling.<br />If you draw a circle of radius r and then draw a square with sides that touch the circle, the sides of the square are 2 * r in length, as shown in Figure 1.<br /> <br /> <br />
</div>philpennSat, 27 Feb 2010 00:33:30 GMTUPDATED WIKI: Home 20100227A