<s>
Loop-level	B-Operating_System
parallelism	I-Operating_System
is	O
a	O
form	O
of	O
parallelism	B-Operating_System
in	O
software	B-General_Concept
programming	I-General_Concept
that	O
is	O
concerned	O
with	O
extracting	O
parallel	O
tasks	O
from	O
loops	O
.	O
</s>
<s>
The	O
opportunity	O
for	O
loop-level	B-Operating_System
parallelism	I-Operating_System
often	O
arises	O
in	O
computing	O
programs	O
where	O
data	O
is	O
stored	O
in	O
random	B-General_Concept
access	I-General_Concept
data	B-General_Concept
structures	I-General_Concept
.	O
</s>
<s>
Where	O
a	O
sequential	O
program	O
will	O
iterate	O
over	O
the	O
data	B-General_Concept
structure	I-General_Concept
and	O
operate	O
on	O
indices	O
one	O
at	O
a	O
time	O
,	O
a	O
program	O
exploiting	O
loop-level	B-Operating_System
parallelism	I-Operating_System
will	O
use	O
multiple	O
threads	B-Operating_System
or	O
processes	B-Operating_System
which	O
operate	O
on	O
some	O
or	O
all	O
of	O
the	O
indices	O
at	O
the	O
same	O
time	O
.	O
</s>
<s>
Such	O
parallelism	B-Operating_System
provides	O
a	O
speedup	B-Operating_System
to	O
overall	O
execution	O
time	O
of	O
the	O
program	O
,	O
typically	O
in	O
line	O
with	O
Amdahl	B-Operating_System
's	I-Operating_System
law	I-Operating_System
.	O
</s>
<s>
For	O
simple	O
loops	O
,	O
where	O
each	O
iteration	O
is	O
independent	O
of	O
the	O
others	O
,	O
loop-level	B-Operating_System
parallelism	I-Operating_System
can	O
be	O
embarrassingly	B-Operating_System
parallel	I-Operating_System
,	O
as	O
parallelizing	O
only	O
requires	O
assigning	O
a	O
process	O
to	O
handle	O
each	O
iteration	O
.	O
</s>
<s>
However	O
,	O
many	O
algorithms	O
are	O
designed	O
to	O
run	O
sequentially	O
,	O
and	O
fail	O
when	O
parallel	O
processes	B-Operating_System
race	B-Operating_System
due	O
to	O
dependence	O
within	O
the	O
code	O
.	O
</s>
<s>
Synchronization	O
can	O
be	O
either	O
implicit	O
,	O
via	O
message	B-Application
passing	I-Application
,	O
or	O
explicit	O
,	O
via	O
synchronization	O
primitives	O
like	O
semaphores	B-Operating_System
.	O
</s>
<s>
Now	O
,	O
consider	O
a	O
system	O
with	O
p	O
processors	O
where	O
p	O
>	O
n	O
.	O
If	O
n	O
threads	B-Operating_System
run	O
in	O
parallel	O
,	O
the	O
time	O
to	O
execute	O
all	O
n	O
steps	O
is	O
reduced	O
to	O
T	O
.	O
</s>
<s>
non-serializable	B-Operating_System
outcomes	O
.	O
</s>
<s>
With	O
multiple	O
threads	B-Operating_System
,	O
process	O
scheduling	O
and	O
other	O
considerations	O
prevent	O
the	O
execution	O
order	O
from	O
guaranteeing	O
an	O
iteration	O
will	O
execute	O
only	O
after	O
its	O
dependence	O
is	O
met	O
.	O
</s>
<s>
Serializability	B-Operating_System
can	O
be	O
restored	O
by	O
adding	O
synchronization	O
to	O
preserve	O
the	O
dependence	O
on	O
previous	O
iterations	O
.	O
</s>
<s>
Each	O
implementation	O
varies	O
slightly	O
in	O
how	O
threads	B-Operating_System
synchronize	O
,	O
if	O
at	O
all	O
.	O
</s>
<s>
Each	O
concrete	O
loop-parallelization	O
below	O
implicitly	O
performs	O
them	O
.	O
</s>
<s>
Assignment	O
Tasks	O
are	O
assigned	O
to	O
processes	B-Operating_System
.	O
</s>
<s>
Orchestration	O
Data	O
access	O
,	O
communication	O
,	O
and	O
synchronization	O
of	O
processes	B-Operating_System
.	O
</s>
<s>
Mapping	O
Processes	B-Operating_System
are	O
bound	O
to	O
processors	O
.	O
</s>
<s>
Statements	O
that	O
are	O
not	O
dependent	O
on	O
each	O
other	O
are	O
separated	O
so	O
that	O
these	O
distributed	B-Operating_System
loops	O
can	O
be	O
executed	O
in	O
parallel	O
.	O
</s>
<s>
Instead	O
of	O
single	O
instruction	O
being	O
performed	O
in	O
parallel	O
on	O
different	O
data	O
as	O
in	O
data	B-Operating_System
level	I-Operating_System
parallelism	I-Operating_System
,	O
here	O
different	O
loops	O
perform	O
different	O
tasks	O
on	O
different	O
data	O
.	O
</s>
<s>
We	O
call	O
this	O
type	O
of	O
parallelism	B-Operating_System
either	O
function	O
or	O
task	B-Operating_System
parallelism	I-Operating_System
.	O
</s>
<s>
DOALL	O
parallelism	B-Operating_System
exists	O
when	O
statements	O
within	O
a	O
loop	O
can	O
be	O
executed	O
independently	O
(	O
situations	O
where	O
there	O
is	O
no	O
loop-carried	O
dependence	O
)	O
.	O
</s>
<s>
Let	O
's	O
say	O
the	O
time	O
of	O
one	O
execution	O
of	O
S1	O
be	O
then	O
the	O
execution	O
time	O
for	O
sequential	O
form	O
of	O
above	O
code	O
is	O
,	O
Now	O
because	O
DOALL	O
Parallelism	B-Operating_System
exists	O
when	O
all	O
iterations	O
are	O
independent	O
,	O
speed-up	O
may	O
be	O
achieved	O
by	O
executing	O
all	O
iterations	O
in	O
parallel	O
which	O
gives	O
us	O
an	O
execution	O
time	O
of	O
,	O
which	O
is	O
the	O
time	O
taken	O
for	O
one	O
iteration	O
in	O
sequential	O
execution	O
.	O
</s>
<s>
The	O
following	O
example	O
,	O
using	O
a	O
simplified	O
pseudo	O
code	O
,	O
shows	O
how	O
a	O
loop	O
might	O
be	O
parallelized	B-Operating_System
to	O
execute	O
each	O
iteration	O
independently	O
.	O
</s>
<s>
DOACROSS	O
Parallelism	B-Operating_System
exists	O
where	O
iterations	O
of	O
a	O
loop	O
are	O
parallelized	B-Operating_System
by	O
extracting	O
calculations	O
that	O
can	O
be	O
performed	O
independently	O
and	O
running	O
them	O
simultaneously	O
.	O
</s>
<s>
The	O
loop	O
can	O
then	O
be	O
parallelized	B-Operating_System
by	O
computing	O
the	O
temp	O
value	O
in	O
parallel	O
,	O
and	O
then	O
synchronizing	O
the	O
assignment	O
to	O
a[i]	O
.	O
</s>
<s>
Let	O
's	O
say	O
the	O
time	O
of	O
execution	O
of	O
S1	O
and	O
S2	O
be	O
and	O
then	O
the	O
execution	O
time	O
for	O
sequential	O
form	O
of	O
above	O
code	O
is	O
,	O
Now	O
because	O
DOACROSS	O
Parallelism	B-Operating_System
exists	O
,	O
speed-up	O
may	O
be	O
achieved	O
by	O
executing	O
iterations	O
in	O
a	O
pipelined	O
fashion	O
which	O
gives	O
us	O
an	O
execution	O
time	O
of	O
.	O
</s>
<s>
DOPIPE	O
Parallelism	B-Operating_System
implements	O
pipelined	O
parallelism	B-Operating_System
for	O
loop-carried	O
dependence	O
where	O
a	O
loop	O
iteration	O
is	O
distributed	B-Operating_System
over	O
multiple	O
,	O
synchronized	O
loops	O
.	O
</s>
<s>
S2	O
could	O
be	O
executed	O
in	O
parallel	O
using	O
DOALL	O
Parallelism	B-Operating_System
after	O
performing	O
all	O
calculations	O
needed	O
by	O
S1	O
in	O
series	O
.	O
</s>
<s>
However	O
,	O
the	O
speedup	B-Operating_System
is	O
limited	O
if	O
this	O
is	O
done	O
.	O
</s>
<s>
Implementing	O
pipelined	O
parallelism	B-Operating_System
results	O
in	O
the	O
following	O
set	O
of	O
loops	O
,	O
where	O
the	O
second	O
loop	O
may	O
execute	O
for	O
an	O
index	O
as	O
soon	O
as	O
the	O
first	O
loop	O
has	O
finished	O
its	O
corresponding	O
index	O
.	O
</s>
<s>
Let	O
's	O
say	O
the	O
time	O
of	O
execution	O
of	O
S1	O
and	O
S2	O
be	O
and	O
then	O
the	O
execution	O
time	O
for	O
sequential	O
form	O
of	O
above	O
code	O
is	O
,	O
Now	O
because	O
DOPIPE	O
Parallelism	B-Operating_System
exists	O
,	O
speed-up	O
may	O
be	O
achieved	O
by	O
executing	O
iterations	O
in	O
a	O
pipelined	O
fashion	O
which	O
gives	O
us	O
an	O
execution	O
time	O
of	O
,	O
where	O
is	O
the	O
number	O
of	O
processor	O
in	O
parallel	O
.	O
</s>
