| 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 | This file is part of DataRaceBench. For details, see
|
|---|
| 11 | https://github.com/LLNL/dataracebench. Please also see the LICENSE file
|
|---|
| 12 | for our additional BSD notice.
|
|---|
| 13 | Redistribution and use in source and binary forms, with
|
|---|
| 14 | or without modification, are permitted provided that the following
|
|---|
| 15 | conditions are met:
|
|---|
| 16 | * Redistributions of source code must retain the above copyright
|
|---|
| 17 | notice, this list of conditions and the disclaimer below.
|
|---|
| 18 | * Redistributions in binary form must reproduce the above copyright
|
|---|
| 19 | notice, this list of conditions and the disclaimer (as noted below)
|
|---|
| 20 | in the documentation and/or other materials provided with the
|
|---|
| 21 | distribution.
|
|---|
| 22 | * Neither the name of the LLNS/LLNL nor the names of its contributors
|
|---|
| 23 | may be used to endorse or promote products derived from this
|
|---|
| 24 | software without specific prior written permission.
|
|---|
| 25 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|---|
| 26 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|---|
| 27 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|---|
| 28 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|---|
| 29 | DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL
|
|---|
| 30 | SECURITY, LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE
|
|---|
| 31 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
|---|
| 32 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|---|
| 33 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 34 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|---|
| 35 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|---|
| 36 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
|---|
| 37 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|---|
| 38 | THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 39 | */
|
|---|
| 40 |
|
|---|
| 41 | /*
|
|---|
| 42 | A single directive is used to protect a write.
|
|---|
| 43 | */
|
|---|
| 44 | #include <stdio.h>
|
|---|
| 45 |
|
|---|
| 46 | int main()
|
|---|
| 47 | {
|
|---|
| 48 | int count=0;
|
|---|
| 49 |
|
|---|
| 50 | #pragma omp parallel shared(count)
|
|---|
| 51 | {
|
|---|
| 52 | #pragma omp single
|
|---|
| 53 | count += 1;
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | printf ("count= %d\n", count);
|
|---|
| 57 | return 0;
|
|---|
| 58 | }
|
|---|