source: CIVL/examples/omp/dataracebench-1.3.2/micro-benchmarks/DRB052-indirectaccesssharebase-orig-no.c

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: 4.3 KB
RevLine 
[a1acb0c5]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
[e3f356c]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 */
52#ifndef N
53#define N 180
54#endif
55
[86ee0b6]56/*
57This example is to mimic a memory access pattern extracted from an LLNL proxy app.
58Two pointers have distance of 12.
59They are used as base addresses of two arrays, indexed through an index set.
60The index set has no two indices with distance of 12.
61So there is no loop carried dependence.
62*/
[a1acb0c5]63
64#include <assert.h>
65#include <stdio.h>
66#include <stdlib.h>
67
[e3f356c]68// #define N 180 // move above
[a1acb0c5]69int indexSet[N] = {
70521, 523, 525, 527, 529, 531,
71547, 549, 551, 553, 555, 557,
72573, 575, 577, 579, 581, 583,
73599, 601, 603, 605, 607, 609,
74625, 627, 629, 631, 633, 635,
75
76651, 653, 655, 657, 659, 661,
77859, 861, 863, 865, 867, 869,
78885, 887, 889, 891, 893, 895,
79911, 913, 915, 917, 919, 921,
80937, 939, 941, 943, 945, 947,
81
82963, 965, 967, 969, 971, 973,
83989, 991, 993, 995, 997, 999,
841197, 1199, 1201, 1203, 1205, 1207,
851223, 1225, 1227, 1229, 1231, 1233,
861249, 1251, 1253, 1255, 1257, 1259,
87
881275, 1277, 1279, 1281, 1283, 1285,
891301, 1303, 1305, 1307, 1309, 1311,
901327, 1329, 1331, 1333, 1335, 1337,
911535, 1537, 1539, 1541, 1543, 1545,
921561, 1563, 1565, 1567, 1569, 1571,
93
941587, 1589, 1591, 1593, 1595, 1597,
951613, 1615, 1617, 1619, 1621, 1623,
961639, 1641, 1643, 1645, 1647, 1649,
971665, 1667, 1669, 1671, 1673, 1675,
981873, 1875, 1877, 1879, 1881, 1883,
99
1001899, 1901, 1903, 1905, 1907, 1909,
1011925, 1927, 1929, 1931, 1933, 1935,
1021951, 1953, 1955, 1957, 1959, 1961,
1031977, 1979, 1981, 1983, 1985, 1987,
1042003, 2005, 2007, 2009, 2011, 2013};
105
106int main (int argc, char* argv[])
107{
108 double * base = (double*) malloc(sizeof(double)* (2013+12+1));
109 if (base == 0)
110 {
111 printf("Error, malloc() returns NULL. End execution. \n");
112 return 1;
113 }
114
115 double * xa1 = base;
[86ee0b6]116 double * xa2 = base + 12;
[a1acb0c5]117 int i;
118
[e3f356c]119 for (i =521; i<= indexSet[N-1]+12; ++i)
[a1acb0c5]120 {
121 base[i]=0.0;
122 }
123
124#pragma omp parallel for
125 for (i =0; i< N; ++i) // this level of loop has no loop carried dependence
126 {
127 int idx = indexSet[i];
128 xa1[idx]+= 1.0;
[86ee0b6]129 xa2[idx]+= 3.0;
[a1acb0c5]130 }
131
[86ee0b6]132 // verify the results, no overlapping of xa1 vs. xa2, no addition happens to the same element twice
[e3f356c]133 for (i =521; i<= indexSet[N-1]+12; ++i)
[a1acb0c5]134 {
[86ee0b6]135 //printf ("%f ", base[i]);
[a1acb0c5]136 assert (base[i]!=4.0);
137 }
138
139 free (base);
140 return 0;
141}
142
Note: See TracBrowser for help on using the repository browser.