| [a1acb0c5] | 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 |
|
|---|
| [86ee0b6] | 47 | /*
|
|---|
| 48 | This benchmark is extracted from flush_nolist.1c of OpenMP Application
|
|---|
| 49 | Programming Interface Examples Version 4.5.0 .
|
|---|
| 50 | We added one critical section to make it a test with only one pair of data races.
|
|---|
| 51 | The data race will not generate wrong result though. So the assertion always passes.
|
|---|
| 52 | Data race pair: i@70:10 vs. i@71:11
|
|---|
| 53 | */
|
|---|
| 54 | #include<stdio.h>
|
|---|
| 55 | #include<assert.h>
|
|---|
| [a1acb0c5] | 56 |
|
|---|
| [86ee0b6] | 57 | void f1(int *q)
|
|---|
| [a1acb0c5] | 58 | {
|
|---|
| [86ee0b6] | 59 | #pragma omp critical
|
|---|
| 60 | *q = 1;
|
|---|
| 61 | #pragma omp flush
|
|---|
| [a1acb0c5] | 62 | }
|
|---|
| 63 |
|
|---|
| 64 | int main()
|
|---|
| [86ee0b6] | 65 | {
|
|---|
| 66 | int i=0, sum=0;
|
|---|
| [a1acb0c5] | 67 |
|
|---|
| [86ee0b6] | 68 | #pragma omp parallel reduction(+:sum) num_threads(10)
|
|---|
| 69 | {
|
|---|
| 70 | f1(&i);
|
|---|
| 71 | sum+=i;
|
|---|
| 72 | }
|
|---|
| 73 | assert (sum==10);
|
|---|
| 74 | printf("sum=%d\n", sum);
|
|---|
| 75 | return 0;
|
|---|
| 76 | }
|
|---|