source: CIVL/examples/omp/dataracebench-1.0.0/micro-benchmarks/indirectaccess2-orig-yes.c@ bd6628e

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since bd6628e was a1acb0c5, checked in by Ziqing Luo <ziqing@…>, 9 years ago

Add the released version of DataRaceBench v1.0.0

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

  • Property mode set to 100644
File size: 4.4 KB
Line 
1/*
2Copyright (c) 2017, Lawrence Livermore National Security, LLC.
3Produced at the Lawrence Livermore National Laboratory
4Written by Chunhua Liao, Pei-Hung Lin, Joshua Asplund,
5Markus Schordan, and Ian Karlin
6(email: liao6@llnl.gov, lin32@llnl.gov, asplund1@llnl.gov,
7schordan1@llnl.gov, karlin1@llnl.gov)
8LLNL-CODE-732144
9All rights reserved.
10
11This file is part of DataRaceBench. For details, see
12https://github.com/LLNL/dataracebench. Please also see the LICENSE file
13for our additional BSD notice.
14
15Redistribution and use in source and binary forms, with
16or without modification, are permitted provided that the following
17conditions 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
31THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
32CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
33INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
34MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
35DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL
36SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE
37LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
38OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
39PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
40DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
41ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
43IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
44THE POSSIBILITY OF SUCH DAMAGE.
45*/
46
47
48// Two pointers have distance of 12 (p1 - p2 = 12).
49// They are used as base addresses for indirect array accesses using an index set (another array).
50//
51// An index set has two indices with distance of 12 :
52// indexSet[5]- indexSet[0] = 533 - 521 = 12
53// So there is loop carried dependence for N=0 and N=5.
54//
55// We use the default loop scheduling (static even) in OpenMP.
56// It is possible that two dependent iterations will be scheduled
57// within a same chunk to a same thread. So there is no runtime data races.
58//
59// N is 180, two iteraions with N=0 and N= 5 have loop carried dependences.
60// For static even scheduling, we must have at least 36 threads (180/36=5 iterations)
61// so iteration 0 and 5 will be scheduled to two different threads.
62//
63// Liao, 2/07/2017
64
65#include <assert.h>
66#include <stdio.h>
67#include <stdlib.h>
68
69#define N 180
70int indexSet[N] = {
71521, 523, 525, 527, 529, 533, // change 531 to 521+12=533
72547, 549, 551, 553, 555, 557,
73573, 575, 577, 579, 581, 583,
74599, 601, 603, 605, 607, 609,
75625, 627, 629, 631, 633, 635,
76
77651, 653, 655, 657, 659, 661,
78859, 861, 863, 865, 867, 869,
79885, 887, 889, 891, 893, 895,
80911, 913, 915, 917, 919, 921,
81937, 939, 941, 943, 945, 947,
82
83963, 965, 967, 969, 971, 973,
84989, 991, 993, 995, 997, 999,
851197, 1199, 1201, 1203, 1205, 1207,
861223, 1225, 1227, 1229, 1231, 1233,
871249, 1251, 1253, 1255, 1257, 1259,
88
891275, 1277, 1279, 1281, 1283, 1285,
901301, 1303, 1305, 1307, 1309, 1311,
911327, 1329, 1331, 1333, 1335, 1337,
921535, 1537, 1539, 1541, 1543, 1545,
931561, 1563, 1565, 1567, 1569, 1571,
94
951587, 1589, 1591, 1593, 1595, 1597,
961613, 1615, 1617, 1619, 1621, 1623,
971639, 1641, 1643, 1645, 1647, 1649,
981665, 1667, 1669, 1671, 1673, 1675,
991873, 1875, 1877, 1879, 1881, 1883,
100
1011899, 1901, 1903, 1905, 1907, 1909,
1021925, 1927, 1929, 1931, 1933, 1935,
1031951, 1953, 1955, 1957, 1959, 1961,
1041977, 1979, 1981, 1983, 1985, 1987,
1052003, 2005, 2007, 2009, 2011, 2013};
106
107int main (int argc, char* argv[])
108{
109 double * base = (double*) malloc(sizeof(double)* (2013+12+1));
110
111 if (base == 0)
112 {
113 printf ("Error in malloc(). Aborting ...\n");
114 return 1;
115 }
116
117 double * xa1 = base;
118 double * xa3 = xa1 + 12;
119 int i;
120
121 // initialize segments touched by indexSet
122 for (i =521; i<= 2025; ++i)
123 {
124 base[i]=0.5*i;
125 }
126
127#pragma omp parallel for // default static even scheduling may not trigger data race!
128 for (i =0; i< N; ++i)
129 {
130 int idx = indexSet[i];
131 xa1[idx]+= 1.0;
132 xa3[idx]+= 3.0;
133 }
134 printf("x1[999]=%f xa3[1285]=%f\n", xa1[999], xa3[1285]);
135 free (base);
136 return 0;
137}
138
Note: See TracBrowser for help on using the repository browser.