default(none) Clause
10.2. default(none) Clause#
The following example distinguishes the variables that are affected by the default(none) clause from those that are not.
Beginning with OpenMP 4.0, variables with const-qualified type and no mutable member are no longer predetermined shared. Thus, these variables (variable c in the example) need to be explicitly listed in data-sharing attribute clauses when the default(none) clause is specified.
//%compiler: clang
//%cflags: -fopenmp
/*
* name: default_none.1
* type: C
*/
#include <omp.h>
int x, y, z[1000];
#pragma omp threadprivate(x)
void default_none(int a) {
const int c = 1;
int i = 0;
#pragma omp parallel default(none) private(a) shared(z, c)
{
int j = omp_get_num_threads();
/* O.K. - j is declared within parallel region */
a = z[j]; /* O.K. - a is listed in private clause */
/* - z is listed in shared clause */
x = c; /* O.K. - x is threadprivate */
/* - c has const-qualified type and
is listed in shared clause */
z[i] = y; /* Error - cannot reference i or y here */
#pragma omp for firstprivate(y)
/* Error - Cannot reference y in the firstprivate clause */
for (i=0; i<10 ; i++) {
z[i] = i; /* O.K. - i is the loop iteration variable */
}
z[i] = y; /* Error - cannot reference i or y here */
}
}
!!%compiler: gfortran
!!%cflags: -fopenmp
! name: default_none.1
! type: F-fixed
SUBROUTINE DEFAULT_NONE(A)
INCLUDE "omp_lib.h" ! or USE OMP_LIB
INTEGER A
INTEGER X, Y, Z(1000)
COMMON/BLOCKX/X
COMMON/BLOCKY/Y
COMMON/BLOCKZ/Z
!$OMP THREADPRIVATE(/BLOCKX/)
INTEGER I, J
i = 1
!$OMP PARALLEL DEFAULT(NONE) PRIVATE(A) SHARED(Z) PRIVATE(J)
J = OMP_GET_NUM_THREADS();
! O.K. - J is listed in PRIVATE clause
A = Z(J) ! O.K. - A is listed in PRIVATE clause
! - Z is listed in SHARED clause
X = 1 ! O.K. - X is THREADPRIVATE
Z(I) = Y ! Error - cannot reference I or Y here
!$OMP DO firstprivate(y)
! Error - Cannot reference y in the firstprivate clause
DO I = 1,10
Z(I) = I ! O.K. - I is the loop iteration variable
END DO
Z(I) = Y ! Error - cannot reference I or Y here
!$OMP END PARALLEL
END SUBROUTINE DEFAULT_NONE