Placement of flush, barrier, taskwait and taskyield Directives
12.3. Placement of flush, barrier, taskwait and taskyield Directives#
The following example is non-conforming, because the flush, barrier, taskwait, and taskyield directives are stand-alone directives and cannot be the immediate substatement of an if statement.
//%compiler: clang
//%cflags: -fopenmp
/*
* name: standalone.1
* type: C
* version: omp_3.1
*/
void standalone_wrong()
{
int a = 1;
if (a != 0)
#pragma omp flush(a)
/* incorrect as flush cannot be immediate substatement
of if statement */
if (a != 0)
#pragma omp barrier
/* incorrect as barrier cannot be immediate substatement
of if statement */
if (a!=0)
#pragma omp taskyield
/* incorrect as taskyield cannot be immediate substatement of if statement
*/
if (a != 0)
#pragma omp taskwait
/* incorrect as taskwait cannot be immediate substatement
of if statement */
}
The following example is non-conforming, because the flush, barrier, taskwait, and taskyield directives are stand-alone directives and cannot be the action statement of an if statement or a labeled branch target.
!!%compiler: gfortran
!!%cflags: -fopenmp
! name: standalone.1
! type: F-free
! version: omp_3.1
SUBROUTINE STANDALONE_WRONG()
INTEGER A
A = 1
! the FLUSH directive must not be the action statement
! in an IF statement
IF (A .NE. 0) !$OMP FLUSH(A)
! the BARRIER directive must not be the action statement
! in an IF statement
IF (A .NE. 0) !$OMP BARRIER
! the TASKWAIT directive must not be the action statement
! in an IF statement
IF (A .NE. 0) !$OMP TASKWAIT
! the TASKYIELD directive must not be the action statement
! in an IF statement
IF (A .NE. 0) !$OMP TASKYIELD
GOTO 100
! the FLUSH directive must not be a labeled branch target
! statement
100 !$OMP FLUSH(A)
GOTO 200
! the BARRIER directive must not be a labeled branch target
! statement
200 !$OMP BARRIER
GOTO 300
! the TASKWAIT directive must not be a labeled branch target
! statement
300 !$OMP TASKWAIT
GOTO 400
! the TASKYIELD directive must not be a labeled branch target
! statement
400 !$OMP TASKYIELD
END SUBROUTINE
The following version of the above example is conforming because the flush, barrier, taskwait, and taskyield directives are enclosed in a compound statement.
//%compiler: clang
//%cflags: -fopenmp
/*
* name: standalone.2
* type: C
* version: omp_3.1
*/
void standalone_ok()
{
int a = 1;
#pragma omp parallel
{
if (a != 0) {
#pragma omp flush(a)
}
if (a != 0) {
#pragma omp barrier
}
if (a != 0) {
#pragma omp taskwait
}
if (a != 0) {
#pragma omp taskyield
}
}
}
The following example is conforming because the flush, barrier, taskwait, and taskyield directives are enclosed in an if construct or follow the labeled branch target.
!!%compiler: gfortran
!!%cflags: -fopenmp
! name: standalone.2
! type: F-free
! version: omp_3.1
SUBROUTINE STANDALONE_OK()
INTEGER A
A = 1
IF (A .NE. 0) THEN
!$OMP FLUSH(A)
ENDIF
IF (A .NE. 0) THEN
!$OMP BARRIER
ENDIF
IF (A .NE. 0) THEN
!$OMP TASKWAIT
ENDIF
IF (A .NE. 0) THEN
!$OMP TASKYIELD
ENDIF
GOTO 100
100 CONTINUE
!$OMP FLUSH(A)
GOTO 200
200 CONTINUE
!$OMP BARRIER
GOTO 300
300 CONTINUE
!$OMP TASKWAIT
GOTO 400
400 CONTINUE
!$OMP TASKYIELD
END SUBROUTINE