source: CIVL/examples/library/omp/reduction.cvl@ 5c27aa5

1.23 2.0 main test-branch
Last change on this file since 5c27aa5 was a7911c8, checked in by Manchun Zheng <zmanchun@…>, 12 years ago

fixed the "translation" problem of the reduction example; added note to omp library about the legal access of local/share view and status variables of shared variables.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@1595 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 910 bytes
Line 
1#include<civlc.cvh>
2#include<civlc-omp.cvh>
3#include<stdio.h>
4
5void main(){
6 int sum = 0;
7 $omp_gteam gteam = $omp_gteam_create($here, 3);
8 $omp_gshared gshared = $omp_gshared_create(gteam, &sum);
9
10 void thread(int tid) {
11 int sum_local;
12 int sum_status;
13 int private;
14 int _sum = 0;
15
16 $omp_team team = $omp_team_create($here, gteam, tid);
17 $omp_shared shared = $omp_shared_create(team, gshared, &sum_local, &sum_status);
18 printf("Hello from thread %d\n", tid);
19 //(reduction) sum = sum + tid;
20 _sum = _sum + tid+1;
21 $omp_apply_assoc(shared, _SUM, &_sum);
22 $omp_barrier_and_flush(team);
23 $omp_read(shared, &private, &sum_local);
24 $assert private == 6;
25 $omp_shared_destroy(shared);
26 $omp_team_destroy(team);
27 }
28
29 $parfor (int i: ($domain){ 0 .. 2 }) {
30 thread(i);
31 }
32 $assert sum == 6;
33 $omp_gshared_destroy(gshared);
34 $omp_gteam_destroy(gteam);
35}
Note: See TracBrowser for help on using the repository browser.