| 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 | /* NOTE by WenhaoWu (wuwenhao@udel.edu)
|
|---|
| 48 | * This example is modified so that the bound can be adjusted
|
|---|
| 49 | * by defining 'N' and if it isn't defined then the bound value
|
|---|
| 50 | * in the original example is used as the default value of 'N'
|
|---|
| 51 | * And both 'argc' and 'argv' are assumed by using '$assume',
|
|---|
| 52 | * which is included in <civlc.cvh>.
|
|---|
| 53 | */
|
|---|
| 54 | #ifndef N
|
|---|
| 55 | #define N 100
|
|---|
| 56 | #endif
|
|---|
| 57 | #ifdef _CIVL
|
|---|
| 58 | #include <civlc.cvh>
|
|---|
| 59 | #endif
|
|---|
| 60 |
|
|---|
| 61 | /*
|
|---|
| 62 | The outmost loop is be parallelized.
|
|---|
| 63 | But the inner level loop has out of bound access for b[i][j] when j equals to 0.
|
|---|
| 64 | This will case memory access of a previous row's last element.
|
|---|
| 65 |
|
|---|
| 66 | For example, an array of 4x4:
|
|---|
| 67 | j=0 1 2 3
|
|---|
| 68 | i=0 x x x x
|
|---|
| 69 | 1 x x x x
|
|---|
| 70 | 2 x x x x
|
|---|
| 71 | 3 x x x x
|
|---|
| 72 |
|
|---|
| 73 | outer loop: i=2,
|
|---|
| 74 | inner loop: j=0
|
|---|
| 75 | array element accessed b[i][j-1] becomes b[2][-1], which in turn is b[1][3]
|
|---|
| 76 | due to linearized row-major storage of the 2-D array.
|
|---|
| 77 |
|
|---|
| 78 | This causes loop-carried data dependence between i=2 and i=1.
|
|---|
| 79 | Data race pair: b[i][j]@100:7 vs. b[i][j-1]@100:15
|
|---|
| 80 | */
|
|---|
| 81 | #include <stdlib.h>
|
|---|
| 82 | int main(int argc, char* argv[])
|
|---|
| 83 | {
|
|---|
| 84 |
|
|---|
| 85 | #ifdef _CIVL
|
|---|
| 86 | $assume(argc == 2);
|
|---|
| 87 | $assume(atoi(argv[1]) == N);
|
|---|
| 88 | #endif
|
|---|
| 89 |
|
|---|
| 90 | int i,j;
|
|---|
| 91 | int len=100;
|
|---|
| 92 | if (argc>1)
|
|---|
| 93 | len = atoi(argv[1]);
|
|---|
| 94 |
|
|---|
| 95 | int n=len, m=len;
|
|---|
| 96 | double b[n][m];
|
|---|
| 97 | #pragma omp parallel for private(j)
|
|---|
| 98 | for (i=1;i<n;i++)
|
|---|
| 99 | for (j=0;j<m;j++) // Note there will be out of bound access
|
|---|
| 100 | b[i][j]=b[i][j-1];
|
|---|
| 101 |
|
|---|
| 102 | return 0;
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|