logo资料库

parallel programming with microsoft visual c++.pdf

第1页 / 共195页
第2页 / 共195页
第3页 / 共195页
第4页 / 共195页
第5页 / 共195页
第6页 / 共195页
第7页 / 共195页
第8页 / 共195页
资料共195页,剩余部分请下载后查看
Contents
Foreword
Foreword
Preface
Why This Book Is Pertinent Now
What You Need to Use the Code
How to Use This Book
Introduction
Parallelism with Control Dependencies Only
Parallelism with Control and Data Dependencies
Dynamic Task Parallelism and Pipelines
Supporting Material
What Is Not Covered
Goals
Acknowledgments
Chapter 1. Introduction
The Importance of Potential Parallelism
Decomposition, Coordination, and Scalable Sharing
Understanding Tasks
Coordinating Tasks
Scalable Sharing of Data
Design Approaches
Selecting the Right Pattern
A Word about Terminology
The Limits of Parallelism
A Few Tips
Exercises
For More Information
Parallel Loops
The Basics
Parallel for Loops
parallel_for_each
What to Expect
An Example
Sequential Credit Review Example
Credit Review Example Using parallel_for_each
Performance Comparison
Variations
Breaking out of Loops Early
Exception Handling
Special Handling of Small Loop Bodies
Controlling the Degree of Parallelism
Anti-Patterns
Hidden Loop Body Dependencies
Small Loop Bodies with Few Iterations
Duplicates in the Input Enumeration
Scheduling Interactions with Cooperative Blocking
Related Patterns
Exercises
Further Reading
Chapter 3. Parallel Tasks
The Basics
An Example
Variations
Coordinating Tasks with Cooperative Blocking
Canceling a Task Group
Handling Exceptions
Speculative Execution
Anti-Patterns
Variables Captured by Closures
Unintended Propagation of Cancellation Requests
The Cost of Synchronization
Design Notes
Task Group Calling Conventions
Tasks and Threads
How Tasks Are Scheduled
Structured Task Groups and Task Handles
Lightweight Tasks
Exercises
Further Reading
Chapter 4. Parallel Aggregation
The Basics
An Example
Variations
Considerations for Small Loop Bodies
Other Uses for Combinable Objects
Design Notes
Related Patterns
Exercises
Further Reading
Chapter 5. Futures
The Basics
Futures
Example: The Adatum Financial Dashboard
The Business Objects
The Analysis Engine
Variations
Canceling Futures
Removing Bottlenecks
Modifying the Graph at Run Time
Design Notes
Decomposition into Futures
Functional Style
Related Patterns
Pipeline Pattern
Master/Worker Pattern
Dynamic Task Parallelism Pattern
Discrete Event Pattern
Exercises
Chapter 6. Dynamic Task Parallelism
An Example
Variations
Parallel While-Not-Empty
Adding Tasks to a Pending Wait Context
Exercises
Further Reading
Chapter 7. Pipelines
Types of Messaging Blocks
The Basics
An Example
Sequential Image Processing
The Image Pipeline
Performance Characteristics
Variations
Asynchronous Pipelines
Canceling a Pipeline
Handling Pipeline Exceptions
Load Balancing Using Multiple Producers
Pipelines and Streams
Anti-Patterns
Copying Large Amounts of Data between Pipeline Stages
Pipeline Stages that Are Too Small
Forgetting to Use Message Passing for Isolation
Infinite Waits
Unbounded Queue Growth
More Information
Design Notes
Related Patterns
Exercises
Further Reading
Appendix A. The Task Scheduler and Resource Manager
Resource Manager
Why It’s Needed
How Resource Management Works
Dynamic Resource Management
Oversubscribing Cores
Querying the Environment
Kinds of Tasks
Lightweight Tasks
Tasks Created Using PPL
Task Schedulers
Managing Task Schedulers
Creating and Attaching a Task Scheduler
Detaching a Task Scheduler
Destroying a Task Scheduler
Scenarios for Using Multiple Task Schedulers
Implementing a Custom Scheduling Component
The Scheduling Algorithm
Schedule Groups
Adding Tasks
Running Tasks
Enhanced Locality Mode
Forward Progress Mode
Task Execution Order
Tasks That Are Run Inline
Using Contexts to Communicate with the Scheduler
Debugging Information
Querying for Cancellation
Interface to Cooperative Blocking
Waiting
The Caching Suballocator
Long-Running I/O Tasks
Setting Scheduler Policy
Anti-Patterns
Multiple Resource Managers
Resource Management Overhead
Unintentional Oversubscription from Inlined Tasks
Deadlock from Thread Starvation
Ignored Process Affinity Mask
References
Appendix B. Debugging and Profiling Parallel Applications
The Parallel Tasks and Parallel Stacks Windows
Breakpoints and Memory Allocation
The Concurrency Visualizer
Scenario Markers
Visual Patterns
Oversubscription
Lock Contention and Serialization
Load Imbalance
Further Reading
Appendix C. Technology Overview
Further Reading
Glossary
Index
P A R A L L E L P R O G R A M M I N G M I C R O S O F T V I S U A L C++ WITH Design Patterns for Decomposition and Coordination on Multicore Architectures Colin Campbell Ade Miller Forewords by Tony Hey Herb Sutter • • • • • • • • • • • • • • • • • • • • • • • • • •
parallel programming with microsoft visual c++ ® > m o c . k o o b e w o w w w w < k o o B e ! . w o W m o r f d a o n w o D l
Parallel Programming with Microsoft Visual C++® Design Patterns for Decomposition and Coordination on Multicore Architectures Colin Campbell Ade Miller
ISBN 978-0-7356-5175-3 This document is provided “as-is.” Information and views expressed in this document, including URL and other Internet website references, may change without notice. You bear the risk of using it. Unless otherwise noted, the companies, organizations, products, domain names, email addresses, logos, people, places, and events depicted in examples herein are fictitious. No association with any real company, organization, product, domain name, email address, logo, person, place, or event is intended or should be inferred. Comply- ing with all applicable copyright laws is the responsibility of the user. Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of Microsoft Corporation. Microsoft may have patents, patent applications, trademarks, copyrights, or other intellectual property rights covering subject matter in this document. Except as expressly provided in any written license agreement from Microsoft, the furnishing of this document does not give you any license to these patents, trademarks, copyrights, or other intellectual property. © 2011 Microsoft Corporation. All rights reserved. Microsoft, MSDN, Visual Basic, Visual C++, Visual C#, Visual Studio, Windows, Windows Live, Windows Server, and Windows Vista are trademarks of the Microsoft group of companies. All other trademarks are property of their respective owners.
Contents xi xiii xv xv xvi xvi xvii xviii xviii xviii xviii xix xx xx xxi 1 2 3 3 4 5 6 7 8 8 10 11 11 Who This Book Is For Why This Book Is Pertinent Now What You Need to Use the Code How to Use This Book Introduction Parallelism with Control Dependencies Only Parallelism with Control and Data Dependencies Dynamic Task Parallelism and Pipelines Supporting Material What Is Not Covered Goals acknowledgments 1 Introduction foreword Tony Hey foreword Herb Sutter preface The Importance of Potential Parallelism Decomposition, Coordination, and Scalable Sharing Understanding Tasks Coordinating Tasks Scalable Sharing of Data Design Approaches Selecting the Right Pattern A Word about Terminology The Limits of Parallelism A Few Tips Exercises For More Information
vi 2 Parallel Loops The Basics Parallel for Loops parallel_for_each What to Expect An Example Sequential Credit Review Example Credit Review Example Using parallel_for_each Performance Comparison Variations Anti-Patterns Breaking out of Loops Early Exception Handling Special Handling of Small Loop Bodies Controlling the Degree of Parallelism Hidden Loop Body Dependencies Small Loop Bodies with Few Iterations Duplicates in the Input Enumeration Scheduling Interactions with Cooperative Blocking Related Patterns Exercises Further Reading 3 Parallel Tasks The Basics An Example Variations Coordinating Tasks with Cooperative Blocking Canceling a Task Group Handling Exceptions Speculative Execution Anti-Patterns Design Notes Variables Captured by Closures Unintended Propagation of Cancellation Requests The Cost of Synchronization Task Group Calling Conventions Tasks and Threads How Tasks Are Scheduled Structured Task Groups and Task Handles Lightweight Tasks Exercises Further Reading 13 14 14 15 16 17 18 18 19 19 19 20 21 22 23 23 23 23 24 24 24 25 27 28 29 31 31 33 35 36 37 37 38 39 39 39 40 40 41 41 42 42
4 Parallel Aggregation The Basics An Example Variations Considerations for Small Loop Bodies Other Uses for Combinable Objects Design Notes Related Patterns Exercises Further Reading 5 Futures The Basics Futures Example: The Adatum Financial Dashboard The Business Objects The Analysis Engine Variations Canceling Futures Removing Bottlenecks Modifying the Graph at Run Time Design Notes Decomposition into Futures Functional Style Related Patterns Pipeline Pattern Master/Worker Pattern Dynamic Task Parallelism Pattern Discrete Event Pattern 6 Dynamic Task Parallelism Exercises The Basics An Example Variations Exercises Further Reading 7 Pipelines Types of Messaging Blocks The Basics Parallel While-Not-Empty Adding Tasks to a Pending Wait Context vii 45 46 49 55 55 55 55 57 58 58 61 62 63 65 66 67 70 70 70 71 72 72 72 72 73 73 73 73 73 75 75 77 80 80 81 83 83 85 86 86
分享到:
收藏