Why is this an important problem? We are in a multi-core world, with single-thread processor performance being basically flat for the foreseeable future. We have to do more work ourselves to exploit multiple cores. However, this isn’t an easy thing to do, and Microsoft is providing libraries to help developers.
VS 2010 includes many features specific to parallel programming, including concurrency analysis tools and the Task Parallel Library.
Parallelism is all about performance. The cycle:
- Understand your code
- Measure existing performance
- Performance tuning
- Identify opportunities for parallelism
- Express parallelism
- Tune
Goal-setting
- Know your users: use realistic datasets; know your ecosystem
- Parallelize only if necessary, but plan for it: adds complexity and introduces bugs
- I/O, memory latency and algorithmic optimizations
Profiling
- sampling based: good for CPU-bound apps
- instrumented: good for non-CPU-bound apps
- new tools in VS2010 require instrumentation to profile parallel apps
- divide and conquer approach (remember Amdahl’s Law)
- VS2010 Concurrency Analysis Tools: CPU utilization analysis; thread blocking analysis; core execution analysis (thread migration or affinity issues)
Other things in the new tools: thread synchronization dependencies, multi-process scenarios, more statistics and guidance
Exploiting Parallelism
- Identify the form of parallelism (task, data, latency hiding, etc)
- Legacy programming patterns: thread pools, hard-coded thread creation
- New programming paradigms:programming abstractions (PLINQ, TPL)