source: CIVL/examples/omp/dataracebench-1.3.2/micro-benchmarks-fortran/DRB118-nestlock-orig-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!This example is modified version of nestable_lock.1.c example, OpenMP 5.0 Application Programming Examples.
9!A nested lock can be locked several times. It doesn't unlock until you have unset it as many times as the
10!number of calls to omp_set_nest_lock.
11!incr_b is called at line 54 and line 59. So, it needs a nest_lock for p%b@35:5. No data race.
12
13module DRB118
14 use OMP_LIB, ONLY: OMP_NEST_LOCK_KIND
15 type pair
16 integer a
17 integer b
18 integer (OMP_NEST_LOCK_KIND) lck
19 end type
20end module
21
22subroutine incr_a(p, a)
23 use DRB118
24 type(pair) :: p
25 integer a
26 p%a = p%a + 1
27end subroutine
28
29subroutine incr_b(p, b)
30 use omp_lib
31 use DRB118
32 type(pair) :: p
33 integer b
34 call OMP_SET_NEST_LOCK(p%lck)
35 p%b = p%b + 1
36 call OMP_UNSET_NEST_LOCK(p%lck)
37end subroutine
38
39program DRB118_nestlock_orig_no
40 use omp_lib
41 use DRB118
42 implicit none
43
44 integer :: a, b
45
46 type(pair) :: p
47 p%a = 0
48 p%b = 0
49 call omp_init_nest_lock(p%lck);
50
51 !$omp parallel sections
52 !$omp section
53 call omp_set_nest_lock(p%lck)
54 call incr_b(p, a)
55 call incr_a(p, b)
56 call omp_unset_nest_lock(p%lck)
57
58 !$omp section
59 call incr_b(p, b);
60
61 !$omp end parallel sections
62
63 call omp_destroy_nest_lock(p%lck)
64
65 print*,p%b
66
67end program
Note: See TracBrowser for help on using the repository browser.