source: CIVL/examples/omp/dataracebench-1.3.2/micro-benchmarks-fortran/DRB019-plusplus-var-yes.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.9 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!Race condition on outLen due to unprotected writes.
9!Adding private (outLen) can avoid race condition. But it is wrong semantically.
10!
11!Data race pairs: we allow two pair to preserve the original code pattern.
12!1. outLen@60 vs. outLen@60
13!2. output[]@59 vs. output[]@59
14
15
16program DRB019_plusplus_var_yes
17 use omp_lib
18 implicit none
19
20 integer :: i, inLen, outLen, argCount, allocStatus, rdErr, ix
21 character(len=80), dimension(:), allocatable :: args
22 integer, dimension(:), allocatable :: input
23 integer, dimension(:), allocatable :: output
24
25 inLen = 1000
26 outLen = 1
27
28 argCount = command_argument_count()
29 if (argCount == 0) then
30 write (*,'(a)') "No command line arguments provided."
31 end if
32
33 allocate(args(argCount), stat=allocStatus)
34 if (allocStatus > 0) then
35 write (*,'(a)') "Allocation error, program terminated."
36 stop
37 end if
38
39 do ix = 1, argCount
40 call get_command_argument(ix,args(ix))
41 end do
42
43 if (argCount >= 1) then
44 read (args(1), '(i10)', iostat=rdErr) inLen
45 if (rdErr /= 0 ) then
46 write (*,'(a)') "Error, invalid integer value."
47 end if
48 end if
49
50 allocate (input(inLen))
51 allocate (output(inLen))
52
53 do i = 1, inLen
54 input(i) = i
55 end do
56
57 !$omp parallel do
58 do i = 1, inLen
59 output(outLen) = input(i)
60 outLen = outLen + 1
61 end do
62 !$omp end parallel do
63
64 print 100, output(0)
65 100 format ("output(0)=",i3)
66
67
68 deallocate(input,output,args)
69end program
Note: See TracBrowser for help on using the repository browser.