source: CIVL/examples/loop_invariants/Jans_example/invariant.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 100644
File size: 1.7 KB
Line 
1/* Simplified transformation example from Devito compiler.
2 */
3#include <stdio.h>
4#ifdef _CIVL
5#include <civlc.cvh>
6#endif
7
8#ifdef _CIVL
9$input int ni;
10$input int nj;
11$assume(ni>0);
12$assume(ni<10);
13$assume(nj>0);
14$assume(nj<10);
15$input double uin[ni][nj];
16#endif
17double u1[ni][nj];
18double u2[ni][nj];
19
20int main(int argc, char** argv) {
21 int i,j,ir,jr;
22
23 for(i=0;i<ni;i++) {
24 for(j=0;j<nj;j++) {
25 u1[i][j] = 0;
26 u2[i][j] = 0;
27 }
28 }
29
30 // straightforward loop nest
31 for(i=1;i<ni-1;i++) {
32 for(j=1;j<nj-1;j++) {
33 u1[i][j] = uin[i][j]*uin[i][j];
34 }
35 }
36
37 if (ni > 2) {
38 $assert(i == ni - 1);
39 if (nj > 2)
40 $assert(j == nj - 1);
41 else
42 $assert(j == 1);
43 } else {
44 $assert(i == 1);
45 $assert(j == nj);
46 }
47
48 // blocked loop nest
49 for(i=1;i<ni-2;i=i+2) {
50 for(j=1;j<nj-2;j=j+2) {
51 u2[i][j] = uin[i][j]*uin[i][j];
52 u2[i+1][j] = uin[i+1][j]*uin[i+1][j];
53 u2[i][j+1] = uin[i][j+1]*uin[i][j+1];
54 u2[i+1][j+1] = uin[i+1][j+1]*uin[i+1][j+1];
55 }
56 }
57 // remainder
58 if(i==ni-2) {
59 for(jr=1;jr<nj-1;jr++) {
60 u2[i][jr] = uin[i][jr]*uin[i][jr];
61 }
62 }
63 if(j==nj-2) {
64 for(ir=1;ir<ni-1;ir++) {
65 u2[ir][j] = uin[ir][j]*uin[ir][j];
66 }
67 }
68 if(i==ni-2 && j==nj-2) u2[i][j] = uin[i][j]*uin[i][j];
69
70
71 // print
72 printf("j = %d\n", j);
73 printf("uout1:%s","\n");
74 for(i=0;i<ni;i++) {
75 for(j=0;j<nj;j++) {
76 printf("%f ",u1[i][j]);
77 }
78 printf("\n");
79 }
80 printf("uout2:%s","\n");
81 for(i=0;i<ni;i++) {
82 for(j=0;j<nj;j++) {
83 printf("%f ",u2[i][j]);
84 }
85 printf("\n");
86 }
87
88 // assert equality of u1 and u2
89 for(i=0;i<ni;i++) {
90 for(j=0;j<nj;j++) {
91 $assert(u1[i][j] == u2[i][j]);
92 }
93 }
94}
Note: See TracBrowser for help on using the repository browser.