source: CIVL/examples/arithmetic/matmatBad.cvl@ 6a4e2e0

1.23 2.0 main test-branch
Last change on this file since 6a4e2e0 was 06b8536c, checked in by Stephen Siegel <siegel@…>, 13 years ago

Starting to clean up examples, but adding some extra versions of matmat as bug have been revealed.
Optimized somewhat evaluation of conditional (if then else) expressions, though I now feel this construct should be translated away.
Added a method to get the canonic ID of a state, minor changes.

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

  • Property mode set to 100644
File size: 1.7 KB
Line 
1/* matmat.cvl: two matrix-matrix multiplication algorithms.
2 * The first is the standard one, the second uses a complex
3 * tiling optimization. This model is used to determine
4 * whether the two are equivalent. Example:
5 * civl verify matmat.cvl -inputBOUND=4
6 * will verify equivalent for all matrix dimensions and tile
7 * sizes in the range 1..4.
8 */
9$input int BOUND;
10$input int L;
11$assume 1<=L && L<=BOUND;
12$input int M;
13$assume 1<=M && M<=BOUND;
14$input int N;
15$assume 1<=N && N<=BOUND;
16$input int TILE_SIZE;
17$assume 1<=TILE_SIZE && TILE_SIZE<=BOUND;
18$input double A[L][M];
19$input double B[M][N];
20double C[L][N]; // A*B computed by standard algorithm
21double D[L][N]; // A*B computed by tiled algorithm
22
23void spec() {
24 for (int i = 0; i < L; i++)
25 for (int j = 0; j < N; j++) {
26 C[i][j] = 0.0;
27 for (int k = 0; k < M; k++)
28 C[i][j] += A[i][k] * B[k][j];
29 }
30}
31
32void rowdist() {
33 int hi1, hi2, hi3;
34
35 for (int i = 0; i < L; i++) {
36 for (int j = 0; j < N; j++) {
37 D[i][j] = 0.0;
38 }
39 }
40
41 for (int ii = 0; ii < L; ii+=TILE_SIZE) {
42 for (int jj = 0; jj < N; jj+=TILE_SIZE) {
43 for (int kk = 0; kk < M; kk+=TILE_SIZE) {
44 hi1 = (ii + TILE_SIZE < L ? ii+TILE_SIZE : L);
45 for (int i = ii; i < hi1; i++) {
46 hi2 = (jj + TILE_SIZE < N ? jj + TILE_SIZE : N);
47 for (int j = jj; j < hi2; j++) {
48 hi3 = (kk + TILE_SIZE < M ? kk + TILE_SIZE : M);
49 for (int k = kk; k < hi1; k++) // oops, hi1->hi3
50 D[i][j] = D[i][j] + A[i][k] * B[k][j];
51 }
52 }
53 }
54 }
55 }
56}
57
58void main() {
59 spec();
60 rowdist();
61 for (int i = 0; i < L; i++) {
62 for (int j = 0; j < N; j++) {
63 $assert C[i][j] == D[i][j];
64 }
65 }
66}
Note: See TracBrowser for help on using the repository browser.