source: CIVL/examples/omp/dataracebench-1.3.2/micro-benchmarks/DRB134-taskdep5-orig-omp45-yes.c

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.5 KB
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/* The first two tasks are serialized, because a dependence on the first child is produced
11 * by x with the in dependence type in the depend clause of the second task. Generating task
12 * at the first taskwait only waits for the first child task to complete. The second taskwait
13 * guarantees completion of the second task before y is accessed. If we access y before the
14 * second taskwait, there is a race condition at line 28:2 and 34:18. Data Race Pair, y@28:2 and y@34:19
15 * */
16
17
18#include <stdio.h>
19#include <omp.h>
20
21void foo(){
22 int x = 0, y = 2;
23
24 #pragma omp task depend(inout: x) shared(x)
25 x++; // 1st child task
26
27 #pragma omp task depend(in: x) depend(inout: y) shared(x, y)
28 y -= x; //2nd child task
29
30 #pragma omp task depend(in: x) if(0) // 1st taskwait
31 {}
32
33 printf("x=%d\n",x);
34 printf("y=%d\n",y);
35
36 #pragma omp taskwait // 2nd taskwait
37
38}
39
40int main(){
41 #pragma omp parallel
42 #pragma omp single
43 foo();
44
45 return 0;
46}
47
Note: See TracBrowser for help on using the repository browser.