Home

firstprivate

Firstprivate is a data-sharing clause in OpenMP used in parallel regions. It specifies that for each thread, there is a private copy of the listed variables, and that each private copy is initialized with the value that the corresponding variable had immediately before entering the parallel region.

For scalar variables, each thread’s private copy is initialized to the current value of that variable. For

Because the private copies are independent, updates performed inside the parallel region do not affect the

arrays,
each
thread
receives
its
own
private
array
whose
elements
are
initialized
from
the
corresponding
elements
of
the
original
array.
For
objects
of
a
class
type,
the
per-thread
copies
are
constructed
using
the
object’s
copy
constructor.
The
initialization
occurs
once
at
the
start
of
the
parallel
region;
after
that,
modifications
in
one
thread
affect
only
its
own
copy
and
do
not
change
the
original
variable.
original
variable
outside
the
region.
After
the
region
ends,
the
original
value
remains
unchanged
unless
the
program
assigns
to
it
through
other
means
or
uses
other
data-sharing
constructs
to
propagate
results.
Firstprivate
is
commonly
used
to
provide
each
thread
with
an
initial
value
that
should
be
preserved
for
the
duration
of
the
parallel
work
while
avoiding
data
races
on
subsequent
updates
to
that
same
variable.