source: CIVL/examples/omp/dataracebench-1.3.2/micro-benchmarks-fortran/DRB006-indirectaccess2-orig-yes.f95

main
Last change on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100755
File size: 3.1 KB
Line 
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!Two pointers have a distance of 12 (p1 - p2 = 12).
9!They are used as base addresses for indirect array accesses using an index set (another array).
10!
11!The index set has two indices with a distance of 12 :
12!indexSet[5]- indexSet[0] = 533 - 521 = 12
13!So there is loop carried dependence (e.g. between loops with index values of 0 and 5).
14!
15!We use the default loop scheduling (static even) in OpenMP.
16!It is possible that two dependent iterations will be scheduled
17!within a same chunk to a same thread. So there is no runtime data races.
18!
19!When N is 180, two iterations with N=0 and N= 5 have loop carried dependences.
20!For static even scheduling, we must have at least 36 threads (180/36=5 iterations)
21!so iteration 0 and 5 will be scheduled to two different threads.
22!Data race pair: base[idx]@80:9 vs. base[idx]@81:9
23
24
25module DRB006
26 implicit none
27
28 integer, dimension(180) :: indexSet
29 integer :: n
30
31end module
32
33
34program DRB006_indirectaccess2_orig_yes
35 use omp_lib
36 use DRB006
37 implicit none
38
39 integer :: i, idx1, idx2
40 integer, parameter :: dp = kind(1.0d0)
41 real(dp), dimension(:), pointer :: xa1=>NULL(), xa2=>NULL()
42 real(dp), dimension(2025), target :: base
43
44 allocate (xa1(2025))
45 allocate (xa2(2025))
46
47 xa1 => base(1:2025)
48 xa2 => base(1:2025)
49
50 n=180
51
52 indexSet = (/ 521, 523, 525, 527, 529, 531, 547, 549, &
53 551, 553, 555, 557, 573, 575, 577, 579, 581, 583, 599, &
54 601, 603, 605, 607, 609, 625, 627, 629, 631, 633, 635, &
55 651, 653, 655, 657, 659, 661, 859, 861, 863, 865, 867, &
56 869, 885, 887, 889, 891, 893, 895, 911, 913, 915, 917, &
57 919, 921, 937, 939, 941, 943, 945, 947, 963, 965, 967, &
58 969, 971, 973, 989, 991, 993, 995, 997, 999, 1197, 1199, &
59 1201, 1203, 1205, 1207, 1223, 1225, 1227, 1229, 1231, &
60 1233, 1249, 1251, 1253, 1255, 1257, 1259, 1275, 1277, &
61 1279, 1281, 1283, 1285, 1301, 1303, 1305, 1307, 1309, &
62 1311, 1327, 1329, 1331, 1333, 1335, 1337, 1535, 1537, &
63 1539, 1541, 1543, 1545, 1561, 1563, 1565, 1567, 1569, &
64 1571, 1587, 1589, 1591, 1593, 1595, 1597, 1613, 1615, &
65 1617, 1619, 1621, 1623, 1639, 1641, 1643, 1645, 1647, &
66 1649, 1665, 1667, 1669, 1671, 1673, 1675, 1873, 1875, &
67 1877, 1879, 1881, 1883, 1899, 1901, 1903, 1905, 1907, &
68 1909, 1925, 1927, 1929, 1931, 1933, 1935, 1951, 1953, &
69 1955, 1957, 1959, 1961, 1977, 1979, 1981, 1983, 1985, &
70 1987, 2003, 2005, 2007, 2009, 2011, 2013 /)
71
72 do i = 521, 2025
73 base(i) = 0.5*i
74 end do
75
76 !$omp parallel do
77 do i = 1, n
78 idx1 = indexSet(i)
79 idx2 = indexSet(i)+12
80 base(idx1) = base(idx1)+1.0
81 base(idx2) = base(idx2)+3.0
82 end do
83 !$omp end parallel do
84
85 print*,'xa1(999) =',base(999),' xa2(1285) =',base(1285)
86
87 nullify(xa1,xa2)
88end program
Note: See TracBrowser for help on using the repository browser.