aboutsummaryrefslogtreecommitdiffstats
path: root/benchmarks/polybench-syn-div/linear-algebra/solvers/lu.c
blob: e0e8bfb48e3c83b02c1444cbf44e71136c3f0ee0 (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
106
107
108
109
110
111
112
113
114
115
116
/**
 * 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
 */
/* lu.c: this file is part of PolyBench/C */

//#include <stdio.h>
//#include <unistd.h>
//#include <string.h>
//#include <math.h>

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

#define plus(i) i = i + ONE

static
void init_array (int n,
   int A[40][40])
{
  int ONE = 1;
  int i, j;

  for (i = 0; i < n; plus(i))
    {
      for (j = 0; j <= i; plus(j))
 A[i][j] = (((-j) % n) / n) + ONE;
      for (j = i+1; j < n; plus(j)) {
 A[i][j] = 0;
      }
      A[i][i] = 1;
    }



  int r,s,t;
  int B[40][40]; // B = (int(*)[40 + 0][40 + 0])polybench_alloc_data ((40 + 0) * (40 + 0), sizeof(int));;
  for (r = 0; r < n; plus(r))
    for (s = 0; s < n; plus(s))
      B[r][s] = 0;
  for (t = 0; t < n; plus(t))
    for (r = 0; r < n; plus(r))
      for (s = 0; s < n; plus(s))
 B[r][s] += A[r][t] * A[s][t];
    for (r = 0; r < n; plus(r))
      for (s = 0; s < n; plus(s))
 A[r][s] = B[r][s];
  //free((void*)B);;

}

static
void kernel_lu(int n,
        int A[ 40][40])
{
  int i, j, k;
  int ONE = 1;

 for (i = 0; i < n; plus(i)) {
    for (j = 0; j <i; plus(j)) {
       for (k = 0; k < j; plus(k)) {
          A[i][j] -= A[i][k] * A[k][j];
       }
        A[i][j] = (A[i][j] / A[j][j]);
    }
   for (j = i; j < n; plus(j)) {
       for (k = 0; k < i; plus(k)) {
          A[i][j] -= A[i][k] * A[k][j];
       }
    }
  }
}

static
int check_array(int n,
   int A[40][40])
{
  int res = 0;
  int i, j;
  int ONE = 1;

  for (i = 0; i < n; plus(i))
    for (j = 0; j < n; plus(j)) 
      if(A[i][j] !=0) res = 1;
    #ifndef SYNTHESIS
    printf("finished: %u\n", res);
    #endif 

  return res;
}


int main()
{
  
  int n = 40;


  int A[40][40]; //A = (int(*)[40 + 0][40 + 0])polybench_alloc_data ((40 + 0) * (40 + 0), sizeof(int));;


  init_array (n, A);

  kernel_lu (n, A);

  return check_array(n, A);
  return 0;

  //free((void*)A);;
}