| 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 | */
|
|---|
| 46 |
|
|---|
| 47 | /*
|
|---|
| 48 | This example is to mimic a memory access pattern extracted from an LLNL proxy app.
|
|---|
| 49 | Two pointers have distance of 12.
|
|---|
| 50 | They are used as base addresses of two arrays, indexed through an index set.
|
|---|
| 51 | The index set has no two indices with distance of 12.
|
|---|
| 52 | So there is no loop carried dependence.
|
|---|
| 53 | */
|
|---|
| 54 |
|
|---|
| 55 | #include <assert.h>
|
|---|
| 56 | #include <stdio.h>
|
|---|
| 57 | #include <stdlib.h>
|
|---|
| 58 |
|
|---|
| 59 | #define N 180
|
|---|
| 60 | int indexSet[N] = {
|
|---|
| 61 | 521, 523, 525, 527, 529, 531,
|
|---|
| 62 | 547, 549, 551, 553, 555, 557,
|
|---|
| 63 | 573, 575, 577, 579, 581, 583,
|
|---|
| 64 | 599, 601, 603, 605, 607, 609,
|
|---|
| 65 | 625, 627, 629, 631, 633, 635,
|
|---|
| 66 |
|
|---|
| 67 | 651, 653, 655, 657, 659, 661,
|
|---|
| 68 | 859, 861, 863, 865, 867, 869,
|
|---|
| 69 | 885, 887, 889, 891, 893, 895,
|
|---|
| 70 | 911, 913, 915, 917, 919, 921,
|
|---|
| 71 | 937, 939, 941, 943, 945, 947,
|
|---|
| 72 |
|
|---|
| 73 | 963, 965, 967, 969, 971, 973,
|
|---|
| 74 | 989, 991, 993, 995, 997, 999,
|
|---|
| 75 | 1197, 1199, 1201, 1203, 1205, 1207,
|
|---|
| 76 | 1223, 1225, 1227, 1229, 1231, 1233,
|
|---|
| 77 | 1249, 1251, 1253, 1255, 1257, 1259,
|
|---|
| 78 |
|
|---|
| 79 | 1275, 1277, 1279, 1281, 1283, 1285,
|
|---|
| 80 | 1301, 1303, 1305, 1307, 1309, 1311,
|
|---|
| 81 | 1327, 1329, 1331, 1333, 1335, 1337,
|
|---|
| 82 | 1535, 1537, 1539, 1541, 1543, 1545,
|
|---|
| 83 | 1561, 1563, 1565, 1567, 1569, 1571,
|
|---|
| 84 |
|
|---|
| 85 | 1587, 1589, 1591, 1593, 1595, 1597,
|
|---|
| 86 | 1613, 1615, 1617, 1619, 1621, 1623,
|
|---|
| 87 | 1639, 1641, 1643, 1645, 1647, 1649,
|
|---|
| 88 | 1665, 1667, 1669, 1671, 1673, 1675,
|
|---|
| 89 | 1873, 1875, 1877, 1879, 1881, 1883,
|
|---|
| 90 |
|
|---|
| 91 | 1899, 1901, 1903, 1905, 1907, 1909,
|
|---|
| 92 | 1925, 1927, 1929, 1931, 1933, 1935,
|
|---|
| 93 | 1951, 1953, 1955, 1957, 1959, 1961,
|
|---|
| 94 | 1977, 1979, 1981, 1983, 1985, 1987,
|
|---|
| 95 | 2003, 2005, 2007, 2009, 2011, 2013};
|
|---|
| 96 |
|
|---|
| 97 | int main (int argc, char* argv[])
|
|---|
| 98 | {
|
|---|
| 99 | double * base = (double*) malloc(sizeof(double)* (2013+12+1));
|
|---|
| 100 | if (base == 0)
|
|---|
| 101 | {
|
|---|
| 102 | printf("Error, malloc() returns NULL. End execution. \n");
|
|---|
| 103 | return 1;
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | double * xa1 = base;
|
|---|
| 107 | double * xa2 = base + 12;
|
|---|
| 108 | int i;
|
|---|
| 109 |
|
|---|
| 110 | for (i =521; i<= 2025; ++i)
|
|---|
| 111 | {
|
|---|
| 112 | base[i]=0.0;
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | #pragma omp parallel for
|
|---|
| 116 | for (i =0; i< N; ++i) // this level of loop has no loop carried dependence
|
|---|
| 117 | {
|
|---|
| 118 | int idx = indexSet[i];
|
|---|
| 119 | xa1[idx]+= 1.0;
|
|---|
| 120 | xa2[idx]+= 3.0;
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 | // verify the results, no overlapping of xa1 vs. xa2, no addition happens to the same element twice
|
|---|
| 124 | for (i =521; i<= 2025; ++i)
|
|---|
| 125 | {
|
|---|
| 126 | //printf ("%f ", base[i]);
|
|---|
| 127 | assert (base[i]!=4.0);
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | free (base);
|
|---|
| 131 | return 0;
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|