DevDays 2009 day 1 Tasks threading and parallel programming.

A small introduction for these posts you can find here. The last session of the day was by  Ingo Rammer about parallel programming in .Net 4.0.

The slides and code of this session will be under conferences on http://www.thinktecture.com/.

Multithreading vs Parallelism. Multithreading is easy, just call Thread.start(). It is primarily used to keep the ui responsive.Parallel programming is used to maximally use the cores that are available.

The ray traces sample comes form the parallel extensions.

Ingo shows a demo walking a large tree structure and visualizing this. The first version uses no threading and takes about 1500 ms to complete. In the second version he tries to make a thread for every node. This version blows up, every thread takes up one mb of memory. The third version uses Threadpool.QueueUeserWorkitem, timing is off now because the threads are fire and forget. The fourth version works with the new tasks from the parallel extensions. This version does the work in about 800ms.

More functionality of the Task is making the creation possible using a factory (shorter, cleaner code). Also the results of a task can be simply used, all synchronization is done for you. In the demo he sums up all values in the tree without having to worry about synchronisation.

After that my netbook just closed down. Basically Ingo covered three ways to do parallel programming in C# 4.0.

  • Fine-Grained Parallelism: Task-API and coordination structures (the foundation of it all)
  • Structured Parallelism: Parallel
  • Declarative Parallelism: PLINQ

Ingo is a great speaker and made this last session while everybody was tired still fun.

About Kees Dijk

Husband, father and Software Architect at Sogeti. Loving my work and having fun while doing it. Interested in all the aspects of software development with a special love for Model Driven Development, Code Generation and Software production lines.

Published by

KeesDijk

Husband, father and Software Architect at Sogeti. Loving my work and having fun while doing it. Interested in all the aspects of software development with a special love for Model Driven Development, Code Generation and Software production lines.

One thought on “DevDays 2009 day 1 Tasks threading and parallel programming.”

Leave a Reply

Your email address will not be published. Required fields are marked *