Yes, local variables are automatically private.
The reason for the existence of the private
clause is so that you don't have to change your code.
The only way to parallelize the following code without the private clause
int i,j;
#pragma omp parallel for private(j)
for(i = 0; i < n; i++) {
for(j = 0; j < n; j++) {
//do something
}
}
is to change the code. For example like this:
int i
#pragma omp parallel for
for(i = 0; i < n; i++) {
int j;
for(j = 0; j < n; j++) {
//do something
}
}
That's perfectly valid C89/C90 code but one of the goals of OpenMP is not have to change your code except to add pragma
statements which can be enabled or disabled at compile time.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…