| 1 | !!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!!
|
|---|
| 2 | !!! Copyright (c) 2017-20, Lawrence Livermore National Security, LLC
|
|---|
| 3 | !!! and DataRaceBench project contributors. See the DataRaceBench/COPYRIGHT file for details.
|
|---|
| 4 | !!!
|
|---|
| 5 | !!! SPDX-License-Identifier: (BSD-3-Clause)
|
|---|
| 6 | !!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!!
|
|---|
| 7 |
|
|---|
| 8 | !The outmost loop is be parallelized.
|
|---|
| 9 | !But the inner level loop has out of bound access for b[i][j] when i equals to 1.
|
|---|
| 10 | !This will case memory access of a previous column's last element.
|
|---|
| 11 | !
|
|---|
| 12 | !For example, an array of 4x4:
|
|---|
| 13 | ! j=1 2 3 4
|
|---|
| 14 | ! i=1 x x x x
|
|---|
| 15 | ! 2 x x x x
|
|---|
| 16 | ! 3 x x x x
|
|---|
| 17 | ! 4 x x x x
|
|---|
| 18 | ! outer loop: j=3,
|
|---|
| 19 | ! inner loop: i=1
|
|---|
| 20 | ! array element accessed b[i-1][j] becomes b[0][3], which in turn is b[4][2]
|
|---|
| 21 | ! due to linearized column-major storage of the 2-D array.
|
|---|
| 22 | ! This causes loop-carried data dependence between j=2 and j=3.
|
|---|
| 23 | !
|
|---|
| 24 | !
|
|---|
| 25 | !Data race pair: b[i][j]@67 vs. b[i-1][j]@67
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 | program DRB015_outofbounds_var_yes
|
|---|
| 29 | use omp_lib
|
|---|
| 30 | implicit none
|
|---|
| 31 |
|
|---|
| 32 | integer :: i, j, n, m, len, argCount, allocStatus, rdErr, ix
|
|---|
| 33 | character(len=80), dimension(:), allocatable :: args
|
|---|
| 34 | real, dimension (:,:), allocatable :: b
|
|---|
| 35 | len = 100
|
|---|
| 36 |
|
|---|
| 37 | argCount = command_argument_count()
|
|---|
| 38 | if (argCount == 0) then
|
|---|
| 39 | write (*,'(a)') "No command line arguments provided."
|
|---|
| 40 | end if
|
|---|
| 41 |
|
|---|
| 42 | allocate(args(argCount), stat=allocStatus)
|
|---|
| 43 | if (allocStatus > 0) then
|
|---|
| 44 | write (*,'(a)') "Allocation error, program terminated."
|
|---|
| 45 | stop
|
|---|
| 46 | end if
|
|---|
| 47 |
|
|---|
| 48 | do ix = 1, argCount
|
|---|
| 49 | call get_command_argument(ix,args(ix))
|
|---|
| 50 | end do
|
|---|
| 51 |
|
|---|
| 52 | if (argCount >= 1) then
|
|---|
| 53 | read (args(1), '(i10)', iostat=rdErr) len
|
|---|
| 54 | if (rdErr /= 0 ) then
|
|---|
| 55 | write (*,'(a)') "Error, invalid integer value."
|
|---|
| 56 | end if
|
|---|
| 57 | end if
|
|---|
| 58 |
|
|---|
| 59 | n = len
|
|---|
| 60 | m = len
|
|---|
| 61 |
|
|---|
| 62 | allocate (b(n,m))
|
|---|
| 63 |
|
|---|
| 64 | !$omp parallel do private(i)
|
|---|
| 65 | do j = 2, n
|
|---|
| 66 | do i = 1, m
|
|---|
| 67 | b(i,j) = b(i-1,j)
|
|---|
| 68 | end do
|
|---|
| 69 | end do
|
|---|
| 70 | !$omp end parallel do
|
|---|
| 71 | print*,"b(50,50)=",b(50,50)
|
|---|
| 72 |
|
|---|
| 73 | deallocate(args,b)
|
|---|
| 74 | end program
|
|---|