PandA-2024.02
syr2k.c
Go to the documentation of this file.
1 
10 /* syr2k.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 "syr2k.h"
22 
23 
24 /* Array initialization. */
25 static
26 void init_array(int n, int m,
27  DATA_TYPE *alpha,
28  DATA_TYPE *beta,
29  DATA_TYPE POLYBENCH_2D(C,N,N,n,n),
30  DATA_TYPE POLYBENCH_2D(A,N,M,n,m),
31  DATA_TYPE POLYBENCH_2D(B,N,M,n,m))
32 {
33  int i, j;
34 
35  *alpha = 1.5;
36  *beta = 1.2;
37  for (i = 0; i < n; i++)
38  for (j = 0; j < m; j++) {
39  A[i][j] = (DATA_TYPE) ((i*j+1)%n) / n;
40  B[i][j] = (DATA_TYPE) ((i*j+2)%m) / m;
41  }
42  for (i = 0; i < n; i++)
43  for (j = 0; j < n; j++) {
44  C[i][j] = (DATA_TYPE) ((i*j+3)%n) / m;
45  }
46 }
47 
48 
49 /* DCE code. Must scan the entire live-out data.
50  Can be used also to check the correctness of the output. */
51 static
52 void print_array(int n,
53  DATA_TYPE POLYBENCH_2D(C,N,N,n,n))
54 {
55  int i, j;
56 
59  for (i = 0; i < n; i++)
60  for (j = 0; j < n; j++) {
61  if ((i * n + j) % 20 == 0) fprintf (POLYBENCH_DUMP_TARGET, "\n");
63  }
64  POLYBENCH_DUMP_END("C");
66 }
67 
68 
69 /* Main computational kernel. The whole function will be timed,
70  including the call and return. */
71 __attribute__((noinline))
72 void kernel_syr2k(int n, int m,
73  DATA_TYPE alpha,
74  DATA_TYPE beta,
75  DATA_TYPE POLYBENCH_2D(C,N,N,n,n),
76  DATA_TYPE POLYBENCH_2D(A,N,M,n,m),
77  DATA_TYPE POLYBENCH_2D(B,N,M,n,m))
78 {
79  int i, j, k;
80 
81 //BLAS PARAMS
82 //UPLO = 'L'
83 //TRANS = 'N'
84 //A is NxM
85 //B is NxM
86 //C is NxN
87 #pragma scop
88  for (i = 0; i < _PB_N; i++) {
89  for (j = 0; j <= i; j++)
90  C[i][j] *= beta;
91  for (k = 0; k < _PB_M; k++)
92  for (j = 0; j <= i; j++)
93  {
94  C[i][j] += A[j][k]*alpha*B[i][k] + B[j][k]*alpha*A[i][k];
95  }
96  }
97 #pragma endscop
98 
99 }
100 
101 
102 int main(int argc, char** argv)
103 {
104  /* Retrieve problem size. */
105  int n = N;
106  int m = M;
107 
108  /* Variable declaration/allocation. */
109  DATA_TYPE alpha;
110  DATA_TYPE beta;
114 
115  /* Initialize array(s). */
116  init_array (n, m, &alpha, &beta,
119  POLYBENCH_ARRAY(B));
120 
121  /* Start timer. */
123 
124  /* Run kernel. */
125  kernel_syr2k (n, m,
126  alpha, beta,
129  POLYBENCH_ARRAY(B));
130 
131  /* Stop and print timer. */
134 
135  /* Prevent dead-code elimination. All live-out data must be printed
136  by the function call in argument. */
138 
139  /* Be clean. */
143 
144  return 0;
145 }
#define POLYBENCH_ARRAY(x)
Definition: polybench.h:84
#define POLYBENCH_DUMP_BEGIN(s)
Definition: polybench.h:167
static void init_array(int n, int m, DATA_TYPE *alpha, DATA_TYPE *beta, DATA_TYPE POLYBENCH_2D(C, N, N, n, n), DATA_TYPE POLYBENCH_2D(A, N, M, n, m), DATA_TYPE POLYBENCH_2D(B, N, M, n, m))
This version is stamped on May 10, 2016.
Definition: syr2k.c:26
#define C
Definition: generate.c:15
#define POLYBENCH_FREE_ARRAY(x)
Definition: polybench.h:88
static void print_array(int n, DATA_TYPE POLYBENCH_2D(C, N, N, n, n))
Definition: syr2k.c:52
#define POLYBENCH_2D(var, dim1, dim2, ddim1, ddim2)
Definition: polybench.h:98
int main(int argc, char **argv)
Definition: syr2k.c:102
#define A
Definition: generate.c:13
__attribute__((noinline))
Convert the given fixedpt number to a decimal string.
Definition: syr2k.c:71
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
#define M
Definition: gsm.c:30
#define POLYBENCH_DUMP_FINISH
Definition: polybench.h:166
#define _PB_N
Definition: correlation.h:49
#define B
Definition: generate.c:14
#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