Parallel Programming With Microsoft Visual C Design Patterns For Decomposition and Coordination On Multicore Architectures Patterns and Practices 1st Edition Colin Campbell PDF Download
Parallel Programming With Microsoft Visual C Design Patterns For Decomposition and Coordination On Multicore Architectures Patterns and Practices 1st Edition Colin Campbell PDF Download
https://ebookbell.com/product/parallel-programming-with-microsoft-
visual-studio-2010-step-by-step-1st-edition-donis-marshall-2429704
https://ebookbell.com/product/parallel-programming-with-microsoft-net-
design-patterns-for-decomposition-and-coordination-on-multicore-
architectures-patterns-practices-1st-edition-colin-campbell-2488296
https://ebookbell.com/product/parallel-programming-with-python-
develop-efficient-parallel-systems-using-the-robust-python-
environment-martini-20632918
https://ebookbell.com/product/parallel-programming-with-intel-
parallel-studio-xe-wrox-programmer-to-programmer-1-auflage-stephen-
blairchappell-2614310
Parallel Programming With C And Net Core Developing Multithreaded
Applications Using C And Net Core 31 From Scratch English Edition
Rishabh Verma
https://ebookbell.com/product/parallel-programming-with-c-and-net-
core-developing-multithreaded-applications-using-c-and-net-
core-31-from-scratch-english-edition-rishabh-verma-34712956
https://ebookbell.com/product/parallel-programming-with-openacc-1st-
edition-rob-farber-5876386
https://ebookbell.com/product/parallel-programming-with-coarrays-
robert-w-numrich-7435178
https://ebookbell.com/product/parallel-programming-with-c-and-net-
fundamentals-of-concurrency-and-asynchrony-behind-fastpaced-
applications-1st-edition-vaskaran-sarcar-60450582
https://ebookbell.com/product/parallel-programming-with-c-and-net-
fundamentals-of-concurrency-and-asynchrony-behind-fastpaced-
applications-vaskaran-sarcar-60477158
PARALLEL
PROGRAM M ING
WITH
MICROSOFT
V I S U A L C++
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++ ®
Parallel Programming
with Microsoft Visual
C++ ®
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
foreword xi
Tony Hey
foreword xiii
Herb Sutter
preface xv
Who This Book Is For xv
Why This Book Is Pertinent Now xvi
What You Need to Use the Code xvi
How to Use This Book xvii
Introduction xviii
Parallelism with Control Dependencies Only xviii
Parallelism with Control and Data
Dependencies xviii
Dynamic Task Parallelism and Pipelines xviii
Supporting Material xix
What Is Not Covered xx
Goals xx
acknowledgments xxi
1 Introduction 1
The Importance of Potential Parallelism 2
Decomposition, Coordination, and Scalable Sharing 3
Understanding Tasks 3
Coordinating Tasks 4
Scalable Sharing of Data 5
Design Approaches 6
Selecting the Right Pattern 7
A Word about Terminology 8
The Limits of Parallelism 8
A Few Tips 10
Exercises 11
For More Information 11
vi
2 Parallel Loops 13
The Basics 14
Parallel for Loops 14
parallel_for_each 15
What to Expect 16
An Example 17
Sequential Credit Review Example 18
Credit Review Example Using
parallel_for_each 18
Performance Comparison 19
Variations 19
Breaking out of Loops Early 19
Exception Handling 20
Special Handling of Small Loop Bodies 21
Controlling the Degree of Parallelism 22
Anti-Patterns 23
Hidden Loop Body Dependencies 23
Small Loop Bodies with Few Iterations 23
Duplicates in the Input Enumeration 23
Scheduling Interactions with
Cooperative Blocking 24
Related Patterns 24
Exercises 24
Further Reading 25
3 Parallel Tasks 27
The Basics 28
An Example 29
Variations 31
Coordinating Tasks with Cooperative Blocking 31
Canceling a Task Group 33
Handling Exceptions 35
Speculative Execution 36
Anti-Patterns 37
Variables Captured by Closures 37
Unintended Propagation of Cancellation Requests 38
The Cost of Synchronization 39
Design Notes 39
Task Group Calling Conventions 39
Tasks and Threads 40
How Tasks Are Scheduled 40
Structured Task Groups and Task Handles 41
Lightweight Tasks 41
Exercises 42
Further Reading 42
vii
4 Parallel Aggregation 45
The Basics 46
An Example 49
Variations 55
Considerations for Small Loop Bodies 55
Other Uses for Combinable Objects 55
Design Notes 55
Related Patterns 57
Exercises 58
Further Reading 58
5 Futures 61
The Basics 62
Futures 63
Example: The Adatum Financial Dashboard 65
The Business Objects 66
The Analysis Engine 67
Variations 70
Canceling Futures 70
Removing Bottlenecks 70
Modifying the Graph at Run Time 71
Design Notes 72
Decomposition into Futures 72
Functional Style 72
Related Patterns 72
Pipeline Pattern 73
Master/Worker Pattern 73
Dynamic Task Parallelism Pattern 73
Discrete Event Pattern 73
Exercises 73
7 Pipelines 85
Types of Messaging Blocks 86
The Basics 86
viii
An Example 92
Sequential Image Processing 92
The Image Pipeline 94
Performance Characteristics 96
Variations 97
Asynchronous Pipelines 97
Canceling a Pipeline 101
Handling Pipeline Exceptions 102
Load Balancing Using Multiple Producers 104
Pipelines and Streams 106
Anti-Patterns 107
Copying Large Amounts of Data between
Pipeline Stages 107
Pipeline Stages that Are Too Small 107
Forgetting to Use Message Passing for Isolation 107
Infinite Waits 107
Unbounded Queue Growth 107
More Information 107
Design Notes 108
Related Patterns 109
Exercises 109
Further Reading 109
appendices
glossary 153
index
Foreword
xi
xii for ewor d
Tony Hey
Corporate Vice President, Microsoft Research
Foreword
xiii
xiv
Herb Sutter
Principal Architect, Microsoft
Bellevue, WA, USA
February 2011
Preface
xv
xvi pr eface
Coordinated by
control flow only
Coordinated by control
flow and data flow
figure 1
Parallel programming patterns
After the introduction, the book has one branch that discusses
data parallelism and another that discusses task parallelism.
Both parallel loops and parallel tasks use only the program’s con-
trol flow as the means to coordinate and order tasks. The other pat-
terns use both control flow and data flow for coordination. Control
flow refers to the steps of an algorithm. Data flow refers to the avail-
ability of inputs and outputs.
xviii pr eface
Introduction
Chapter 1, “Introduction,” introduces the common problems faced by
developers who want to use parallelism to make their applications run
faster. It explains basic concepts and prepares you for the remaining
chapters. There is a table in the “Design Approaches” section of Chapter
1 that can help you select the right patterns for your application.
Supporting Material
In addition to the patterns, there are several appendices:
• Appendix A, “The Task Scheduler and Resource Manager.”
This appendix gives an overview of how the Concurrency
Runtime’s task scheduler and resource manager function.
• Appendix B, “Debugging and Profiling Parallel Applications.”
This appendix gives you an overview of how to debug and
profile parallel applications in Visual Studio 2010.
• Appendix C, “Technology Roadmap.” This appendix describes
the various Microsoft technologies and frameworks for parallel
programming.
• Glossary. The glossary contains definitions of the terms used in
this book.
Everyone should read Chapters 1, 2, and 3 for an introduction and Don’t apply the patterns in
overview of the basic principles. Although the succeeding material is this book blindly to your
presented in a logical order, each chapter, from Chapter 4 on, can be applications.
read independently.
Callouts in a distinctive style, such as the one shown in the mar-
gin, alert you to things you should watch out for.
It’s very tempting to take a new tool or technology and try and
use it to solve whatever problem is confronting you, regardless of the
tool’s applicability. As the saying goes, “when all you have is a hammer,
everything looks like a nail.” The “everything’s a nail” mentality can
lead to very unfortunate results, which one hopes the bunny in Figure
2 will be able to avoid.
You also want to avoid unfortunate results in your parallel pro-
grams. Adding parallelism to your application costs time and adds
complexity. For good results, you should only parallelize the parts of
your application where the benefits outweigh the costs.
figure 2
When all you have is a hammer, everything looks like a nail.
Other documents randomly have
different content
The Holly Blue (Cyaniris argiolus).
About the beginning of the eighteenth century this butterfly (Plate
113) was known as the "Blue Speckt," but Harris, in 1775, changed
the name to the "Azure Blue." The male is a pretty lilac-tinged blue,
with a narrow black edging on the outer margin of the fore wings,
often only in evidence towards the tip, and a narrow black line on
the outer margin of the hind wings. The white fringes of the fore
wings are distinctly marked with black at the ends of the veins. The
female is of the same shade of blue, or sometimes much paler (var.
clara, Tutt), with a broad blackish border on the outer margin of the
fore wings extending along the front margin to about the middle;
this border varies in width and seems to be wider in summer
specimens than in those of the earlier flight; the discal mark on the
fore wings is black, but this is sometimes very faint; there is a series
of black dots on the outer margin of the wings.
Larger Image
Pl. 110
Adonis Blue.
1, 2, 4, 5, 9 male; 3, 6, 7, 8, 10, 11 female.
Pl. 111
Adonis Blue.
Eggs, natural size and enlarged; caterpillars and chrysalis.
Although the colour of the upper side is somewhat like that of the
Common Blue, it should not be confused with that species, as the
under side is very different both as regards the colour, which is
bluish-white, and the arrangement of the black spots. On the outer
margins of the wings in some specimens there are more or less
distinct traces of blackish crescents.
There is no considerable variation in this species, but the spots on
the under side are subject to slight modification in the matters of
size and shape; the borders also vary in width, and in the female the
blue area is thus sometimes much restricted. A gynandrous
specimen has been recorded, in which the right side is male.
The egg (Plate 112) is described as whitish or bluish-green in colour.
The full-grown caterpillar has a blackish head, the body is bright
yellowish-green with paler lines; eight rings from and including the
second are crested with two ridges of humps, between which lies
the sunk dorsal space; the whole skin of the body is velvety, with its
surface thickly covered with yellowish warty granules, each bearing a
minute bristly white hair. Sometimes the humps and the middle of
the back are marked with rose-pink.
The chrysalis is pale brownish-ochreous with a thin blackish-brown
line on the back of the brown freckled thorax; the body is marked
with rather blotchy arrow-head dashes, and some larger dark brown
blotches; the wing-cases are pale greyish freckled and outlined with
brown, their surface is smooth and rather more glistening than the
other parts, which are thickly studded with fine, short, brownish
bristles. (Adapted from Buckler.)
The following is a brief summary of a paper by Mr. R. Adkin (Proc. S.
Lond. Ent. and Nat. Hist. Soc. for 1896), in which he gives a most
interesting account of the earlier stages of the second brood of this
species.
At the time when the butterflies of the second brood are on the
wing, the flower-buds of the ivy (Hedera helix) are still young, and
form compact heads. The butterfly, having selected one of these
heads, settles upon its top, closes her wings over her back, and
bending her abdomen down and round underneath the buds, affixes
an egg to the under side of one of the slender single bud-stalks. In
about a week the eggs hatch. The young larva which in colour
matches the buds very closely, rests on the bud-stalk with its
anterior segments, which completely cover its head, pressed closely
against the bud, and looks so exactly like a slight swelling of the
upper part of the stalk as to make detection a matter of great
difficulty, even with the aid of a fairly powerful lens. The larva is very
sluggish in its habits, seldom leaving the head of the buds on which
it is hatched, so long as sufficient food remains for its nourishment,
or occasionally when about to change its skin. It appears to feed
only at night, and its manner of feeding, which is the same
throughout its life, is to eat a round hole through the outer shell of a
bud, and pressing its head forward through it to clear out the soft
inside of the bud. In from four to six weeks it is full-fed; it then quits
the buds, and attaches itself by slender threads to a leaf, and in a
few days becomes a pupa, in which state it passes the winter.
Normally the eggs of the spring butterflies are laid on the under side
of the calyces of flower-buds of holly (Ilex). The caterpillars feed on
the flower-buds and also on the young green berries. They are full
grown in about a month, change to chrysalids, and the butterflies
emerge in July and August. Among other pabula that have been
mentioned are the flowers of dogwood (Cornus sanguinea), berry-
bearing alder (Rhamnus frangula), and spindle (Euonymus
europæus).
Pl. 112.
Holly Blue.
Eggs enlarged; caterpillar and chrysalis.
Larger Image
Pl. 113.
Holly Blue.
1, 2, 6 male: 3, 4, 7 female (spring); 5 male; 8, 9 female
(summer).
The eggs of this species are to be found at the end of May on the
under sides of the leaves of the cowslip (Primula veris), sometimes
as many as ten on one leaf, but as a rule there will only be one or
two on a plant. When laid, the egg is very glassy in appearance, but
it gradually turns to a pinkish-grey; and when the caterpillar is
formed inside, the shell becomes transparent, and its occupant can
be clearly seen. It eats a considerable portion of the shell in making
its exit therefrom, and afterwards consumes the remainder of the
shell. When in its last skin the caterpillar is brown, covered with
short whitish hair, among which are some longer dark brown or
blackish hairs; the lines on the back and sides are blackish, and
there are black dots on the front part of each segment or ring. Head,
honey brown, notched on the crown; eyes and jaws, brownish. It
feeds from June to August on cowslip, but will also eat primrose
(Primula vulgaris), and hides among dead and withered leaves
beneath the food-plant (Plate 121).
The chrysalis is pale whity-brown, hairy above, with black dots; head
and the upper edge of the wing-cases streaked with black.
Occasionally a few butterflies emerge in August, but they usually
remain in the chrysalis until May or June.
This is a woodland species, and prefers the sunny but sheltered
nooks and glades, but also resorts to the broader rides and
pathways. Flowers do not seem to have any strong attraction for it,
but it may often be seen sitting on the foliage of a bush or sapling
tree. It appears to be pretty widely distributed, although to a certain
extent local, throughout the southern half of England, but seems to
have almost or quite disappeared from the counties of
Cambridgeshire, Suffolk, and Essex. Dumfries is the only locality in
Scotland from which it has been reported.
Its distribution abroad is limited to Central Europe, Denmark,
Livonia, Southern Sweden, Central Spain, North Italy, and the
Balkans.
Now follow the Skippers (Hesperiidæ), of which kind of butterfly we
have eight species in England. Of these the first two belong to the
Hesperiinæ and the others to the Pamphilinæ.
ebookbell.com