0% found this document useful (0 votes)
11 views49 pages

Parallel Programming With Microsoft Visual C Design Patterns For Decomposition and Coordination On Multicore Architectures Patterns and Practices 1st Edition Colin Campbell PDF Download

The document discusses 'Parallel Programming with Microsoft Visual C++', focusing on design patterns for decomposing and coordinating tasks on multicore architectures. It emphasizes the importance of parallel programming in modern computing, driven by the shift towards multicore processors and the need for developers to efficiently utilize this technology. The book provides practical guidance and examples to help programmers incorporate parallelism into their applications using Microsoft libraries.

Uploaded by

luutjulus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views49 pages

Parallel Programming With Microsoft Visual C Design Patterns For Decomposition and Coordination On Multicore Architectures Patterns and Practices 1st Edition Colin Campbell PDF Download

The document discusses 'Parallel Programming with Microsoft Visual C++', focusing on design patterns for decomposing and coordinating tasks on multicore architectures. It emphasizes the importance of parallel programming in modern computing, driven by the shift towards multicore processors and the need for developers to efficiently utilize this technology. The book provides practical guidance and examples to help programmers incorporate parallelism into their applications using Microsoft libraries.

Uploaded by

luutjulus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 49

Parallel Programming With Microsoft Visual C

Design Patterns For Decomposition And


Coordination On Multicore Architectures Patterns
And Practices 1st Edition Colin Campbell
download
https://ebookbell.com/product/parallel-programming-with-
microsoft-visual-c-design-patterns-for-decomposition-and-
coordination-on-multicore-architectures-patterns-and-
practices-1st-edition-colin-campbell-2112720

Explore and download more ebooks at ebookbell.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

Parallel Programming With Microsoft Visual Studio 2010 Step By Step


1st Edition Donis Marshall

https://ebookbell.com/product/parallel-programming-with-microsoft-
visual-studio-2010-step-by-step-1st-edition-donis-marshall-2429704

Parallel Programming With Microsoft Net Design Patterns For


Decomposition And Coordination On Multicore Architectures Patterns
Practices 1st Edition Colin Campbell

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

Parallel Programming With Python Develop Efficient Parallel Systems


Using The Robust Python Environment Martini

https://ebookbell.com/product/parallel-programming-with-python-
develop-efficient-parallel-systems-using-the-robust-python-
environment-martini-20632918

Parallel Programming With Intel Parallel Studio Xe Wrox Programmer To


Programmer 1 Auflage Stephen Blairchappell

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

Parallel Programming With Openacc 1st Edition Rob Farber

https://ebookbell.com/product/parallel-programming-with-openacc-1st-
edition-rob-farber-5876386

Parallel Programming With Coarrays Robert W Numrich

https://ebookbell.com/product/parallel-programming-with-coarrays-
robert-w-numrich-7435178

Parallel Programming With C And Net Fundamentals Of Concurrency And


Asynchrony Behind Fastpaced Applications 1st Edition Vaskaran Sarcar

https://ebookbell.com/product/parallel-programming-with-c-and-net-
fundamentals-of-concurrency-and-asynchrony-behind-fastpaced-
applications-1st-edition-vaskaran-sarcar-60450582

Parallel Programming With C And Net Fundamentals Of Concurrency And


Asynchrony Behind Fastpaced Applications Vaskaran Sarcar

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++ ®

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

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

6 Dynamic Task Parallelism 75


The Basics 75
An Example 77
Variations 80
Parallel While-Not-Empty 80
Adding Tasks to a Pending Wait Context 81
Exercises 83
Further Reading 83

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

a the task scheduler and


resource manager 111
Resource Manager 113
Why It’s Needed 113
How Resource Management Works 113
Dynamic Resource Management 115
Oversubscribing Cores 116
Querying the Environment 116
Kinds of Tasks 116
Lightweight Tasks 117
Tasks Created Using PPL 117
Task Schedulers 118
Managing Task Schedulers 118
Creating and Attaching a Task Scheduler 119
Detaching a Task Scheduler 120
Destroying a Task Scheduler 120
Scenarios for Using Multiple Task Schedulers 120
Implementing a Custom Scheduling Component 121
ix

The Scheduling Algorithm 121


Schedule Groups 121
Adding Tasks 122
Running Tasks 123
Enhanced Locality Mode 124
Forward Progress Mode 125
Task Execution Order 125
Tasks That Are Run Inline 125
Using Contexts to Communicate with the Scheduler 126
Debugging Information 126
Querying for Cancellation 126
Interface to Cooperative Blocking 127
Waiting 127
The Caching Suballocator 127
Long-Running I/O Tasks 128
Setting Scheduler Policy 128
Anti-Patterns 129
Multiple Resource Managers 129
Resource Management Overhead 129
Unintentional Oversubscription from Inlined Tasks 130
Deadlock from Thread Starvation 131
Ignored Process Affinity Mask 131
References 132

b debugging and profiling parallel


applications 133
The Parallel Tasks and Parallel Stacks Windows 133
Breakpoints and Memory Allocation 136
The Concurrency Visualizer 137
Scenario Markers 141
Visual Patterns 142
Oversubscription 142
Lock Contention and Serialization 143
Load Imbalance 145
Further Reading 147

c technology overview 149


Further Reading 151

glossary 153

index
Foreword

At its inception some 40 or so years ago, parallel computing was the


province of experts who applied it to exotic fields, such as high en-
ergy physics, and to engineering applications, such as computational
fluid dynamics. We’ve come a long way since those early days.
This change is being driven by hardware trends. The days of per-
petually increasing processor clock speeds are now at an end. Instead,
the increased chip densities that Moore’s Law predicts are being used
to create multicore processors, or single chips with multiple processor
cores. Quad-core processors are now common, and this trend will
continue, with 10’s of cores available on the hardware in the not-too-
distant future.
In the last five years, Microsoft has taken advantage of this tech-
nological shift to create a variety of parallel implementations. These
include the Microsoft® Windows® High Performance Cluster (HPC)
technology for message-passing interface (MPI) programs, Dryad,
which offers a Map-Reduce style of parallel data processing, the Win-
dows Azure™ technology platform, which can supply compute cores
on demand, the Parallel Patterns Library (PPL) and Asynchronous
Agents Library for native code, and the parallel extensions of the
Microsoft .NET Framework 4.
Multicore computation affects the whole spectrum of applica-
tions, from complex scientific and design problems to consumer ap-
plications and new human/computer interfaces. We used to joke that
“parallel computing is the future, and always will be,” but the pessi-
mists have been proven wrong. Parallel computing has at last moved
from being a niche technology to being center stage for both applica-
tion developers and the IT industry.
But, there is a catch. To obtain any speed-up of an application,
programmers now have to divide the computational work to make
efficient use of the power of multicore processors, a skill that still
belongs to experts. Parallel programming presents a massive challenge
for the majority of developers, many of whom are encountering it for

xi
xii for ewor d

the first time. There is an urgent need to educate them in practical


ways so that they can incorporate parallelism into their applications.
Two possible approaches are popular with some of my computer
science colleagues: either design a new parallel programming language,
or develop a “heroic” parallelizing compiler. While both are certainly
interesting academically, neither has had much success in popularizing
and simplifying the task of parallel programming for non-experts. In
contrast, a more pragmatic approach is to provide programmers with
a library that hides much of parallel programming’s complexity and
teach programmers how to use it.
To that end, the Microsoft Visual C++® Parallel Patterns Library
and Asynchronous Agents Library present a higher-level programming
model than earlier APIs. Programmers can, for example, think in terms
of tasks rather than threads, and avoid the complexities of thread
management. Parallel Programming with Microsoft Visual C++ teaches
programmers how to use these libraries by putting them in the con-
text of design patterns. As a result, developers can quickly learn to
write parallel programs and gain immediate performance benefits.
I believe that this book, with its emphasis on parallel design pat-
terns and an up-to-date programming model, represents an important
first step in moving parallel programming into the mainstream.

Tony Hey
Corporate Vice President, Microsoft Research
Foreword

This timely book comes as we navigate a major turning point in our


industry: parallel hardware + mobile devices = the pocket supercom-
puter as the mainstream platform for the next 20 years.
Parallel applications are increasingly needed to exploit all kinds of
target hardware. As I write this, getting full computational perfor-
mance out of most machines—nearly all desktops and laptops, most
game consoles, and the newest smartphones—already means harness-
ing local parallel hardware, mainly in the form of multicore CPU pro-
cessing; this is the commoditization of the supercomputer. Increas-
ingly in the coming years, getting that full performance will also mean
using gradually ever-more-heterogeneous processing, from local
general-purpose computation on graphics processing units (GPGPU)
flavors to harnessing “often-on” remote parallel computing power in
the form of elastic compute clouds; this is the generalization of the
heterogeneous cluster in all its NUMA glory, with instantiations rang-
ing from on-die to on-machine to on-cloud, with early examples of
each kind already available in the wild.
Starting now and for the foreseeable future, for compute-bound
applications, “fast” will be synonymous not just with “parallel,” but
with “scalably parallel.” Only scalably parallel applications that can be
shipped with lots of latent concurrency beyond what can be ex-
ploited in this year’s mainstream machines will be able to enjoy the
new Free Lunch of getting substantially faster when today’s binaries
can be installed and blossom on tomorrow’s hardware that will have
more parallelism.
Visual C++ 2010 with its Parallel Patterns Library (PPL), described
in this book, helps enable applications to take the first steps down
this new path as it continues to unfold. During the design of PPL,
many people did a lot of heavy lifting. For my part, I was glad to be
able to contribute the heavy emphasis on lambda functions as the key
central language extension that enabled the rest of PPL to be built as
Standard Template Library (STL)-like algorithms implemented as a

xiii
xiv

normal library. We could instead have built a half-dozen new kinds of


special-purpose parallel loops into the language itself (and almost did),
but that would have been terribly invasive and non-general. Adding a
single general-purpose language feature like lambdas that can be used
everywhere, including with PPL but not limited to only that, is vastly
superior to baking special cases into the language.
The good news is that, in large parts of the world, we have as an
industry already achieved pervasive computing: the vision of putting
a computer on every desk, in every living room, and in everyone’s
pocket. But now we are in the process of delivering pervasive and
even elastic supercomputing: putting a supercomputer on every desk,
in every living room, and in everyone’s pocket, with both local and
non-local resources. In 1984, when I was just finishing high school, the
world’s fastest computer was a Cray X-MP with four processors,
128MB of RAM, and peak performance of 942MFLOPS—or, put an-
other way, a fraction of the parallelism, memory, and computational
power of a 2005 vintage Xbox, never mind modern “phones” and Ki-
nect. We’ve come a long way, and the pace of change is not only still
strong, but still accelerating.
The industry turn to parallelism that has begun with multicore
CPUs (for the reasons I outlined a few years ago in my essay “The Free
Lunch Is Over”) will continue to be accelerated by GPGPU comput-
ing, elastic cloud computing, and other new and fundamentally paral-
lel trends that deliver vast amounts of new computational power in
forms that will become increasingly available to us through our main-
stream programming languages. At Microsoft, we’re very happy to be
able to be part of delivering this and future generations of tools for
mainstream parallel computing across the industry. With PPL in par-
ticular, I’m very pleased to see how well the final product has turned
out and look forward to seeing its capabilities continue to grow as we
re-enable the new Free Lunch applications—scalable parallel applica-
tions ready for our next 20 years.

Herb Sutter
Principal Architect, Microsoft
Bellevue, WA, USA
February 2011
Preface

This book describes patterns for parallel programming, with code


examples, that use the new parallel programming support in the Mi-
crosoft® Visual C++® development system. This support is com-
monly referred to as the Parallel Patterns Library (PPL). There is also
an example of how to use the Asynchronous Agents Library in con-
junction with the PPL. You can use the patterns described in this book
to improve your application’s performance on multicore computers.
Adopting the patterns in your code can make your application run
faster today and also help prepare for future hardware environments,
which are expected to have an increasingly parallel computing archi-
tecture.

Who This Book Is For


The book is intended for programmers who write native code for the
Microsoft Windows® operating system, but the portability of PPL
makes this book useful for platforms other than Windows. No prior
knowledge of parallel programming techniques is assumed. However,
readers need to be familiar with features of the C++ environment such
as templates, the Standard Template Library (STL) and lambda expres-
sions (which are new to Visual C++ in the Microsoft Visual Studio®
2010 development system). Readers should also have at least a basic
familiarity with the concepts of processes and threads of execution.
Note: The examples in this book are written in C++ and use the
features of the Parallel Patterns Library (PPL).
Complete code solutions are posted on CodePlex. See http://
parallelpatternscpp.codeplex.com/.
There is also a companion volume to this guide, Parallel
Programming with Microsoft .NET, which presents the same
patterns in the context of managed code.

xv
xvi pr eface

Why This Book Is Pertinent Now


The advanced parallel programming features that are delivered with
Visual Studio 2010 make it easier than ever to get started with parallel
programming.
The Parallel Patterns Library and Asynchronous Agents Library
are for C++ programmers who want to write parallel programs. They
simplify the process of adding parallelism and concurrency to applica-
tions. PPL dynamically scales the degree of parallelism to most effi-
ciently use all the processors that are available. In addition, PPL and
agents assist in the partitioning of work and the scheduling of tasks
in threads. The library provides cancellation support, state manage-
ment, and other services. These libraries make use of the Concurrency
Runtime, which is part of the Visual C++ platform.
Visual Studio 2010 includes tools for debugging parallel applica-
tions. The Parallel Stacks window shows call stack information for all
the threads in your application. It lets you navigate between threads
and stack frames on those threads. The Parallel Tasks window re-
sembles the Threads window, except that it shows information about
each task instead of each thread. The Concurrency Visualizer views in
the Visual Studio profiler enable you to see how your application in-
teracts with the hardware, the operating system, and other processes
on the computer. You can use the Concurrency Visualizer to locate
performance bottlenecks, processor underutilization, thread conten-
tion, cross-core thread migration, synchronization delays, areas of
overlapped I/O, and other information.
For a complete overview of the parallel technologies available
from Microsoft, see Appendix C, “Technology Overview.”

What You Need to Use the Code


The code that is used for examples in this book is at http://parallelpat-
ternscpp.codeplex.com/. These are the system requirements:
• Microsoft Windows Vista® SP1, Windows 7, Windows Server®
2008, or Windows XP SP3 (32-bit or 64-bit) operating system.
• Microsoft Visual Studio 2010 SP1 (Ultimate or Premium edition
is required for the Concurrency Visualizer, which allows you to
analyze the performance of your application); this includes the
PPL, which is required to run the samples and the Asynchronous
Agents Library.
xvii

How to Use This Book


This book presents parallel programming techniques in terms of par-
ticular patterns. Figure 1 shows the different patterns and their rela-
tionships to each other. The numbers refer to the chapters in this
book where the patterns are described.
1 Introduction

Data Parallelism Task Parallelism

Coordinated by
control flow only

2 Parallel Loops 3 Parallel Tasks

Coordinated by control
flow and data flow

4 Parallel Aggregation 5 Futures 7 Pipelines

6 Dynamic Task Parallelism

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.

Parallelism with Control Dependencies


Only
Chapters 2 and 3 deal with cases where asynchronous operations are
ordered only by control flow constraints:
• Chapter 2, “Parallel Loops.” Use parallel loops when you want
to perform the same calculation on each member of a collection
or for a range of indices, and where there are no dependencies
between the members of the collection. For loops with depen-
dencies, see Chapter 4, “Parallel Aggregation.”
• Chapter 3, “Parallel Tasks.” Use parallel tasks when you have
several distinct asynchronous operations to perform. This
chapter explains why tasks and threads serve two distinct
purposes.

Parallelism with Control and Data


Dependencies
Chapters 4 and 5 show patterns for concurrent operations that are
constrained by both control flow and data flow:
• Chapter 4, “Parallel Aggregation.” Patterns for parallel aggre-
gation are appropriate when the body of a parallel loop includes
data dependencies, such as when calculating a sum or searching
a collection for a maximum value.
• Chapter 5, “Futures.” The Futures pattern occurs when opera-
tions produce some outputs that are needed as inputs to other
operations. The order of operations is constrained by a directed
graph of data dependencies. Some operations are performed in
parallel and some serially, depending on when inputs become
available.

Dynamic Task Parallelism and Pipelines


Chapters 6 and 7 discuss some more advanced scenarios:
• Chapter 6, “Dynamic Task Parallelism.” In some cases, opera-
tions are dynamically added to the backlog of work as the
computation proceeds. This pattern applies to several domains,
including graph algorithms and sorting.
• Chapter 7, “Pipelines.” Use a pipeline to feed successive
outputs of one component to the input queue of another
xix

component, in the style of an assembly line. Parallelism results


when the pipeline fills, and when more than one component is
simultaneously active.

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).

In confinement the caterpillars will eat young leaves of holly and


probably of ivy also, but where flower-buds are available they prefer
them and ignore the tender leaves.
The Rev. Gilbert Raynor, on May 18, 1901, observed a female
deposit an egg on an unopened flower-bud of rhododendron in his
garden; and he also mentions that he beat a number of the
caterpillars of all sizes from holly during the first week of July in the
same year.
Mr. Dennis reported that on October 9, 1902, all stages of the
species were to be found at Earl's Colne, Essex.
Butterflies of the first flight are usually to be seen in April and May,
and of the second, which is perhaps only partial and may not be
represented at all, in July and August. Specimens have been
observed as early as the last week of March, and, as adverted to
above, as late as October. For a few years in succession the species
may become increasingly numerous, and then suddenly become
quite scarce for a year or two. Most probably this is the result of
favourable or unfavourable weather conditions.
The taller hollies, where these grow in gardens, open woody places,
on hillsides, or even in hedgerows, are frequented by these
butterflies in the spring; and the ivy-clad walls, etc., are their haunts
in the summer.
The species is widely distributed, and often common, over the whole
of the south of England and Wales. North of the Midlands, as well as
in Ireland, it is more local, and occurs, I believe, only in the first
brood. Possibly in the South of Ireland there may be a second brood.
Barrett states that there is no reliable record for Scotland.
Abroad, its range extends throughout Europe and Northern Asia,
except the Polar Regions, to China and Japan. It also occurs in North
Africa.

The Small Blue (Zizera minima).


The butterfly on Plate 115 is sometimes referred to as the "Bedford
Blue" and also as the "Little Blue."
Both sexes are blackish, or sooty-brown; the male is powdered,
more or less, with silvery-blue scales. The under side is greyish-
white with a tinge of blue at the base of each wing, but chiefly on
the hind pair; the spots are black encircled with white. As will be
seen on turning to the plate, there is variation in size. Fig. 5
represents a giant race occurring in some localities, and the
particular specimen depicted was taken, with many others, on the
coast near Lymington, Hants; it seems to be referable to var.
alsoides, Gerhard. Variation on the under side is usually in the
direction of complete absence of spots, but Mr. Joy has recorded a
specimen with the spots on the hind wings extended into streaks of
considerable but varying length.
Figures of the early stages will be found on Plate 114.
The egg is pale greenish in colour, netted with whitish; it is laid in
June on the calyx of a flower-bud, generally low down, of the
kidney-vetch (Anthyllis vulneraria).
According to Buckler, caterpillars hatched on June 21 from eggs laid
between the 16th and 18th of that month, and at once commenced
to feed on the flowers of the kidney-vetch, and made their way to
the seed, for which they evinced a marked preference. When full
grown, the caterpillar is brownish, sometimes tinged with pink. The
fine bristles are dark brown; there is a darker line along the middle
of the back, and a line of dark marks on each side. The head is black
and shining.
The chrysalis is described by Buckler as "dirty whitish-grey,
approaching to drab, palest on the back of the abdomen, greyish on
the head and thorax, both of which are marked with a black dorsal
stripe, which is a little interrupted; on either side is a subdorsal row
of short slanting black dashes. The pale ground colour is sprinkled
with some very minute black specks. The head, thorax, and
abdomen are hairy with bristly whitish hairs." Although the
caterpillars feed up rather quickly and are full grown and apparently
ready to assume the chrysalis state, they do not effect the change
until the following May or June.
Pl. 114.
Small Blue.
Eggs, natural size and enlarged; caterpillar and chrysalids.
Larger Image
Pl. 115.
Small Blue. 1 male; 2, 3 female; 4, 5, 6, 7, 8 male vars.
Mazarine Blue. 9, 11 male; 10, 12 female.

The butterfly emerges in about three weeks, so it will be seen that


this species continues the caterpillar existence for something over
ten months.
On the Continent there are two broods of the butterfly, and in
England there appears to be a partial second flight in some years,
as, for instance, in 1901, when captures in August were reported
from Herts, Kent, Surrey, and Wilts. Its haunts are warm and sunny
grassy hollows and slopes, and it is often common in such places on
the chalk hills in the south, from the end of May to the end of June.
According to Barrett it is scarce in the Eastern Counties; widely
distributed but local in the Midland and Western Counties, even to
Devon, and in Wales, where chalk or limestone is found; also in
extremely restricted localities in Yorkshire, Lancashire, Cumberland,
and Durham, and in various places in Scotland, extending as far
north as Aberdeen. In Ireland it is much more plentiful, especially on
the limestone of the west and on the coast hills near Belfast, and
even frequents the sand-hills of the Dublin coast.
It is widely spread over Europe, except the Polar parts, and,
apparently, the south of Portugal and Spain; its range extends
eastward to Amurland, Mongolia, and China.

The Mazarine Blue (Nomiades


semiargus).
The male is dull purplish-blue, narrowly bordered with blackish on
the outer margin; the female is dark brown. On the underside both
sexes are pale greyish-brown, with a bluish tinge at the base; there
is a black discal spot and a series of black spots beyond, all ringed
with white.
The egg is described as being white in colour and small, and round
in shape.
The caterpillar is of a dingy yellowish-green, with darker lines on the
back and sides; there are fine hairs on the body, and the head and
spiracles are dark brown (Rühl).
It feeds in July and August on the flowers and seeds of thrift
(Armeria vulgaris), kidney-vetch (Anthyllis vulneraria), and melilot
(Melilotus officinalis).
The chrysalis is rather oval in shape, pale olive-green in colour when
first formed, in September, but olive-brown later; it is attached by
the tail to a stalk of the food-plant and has a silken girdle (Rühl).
This butterfly (Plate 115) is the cymon of Lewin, who, writing in
1795, considered it very rare. In 1828 Stephens refers to it as scarce
and local, "found in chalky districts in Norfolk, Cambridge, Yorkshire,
and Dorsetshire; also near Brockenhurst and Amesbury, Hants; and
on Windlesham Heath, Surrey, towards the end of May and of July."
Newman (1871) adds Warwickshire, Herefordshire, Gloucestershire,
Monmouthshire, Glamorganshire, Somersetshire, and Lincolnshire.
Curtis gives Leicestershire and Worcestershire. It seems to have
been fairly common, and even plentiful in some years around
Glanville's Wotton, Dorset, but has not been seen in that district
since 1841; at Wotton-under-Edge, Gloucester, it was not uncommon
up to 1858; as late as 1864 it occurred at Epworth, North
Lincolnshire. Probably the latest captures in Britain were the
specimens taken in Glamorganshire in the years 1874-77. Tutt
mentions that the butterfly was taken near Cuxton in Kent, some
thirty-five years ago, but it has not since been seen in that locality.
Occurs in May and June and again in July and August over the
greater part of Europe; its range extends to Asia Minor, and
eastward to Siberia, Mongolia, and Amurland.
Pl. 116.
Large Blue.
Egg, natural size and enlarged; chrysalis.
Larger Image
Pl. 117.
Large Blue. 1, 5 male; 2, 3, 4, 6
female.
Chalkhill Blue vars. 7 female; 8
do. var. syngrapha.

The Large Blue (Nomiades arion).


The butterfly on Plate 117, Figs. 1-6, is the largest "Blue" found in
this country. All the wings on the upper side are deep blue, and their
outer margins are bordered with blackish; the discal spot, and a row
of spots beyond, are black; the hind wings have a row of black dots
on the outer margin, and sometimes, and especially in the female,
there is a series of black dots just beyond the central area; the
fringes are white. The under side is greyish tinged with blue towards
the base of each wing, but covering nearly the whole of the basal
third of the hind pair; the spots are black ringed or edged with
white; on the fore wings there are two in the discal cell and a row of
six beyond; on the hind wings there are four or five before the discal
spot, and a series of seven beyond; all the wings have a double
marginal series, and some black dots at the ends of the nervules.
Sometimes the wings have a purplish tinge, and this is more usually
so in Gloucestershire specimens. The chief variation is in the number
and the size of the spots; these are occasionally only faintly in
evidence, but more rarely perhaps those beyond the discal spot on
the fore wings are of large size and bar or wedge-like in shape; the
smaller cell-spot is often absent. A dwarf form is stated to occur at
times in all localities.
The complete life-history of this species has yet to be ascertained;
no one seems to be acquainted with the caterpillar after hibernation.
Pretty much all that is known of the early stages has been worked
out by Mr. Frohawk, who has published some very interesting
accounts of his observations in the Entomologist for 1899 and 1903,
and from these the following details have been obtained.
The egg (Plate 116) is bluish-white in colour, and is laid singly
among the buds of wild thyme (Thymus serpyllum).
Caterpillars hatched on July 10 from eggs received the previous day;
they were placed upon thyme blossoms and soon commenced to
feed, one being observed to eat its way into the base of the calyx so
that the forepart of the caterpillar was hidden. In its colouring and
downy covering the caterpillar so closely resembles the flower-buds
of the thyme that it is very difficult to detect. After the third moult
(July 26) the colour is a uniform, dull, ochreous-pink; there are four
rows of long curved hairs, each row composed of a single hair on
each ring from the fourth to the ninth inclusive; the first three rings
have each a set of three subdorsal hairs, those on the first ring
curving forwards; the bases of the hairs resemble glass-like
pedestals with fluted sides. The head is ochreous with dark brown
markings in front. The caterpillar at this stage develops an aversion
to thyme or any other plant offered to it, and seems to be anxious to
hide itself in the ground.
The chrysalis, which is figured on Plate 116 (after Frohawk), is
ochreous when first formed, but becomes darker gradually; the
wing-cases, however, remain of the original colour, but their hind
margins darken. From a chrysalis found on July 12 the butterfly
emerged on July 16.
There is some evidence in favour of the supposition that this
caterpillar is in some way dependent upon ants for nourishment
after the third moult, if not before, but what the exact requirement
may be is not known. Probably the circumstances connected with
the discovery of the chrysalis in 1905 by Messrs. Frohawk & Rayward
may afford a valuable clue to the direction in which their future
investigation will have to be conducted. We may hope, therefore,
that the mystery that has so long hung over the last stages of the
caterpillar will be solved before very long.
Lewin (1795) and Donovan (1796) both refer to this as a rare
English butterfly. The former states that it is on the wing in July, and
is found on high chalky lands in different parts of the kingdom,
having been taken on the cliffs in the neighbourhood of Dover,
Marlborough Downs, the hills near Bath, and near Clifden in Bucks.
Stephens, in 1828, wrote of it as "an insect of great rarity." He
mentioned the localities given by the older authors, and added that
it had been taken in the Mouse's Pasture, near Bedford, in rocky
situations in North Wales, and had been plentiful near Winchester.
Newman (1871) wrote, "Its 'metropolis,' if I may borrow an
expression from the revered fathers of British entomology, is in
South Devon; it has occurred in some abundance in Somersetshire,
and on the Cotswold Hills in Gloucestershire; from Gloucestershire
we ascend to a Midland county, Northamptonshire, in which county
(at Barnwell Wold) a considerable number have been taken." One
specimen was reported from Charmouth in Dorsetshire, and the
butterfly has also been recorded from Herefordshire, but these are
matters of ancient history. At the present time the species is only to
be found in limited numbers in the Cotswolds; it seems to have
become much rarer than formerly in its South Devon locality, i.e.
Bolthead, near Plymouth; one never hears of it now from Clovelly, in
North Devon, where, according to Dale, it was once reported to be
abundant. In 1891 Messrs. Waterhouse obtained a fine series of
specimens in West Cornwall, and since that time the district has
been annually visited by an increasing number of entomologists.
Judging from the "big bags" that are made each year it would seem
that the butterfly has a very strong and widely distributed settlement
in those parts.
Abroad it is distributed throughout Europe, except the Polar and the
south-western parts, and is also found in Armenia, Bithynia, and
South Siberia.

Our next species belongs to the Nemeobiinæ, a sub-family of


Lemoniidæ = Erycinidæ. Only one member of the family is known to
occur in Europe; this is Nemeobius lucina.
As the fore legs of the male butterfly are aborted, and are therefore
useless for walking, the species would seem to come near the
Nymphalidæ, in which the fore legs of the butterflies, in both sexes,
are reduced. In its early stages, however, the species seems to be
most nearly related to the Lycænidæ.

The Duke of Burgundy Fritillary


(Nemeobius lucina).
This butterfly is figured on Plate 120. The male is black, with three
transverse tawny bands on the fore wings; these are crossed by the
black veins, and so form series of irregular spots. Those on the outer
margin have black centres; on the hind wings there are three or four
tawny spots on the disc, and a series of black centred tawny spots
on the outer area. The female is similar to the male, but the tawny
markings are wider, so that the fore wings appear to be of this
colour, with a black patch at the base, two black irregular lines, and
a series of black spots on the outer margin. On the under side of the
hind wings there are two transverse series of whitish spots, and a
series of black spots on the outer margin. The wings of this sex are
always broader than those of the male, and the apex of the fore
wings is not so distinctly pointed. Variation is not usually of a very
pronounced character, and in a general way it consists mainly in a
greater or lesser amount of black in the male, and this more
particularly on the hind wings, and an increase in the tawny colour in
the female; in the latter sex, outer marginal black spots are
sometimes absent from all the wings. Barrett mentions two extreme
aberrations. In one, a female, the usually dark spaces, bands, and
veins are of an exceedingly pale brown, suffused with fulvous, so as
to be comparatively indistinct; another example, a male, has the
basal area of the fore wings pale, and the first transverse dark band
absent.
Larger Image
Pl. 118.
1, 3 Common Blue vars., male; 6 do. female.
2, 5, 8, 11 Adonis Blue vars., male; 4, 7, do. female.
9, 10 Chalkhill Blue vars., female; 12 do. male.
Pl. 119.
1, 2, 3 Small Copper vars.; 4 Adonis Blue var.
5 Common Blue var.; 6, 7, 8 Gatekeeper vars.

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æ.

The Grizzled Skipper (Hesperia


malvæ).
The wings of the butterfly figured on Plate 122 are blackish,
ornamented with numerous white spots, which are more or less
square in shape, on the fore wings. The fringes are chequered black
and white.
The male differs from the female in having the front edge of the fore
wings folded towards the base, and these wings have scattered
greyish scales on the basal area; the central series of spots on the
hind wings are also more in evidence, and not infrequently unite and
become band-like. Variation consists in modification of the markings,
chiefly in a tendency of the spots to run together, culminating in var.
taras, Bergstr., in which the white spots of the fore wings are
confluent and form a large blotch. This variety was figured by Petiver
in 1717, but was not named by Bergsträsser until 1780. Haworth
described it as lavateræ, and Newman figured it under the same
name.
On a small plant of Alpine strawberry, sent by the Rev. Gilbert
Raynor, were three eggs of this butterfly. These were pale green in
colour, ribbed, and delicately netted with cross-lines. On June 26,
three caterpillars were noticed on the upper side of the leaves, each
on a separate leaf, and under cover of a few coarse silken threads.
They were pale steely-grey, with black heads, and plates on the first
and last segments of the body.
As the supply of strawberry foliage was failing, the caterpillars were
given bramble on July 21, and the next day each was found
enclosed in a sort of envelope formed of a bramble leaf. They were
then seemingly in their last skin, whitish-green in colour, and
covered with short whitish hair; a whitish edged dark olive-brown
line along the back, and similar lines on the sides; between the rings
the colour was pale ochreous. The date of pupation was not noted,
but on September 9, one of the spun-together bramble leaves was
opened, and a chrysalis found within. This was pale brown, with
dark brown or blackish marks along the back and sides; the head
and back were covered with dense pale reddish-brown bristles; the
wing, leg, and antennæ cases were greenish, smooth, and shaded
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.

More than just a book-buying platform, we strive to be a bridge


connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.

Join us on a journey of knowledge exploration, passion nurturing, and


personal growth every day!

ebookbell.com

You might also like