source: CIVL/examples/omp/dataracebench-1.0.0/micro-benchmarks/restrictpointer2-orig-no.c@ 65582ca

1.23 2.0 main test-branch
Last change on this file since 65582ca 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: 3.0 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// A C99 restrict feature.
49// must use -std=c99
50
51#include <stdlib.h>
52#include <stdio.h>
53/*
54
55The restrict type qualifier is an indication to the compiler that,
56 if the memory addressed by the restrict -qualified pointer is modified, no other pointer will access that same memory.
57 If a particular chunk of memory is not modified, it can be aliased through more than one restricted pointer.
58
59*/
60void foo(int n, int * restrict a, int * restrict b, int * restrict c)
61{
62 int i;
63#pragma omp parallel for
64 for (i = 0; i < n; i++)
65 a[i] = b[i] + c[i];
66}
67
68int main()
69{
70 int n = 1000;
71 int * a , *b, *c;
72
73 a = (int*) malloc (n* sizeof (int));
74 if (a ==0)
75 {
76 fprintf (stderr, "skip the execution due to malloc failures.\n");
77 return 1;
78 }
79
80 b = (int*) malloc (n* sizeof (int));
81 if (b ==0)
82 {
83 fprintf (stderr, "skip the execution due to malloc failures.\n");
84 return 1;
85 }
86
87 c = (int*) malloc (n* sizeof (int));
88 if (c ==0)
89 {
90 fprintf (stderr, "skip the execution due to malloc failures.\n");
91 return 1;
92 }
93
94 foo (n, a, b,c);
95
96 free (a);
97 free (b);
98 free (c);
99 return 0;
100}
101
Note: See TracBrowser for help on using the repository browser.