source: CIVL/examples/omp/dataracebench-1.3.2/micro-benchmarks/DRB167-taskdep4-orig-omp50-no.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.4 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. Therefore there is no race
14 * condition.
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 = y-x; //2nd child task
29
30 #pragma omp taskwait depend(in: x) // 1st taskwait
31
32 printf("x=%d\n",x);
33
34 #pragma omp taskwait // 2nd taskwait
35
36 printf("y=%d\n",y);
37}
38
39int main(){
40 #pragma omp parallel
41 #pragma omp single
42 foo();
43
44 return 0;
45}
46
Note: See TracBrowser for help on using the repository browser.