aboutsummaryrefslogtreecommitdiffstats
path: root/benchmarks/polybench-syn-div/linear-algebra/kernels/doitgen.c
blob: 6eaef562d195eed8d2851434ae9041236531eae0 (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/**
 * This version is stamped on May 10, 2016
 *
 * Contact:
 *   Louis-Noel Pouchet <pouchet.ohio-state.edu>
 *   Tomofumi Yuki <tomofumi.yuki.fr>
 *
 * Web address: http://polybench.sourceforge.net
 */
/* doitgen.c: this file is part of PolyBench/C */

#ifndef SYNTHESIS
 #include <stdio.h> 
#endif

#define plus(i) i = i + ONE
static
void init_array(int nr, int nq, int np,
  int A[ 10 + 0][8 + 0][12 + 0],
  int C4[ 12 + 0][12 + 0])
{
  int i, j, k;
  int ONE = 1;

  for (i = 0; i < nr; plus(i))
    for (j = 0; j < nq; plus(j))
      for (k = 0; k < np; plus(k))
 A[i][j][k] = (int) (((i*j + k) % np) / np);
  for (i = 0; i < np; plus(i))
    for (j = 0; j < np; plus(j))
      C4[i][j] = (int) (((i*j) % np) / np);
}


static
int print_array(int nr, int nq, int np,
   int A[ 10 + 0][8 + 0][12 + 0])
{
  int i, j, k;
  int ONE = 1;
  int res = 0;

  for (i = 0; i < nr; plus(i))
    for (j = 0; j < nq; plus(j))
      for (k = 0; k < np; plus(k)) {
      res ^= A[i][j][k];
      }
#ifndef SYNTHESIS
  printf("finished %u\n", res);
#endif
      return res;
}




void kernel_doitgen(int nr, int nq, int np,
      int A[ 10 + 0][8 + 0][12 + 0],
      int C4[ 12 + 0][12 + 0],
      int sum[ 12 + 0])
{
  int r, q, p, s;
  int ONE = 1;

 for (r = 0; r < nr; plus(r))
    for (q = 0; q < nq; plus(q)) {
      for (p = 0; p < np; plus(p)) {
 sum[p] = 0;
 for (s = 0; s < np; plus(s))
   sum[p] += A[r][q][s] * C4[s][p];
      }
      for (p = 0; p < np; plus(p))
 A[r][q][p] = sum[p];
    }

}


int main()
{

  int nr = 10;
  int nq = 8;
  int np = 12;


  int A[10 + 0][8 + 0][12 + 0]; 
  int sum[12 + 0]; 
  int C4[12 + 0][12 + 0]; 


  init_array (nr, nq, np,
       A,
       C4);


  kernel_doitgen (nr, nq, np,
    A,
    C4,
    sum);



  return print_array(nr, nq, np, A);
}