Pro TBB: C++ Parallel Programming With Threading Building Blocks 1st Edition Michael Voss Download PDF
Pro TBB: C++ Parallel Programming With Threading Building Blocks 1st Edition Michael Voss Download PDF
com
https://textbookfull.com/product/pro-tbb-c-
parallel-programming-with-threading-building-
blocks-1st-edition-michael-voss/
https://textbookfull.com/product/primary-mathematics-
textbook-2b-jennifer-hoerst/
textbookfull.com
https://textbookfull.com/product/handbook-of-macroeconomics-
volume-2a-2b-set-1st-edition-john-b-taylor/
textbookfull.com
https://textbookfull.com/product/fortran-2018-with-parallel-
programming-1st-edition-subrata-ray-author/
textbookfull.com
https://textbookfull.com/product/the-biological-resources-of-model-
organisms-1st-edition-robert-l-jarret/
textbookfull.com
https://textbookfull.com/product/grammar-for-teachers-a-guide-to-
american-english-for-native-and-non-native-speakers-2nd-edition-
andrea-decapua-2/
textbookfull.com
https://textbookfull.com/product/understanding-the-business-of-media-
entertainment-american-film-market-presents-2nd-edition-bernstein/
textbookfull.com
Michael Voss
Rafael Asenjo
James Reinders
Pro TBB: C++ Parallel Programming with Threading Building Blocks
Michael Voss Rafael Asenjo
Austin, Texas, USA Málaga, Spain
James Reinders
Portland, Oregon, USA
Acknowledgments�������������������������������������������������������������������������������������������������xvii
Preface�������������������������������������������������������������������������������������������������������������������xix
Part 1�������������������������������������������������������������������������������������������������������������� 1
Chapter 1: Jumping Right In: “Hello, TBB!”�������������������������������������������������������������� 3
Why Threading Building Blocks?��������������������������������������������������������������������������������������������������� 3
Performance: Small Overhead, Big Benefits for C++�������������������������������������������������������������� 4
Evolving Support for Parallelism in TBB and C++������������������������������������������������������������������� 5
Recent C++ Additions for Parallelism������������������������������������������������������������������������������������� 6
The Threading Building Blocks (TBB) Library�������������������������������������������������������������������������������� 7
Parallel Execution Interfaces��������������������������������������������������������������������������������������������������� 8
Interfaces That Are Independent of the Execution Model������������������������������������������������������ 10
Using the Building Blocks in TBB������������������������������������������������������������������������������������������� 10
Let’s Get Started Already!����������������������������������������������������������������������������������������������������������� 11
Getting the Threading Building Blocks (TBB) Library������������������������������������������������������������� 11
Getting a Copy of the Examples��������������������������������������������������������������������������������������������� 12
Writing a First “Hello, TBB!” Example������������������������������������������������������������������������������������ 12
Building the Simple Examples����������������������������������������������������������������������������������������������� 15
Building on Windows Using Microsoft Visual Studio������������������������������������������������������������� 16
Building on a Linux Platform from a Terminal����������������������������������������������������������������������� 17
A More Complete Example���������������������������������������������������������������������������������������������������������� 21
Starting with a Serial Implementation����������������������������������������������������������������������������������� 21
Adding a Message-Driven Layer Using a Flow Graph������������������������������������������������������������ 25
Adding a Fork-Join Layer Using a parallel_for���������������������������������������������������������������������� 27
Adding a SIMD Layer Using a Parallel STL Transform����������������������������������������������������������� 29
iii
Table of Contents
v
Table of Contents
vi
Table of Contents
cached_aligned_allocator��������������������������������������������������������������������������������������������������������� 223
Memory Pool Support: memory_pool_allocator������������������������������������������������������������������ 223
Array Allocation Support: aligned_space����������������������������������������������������������������������������� 224
Replacing new and delete Selectively�������������������������������������������������������������������������������������� 224
Performance Tuning: Some Control Knobs�������������������������������������������������������������������������������� 228
What Are Huge Pages?�������������������������������������������������������������������������������������������������������� 228
TBB Support for Huge Pages����������������������������������������������������������������������������������������������� 228
scalable_allocation_mode(int mode, intptr_t value)����������������������������������������������������������� 229
TBBMALLOC_USE_HUGE_PAGES����������������������������������������������������������������������������������������� 229
TBBMALLOC_SET_SOFT_HEAP_LIMIT��������������������������������������������������������������������������������� 230
int scalable_allocation_command(int cmd, void *param)��������������������������������������������������� 230
TBBMALLOC_CLEAN_ALL_BUFFERS����������������������������������������������������������������������������������� 230
TBBMALLOC_CLEAN_THREAD_BUFFERS���������������������������������������������������������������������������� 230
vii
Table of Contents
Chapter 11: Controlling the Number of Threads Used for Execution�������������������� 313
A Brief Recap of the TBB Scheduler Architecture��������������������������������������������������������������������� 314
Interfaces for Controlling the Number of Threads��������������������������������������������������������������������� 315
viii
Table of Contents
Chapter 12: Using Work Isolation for Correctness and Performance������������������� 337
Work Isolation for Correctness�������������������������������������������������������������������������������������������������� 338
Creating an Isolated Region with this_task_arena::isolate������������������������������������������������� 343
Using Task Arenas for Isolation: A Double-Edged Sword���������������������������������������������������������� 349
Don’t Be Tempted to Use task_arenas to Create Work Isolation for Correctness���������������� 353
ix
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
Table of Contents
x
Table of Contents
xi
Table of Contents
xii
Table of Contents
Glossary���������������������������������������������������������������������������������������������������������������� 729
Index��������������������������������������������������������������������������������������������������������������������� 745
xiii
About the Authors
Michael Voss is a Principal Engineer in the Intel Architecture, Graphics and Software
Group at Intel. He has been a member of the TBB development team since before the
1.0 release in 2006 and was the initial architect of the TBB flow graph API. He is also
one of the lead developers of Flow Graph Analyzer, a graphical tool for analyzing data
flow applications targeted at both homogeneous and heterogeneous platforms. He
has co-authored over 40 published papers and articles on topics related to parallel
programming and frequently consults with customers across a wide range of domains to
help them effectively use the threading libraries provided by Intel. Prior to joining Intel
in 2006, he was an Assistant Professor in the Edward S. Rogers Department of Electrical
and Computer Engineering at the University of Toronto. He received his Ph.D. from the
School of Electrical and Computer Engineering at Purdue University in 2001.
James Reinders is a consultant with more than three decades experience in Parallel
Computing, and is an author/co-author/editor of nine technical books related to parallel
programming. He has had the great fortune to help make key contributions to two of
the world’s fastest computers (#1 on Top500 list) as well as many other supercomputers,
xv
About the Authors
and software developer tools. James finished 10,001 days (over 27 years) at Intel in mid-
2016, and now continues to write, teach, program, and do consulting in areas related to
parallel computing (HPC and AI).
xvi
Acknowledgments
Two people offered their early and continuing support for this project – Sanjiv Shah and
Herb Hinstorff. We are grateful for their encouragement, support, and occasional gentle
pushes.
The real heroes are reviewers who invested heavily in providing thoughtful and
detailed feedback on draft copies of the chapters within this book. The high quality
of their input helped drive us to allow more time for review and adjustment than we
initially planned. The book is far better as a result.
The reviewers are a stellar collection of users of TBB and key developers of TBB. It
is rare for a book project to have such an energized and supportive base of help in
refining a book. Anyone reading this book can know it is better because of these kind
souls: Eduard Ayguade, Cristina Beldica, Konstantin Boyarinov, José Carlos Cabaleiro
Domínguez, Brad Chamberlain, James Jen-Chang Chen, Jim Cownie, Sergey Didenko,
Alejandro (Alex) Duran, Mikhail Dvorskiy, Rudolf (Rudi) Eigenmann, George Elkoura,
Andrey Fedorov, Aleksei Fedotov, Tomás Fernández Pena, Elvis Fefey, Evgeny Fiksman,
Basilio Fraguela, Henry Gabb, José Daniel García Sánchez, Maria Jesus Garzaran,
Alexander Gerveshi, Darío Suárez Gracia, Kristina Kermanshahche, Yaniv Klein, Mark
Lubin, Anton Malakhov, Mark McLaughlin, Susan Meredith, Yeser Meziani, David
Padua, Nikita Ponomarev, Anoop Madhusoodhanan Prabha, Pablo Reble, Arch Robison,
Timmie Smith, Rubén Gran Tejero, Vasanth Tovinkere, Sergey Vinogradov, Kyle Wheeler,
and Florian Zitzelsberger.
We sincerely thank all those who helped, and we apologize for any who helped us
and we failed to mention!
Mike (along with Rafa and James!) thanks all of the people who have been involved
in TBB over the years: the many developers at Intel who have left their mark on the
library, Alexey Kukanov for sharing insights as we developed this book, the open-source
contributors, the technical writers and marketing professionals that have worked on
documentation and getting the word out about TBB, the technical consulting engineers
and application engineers that have helped people best apply TBB to their problems, the
managers who have kept us all on track, and especially the users of TBB that have always
provided the feedback on the library and its features that we needed to figure out where
xvii
Acknowledgments
to go next. And most of all, Mike thanks his wife Natalie and their kids, Nick, Ali, and
Luke, for their support and patience during the nights and weekends spent on this book.
Rafa thanks his PhD students and colleagues for providing feedback regarding
making TBB concepts more gentle and approachable: José Carlos Romero, Francisco
Corbera, Alejandro Villegas, Denisa Andreea Constantinescu, Angeles Navarro;
particularly to José Daniel García for his engrossing and informative conversations about
C++11, 14, 17, and 20, to Aleksei Fedotov and Pablo Reble for helping with the OpenCL_
node examples, and especially his wife Angeles Navarro for her support and for taking
over some of his duties when he was mainly focused on the book.
James thanks his wife Susan Meredith – her patient and continuous support was
essential to making this book a possibility. Additionally, her detailed editing, which often
added so much red ink on a page that the original text was hard to find, made her one of
our valued reviewers.
As coauthors, we cannot adequately thank each other enough. Mike and James have
known each other for years at Intel and feel fortunate to have come together on this book
project. It is difficult to adequately say how much Mike and James appreciate Rafa! How
lucky his students are to have such an energetic and knowledgeable professor! Without
Rafa, this book would have been much less lively and fun to read. Rafa’s command of
TBB made this book much better, and his command of the English language helped
correct the native English speakers (Mike and James) more than a few times. The three
of us enjoyed working on this book together, and we definitely spurred each other on to
great heights. It has been an excellent collaboration.
We thank Todd Green who initially brought us to Apress. We thank Natalie Pao, of
Apress, and John Somoza, of Intel, who cemented the terms between Intel and Apress
on this project. We appreciate the hard work by the entire Apress team through contract,
editing, and production.
Thank you all,
Mike Voss, Rafael Asenjo, and James Reinders
xviii
Preface
Think Parallel
We have aimed to make this book useful for those who are new to parallel programming
as well as those who are expert in parallel programming. We have also made this book
approachable for those who are comfortable only with C programming, as well as those
who are fluent in C++.
In order to address this diverse audience without “dumbing down” the book, we
have written this Preface to level the playing field.
What Is TBB
TBB is a solution for writing parallel programs in C++ which has become the most
popular, and extensive, support for parallel programming in C++. It is widely used
and very popular for a good reason. More than 10 years old, TBB has stood the test
of time and has been influential in the inclusion of parallel programming support in
the C++ standard. While C++11 made major additions for parallel programming, and
C++17 and C++2x take that ever further, most of what TBB offers is much more than
what belongs in a language standard. TBB was introduced in 2006, so it contains
support for pre-C++11 compilers. We have simplified matters by taking a modern
look at TBB and assuming C++11. Common advice today is “if you don’t have a
C++11 compiler, get one.” Compared with the 2007 book on TBB, we think C++11,
with lambda support in particular, makes TBB both richer and easier to understand
and use.
TBB is simply the best way to write a parallel program in C++, and we hope to help
you be very productive in using TBB.
xix
Preface
T hink Parallel
For those new to parallel programming, we offer this Preface to provide a foundation
that will make the remainder of the book more useful, approachable, and self-contained.
We have attempted to assume only a basic understanding of C programming and
introduce the key elements of C++ that TBB relies upon and supports. We introduce
parallel programming from a practical standpoint that emphasizes what makes parallel
programs most effective. For experienced parallel programmers, we hope this Preface
will be a quick read that provides a useful refresher on the key vocabulary and thinking
that allow us to make the most of parallel computer hardware.
xx
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
Preface
After reading this Preface, you should be able to explain what it means to “Think
Parallel” in terms of decomposition, scaling, correctness, abstraction, and patterns.
You will appreciate that locality is a key concern for all parallel programming. You
will understand the philosophy of supporting task programming instead of thread
programming – a revolutionary development in parallel programming supported by TBB.
You will also understand the elements of C++ programming that are needed above and
beyond a knowledge of C in order to use TBB well.
The remainder of this Preface contains five parts:
(1) An explanation of the motivations behind TBB (begins on page xxi)
xxi
Preface
xxii
Preface
With these definitions in mind, a program written in terms of threads would have
to map each algorithm onto specific systems of hardware and software. This is not only
a distraction, it causes a whole host of issues that make parallel programming more
difficult, less effective, and far less portable.
Whereas, a program written in terms of tasks allows a runtime mechanism, for
example, the TBB runtime, to map tasks onto the hardware which is actually present at
runtime. This removes the distraction of worrying about the number of actual hardware
threads available on a system. More importantly, in practice this is the only method
which opens up nested parallelism effectively. This is such an important capability, that
we will revisit and emphasize the importance of nested parallelism in several chapters.
xxiii
Preface
available nonmandatory parallelism, the runtime is free to use that information to match
the capabilities of the machine in the most effective manner.
We have come to expect composability in our programming languages, but most
parallel programming models have failed to preserve it (fortunately, TBB does preserve
composability!). Consider “if” and “while” statements. The C and C++ languages allow
them to freely mix and nest as we desire. Imagine this was not so, and we lived in a world
where a function called from within an if statement was forbidden to contain a while
statement! Hopefully, any suggestion of such a restriction seems almost silly. TBB brings
this type of composability to parallel programming by allowing parallel constructs to be
freely mixed and nested without restrictions, and without causing issues.
WHAT IS SPEEDUP?
Speedup is formerly defined to be the time to run sequentially (not in parallel) divided by the
time to run in parallel. If my program runs in 3 seconds normally, but in only 1 second on a
quad-core processor, we would say it has a speedup of 3×. Sometimes, we might speak of
efficiency which is speedup divided by the number of processing cores. Our 3× would be 75%
efficient at using the parallelism.
The ideal goal of a 16× gain in performance when moving from a quad-core machine
to one with 64 cores is called linear scaling or perfect scaling.
xxiv
Preface
To accomplish this, we need to keep all the cores busy as we grow their
numbers – something that requires considerable available parallelism. We will dive
more into this concept of “available parallelism” starting on page xxxvii when we discuss
Amdahl’s Law and its implications.
For now, it is important to know that TBB supports high-performance programming
and helps significantly with performance portability. The high-performance support
comes because TBB introduces essentially no overhead which allows scaling to proceed
without issue. Performance portability lets our application harness available parallelism
as new machines offer more.
In our confident claims here, we are assuming a world where the slight additional
overhead of dynamic task scheduling is the most effective at exposing the parallelism
and exploiting it. This assumption has one fault: if we can program an application to
perfectly match the hardware, without any dynamic adjustments, we may find a few
percentage points gain in performance. Traditional High-Performance Computing
(HPC) programming, the name given to programming the world’s largest computers
for intense computations, has long had this characteristic in highly parallel scientific
computations. HPC developer who utilize OpenMP with static scheduling, and find it
does well with their performance, may find the dynamic nature of TBB to be a slight
reduction in performance. Any advantage previously seen from such static scheduling is
becoming rarer for a variety of reasons. All programming including HPC programming,
is increasing in complexity in a way that demands support for nested and dynamic
parallelism support. We see this in all aspects of HPC programming as well, including
growth to multiphysics models, introduction of AI (artificial intelligence), and use of ML
(machine learning) methods. One key driver of additional complexity is the increasing
diversity of hardware, leading to heterogeneous compute capabilities within a single
machine. TBB gives us powerful options for dealing with these complexities, including
its flow graph features which we will dive into in Chapter 3.
xxv
Random documents with unrelated
content Scribd suggests to you:
the Molly Maguires, and get as high in their counsels as possible, in
order that he might reveal their secrets to the authorities, thereby
preventing outrages when possible and securing convictions where
he could not prevent. He was successful in both efforts. After many
months of work and peril he finally succeeded in securing sufficient
evidence to accomplish the conviction of a large number of the
members of the society, breaking down completely their customary
defense of an alibi. In all, nineteen Molly Maguires were hanged, and
a larger number imprisoned, and the power of the organization was
completely shattered.
This series of events is a remarkable illustration of the way in
which customs, and habits of thought, and standards of conduct,
which have grown up by a natural process, and are comprehensible if
not excusable in one land, may develop most alarming and
disgraceful features when transplanted to a new environment. The
essential strength of the Molly Maguires lay in that deep-seated
hatred of an informer which has become a pronounced feature of the
Irish character, as a result of the conditions to which they have been
subjected at home. Thus, while the great mass of the Irish settlers of
the anthracite region abhorred the principles and deeds of the Molly
Maguires, it was almost impossible to secure witnesses against
criminals whose identity was a matter of general knowledge, because
of the greater repugnance to the character of an informer. The
traditional hatred of the Irish peasant towards the landlord was, in
this country, diverted to the capitalist class in a wholly unreasonable
but efficient manner.
There is here, also, a striking demonstration of the capacity of a
relatively small group of turbulent and unassimilated foreigners so to
conduct themselves as to bring an undeserved disrepute upon their
whole group, and foster economic and social changes in society
which will last on long after they are all dead.[98]
While the Irish and Germans were dominating the immigration
situation on the Atlantic coast, the Chinese were occupying the
center of the stage in the west. The stream of Chinese immigration
became considerable at about the same time that the great increase
in European immigration was taking place on the other side of the
continent. As to its causes, Mrs. Mary Roberts Coolidge speaks as
follows: “The first effective contact of China with Western nations
was through the Opium War of 1840, which resulted in an increase of
Chinese taxes, a general disturbance of the laboring classes, and the
penetration of some slight knowledge of European ideas into the
maritime provinces. Although this prepared the way for the
emigration to the West, its precipitating cause lay in ‘the Golden
Romance’ that had filled the world,”—that is, the news of the
discovery of gold in California. “Masters of foreign vessels afforded
every facility to emigration, distributing placards, maps, and
pamphlets with highly colored accounts of the Golden Hills.... But
behind the opportunity afforded by foreign shipping and the
enticement of the discovery of gold lay deeper causes for emigration
—the poverty and ruin in which the inhabitants of Southeastern
China were involved by the great Taiping rebellion which began in
the summer of 1850. The terrors of war, famine, and plundering
paralyzed all industry and trade, and the agricultural classes of the
maritime districts especially were driven to Hong Kong and
Macao.”[99] By the end of 1852 there were in the neighborhood of
25,000 Chinese on the Pacific coast, almost all of them in California.
During the first few years of their coming, the Chinese in
California were welcomed, and were looked upon with favor. They
were industrious, tractable, and inoffensive, and were willing to
undertake the hard, menial, and disagreeable forms of labor—partly
work generally done by women—for which native labor was not
available under existing conditions. Their strange manners and
customs aroused nothing more than feelings of curiosity. But
gradually a feeling of opposition to them began to grow up, fomented
by the jealousy and race prejudice of the miners. Their peculiar
appearance and strange customs began to make them the objects of
suspicion and hatred. This feeling was intensified by the presence of
a large element of southerners in California, who classed all people of
dark skin—“South Americans, South Europeans, Kanakas, Malays, or
Chinese”—together as colored. Wild stories of their character and
habits began to circulate, and with each repetition gained strength
until they passed current as facts. Among these were the assertions
that the Chinese were practically all coolies, or labor slaves, that they
were highly immoral and vicious, that they had secret tribunals
which inflicted the death penalty without due process of law, that
they displaced native labor, that they could not be Christianized, that
they had no intention of remaining as permanent residents of the
country and would not assimilate with the natives, that they sent
money out of the country, etc. Most of these charges have been
proven to be either wholly false or highly exaggerated by recent
investigations, and were so recognized by the more sober and fair-
minded students of the subject at the time. But for the mass of the
people of the Pacific coast, and for many in other parts of the
country, they acquired all the force of established dogma, and their
reiteration passed for argument.
The Chinaman became the scapegoat for all the ills that afflicted
the youthful community, from whatever cause they really arose, and
in time an anti-Chinese declaration came to be essential for the
success of any political party or candidate. In such a state of public
opinion it was inevitable that their lot should be a hard one. They
were robbed, beaten, murdered, and persecuted in a variety of ways.
The foreign miners’ license tax was used against them in a
discriminating way which amounted to quasi legal plunder.
In 1876 the California State Legislature appointed a committee to
look into the matter of Chinese immigration and to make a report.
This was done in 1877, and although the resulting Address and
Memorial to Congress have had a large influence in forming public
opinion, and in shaping legislation, it appears that it was in fact a
purely political document, and that everything was arranged in
advance to secure a report which should accomplish a certain
definite result—the satisfaction of the workingmen of the state, and
the emphasizing of the necessity of federal legislation. The need of
this was strongly felt, because nearly all the acts passed by the coast
states against the Chinese had been declared either unconstitutional
or a violation of treaty.
In response to the repeated demands of the coast states for some
federal action, Congress in 1876 appointed a special committee on
Chinese immigration, which made what purported to be a thorough
investigation of the matter, and reported thereupon. The report was
wholly anti-Chinese. But this was inevitable, as it is apparent from a
careful study of the testimony, that the committee “came to its task
committed to an anti-Chinese conclusion and that it had no judicial
character whatever.”[100] The evidence was willfully distorted to
produce the desired result.
During all this time our relations with China had been nominally
subject to a series of treaties, beginning with that of 1844, and
including the famous Burlingame treaty of 1868. While the earlier
agreements did not specifically mention the rights of Chinese to
reside and trade in the United States, they were in fact allowed the
same privileges in these respects as the citizens of other nations. By
the treaty of 1868, however, the right of voluntary emigration was
definitely recognized as between the two countries on the basis of the
most favored nation; but the Chinese were not given the right of
naturalization. From this privilege they were definitely excluded by
the law of 1870.
It became evident in time that no federal legislation, satisfactory to
the politicians of the western states, could be secured under the
existing treaties. There arose accordingly a demand for a new treaty
which would allow the passage of laws which would include the
points desired by the western representatives, practically the
exclusion of all Chinese not belonging to the merchant class. In
response to this demand there was negotiated, after much conference
between the representatives of the two nations, a new treaty in 1880.
The most important feature of this new instrument was the right
conferred upon the government of the United States reasonably to
regulate, limit, or suspend, but not to prohibit, the coming or
residence of Chinese laborers, whenever it deemed that the interests
of the country demanded such action. It is under this treaty that the
various Chinese exclusion acts have been passed.
The first of these acts was passed in 1882, and provided for the
exclusion of Chinese laborers for a period of ten years. This was not
to apply to Chinese who were already in the country, or who should
enter within ninety days after the passage of the act. Such persons,
who desired to leave the country and return, were required to secure
a certificate, which by an amendatory act of 1884 was made the sole
evidence of the right of a Chinaman to return. This act also required
a certificate of the exempt classes, to be issued by the Chinese
government or such other foreign governments as they might be
subject to. The deportation of Chinese unlawfully in the country was
also provided for by these acts.
These laws were in many respects carelessly drawn and extremely
difficult of execution. In their application they entailed great expense
upon the United States government, and worked extreme hardship
and injustice to many Chinese. They were, nevertheless, effective as
regards their main purpose, for the volume of Chinese immigration
at once diminished exceedingly. The strictness of the exclusion was
increased by the act of 1888, which refused return to any Chinese
laborer unless he had a lawful wife, child, or parent in the United
States, or owned property of the value of $1000 or had debts due him
of like amount. The acts in force were extended for another ten years
by the act of 1892, and again indefinitely in 1902, in each case with
relatively unimportant modifications in detail.
This history of Chinese immigration is not a matter in which the
citizen of the United States can take much pride. Race prejudice,
bigotry, ignorance, and political ambition have played a prominent
part in the agitation, and have been instrumental in securing much of
the legislation. The attitude and conduct of the United States
contrasts unfavorably with the position of China, which has been one
of patient, courteous, dignified, but emphatic protest, and
willingness to coöperate in securing reasonable and beneficial
regulation. The boycott of 1905 has been her principal active reprisal.
In spite of these facts, however, it would be rash to assert that the
exclusion of Chinese laborers, by whatever unfortunate means
accomplished, has not been of actual benefit to the United States.
The assertion that the failure of the Chinese to assimilate has been
due more to race prejudice and exclusiveness on the part of
Americans than to unwillingness to be Americanized on the part of
the Chinese, does not do away with the fact of nonassimilation. Until
Americans are willing to fraternize on terms of social equality with
members of any race, there is great danger to national institutions in
the presence of large numbers of that race within the country.[101]
And when we reflect how enormous Chinese immigration might
easily have become in these recent years of quick and easy
transportation, and excessive activity of steamship agents, contract
labor agents, and others of their kind, it is apparent that if free
immigration had been allowed to these people of a widely diverse
race, we might now be facing a Chinese problem in this country
second in gravity only to the negro question.[102]
By the end of this period the conditions of life in America had so
changed as to diminish the general feeling of complacency toward
unlimited immigration. There was in particular a growing opposition
to contract labor, and an increased demand for federal control of the
immigration situation, especially as all state laws in regard to the
regulation of foreign immigration had been declared
unconstitutional in 1876. There was a conviction in the minds of
some thinkers that the United States no longer stood in need of an
increased labor force. These views were clearly expressed in an
article by Mr. A. B. Mason, published in 1874. Some of his statements
have a new ring. “The conditions that have hitherto greatly favored
immigration no longer exist in their full force.” “The labour market,
especially for agricultural labour, is overstocked.” “The especial
disadvantages of American labour more than counterbalance its
especial advantages.” “English labour is in the main as well off as
American labour.”[103] It is evident that the time was at hand when
the competition of the foreigner in the American labor market could
no longer be regarded with equanimity.
This sentiment did not bear fruit, however, until the year 1882.
The only federal legislation bearing on immigration after the repeal
of the favorable contract labor law in 1868 up to this date, was the act
of March 3, 1875, prohibiting the importation or immigration into
the United States of women for the purpose of prostitution, and also
prohibiting the immigration of criminals, convicted of other than
political offenses. This law, while couched in general terms, was an
outcome of the anti-Chinese agitation, and was passed with this race
particularly in mind.
CHAPTER VI
MODERN PERIOD. FEDERAL LEGISLATION