You are previewing Parallel Programming with Microsoft® .NET.
O'Reilly logo
Parallel Programming with Microsoft® .NET

Book Description

Save time and reduce risk on your software development projects by incorporating patterns & practices, Microsoft’s applied engineering guidance that includes both production quality source code and documentation.

Table of Contents

  1. Parallel Programming with Microsoft® .Net
  2. Foreword
  3. Preface
    1. Who This Book Is For
    2. Why This Book Is Pertinent Now
    3. What You Need to Use the Code
    4. How to Use This Book
      1. Introduction
      2. Parallelism with Control Dependencies Only
      3. Parallelism with Control and Data Dependencies
      4. Dynamic Task Parallelism and Pipelines
      5. Supporting Material
    5. What Is Not Covered
    6. Goals
  4. Acknowledgments
  5. 1. Introduction
    1. The Importance of Potential Parallelism
    2. Decomposition, Coordination, and Scalable Sharing
      1. Understanding Tasks
      2. Coordinating Tasks
      3. Scalable Sharing of Data
      4. Design Approaches
    3. Selecting the Right Pattern
    4. A Word About Terminology
    5. The Limits of Parallelism
    6. A Few Tips
    7. Exercises
    8. For More Information
  6. 2. Parallel Loops
    1. The Basics
      1. Parallel for Loops
      2. Parallel for Each
      3. Parallel Linq (PLINQ)
      4. What to Expect
    2. An Example
      1. Sequential Credit Review Example
      2. Credit Review Example Using Parallel.For Each
      3. Credit Review Example with PLINQ
      4. Performance Comparison
    3. Variations
      1. Breaking Out of Loops Early
        1. Parallel Break
        2. Parallel Stop
      2. External Loop Cancellation
      3. Exception Handling
      4. Special Handling of Small Loop Bodies
      5. Controlling the Degree of Parallelism
      6. Using Task-Local State in a Loop Body
      7. Using a Custom Task Scheduler for a Parallel Loop
    4. Anti-Patterns
      1. Step Size Other Than One
      2. Hidden Loop Body Dependencies
      3. Small Loop Bodies with Few Iterations
      4. Processor Oversubscription and Undersubscription
      5. Mixing the Parallel Class and PLINQ
      6. Duplicates in the Input Enumeration
    5. Design Notes
      1. Adaptive Partitioning
      2. Adaptive Concurrency
      3. Support for Nested Loops and Server Applications
    6. Related Patterns
    7. Exercises
    8. Further Reading
  7. 3. Parallel Tasks
    1. The Basics
    2. An Example
    3. Variations
      1. Canceling a Task
      2. Handling Exceptions
        1. Ways to Observe an Unhandled Task Exception
        2. Aggregate Exceptions
        3. The Handle Method
        4. The Flatten Method
      3. Waiting for the First Task to Complete
      4. Speculative Execution
      5. Creating Tasks with Custom Scheduling
    4. Anti-Patterns
      1. Variables Captured by Closures
      2. Disposing a Resource Needed by a Task
      3. Avoid Thread Abort
    5. Design Notes
      1. Tasks and Threads
      2. Task Life Cycle
      3. Writing a Custom Task Scheduler
      4. Unobserved Task Exceptions
      5. Relationship Between Data Parallelism and Task Parallelism
    6. The Default Task Scheduler
      1. The Thread Pool
      2. Decentralized Scheduling Techniques
      3. Work Stealing
      4. Top-Level Tasks in the Global Queue
      5. Subtasks in a Local Queue
      6. Inlined Execution of Suntasks
      7. Thread Injection
      8. Bypassing The Thread Pool
    7. Exercises
    8. Further Reading
  8. 4. Parallel Aggregation
    1. The Basics
    2. An Example
    3. Variations
      1. Using Parallel Loops for Aggregation
      2. Using a Range Partitioner for Aggregation
      3. Using PLINQ Aggreation with Range Selection
    4. Design Notes
    5. Related Patterns
    6. Exercises
    7. Further Reading
  9. 5. Futures
    1. The Basics
      1. Futures
      2. Continuation Tasks
    2. Example: The Adatum Financial Dashboard
      1. The Business Objects
      2. The Analysis Engine
        1. Loading External Data
        2. Merging
        3. Normalizing
        4. Analysis and Model Creation
        5. Processing Historical Data
        6. Comparing Models
      3. View and View Model
    3. Variations
      1. Canceling Futures and Continuation Tasks
      2. Continue When “At Least One” Antecedent Completes
      3. Using .Net Asynchronous Calls with Futures
      4. Removing Bottlenecks
      5. Modifying the Graph At Run Time
    4. Design Notes
      1. Decomposition Into Futures and Continuation Tasks
      2. Functional Style
    5. Related Patterns
      1. Pipelines Pattern
      2. Master/Worker Pattern
      3. Dynamic Task Parallelism Pattern
      4. Discrete Event Pattern
    6. Exercises
    7. Further Reading
  10. 6. Dynamic Task Parallelism
    1. The Basics
    2. An Example
    3. Variations
      1. Parallel While-Not-Empty
      2. Task Chaining with Parent/Child Tasks
    4. Design Notes
    5. Exercises
    6. Further Reading
  11. 7. Pipelines
    1. The Basics
    2. An Example
      1. Sequential Image Processing
      2. The Image Pipeline
      3. Performance Characteristics
    3. Variations
      1. Canceling a Pipeline
      2. Handling Pipeline Exceptions
      3. Load Balancing Using Multiple Producers
      4. Pipelines and Streams
      5. Asynchronous Pipelines
    4. Anti-Patterns
      1. Thread Starvation
      2. Infinite Blocking Collection Waits
      3. Forgetting Getconsumingenumerable()
      4. Using Other Producer/Consumer Collections
    5. Design Notes
    6. Related Patterns
    7. Exercises
    8. Further Reading
  12. A. Adapting Object-Oriented Patterns
    1. Structural Patterns
      1. Façade
        1. Example
        2. Guidelines
      2. Decorators
        1. Example
        2. Guidelines
      3. Adapters
        1. Example
        2. Guidelines
      4. Repositories and Parallel Data Access
        1. Example
        2. Guidelines
    2. Singletons and Service Locators
      1. Implementing a Singleton with the Lazy<T> Class
      2. Notes
      3. Guidelines
    3. Model-View-ViewModel
      1. Example
      2. The Dashboard’s User Interface
      3. Guidelines
    4. Immutable Types
      1. Example
      2. Immutable Types as Value Types
      3. Compound Values
      4. Guidelines
    5. Shared Data Classes
      1. Guidelines
    6. Iterators
      1. Example
    7. Lists and Enumerables
    8. Further Reading
      1. Structural Patterns
      2. Singleton
      3. Model-View-Viewmodel
      4. Immutable Types
  13. B. Debugging and Profiling Parallel Applications
    1. The Parallel Tasks and Parallel Stacks Windows
    2. The Concurrency Visualizer
    3. Visual Patterns
      1. Oversubscription
      2. Lock Contention and Serialization
      3. Load Imbalance
    4. Further Reading
  14. C. Technology Overview
    1. Further Reading
  15. Glossary
  16. D. References
    1. Other Online Sources
  17. Index
  18. About the Authors
  19. Copyright