A Tour Through the Parallel Programming Samples for .NET 4

A Tour Through the Parallel Programming Samples for .NET 4

Rate This
  • Comments 23

On Code Gallery, we have a plethora of samples that highlight aspects of the .NET Framework 4 that help with writing scalable and efficient parallel applications.  This post examines each of those samples, providing an overview of what each provides.

image Project Name: AcmePizza
Languages: C#, Visual Basic
Description: This simple and somewhat silly application demonstrates using concurrent collections with WPF.  The collections are wrapped with observable facades, such that multiple threads may modify the collections concurrently, and those updates are safely propagated to UI controls.
image Project Name: Antisocial Robots
Languages: C#
Description: Demonstrates doing a computationally-intensive operation many times per second, as a bunch of “robots” try to get as far away from each other as possible.
image Project Name: BabyNames
Languages: C#, Visual Basic
Description: This is one of the first applications we ever built to use Parallel LINQ.  Using LINQ and PLINQ, it queries a data set of baby name popularity information, sorts the results, and displays the results in a simplistic WPF user interface.
image Project Name: BlendImages
Languages: C#
Description: A demo of very simple image manipulation using a Parallel.For loop.  The application allows the user to load up two images and blends them together into a single, new image.
image Project Name: Boids
Languages: C#
Description: An implementation of a classic flocking algorithm, utilizing WPF for pretty 3D visualization of the “boids”, whose next positions and velocities are computing in parallel.
image Project Name: ComputePi
Languages: C#, Visual Basic
Description: A console application that estimates the value of PI using a variety of both serial and parallel implementations, the latter done with both PLINQ and the Parallel class.
image Project Name: DiningPhilosophers
Languages: C#, Visual Basic
Description: A WPF application that demonstrates the classic “Dining Philosophers” synchronization problem.  The application implements several solutions, including one based on asynchronous techniques using Tasks.
image Project Name: EditDistance
Languages: C#, Visual Basic
Description: A console application that uses Tasks to parallelize a dynamic programming problem, that of computing the “edit distance” between two strings.
image Project Name: GameOfLife
Languages: C#, Visual Basic
Description: This application provides an implementation of Conway’s Game of Life, using the Parallel class to parallelize the processing of the cellular automata.
image Project Name: ImageColorizer
Languages: C#, Visual Basic
Description: This application manipulates an image by converting the majority of the image to grayscale, except for portions of the image containing user-selected hues.
image Project Name: LINQRayTracer
Languages: C#, Visual Basic
Description: Based on Luke Hoban’s LINQ implementation of a ray tracer, this application parallelizes a computationally intensive LINQ query using PLINQ.
image Project Name: MandelbrotFractals
Languages: C#, C++/CLI
Description: This application provides an implementation of the classic Mandelbrot fractal, parallelizing the processing of the fractal using the Parallel class.
image Project Name: Morph
Languages: C#
Description: Implements a morphing algorithm between two images.  Parallelization is done using the Parallel class.
image Project Name: NBodySimulation
Languages: C#, F#
Description: Implements a classic n-body simulation using C# and WPF for the UI and using F# for the core computation. Parallelism is achieved using the Parallel class.
image Project Name: NQueens
Languages: C#, Visual Basic
Description: This application implements a solution to the N-Queens problem, using both LINQ and PLINQ.
image Project Name: OptionPricing
Languages: C#, Visual Basic
Description: This Excel VSTO application utilizes PLINQ to price Asian Options.
image Project Name: ParallelGrep
Languages: C#, Visual Basic
Description: This console application implements “grep” functionality across a file system using PLINQ.
image Project Name: PlinqKnobs
Languages: C#
Description: A simple console application that demonstrates some of the ways execution of a PLINQ query may be controlled and configured.
image Project Name: Raytracer
Languages: C#, Visual Basic, F#
Description: This Windows application provides an animated, ray-traced bouncing ball.  Sequential and parallel implementations are provided, as is a special parallel implementation that colors the animated image based on which thread was used to calculate which regions.
image Project Name: ShakespeareanMonkeys
Languages: C#, Visual Basic
Description: This application implements and parallelizes a genetic algorithm for breeding monkeys able to speak text from Hamlet.
image Project Name: SpellChecker
Languages: C#, Visual Basic
Description: This application implements and parallelizes a spellchecking algorithm based on the same edit distance calculation in the Edit Distance sample.
image Project Name: Strassens
Languages: C#
Description: This application implements several algorithms for performing and parallelizing matrix multiplication, including the Strassen algorithm.
image Project Name: Sudoku
Languages: C#, Visual Basic
Description: This is a fun application that provides a full Sudoku experience, including on-demand puzzle generation and solving.  Unlike many Sudoku demos which parallelize the solver, this implementation parallelizes the generator, using PLINQ.  It also demonstrates a use for speculative execution.
image Project Name: VisualizePartitioning
Languages: C#, Visual Basic
Description: This application demonstrates various approaches to partitioning as employed by both Parallel and PLINQ.
image Project Name: ParallelExtensionsExtras
Languages: C#
Description: This class library provides a plethora of interesting and useful extensions to take advantage of and complement the functionality available in the .NET Framework 4 for parallel programming.
Leave a Comment
  • Please add 4 and 7 and type the answer here:
  • Post
  • Hi there.  I downloaded the BlendImages_CSharp project and loaded into VS2010.  There seem to be some missing files.  I get the error message:

    error  : Unable to read the project file 'ParallelExtensionsExtras.csproj'

    Thanks!

  • Kevin, thanks for letting us know.  The problem was in the solution file, pointing to the ParallelExtensionsExtras.csproj file in the wrong directory.  We've now re-uploaded the samples with a fixed .sln file.  Thanks!

  • The samples are really great but they won't compile with VB Express 2010 only.

  • Peter, thanks for letting us know.  We'll investigate.

  • I get a lot of exceptions trying to run the Mandlebrot sample, both the C++ and C# versions, ex:

    System.OperationCanceledException was unhandled by user code

     Message=The operation was canceled.

     Source=mscorlib

     StackTrace:

          at System.Threading.Tasks.Parallel.ForWorker[TLocal](Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action`1 body, Action`2 bodyWithState, Func`4 bodyWithLocal, Func`1 localInit, Action`1 localFinally)

          at System.Threading.Tasks.Parallel.For(Int32 fromInclusive, Int32 toExclusive, ParallelOptions parallelOptions, Action`1 body)

          at Microsoft.Pcp.Pfx.InteractiveFractal.MandelbrotGenerator.Create(MandelbrotPosition position, Int32 imageWidth, Int32 imageHeight, CancellationToken cancellationToken, Boolean parallelRendering) in C:\Users\baisa\Documents\Visual Studio 2010\Samples\ParallelProgrammingSamples_RC\MandelbrotFractals\MandelbrotFractals_CSharp\MandelbrotGenerator.cs:line 91

          at Microsoft.Pcp.Pfx.InteractiveFractal.MainForm.<>c__DisplayClass2.<UpdateImageAsync>b__0() in C:\Users\baisa\Documents\Visual Studio 2010\Samples\ParallelProgrammingSamples_RC\MandelbrotFractals\MandelbrotFractals_CSharp\MainForm.cs:line 156

          at System.Threading.Tasks.Task.Execute()

     InnerException:

  • Hi Brad-

    The issue here isn't in the code per se, but rather this is the debugger telling you that an exception is being thrown, even though the exception is actually going to be caught and handled.  See http://blogs.msdn.com/pfxteam/archive/2010/01/11/9946736.aspx for more information.  You can avoid this issue either by running without the debugger attached or by following the steps in the aforementioned blog post.  This debugger behavior can often be helpful, however in this application, an exception is generated every time the scene changes, resulting in a poor experience.

    I hope that helps.

  • Has anyone tried the Sudoku example in the newly released VB 2010 Express?  Any issues?  I'm an advanced hobbiest and like a challenge, but not too much (as in dealing with a sample that won't ever work in Express).

  • Bruce, the Sudoku sample should work fine with Visual Basic 2010 Express.  If you have troubles with it, let us know.

  • Thanks.  Is there a good list of limitations of Express in regard to parallel/PLINQ/tasks/etc?  If so, where please?

  • Hi Bruce-

    The .NET Framework 4 is installed as part of Express, and as such everything from TPL/PLINQ/etc. is available through Express, just as it's available to notepad if you just install the .NET Framework SDK.  As such, there is no list of limitations, as it would be empty ;)

    Now, from an IDE perspective, the new tooling we've built for Visual Studio 2010 (i.e. the Parallel Stacks and Parallel Tasks windows in the debugger, and the new Concurrency Visualizer) is not available in Express, but all of the framework support is there.

  • I just opened the Sudoku VB sln in VB Express 2010.  I get a bunch of warnings.  They all seem to be like one or the other of these two examples:

    (1) Warning 1 Could not find type 'Microsoft.ParallelComputingPlatform.ParallelExtensions.Samples.Sudoku.Controls.TextStatefulButton'.  (2) Warning 2 The variable 'tsbLoadPreviousGame' is either undeclared or was never assigned.

    I just downloaded the samples within the last few days (of today, 4/19/10).

    I suspect these warnings are all fixed by one reference or something.  Please advise.

  • By the way, sweet deal on the no limitations in TPL/PLINQ functionality (except for the IDE stuff which I may have heard you talk about on DNR).  Too bad there's not a VB 2010 Standard Edition (so, not free) that would include the concurrency IDE stuff.  Oh well.  Express is still amazing!  Thanks for that!!!

  • Hi Bruce-

    I'm not sure why you're running into problems with the Sudoku example.  I just installed Visual Basic 2010 Express onto a clean box, downloaded the samples, opened the Sudoku solution, compiled without any errors, ran, and it all worked fine.  Are there any other errors besides the ones you mention?  Is it possible the download somehow got corrupted?  And you downloaded the samples from http://code.msdn.microsoft.com/ParExtSamples/Release/ProjectReleases.aspx?ReleaseId=4179, right?

    There is a known issue with some of the other Visual Basic samples when using Express, in that they reference another project in the solution that's in C# (ParallelExtensionsExtras), but the Sudoku solution is standalone and does not need that other C# project.

  • toub,

    I downloaded from the link you provided and it runs! So, no warnings. I'm not sure from where I downloaded before.

    Thank you.  (Now for the studying part!)

  • Hi toub,

    i tried to run your SpellChecker application, but i got this error:

    Error 3 The referenced assembly "C:\Documents\TestCode\ParallelExtensionsExtras\bin\Release\ParallelExtensionsExtras.dll" was not found. If this assembly is produced by another one of your projects, please make sure to build that project before building this one. SpellChecker_CSharp

    Im using the 2008 version of Visual Studio - is this why im encountering these issues?

    Thanks

Page 1 of 2 (23 items) 12