PandA-2024.02
trisolv.c
Go to the documentation of this file.
1 
10 /* trisolv.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 "trisolv.h"
22 
23 
24 /* Array initialization. */
25 static
26 void init_array(int n,
27  DATA_TYPE POLYBENCH_2D(L,N,N,n,n),
30 {
31  int i, j;
32 
33  for (i = 0; i < n; i++)
34  {
35  x[i] = - 999;
36  b[i] = i ;
37  for (j = 0; j <= i; j++)
38  L[i][j] = (DATA_TYPE) (i+n-j+1)*2/n;
39  }
40 }
41 
42 
43 /* DCE code. Must scan the entire live-out data.
44  Can be used also to check the correctness of the output. */
45 static
46 void print_array(int n,
48 
49 {
50  int i;
51 
54  for (i = 0; i < n; i++) {
56  if (i % 20 == 0) fprintf (POLYBENCH_DUMP_TARGET, "\n");
57  }
58  POLYBENCH_DUMP_END("x");
60 }
61 
62 
63 /* Main computational kernel. The whole function will be timed,
64  including the call and return. */
65 __attribute__((noinline))
66 void kernel_trisolv(int n,
67  DATA_TYPE POLYBENCH_2D(L,N,N,n,n),
70 {
71  int i, j;
72 
73 #pragma scop
74  for (i = 0; i < _PB_N; i++)
75  {
76  x[i] = b[i];
77  for (j = 0; j <i; j++)
78  x[i] -= L[i][j] * x[j];
79  x[i] = x[i] / L[i][i];
80  }
81 #pragma endscop
82 
83 }
84 
85 
86 int main(int argc, char** argv)
87 {
88  /* Retrieve problem size. */
89  int n = N;
90 
91  /* Variable declaration/allocation. */
95 
96 
97  /* Initialize array(s). */
99 
100  /* Start timer. */
102 
103  /* Run kernel. */
104  kernel_trisolv (n, POLYBENCH_ARRAY(L), POLYBENCH_ARRAY(x), POLYBENCH_ARRAY(b));
105 
106  /* Stop and print timer. */
109 
110  /* Prevent dead-code elimination. All live-out data must be printed
111  by the function call in argument. */
113 
114  /* Be clean. */
118 
119  return 0;
120 }
#define POLYBENCH_ARRAY(x)
Definition: polybench.h:84
#define POLYBENCH_DUMP_BEGIN(s)
Definition: polybench.h:167
#define POLYBENCH_FREE_ARRAY(x)
Definition: polybench.h:88
#define POLYBENCH_2D(var, dim1, dim2, ddim1, ddim2)
Definition: polybench.h:98
int main(int argc, char **argv)
Definition: trisolv.c:86
__attribute__((noinline))
Convert the given fixedpt number to a decimal string.
Definition: trisolv.c:65
static void init_array(int n, DATA_TYPE POLYBENCH_2D(L, N, N, n, n), DATA_TYPE POLYBENCH_1D(x, N, n), DATA_TYPE POLYBENCH_1D(b, N, n))
This version is stamped on May 10, 2016.
Definition: trisolv.c:26
#define POLYBENCH_DUMP_START
Definition: polybench.h:165
#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
#define L
Definition: spmv.h:13
#define polybench_prevent_dce(func)
Definition: polybench.h:170
static void print_array(int n, DATA_TYPE POLYBENCH_1D(x, N, n))
Definition: trisolv.c:46
#define POLYBENCH_DUMP_TARGET
Definition: polybench.h:164
#define POLYBENCH_DUMP_END(s)
Definition: polybench.h:168
#define POLYBENCH_1D(var, dim1, ddim1)
Definition: polybench.h:97
#define POLYBENCH_DUMP_FINISH
Definition: polybench.h:166
x
Return the smallest n such that 2^n >= _x.
#define POLYBENCH_1D_ARRAY_DECL(var, type, dim1, ddim1)
Definition: polybench.h:128
#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