source: CIVL/examples/omp/dataracebench-1.3.2/micro-benchmarks/DRB126-firstprivatesections-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.1 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 * This example is based on fpriv_sections.1.c OpenMP Examples 5.0.0
12 * The section construct modifies the value of section_count which breaks the independence of the
13 * section constructs. If the same thread executes both the section one will print 1 and the other
14 * will print 2. For a same thread execution, there is no data race.
15 */
16
17#include <omp.h>
18#include <stdio.h>
19
20int main(){
21 int section_count = 0;
22 omp_set_dynamic(0);
23
24 omp_set_num_threads(1);
25
26 #pragma omp parallel
27 #pragma omp sections firstprivate( section_count )
28 {
29 #pragma omp section
30 {
31 section_count++;
32 printf("%d\n",section_count);
33 }
34 #pragma omp section
35 {
36 section_count++;
37 printf("%d\n",section_count);
38 }
39 }
40 return 0;
41}
Note: See TracBrowser for help on using the repository browser.