| 1 |
! REQUIRES: openmp_runtime |
| 2 |
|
| 3 |
! RUN: %python %S/../test_errors.py %s %flang %openmp_flags |
| 4 |
! OpenMP version 5.0.0 |
| 5 |
! 2.13.3 parallel sections Construct |
| 6 |
! The restrictions for the parallel construct and the sections construct apply |
| 7 |
program OmpConstructSections01 |
| 8 |
use omp_lib |
| 9 |
integer :: section_count = 0 |
| 10 |
integer, parameter :: NT = 4 |
| 11 |
integer :: i, array(10) |
| 12 |
type my_type |
| 13 |
integer :: array(10) |
| 14 |
end type my_type |
| 15 |
type(my_type) :: my_var |
| 16 |
print *, 'section_count', section_count |
| 17 |
do i = 1, 10 |
| 18 |
array(i) = i |
| 19 |
end do |
| 20 |
!ERROR: A variable that is part of another variable (as an array or structure element) cannot appear in a SHARED clause |
| 21 |
!$omp parallel sections shared(array(i)) |
| 22 |
!$omp end parallel sections |
| 23 |
!ERROR: A variable that is part of another variable (as an array or structure element) cannot appear in a SHARED clause |
| 24 |
!$omp parallel sections shared(my_var%array) |
| 25 |
!$omp end parallel sections |
| 26 |
|
| 27 |
!ERROR: invalid branch into an OpenMP structured block |
| 28 |
!ERROR: invalid branch into an OpenMP structured block |
| 29 |
!ERROR: invalid branch into an OpenMP structured block |
| 30 |
if (NT) 20, 30, 40 |
| 31 |
!ERROR: invalid branch into an OpenMP structured block |
| 32 |
goto 20 |
| 33 |
!ERROR: A variable that is part of another variable (as an array or structure element) cannot appear in a PRIVATE clause |
| 34 |
!$omp parallel sections private(my_var%array) |
| 35 |
!$omp section |
| 36 |
print *, "This is a single statement structured block" |
| 37 |
!$omp section |
| 38 |
open (10, file="random-file-name.txt", err=30) |
| 39 |
!ERROR: invalid branch into an OpenMP structured block |
| 40 |
!ERROR: invalid branch leaving an OpenMP structured block |
| 41 |
open (10, file="random-file-name.txt", err=40) |
| 42 |
!$omp section |
| 43 |
section_count = section_count + 1 |
| 44 |
20 print *, 'Entering into section' |
| 45 |
call calledFromWithinSection() |
| 46 |
print *, 'section_count', section_count |
| 47 |
!$omp section |
| 48 |
section_count = section_count + 1 |
| 49 |
print *, 'section_count', section_count |
| 50 |
!ERROR: invalid branch leaving an OpenMP structured block |
| 51 |
goto 10 |
| 52 |
!$omp section |
| 53 |
30 print *, "Error in opening file" |
| 54 |
!$omp end parallel sections |
| 55 |
10 print *, 'Jump from section' |
| 56 |
!ERROR: A variable that is part of another variable (as an array or structure element) cannot appear in a PRIVATE clause |
| 57 |
!$omp parallel sections private(array(i)) |
| 58 |
!$omp section |
| 59 |
40 print *, 'Error in opening file' |
| 60 |
!$omp end parallel sections |
| 61 |
end program OmpConstructSections01 |
| 62 |
|
| 63 |
function returnFromSections() |
| 64 |
!$omp parallel sections |
| 65 |
!$omp section |
| 66 |
!ERROR: RETURN statement is not allowed in a PARALLEL SECTIONS construct |
| 67 |
RETURN |
| 68 |
!$omp end parallel sections |
| 69 |
end function |
| 70 |
|
| 71 |
subroutine calledFromWithinSection() |
| 72 |
print *, "I am called from within a 'section' structured block" |
| 73 |
return |
| 74 |
end subroutine calledFromWithinSection |
| 75 |
|
| 76 |
subroutine continueWithinSections() |
| 77 |
integer i |
| 78 |
do i = 1, 10 |
| 79 |
print *, "Statement within loop but outside section construct" |
| 80 |
!$omp parallel sections |
| 81 |
!$omp section |
| 82 |
IF (i .EQ. 5) THEN |
| 83 |
!ERROR: CYCLE to construct outside of PARALLEL SECTIONS construct is not allowed |
| 84 |
CYCLE |
| 85 |
END IF |
| 86 |
!$omp end parallel sections |
| 87 |
print *, "Statement within loop but outside section contruct" |
| 88 |
end do |
| 89 |
|
| 90 |
!$omp parallel sections |
| 91 |
!$omp section |
| 92 |
do i = 1, 10 |
| 93 |
CYCLE |
| 94 |
end do |
| 95 |
!$omp end parallel sections |
| 96 |
|
| 97 |
!$omp parallel sections |
| 98 |
!$omp section |
| 99 |
loop_1: do i = 1, 10 |
| 100 |
IF (i .EQ. 5) THEN |
| 101 |
CYCLE loop_1 |
| 102 |
END IF |
| 103 |
end do loop_1 |
| 104 |
!$omp end parallel sections |
| 105 |
|
| 106 |
loop_2: do i = 1, 10 |
| 107 |
!$omp parallel sections |
| 108 |
!$omp section |
| 109 |
IF (i .EQ. 5) THEN |
| 110 |
!ERROR: CYCLE to construct 'loop_2' outside of PARALLEL SECTIONS construct is not allowed |
| 111 |
CYCLE loop_2 |
| 112 |
END IF |
| 113 |
!$omp end parallel sections |
| 114 |
end do loop_2 |
| 115 |
end subroutine continueWithinSections |
| 116 |
|
| 117 |
subroutine breakWithinSections() |
| 118 |
loop_3: do i = 1, 10 |
| 119 |
!$omp parallel sections |
| 120 |
!$omp section |
| 121 |
IF (i .EQ. 5) THEN |
| 122 |
!ERROR: EXIT to construct 'loop_3' outside of PARALLEL SECTIONS construct is not allowed |
| 123 |
EXIT loop_3 |
| 124 |
END IF |
| 125 |
!$omp end parallel sections |
| 126 |
end do loop_3 |
| 127 |
|
| 128 |
loop_4: do i = 1, 10 |
| 129 |
!$omp parallel sections |
| 130 |
!$omp section |
| 131 |
IF (i .EQ. 5) THEN |
| 132 |
!ERROR: EXIT to construct outside of PARALLEL SECTIONS construct is not allowed |
| 133 |
EXIT |
| 134 |
END IF |
| 135 |
!$omp end parallel sections |
| 136 |
end do loop_4 |
| 137 |
|
| 138 |
!$omp parallel sections |
| 139 |
!$omp section |
| 140 |
do i = 1, 10 |
| 141 |
IF (i .EQ. 5) THEN |
| 142 |
EXIT |
| 143 |
END IF |
| 144 |
end do |
| 145 |
!$omp end parallel sections |
| 146 |
|
| 147 |
!$omp parallel sections |
| 148 |
!$omp section |
| 149 |
loop_5: do i = 1, 10 |
| 150 |
IF (i .EQ. 5) THEN |
| 151 |
EXIT loop_5 |
| 152 |
END IF |
| 153 |
end do loop_5 |
| 154 |
!$omp end parallel sections |
| 155 |
end subroutine breakWithinSections |