summaryrefslogtreecommitdiffstats
path: root/polly/test/CodeGen/do_pluto_matmult.c
blob: d5509698e5b8b74526b5ed6294490478996699dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#define M 36
#define N 36
#define K 36
#define alpha 1
#define beta 1
double A[M][K+13];
double B[K][N+13];
double C[M][N+13];

#include <stdio.h>

void init_array()
{
  int i, j;

  for (i=0; i<N; i++) {
    for (j=0; j<N; j++) {
      A[i][j] = (i + j);
      // We do not want to optimize this.
      __sync_synchronize();
      B[i][j] = (double)(i*j);
      C[i][j] = 0.0;
    }
  }
}


void print_array()
{
  int i, j;

  for (i=0; i<N; i++) {
    for (j=0; j<N; j++) {
      fprintf(stdout, "%lf ", C[i][j]);
      if (j%80 == 79) fprintf(stdout, "\n");
    }
    fprintf(stdout, "\n");
  }
}


void do_pluto_matmult(void) {
  int i, j, k;

  __sync_synchronize();
  i = 0;
  do {
    j = 0;
    do {
      k = 0;
      do {
        C[i][j] = beta*C[i][j] + alpha*A[i][k] * B[k][j];
        ++k;
      } while (k < K);
      ++j;
    } while (j < N);
    ++i;
  } while (i < M);
  __sync_synchronize();
}

int main()
{
    register double s;

    init_array();

#pragma scop
    do_pluto_matmult();
#pragma endscop
    print_array();

  return 0;
}
OpenPOWER on IntegriCloud