source: CIVL/examples/omp/dataracebench-1.3.2/micro-benchmarks/DRB139-worksharingcritical-orig-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.2 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
11/*
12 * Referred from worksharing_critical.1.c
13 * A single thread executes the one and only section in the sections region, and executes the
14 * critical region. The same thread encounters the nested parallel region, creates a new team
15 * of threads, and becomes the master of the new team. One of the threads in the new team enters
16 * the single region and increments i by 1. At the end of this example i is equal to 2.
17*/
18
19
20#include <stdio.h>
21#include <omp.h>
22
23int main(){
24
25 int i = 1;
26
27 #pragma omp parallel sections
28 {
29 #pragma omp section
30 {
31 #pragma omp critical (name)
32 {
33 #pragma omp parallel
34 {
35 #pragma omp single
36 {
37 i++;
38 }
39 }
40 }
41 }
42 }
43
44 printf("%d\n",i);
45 return 0;
46}
Note: See TracBrowser for help on using the repository browser.