The CPU meter shows the problem. One core is running at 100 percent, but all the other cores are idle. Your application is CPU-bound, but you are using only a fraction of the computing power of your multicore system. What next? The answer, in a nutshell, is parallel programming. Where you once would have written the kind of sequential code that is familiar to all programmers, you now find that this no longer meets your performance goals. To use your system’s CPU resources efficiently, you need to split your application into pieces that can run at the same time. This is easier said than done. Parallel programming has a reputation for being the domain of experts and a minefield of subtle, hard-to-reproduce software defects. Everyone seems to have a favorite story about a parallel program that did not behave as expected because of a mysterious bug. These stories should inspire a healthy respect for the difficulty of the problems you face in writing your own parallel programs. Fortunately, help has arrived. Microsoft Visual Studio® 2010 introduces a new programming model for parallelism that significantly simplifies the job. Behind the scenes are supporting libraries with sophisticated algorithms that dynamically distribute computations on multicore architectures. Proven design patterns are another source of help. A Guide to Parallel Programming introduces you to the most important and frequently used patterns of parallel programming and gives executable code samples for them, using the Task Parallel Library (TPL) and Parallel LINQ (PLINQ).
Author(s): Colin Campbell, Ralph Johnson, Ade Miller, Stephen Toub
Edition: 1
Publisher: Microsoft Press
Year: 2010
Language: English
Pages: 224
Contents......Page 6
Foreword......Page 12
Who This Book Is For......Page 14
What You Need to Use the Code......Page 15
How to Use This Book......Page 16
Goals......Page 19
Acknowledgments......Page 20
1. Introduction......Page 22
The Importance of Potential Parallelism......Page 23
Decomposition, Coordination, and Scalable Sharing......Page 24
A Word About Terminology......Page 28
The Limits of Parallelism......Page 29
A Few Tips......Page 31
For More Information......Page 32
2. Parallel Loops......Page 34
The Basics......Page 35
An Example......Page 39
Variations......Page 42
Anti-Patterns......Page 53
Design Notes......Page 55
Related Patterns......Page 56
Further Reading......Page 58
3. Parallel Tasks......Page 60
The Basics......Page 61
An Example......Page 62
Variations......Page 64
Anti-Patterns......Page 72
Design Notes......Page 74
The Default Task Scheduler......Page 77
Exercises......Page 85
Further Reading......Page 86
4. Parallel Aggregation......Page 88
The Basics......Page 89
An Example......Page 90
Variations......Page 94
Design Notes......Page 101
Exercises......Page 103
Further Reading......Page 104
5. Futures......Page 106
The Basics......Page 107
Example: The Adatum Financial Dashboard......Page 110
Variations......Page 118
Design Notes......Page 120
Related Patterns......Page 121
Further Reading......Page 122
The Basics......Page 124
An Example......Page 126
Variations......Page 128
Design Notes......Page 130
Further Reading......Page 131
The Basics......Page 134
An Example......Page 138
Variations......Page 143
Anti-Patterns......Page 150
Related Patterns......Page 152
Further Reading......Page 153
Structural Patterns......Page 154
Singletons and Service Locators......Page 160
Model-View-ViewModel......Page 163
Immutable Types......Page 169
Shared Data Classes......Page 174
Iterators......Page 175
Lists and Enumerables......Page 176
Further Reading......Page 177
The Parallel Tasks and Parallel Stacks Windows......Page 180
The Concurrency Visualizer......Page 183
Visual Patterns......Page 188
Further Reading......Page 193
Appendix C. Technology Overview......Page 194
Further Reading......Page 196
Glossary......Page 198
References......Page 208
Other Online Sources......Page 210
A......Page 212
F......Page 213
N......Page 214
P......Page 215
S......Page 216
W......Page 217