Is it correct apply firstprivate and lastprivate at the same variable?
For example:
void main (){
int a= 100, i;
#pragma omp for firstprivate(a) lastprivate(a)
for(i = 0; i <9; i++){
bla bla bla;
}
printf("a= %d",a);
}
Thank you!
As written in the OpenMP specification version 4.0, Section 2.14.3:
A list item that specifies a given variable may not appear in more than one clause on the same directive, except that a variable may be specified in both
firstprivate
andlastprivate
clauses.
It actually makes a lot of sense to allow for that. firstprivate
affects the value of the list variables on entry into the parallel region, while lastprivate
affects them on exit from the region. Both are non-conflicting and their combined use allows for certain variables to "propagate" through the region and get their values modified by the parallel code in the same way as in the sequential case. It mostly makes sense with parallel loops.