source: CIVL/examples/omp/dataracebench-1.3.2/micro-benchmarks-fortran/DRB143-acquirerelease-orig-omp50-no.f95

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: 1.7 KB
Line 
1!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!!
2!!! Copyright (c) 2017-20, Lawrence Livermore National Security, LLC
3!!! and DataRaceBench project contributors. See the DataRaceBench/COPYRIGHT file for details.
4!!!
5!!! SPDX-License-Identifier: (BSD-3-Clause)
6!!!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~!!!
7
8!The below program will fail to order the write to x on thread 0 before the read from x on thread 1.
9!The implicit release flush on exit from the critical region will not synchronize with the acquire
10!flush that occurs on the atomic read operation performed by thread 1. This is because implicit
11!release flushes that occur on a given construct may only synchronize with implicit acquire flushes
12!on a compatible construct (and vice-versa) that internally makes use of the same synchronization
13!variable.
14!
15!Implicit flush must be used after critical construct to avoid data race.
16!No Data Race pair
17
18program DRB142_acquirerelease_orig_yes
19 use omp_lib
20 implicit none
21
22 integer :: x, y, thrd
23 integer :: tmp
24 x = 0
25
26 !$omp parallel num_threads(2) private(thrd) private(tmp)
27 thrd = omp_get_thread_num()
28 if (thrd == 0) then
29 !$omp critical
30 x = 10
31 !$omp end critical
32
33 !$omp flush(x)
34
35 !$omp atomic write
36 y = 1
37 !$omp end atomic
38 else
39 tmp = 0
40 do while(tmp == 0)
41 !$omp atomic read acquire ! or seq_cst
42 tmp = x
43 !$omp end atomic
44 end do
45 !$omp critical
46 print *, "x = ", x
47 !$omp end critical
48 end if
49 !$omp end parallel
50end program
Note: See TracBrowser for help on using the repository browser.