source: CIVL/examples/library/omp/for.cvl@ 4e86cdd

1.23 2.0 main test-branch
Last change on this file since 4e86cdd was 3ff27cf, checked in by Manchun Zheng <zmanchun@…>, 11 years ago

updated examples since $assert/$assume has been changed to functions; fixed the model builder for the new side-effect remover.

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

  • Property mode set to 100644
File size: 1.2 KB
Line 
1#include<civlc.cvh>
2#include<civl-omp.cvh>
3#include<stdio.h>
4
5#define N 6
6
7void main(){
8 int data[N];
9 $omp_gteam gteam = $omp_gteam_create($here, 3);
10 $omp_gshared gshared = $omp_gshared_create(gteam, &data);
11 $range range = 0 .. N-1 # 1;
12 $domain(1) loop_dom = ($domain) {range};
13
14 void thread(int tid) {
15 int data_local[N];
16 int data_status[N];
17 $omp_team team = $omp_team_create($here, gteam, tid);
18 $omp_shared shared = $omp_shared_create(team, gshared, &data_local, &data_status);
19 $domain(1) my_iters = ($domain(1))$omp_arrive_loop(team, 0, loop_dom, ROUND_ROBIN);
20
21 printf("Hello from thread %d\n", tid);
22 $for (int i : my_iters) {
23 switch (i) {
24 case 0: {
25 $omp_write(shared, &data_local[i], &tid);
26 break;
27 }
28 default: {
29 $omp_write(shared, &data_local[i], &tid);
30 }
31 } /* end of switch */
32 } /* end of $for loop */
33 $omp_barrier_and_flush(team);
34 $omp_shared_destroy(shared);
35 $omp_team_destroy(team);
36 }
37
38 $parfor (int i: ($domain){ 0 .. 2 }) {
39 thread(i);
40 }
41 for(int i = 0; i < N; i++){
42 $assert(i % 3 == data[i]);
43 //printf("*data*[%d] = %d", i, data[i]);
44 }
45 $omp_gshared_destroy(gshared);
46 $omp_gteam_destroy(gteam);
47}
Note: See TracBrowser for help on using the repository browser.