DDD Scotland Parallelisation Talk Overview

Follow Up I was asked a question during the talk I wasn’t immediately able to answer which I’ve now found the definite answer. What happens to parallel tasks running in the background when the application exits? Examples Here are all the examples from Saturday’s introductory talk on Parallelisation at DDD Scotland 2011. Starting tasks Parallel.Invoke […]

Background tasks and application exit

During my talk on Parallelisation at DDD Scotland 2011 I was asked what happens if the application finishes while there were still tasks running. At the time, I was showing the Tasks Within Tasks demo and I showed what happened when the Wait call was removed in the Main method. Since the Wait call was […]

Parallelisation Talk Example – Aggregate Exceptions

The two code examples here show what happens when exceptions are thrown within tasks that are not handled within the task. In each case the task that has the error throws an exception. In the first example, only one task throws an exception. Although from the output you can see that more tasks were expected […]

Parallelisation talk example – Independent Object Graphs

Parallelised code works best when data is not shared. This example shows a simple piece of parallel code where each task operates independently on its own object graph without dependencies on other objects outside its own graph. Each iteration of the Parallel.ForEach statement operates on only one item in the List named initialObjectGraph. The operations […]

Prallelisation Talk Example – Tasks within Tasks

In this example I’m showing the launching of further tasks within an existing task. The Main method launches a single task (of course, it would likely be many tasks in a real system) which is implemented by MainTask and then waits for that task to complete. The MainTask then launches many independent tasks (impelemnted as […]

Parallelisation Talk Example – Parallel.Invoke

Parallel.Invoke is the most basic way to start many tasks as the same time. The method takes as many Action<…> based delegates as needed. The Task Parallel Library takes care of the actual scheduling, degree of parallelism etc. Parallel.Invoke itself blocks until all the tasks have completed. In this example there are two tasks that […]

Parallelisation Talk Example – ConcurrentBag

This example shows a ConcurrentBag being populated and it being accessed while another task is still populating the bag. The ConcurrentBag class can be found in the System.Collections.Concurrent namespace In this example, the ConcurrentBag is populated in task that is running in the background. After a brief pause in order to allow the background task […]

Parallelisation Talk Examples – ConcurrentDictionary

The example used in the talk was one I had already blogged about. The original blog entry the example was based upon is here: Parallelisation in .NET 4.0 – The ConcurrentDictionary. Code Example class Program { private static ConcurrentDictionary<string, int> wordCounts = new ConcurrentDictionary<string, int>(); static void Main(string[] args) { string[] lines = File.ReadAllLines("grimms-fairy-tales.txt"); Parallel.ForEach(lines, […]

Parallelisation Talk Examples – Basic PLINQ

These are some code examples from my introductory talk on Parallelisation showing the difference between a standard sequential LINQ query and its parallel equivalent. The main differences between this and the previous two examples (Parallel.For and Parallel.ForEach) is that LINQ (and PLINQ) is designed to return data back, so the LINQ expression uses a Func<TResult, […]

Parallelisation Talk Examples – Parallel.ForEach

These are some code examples from my introductory talk on Parallelisation. Showing the difference between a standard sequential foreach loop and its parallel equivalent. Code example 1: Serial processing of a foreach loop class Program { private static Random rnd = new Random(); static void Main(string[] args) { DateTime start = DateTime.UtcNow; IEnumerable items = […]