| [a1acb0c5] | 1 | /*
|
|---|
| 2 | Copyright (c) 2017, Lawrence Livermore National Security, LLC.
|
|---|
| 3 | Produced at the Lawrence Livermore National Laboratory
|
|---|
| 4 | Written by Chunhua Liao, Pei-Hung Lin, Joshua Asplund,
|
|---|
| 5 | Markus Schordan, and Ian Karlin
|
|---|
| 6 | (email: liao6@llnl.gov, lin32@llnl.gov, asplund1@llnl.gov,
|
|---|
| 7 | schordan1@llnl.gov, karlin1@llnl.gov)
|
|---|
| 8 | LLNL-CODE-732144
|
|---|
| 9 | All rights reserved.
|
|---|
| 10 |
|
|---|
| 11 | This file is part of DataRaceBench. For details, see
|
|---|
| 12 | https://github.com/LLNL/dataracebench. Please also see the LICENSE file
|
|---|
| 13 | for our additional BSD notice.
|
|---|
| 14 |
|
|---|
| 15 | Redistribution and use in source and binary forms, with
|
|---|
| 16 | or without modification, are permitted provided that the following
|
|---|
| 17 | conditions are met:
|
|---|
| 18 |
|
|---|
| 19 | * Redistributions of source code must retain the above copyright
|
|---|
| 20 | notice, this list of conditions and the disclaimer below.
|
|---|
| 21 |
|
|---|
| 22 | * Redistributions in binary form must reproduce the above copyright
|
|---|
| 23 | notice, this list of conditions and the disclaimer (as noted below)
|
|---|
| 24 | in the documentation and/or other materials provided with the
|
|---|
| 25 | distribution.
|
|---|
| 26 |
|
|---|
| 27 | * Neither the name of the LLNS/LLNL nor the names of its contributors
|
|---|
| 28 | may be used to endorse or promote products derived from this
|
|---|
| 29 | software without specific prior written permission.
|
|---|
| 30 |
|
|---|
| 31 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|---|
| 32 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|---|
| 33 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|---|
| 34 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|---|
| 35 | DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL
|
|---|
| 36 | SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE
|
|---|
| 37 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
|---|
| 38 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|---|
| 39 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 40 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|---|
| 41 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|---|
| 42 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
|---|
| 43 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|---|
| 44 | THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 45 | */
|
|---|
| [86ee0b6] | 46 | /*
|
|---|
| 47 | Two pointers have distance of 12 (p1 - p2 = 12).
|
|---|
| 48 | They are used as base addresses for indirect array accesses using an index set (another array).
|
|---|
| [a1acb0c5] | 49 |
|
|---|
| [86ee0b6] | 50 | An index set has two indices with distance of 12 :
|
|---|
| 51 | indexSet[3]- indexSet[0] = 533 - 521 = 12
|
|---|
| 52 | So there is loop carried dependence for N=0 and N=3.
|
|---|
| [a1acb0c5] | 53 |
|
|---|
| [86ee0b6] | 54 | We use the default loop scheduling (static even) in OpenMP.
|
|---|
| 55 | It is possible that two dependent iterations will be scheduled
|
|---|
| 56 | within a same chunk to a same thread. So there is no runtime data races.
|
|---|
| [a1acb0c5] | 57 |
|
|---|
| [86ee0b6] | 58 | N is 180, two iteraions with N=0 and N= 3 have loop carried dependences.
|
|---|
| 59 | For static even scheduling, we must have at least 60 threads (180/60=3 iterations)
|
|---|
| 60 | so iteration 0 and 3 will be scheduled to two different threads.
|
|---|
| 61 | Data race pair: xa1[idx]@136:5 vs. xa2[idx]@137:5
|
|---|
| 62 | */
|
|---|
| [a1acb0c5] | 63 | #include <assert.h>
|
|---|
| 64 | #include <stdio.h>
|
|---|
| 65 | #include <stdlib.h>
|
|---|
| 66 |
|
|---|
| [86ee0b6] | 67 | /* NOTE by WenhaoWu (wuwenhao@udel.edu)
|
|---|
| 68 | * This example is modified so that the bound can be adjusted
|
|---|
| 69 | * by defining 'N' and if it isn't defined then the bound value
|
|---|
| 70 | * in the original example is used as the default value of 'N'
|
|---|
| 71 | */
|
|---|
| 72 | #ifndef N
|
|---|
| [a1acb0c5] | 73 | #define N 180
|
|---|
| [86ee0b6] | 74 | #endif
|
|---|
| 75 |
|
|---|
| [a1acb0c5] | 76 | int indexSet[N] = {
|
|---|
| [86ee0b6] | 77 | 521, 523, 525, 533, 529, 531, // 521+12=533
|
|---|
| [a1acb0c5] | 78 | 547, 549, 551, 553, 555, 557,
|
|---|
| 79 | 573, 575, 577, 579, 581, 583,
|
|---|
| 80 | 599, 601, 603, 605, 607, 609,
|
|---|
| 81 | 625, 627, 629, 631, 633, 635,
|
|---|
| 82 |
|
|---|
| 83 | 651, 653, 655, 657, 659, 661,
|
|---|
| 84 | 859, 861, 863, 865, 867, 869,
|
|---|
| 85 | 885, 887, 889, 891, 893, 895,
|
|---|
| 86 | 911, 913, 915, 917, 919, 921,
|
|---|
| 87 | 937, 939, 941, 943, 945, 947,
|
|---|
| 88 |
|
|---|
| 89 | 963, 965, 967, 969, 971, 973,
|
|---|
| 90 | 989, 991, 993, 995, 997, 999,
|
|---|
| 91 | 1197, 1199, 1201, 1203, 1205, 1207,
|
|---|
| 92 | 1223, 1225, 1227, 1229, 1231, 1233,
|
|---|
| 93 | 1249, 1251, 1253, 1255, 1257, 1259,
|
|---|
| 94 |
|
|---|
| 95 | 1275, 1277, 1279, 1281, 1283, 1285,
|
|---|
| 96 | 1301, 1303, 1305, 1307, 1309, 1311,
|
|---|
| 97 | 1327, 1329, 1331, 1333, 1335, 1337,
|
|---|
| 98 | 1535, 1537, 1539, 1541, 1543, 1545,
|
|---|
| 99 | 1561, 1563, 1565, 1567, 1569, 1571,
|
|---|
| 100 |
|
|---|
| 101 | 1587, 1589, 1591, 1593, 1595, 1597,
|
|---|
| 102 | 1613, 1615, 1617, 1619, 1621, 1623,
|
|---|
| 103 | 1639, 1641, 1643, 1645, 1647, 1649,
|
|---|
| 104 | 1665, 1667, 1669, 1671, 1673, 1675,
|
|---|
| 105 | 1873, 1875, 1877, 1879, 1881, 1883,
|
|---|
| 106 |
|
|---|
| 107 | 1899, 1901, 1903, 1905, 1907, 1909,
|
|---|
| 108 | 1925, 1927, 1929, 1931, 1933, 1935,
|
|---|
| 109 | 1951, 1953, 1955, 1957, 1959, 1961,
|
|---|
| 110 | 1977, 1979, 1981, 1983, 1985, 1987,
|
|---|
| 111 | 2003, 2005, 2007, 2009, 2011, 2013};
|
|---|
| 112 |
|
|---|
| 113 | int main (int argc, char* argv[])
|
|---|
| 114 | {
|
|---|
| 115 | double * base = (double*) malloc(sizeof(double)* (2013+12+1));
|
|---|
| 116 | if (base == 0)
|
|---|
| 117 | {
|
|---|
| 118 | printf ("Error in malloc(). Aborting ...\n");
|
|---|
| 119 | return 1;
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | double * xa1 = base;
|
|---|
| [86ee0b6] | 123 | double * xa2 = xa1 + 12;
|
|---|
| [a1acb0c5] | 124 | int i;
|
|---|
| 125 |
|
|---|
| 126 | // initialize segments touched by indexSet
|
|---|
| 127 | for (i =521; i<= 2025; ++i)
|
|---|
| 128 | {
|
|---|
| 129 | base[i]=0.5*i;
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | #pragma omp parallel for // default static even scheduling may not trigger data race!
|
|---|
| 133 | for (i =0; i< N; ++i)
|
|---|
| 134 | {
|
|---|
| 135 | int idx = indexSet[i];
|
|---|
| 136 | xa1[idx]+= 1.0;
|
|---|
| [86ee0b6] | 137 | xa2[idx]+= 3.0;
|
|---|
| [a1acb0c5] | 138 | }
|
|---|
| [86ee0b6] | 139 | printf("x1[999]=%f xa2[1285]=%f\n", xa1[999], xa2[1285]);
|
|---|
| [a1acb0c5] | 140 | free (base);
|
|---|
| 141 | return 0;
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|