PandA-2024.02
symm.c
Go to the documentation of this file.
1 
10 /* symm.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 "symm.h"
22 
23 
24 /* Array initialization. */
25 static
26 void init_array(int m, int n,
27  DATA_TYPE *alpha,
28  DATA_TYPE *beta,
29  DATA_TYPE POLYBENCH_2D(C,M,N,m,n),
30  DATA_TYPE POLYBENCH_2D(A,M,M,m,m),
31  DATA_TYPE POLYBENCH_2D(B,M,N,m,n))
32 {
33  int i, j;
34 
35  *alpha = 1.5;
36  *beta = 1.2;
37  for (i = 0; i < m; i++)
38  for (j = 0; j < n; j++) {
39  C[i][j] = (DATA_TYPE) ((i+j) % 100) / m;
40  B[i][j] = (DATA_TYPE) ((n+i-j) % 100) / m;
41  }
42  for (i = 0; i < m; i++) {
43  for (j = 0; j <=i; j++)
44  A[i][j] = (DATA_TYPE) ((i+j) % 100) / m;
45  for (j = i+1; j < m; j++)
46  A[i][j] = -999; //regions of arrays that should not be used
47  }
48 }
49 
50 
51 /* DCE code. Must scan the entire live-out data.
52  Can be used also to check the correctness of the output. */
53 static
54 void print_array(int m, int n,
55  DATA_TYPE POLYBENCH_2D(C,M,N,m,n))
56 {
57  int i, j;
58 
61  for (i = 0; i < m; i++)
62  for (j = 0; j < n; j++) {
63  if ((i * m + j) % 20 == 0) fprintf (POLYBENCH_DUMP_TARGET, "\n");
65  }
66  POLYBENCH_DUMP_END("C");
68 }
69 
70 
71 /* Main computational kernel. The whole function will be timed,
72  including the call and return. */
73 __attribute__((noinline))
74 void kernel_symm(int m, int n,
75  DATA_TYPE alpha,
76  DATA_TYPE beta,
77  DATA_TYPE POLYBENCH_2D(C,M,N,m,n),
78  DATA_TYPE POLYBENCH_2D(A,M,M,m,m),
79  DATA_TYPE POLYBENCH_2D(B,M,N,m,n))
80 {
81  int i, j, k;
82  DATA_TYPE temp2;
83 
84 //BLAS PARAMS
85 //SIDE = 'L'
86 //UPLO = 'L'
87 // => Form C := alpha*A*B + beta*C
88 // A is MxM
89 // B is MxN
90 // C is MxN
91 //note that due to Fortran array layout, the code below more closely resembles upper triangular case in BLAS
92 #pragma scop
93  for (i = 0; i < _PB_M; i++)
94  for (j = 0; j < _PB_N; j++ )
95  {
96  temp2 = 0;
97  for (k = 0; k < i; k++) {
98  C[k][j] += alpha*B[i][j] * A[i][k];
99  temp2 += B[k][j] * A[i][k];
100  }
101  C[i][j] = beta * C[i][j] + alpha*B[i][j] * A[i][i] + alpha * temp2;
102  }
103 #pragma endscop
104 
105 }
106 
107 
108 int main(int argc, char** argv)
109 {
110  /* Retrieve problem size. */
111  int m = M;
112  int n = N;
113 
114  /* Variable declaration/allocation. */
115  DATA_TYPE alpha;
116  DATA_TYPE beta;
120 
121  /* Initialize array(s). */
122  init_array (m, n, &alpha, &beta,
125  POLYBENCH_ARRAY(B));
126 
127  /* Start timer. */
129 
130  /* Run kernel. */
131  kernel_symm (m, n,
132  alpha, beta,
135  POLYBENCH_ARRAY(B));
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 C
Definition: generate.c:15
#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
#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
#define polybench_prevent_dce(func)
Definition: polybench.h:170
#define POLYBENCH_DUMP_TARGET
Definition: polybench.h:164
#define POLYBENCH_DUMP_END(s)
Definition: polybench.h:168
static void init_array(int m, int n, DATA_TYPE *alpha, DATA_TYPE *beta, DATA_TYPE POLYBENCH_2D(C, M, N, m, n), DATA_TYPE POLYBENCH_2D(A, M, M, m, m), DATA_TYPE POLYBENCH_2D(B, M, N, m, n))
This version is stamped on May 10, 2016.
Definition: symm.c:26
#define M
Definition: gsm.c:30
int main(int argc, char **argv)
Definition: symm.c:108
#define POLYBENCH_DUMP_FINISH
Definition: polybench.h:166
static void print_array(int m, int n, DATA_TYPE POLYBENCH_2D(C, M, N, m, n))
Definition: symm.c:54
#define _PB_N
Definition: correlation.h:49
#define B
Definition: generate.c:14
__attribute__((noinline))
Convert the given fixedpt number to a decimal string.
Definition: symm.c:73
#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