1.23
2.0
main
test-branch
| Line | |
|---|
| 1 | /*
|
|---|
| 2 | !!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!!
|
|---|
| 3 | !!! Copyright (c) 2017-20, Lawrence Livermore National Security, LLC
|
|---|
| 4 | !!! and DataRaceBench project contributors. See the DataRaceBench/COPYRIGHT file for details.
|
|---|
| 5 | !!!
|
|---|
| 6 | !!! SPDX-License-Identifier: (BSD-3-Clause)
|
|---|
| 7 | !!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!!
|
|---|
| 8 | */
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 | /* To avoid data race, the initialization of the original list item "a" should complete before any
|
|---|
| 12 | * update of a as a result of the reduction clause. This can be achieved by adding an explicit
|
|---|
| 13 | * barrier after the assignment a=0@26:5, or by enclosing the assignment a=0@26:5 in a single directive
|
|---|
| 14 | * or by initializing a@21:7 before the start of the parallel region.
|
|---|
| 15 | * */
|
|---|
| 16 |
|
|---|
| 17 | #include <stdio.h>
|
|---|
| 18 | #include <omp.h>
|
|---|
| 19 |
|
|---|
| 20 | int main(){
|
|---|
| 21 | int a, i;
|
|---|
| 22 |
|
|---|
| 23 | #pragma omp parallel shared(a) private(i)
|
|---|
| 24 | {
|
|---|
| 25 | #pragma omp master
|
|---|
| 26 | a = 0;
|
|---|
| 27 |
|
|---|
| 28 | #pragma omp barrier
|
|---|
| 29 |
|
|---|
| 30 | #pragma omp for reduction(+:a)
|
|---|
| 31 | for (i=0; i<10; i++){
|
|---|
| 32 | a += i;
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | #pragma omp single
|
|---|
| 36 | printf("Sum is %d\n", a);
|
|---|
| 37 | }
|
|---|
| 38 |
|
|---|
| 39 | return 0;
|
|---|
| 40 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.