| 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 | !use of omp target + teams + distribute + parallel for. No data race pairs.
|
|---|
| 9 |
|
|---|
| 10 | program DRB097_target_teams_distribute_orig_no
|
|---|
| 11 | use omp_lib
|
|---|
| 12 | use ISO_C_Binding
|
|---|
| 13 | implicit none
|
|---|
| 14 | integer, parameter :: dp = kind(1.0d0)
|
|---|
| 15 | integer, parameter :: double_kind = c_double
|
|---|
| 16 | integer (kind=8) :: i, i2, len, l_limit, tmp
|
|---|
| 17 | real(dp) :: sum, sum2
|
|---|
| 18 | real(dp), dimension(:), allocatable :: a, b
|
|---|
| 19 |
|
|---|
| 20 | len = 2560
|
|---|
| 21 | sum = real(0.0,dp)
|
|---|
| 22 | sum2 = real(0.0,dp)
|
|---|
| 23 |
|
|---|
| 24 | allocate (a(len))
|
|---|
| 25 | allocate (b(len))
|
|---|
| 26 |
|
|---|
| 27 | do i = 1, len
|
|---|
| 28 | a(i) = real(i,dp)/real(2.0,dp)
|
|---|
| 29 | b(i) = real(i,dp)/real(3.0,dp)
|
|---|
| 30 | end do
|
|---|
| 31 |
|
|---|
| 32 | !$omp target map(to: a(0:len), b(0:len)) map(tofrom: sum)
|
|---|
| 33 | !$omp teams num_teams(10) thread_limit(256) reduction (+:sum)
|
|---|
| 34 | !$omp distribute
|
|---|
| 35 | do i2 = 1, len, 256
|
|---|
| 36 | !$omp parallel do reduction (+:sum)
|
|---|
| 37 | do i = i2+1, merge(i2+256,len,i2+256<len)
|
|---|
| 38 | sum = sum+a(i)*b(i)
|
|---|
| 39 | end do
|
|---|
| 40 | !$omp end parallel do
|
|---|
| 41 | end do
|
|---|
| 42 | !$omp end distribute
|
|---|
| 43 | !$omp end teams
|
|---|
| 44 | !$omp end target
|
|---|
| 45 |
|
|---|
| 46 | !$omp parallel do reduction (+:sum2)
|
|---|
| 47 | do i = 1, len
|
|---|
| 48 | sum2 = sum2+a(i)*b(i)
|
|---|
| 49 | end do
|
|---|
| 50 | !$omp end parallel do
|
|---|
| 51 |
|
|---|
| 52 | print*,'sum =',int(sum),'; sum2 =',int(sum2)
|
|---|
| 53 |
|
|---|
| 54 | deallocate(a,b)
|
|---|
| 55 | end program
|
|---|