| 1 | subroutine single_loop(arr, n) |
| 2 | implicit none |
| 3 | integer, intent(inout) :: arr(:) |
| 4 | integer, intent(in) :: n |
| 5 | integer :: i |
| 6 | |
| 7 | do i = 1, n |
| 8 | arr(i) = arr(i) * 2 |
| 9 | end do |
| 10 | end subroutine single_loop |
| 11 | |
| 12 | subroutine single_loop_split_access(arr, n) |
| 13 | implicit none |
| 14 | integer, intent(inout) :: arr(:) |
| 15 | integer, intent(in) :: n |
| 16 | integer :: i, nhalf |
| 17 | nhalf = n/2 |
| 18 | do i = 1, nhalf |
| 19 | arr(2*i) = arr(2*i) * 2 |
| 20 | arr(2*i + 1) = arr(2*i + 1) * 2 |
| 21 | end do |
| 22 | end subroutine single_loop_split_access |
| 23 | |
| 24 | subroutine single_loop_arithmetic_operations_for_access(arr, n) |
| 25 | implicit none |
| 26 | integer, intent(inout) :: arr(:) |
| 27 | integer, intent(in) :: n |
| 28 | integer :: i |
| 29 | |
| 30 | do i = 1, n |
| 31 | arr(i*i) = arr(i + i) * 2 |
| 32 | end do |
| 33 | end subroutine single_loop_arithmetic_operations_for_access |
| 34 | |
| 35 | subroutine nested_loop_single_dimensions_access(arr, n) |
| 36 | implicit none |
| 37 | integer, intent(inout) :: arr(:) |
| 38 | integer, intent(in) :: n |
| 39 | integer :: i, j, nhalf |
| 40 | |
| 41 | nhalf = n/2 |
| 42 | do i = 1, nhalf |
| 43 | do j = 1, nhalf |
| 44 | arr(i + j) = arr(i + j) * 2 |
| 45 | end do |
| 46 | end do |
| 47 | end subroutine nested_loop_single_dimensions_access |
| 48 | |
| 49 | |
| 50 | |
| 51 | subroutine nested_loop_partially_used(arr, n) |
| 52 | implicit none |
| 53 | integer, intent(inout) :: arr(:) |
| 54 | integer, intent(in) :: n |
| 55 | integer :: i, j, nfourth |
| 56 | |
| 57 | nfourth = n / 4 |
| 58 | do i = 1, nfourth |
| 59 | do j = 1, nfourth |
| 60 | arr(i + j) = arr(i + j) * 2 |
| 61 | end do |
| 62 | end do |
| 63 | end subroutine nested_loop_partially_used |
| 64 | |
| 65 | |
| 66 | subroutine partially_used_array(arr, n) |
| 67 | implicit none |
| 68 | integer, intent(out) :: arr(:) |
| 69 | integer, intent(in) :: n |
| 70 | integer :: i = 1 , j = 3, nhalf |
| 71 | |
| 72 | nhalf = n/2 |
| 73 | arr(1) = 1 |
| 74 | do i = 2, nhalf |
| 75 | arr(i) = arr(i - 1) |
| 76 | end do |
| 77 | |
| 78 | j = arr(j) |
| 79 | end subroutine partially_used_array |