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.
Home
May 29th, 2009 at 3:08 am
[...] Tasks threading and parallel programming [...]