PandA-2024.02
gramschmidt.c
Go to the documentation of this file.
1 
10 /* gramschmidt.c: this file is part of PolyBench/C */
11 
12 #include <stdio.h>
13 #include <unistd.h>
14 #include <string.h>
15 #include <math.h>
16 
17 /* Include polybench common header. */
18 #include <polybench.h>
19 
20 /* Include benchmark-specific header. */
21 #include "gramschmidt.h"
22 
23 
24 /* Array initialization. */
25 static
26 void init_array(int m, int n,
27  DATA_TYPE POLYBENCH_2D(A,M,N,m,n),
28  DATA_TYPE POLYBENCH_2D(R,N,N,n,n),
29  DATA_TYPE POLYBENCH_2D(Q,M,N,m,n))
30 {
31  int i, j;
32 
33  for (i = 0; i < m; i++)
34  for (j = 0; j < n; j++) {
35  A[i][j] = (((DATA_TYPE) ((i*j) % m) / m )*100) + 10;
36  Q[i][j] = 0.0;
37  }
38  for (i = 0; i < n; i++)
39  for (j = 0; j < n; j++)
40  R[i][j] = 0.0;
41 }
42 
43 
44 /* DCE code. Must scan the entire live-out data.
45  Can be used also to check the correctness of the output. */
46 static
47 void print_array(int m, int n,
48  DATA_TYPE POLYBENCH_2D(A,M,N,m,n),
49  DATA_TYPE POLYBENCH_2D(R,N,N,n,n),
50  DATA_TYPE POLYBENCH_2D(Q,M,N,m,n))
51 {
52  int i, j;
53 
56  for (i = 0; i < n; i++)
57  for (j = 0; j < n; j++) {
58  if ((i*n+j) % 20 == 0) fprintf (POLYBENCH_DUMP_TARGET, "\n");
60  }
61  POLYBENCH_DUMP_END("R");
62 
64  for (i = 0; i < m; i++)
65  for (j = 0; j < n; j++) {
66  if ((i*n+j) % 20 == 0) fprintf (POLYBENCH_DUMP_TARGET, "\n");
67  fprintf (POLYBENCH_DUMP_TARGET, DATA_PRINTF_MODIFIER, Q[i][j]);
68  }
69  POLYBENCH_DUMP_END("Q");
71 }
72 
73 
74 /* Main computational kernel. The whole function will be timed,
75  including the call and return. */
76 /* QR Decomposition with Modified Gram Schmidt:
77  http://www.inf.ethz.ch/personal/gander/ */
78 __attribute__((noinline))
79 void kernel_gramschmidt(int m, int n,
80  DATA_TYPE POLYBENCH_2D(A,M,N,m,n),
81  DATA_TYPE POLYBENCH_2D(R,N,N,n,n),
82  DATA_TYPE POLYBENCH_2D(Q,M,N,m,n))
83 {
84  int i, j, k;
85 
86  DATA_TYPE nrm;
87 
88 #pragma scop
89  for (k = 0; k < _PB_N; k++)
90  {
91  nrm = SCALAR_VAL(0.0);
92  for (i = 0; i < _PB_M; i++)
93  nrm += A[i][k] * A[i][k];
94  R[k][k] = SQRT_FUN(nrm);
95  for (i = 0; i < _PB_M; i++)
96  Q[i][k] = A[i][k] / R[k][k];
97  for (j = k + 1; j < _PB_N; j++)
98  {
99  R[k][j] = SCALAR_VAL(0.0);
100  for (i = 0; i < _PB_M; i++)
101  R[k][j] += Q[i][k] * A[i][j];
102  for (i = 0; i < _PB_M; i++)
103  A[i][j] = A[i][j] - Q[i][k] * R[k][j];
104  }
105  }
106 #pragma endscop
107 
108 }
109 
110 
111 int main(int argc, char** argv)
112 {
113  /* Retrieve problem size. */
114  int m = M;
115  int n = N;
116 
117  /* Variable declaration/allocation. */
121 
122  /* Initialize array(s). */
123  init_array (m, n,
126  POLYBENCH_ARRAY(Q));
127 
128  /* Start timer. */
130 
131  /* Run kernel. */
132  kernel_gramschmidt (m, n,
135  POLYBENCH_ARRAY(Q));
136 
137  /* Stop and print timer. */
140 
141  /* Prevent dead-code elimination. All live-out data must be printed
142  by the function call in argument. */
144 
145  /* Be clean. */
149 
150  return 0;
151 }
#define POLYBENCH_ARRAY(x)
Definition: polybench.h:84
#define POLYBENCH_DUMP_BEGIN(s)
Definition: polybench.h:167
#define R
Definition: mips.c:40
#define POLYBENCH_FREE_ARRAY(x)
Definition: polybench.h:88
#define POLYBENCH_2D(var, dim1, dim2, ddim1, ddim2)
Definition: polybench.h:98
#define A
Definition: generate.c:13
static const uint32_t k[]
Definition: sha-256.c:22
static void init_array(int m, int n, DATA_TYPE POLYBENCH_2D(A, M, N, m, n), DATA_TYPE POLYBENCH_2D(R, N, N, n, n), DATA_TYPE POLYBENCH_2D(Q, M, N, m, n))
This version is stamped on May 10, 2016.
Definition: gramschmidt.c:26
#define POLYBENCH_DUMP_START
Definition: polybench.h:165
#define _PB_M
Definition: correlation.h:48
#define N
Definition: dfdiv.c:60
#define POLYBENCH_2D_ARRAY_DECL(var, type, dim1, dim2, ddim1, ddim2)
Definition: polybench.h:131
#define DATA_PRINTF_MODIFIER
Definition: correlation.h:73
__attribute__((noinline))
Convert the given fixedpt number to a decimal string.
Definition: gramschmidt.c:78
#define polybench_prevent_dce(func)
Definition: polybench.h:170
#define SCALAR_VAL(x)
Definition: correlation.h:74
#define POLYBENCH_DUMP_TARGET
Definition: polybench.h:164
#define POLYBENCH_DUMP_END(s)
Definition: polybench.h:168
int main(int argc, char **argv)
Definition: gramschmidt.c:111
#define M
Definition: gsm.c:30
static void print_array(int m, int n, DATA_TYPE POLYBENCH_2D(A, M, N, m, n), DATA_TYPE POLYBENCH_2D(R, N, N, n, n), DATA_TYPE POLYBENCH_2D(Q, M, N, m, n))
Definition: gramschmidt.c:47
#define POLYBENCH_DUMP_FINISH
Definition: polybench.h:166
#define SQRT_FUN(x)
Definition: correlation.h:75
#define _PB_N
Definition: correlation.h:49
#define polybench_stop_instruments
Definition: polybench.h:177
#define polybench_print_instruments
Definition: polybench.h:178
#define polybench_start_instruments
Definition: polybench.h:176
#define DATA_TYPE
Definition: correlation.h:72

Generated on Mon Feb 12 2024 13:02:50 for PandA-2024.02 by doxygen 1.8.13