As I understand when declaring a variable of private type in OpenMP, it does not initialize, it simply makes the memory reservation and when it leaves the parallel scope, it recovers its initial value.
The doubt arises when implicitly said variable is shared. This will be shared by all its threads and when leaving the parallel scope, it continues having the value obtained in the nth iteration of the private sphere (due to lastPrivate).
Therefore, we can affirm that shared variables, unlike private variables, keep the value of their variables once the parallel execution scope ends and we turn to sequential execution?
I leave you an example in code of what was previously explained:
#include <omp.h>
#include <stdio.h>
#include <time.h>
int main(){
int iam, np, i, x;
x=1234;
#pragma omp parallel private(iam, np,i)
{
printf("Soy el thread %d, antes de actualizar, con x=%d \n",iam,x);
#pragma omp for lastprivate(x) schedule(dynamic)
for(i=0;i<11;i++)
{
x=iam*i;
printf("\tSoy el thread %d, actualizando en for, i=%d x=%d\n",iam,i,x);
}
printf("\t\tSoy el thread %d, despues de actualizar, con x=%d \n",iam,x);
}
printf("\n Despues de pragma parallel x=%d \n\n",x);
}