aboutsummaryrefslogtreecommitdiffstats
path: root/benchmarks/polybench-syn/linear-algebra/blas/trmm.preproc.c
blob: 9b8edfe8e8d33cfc74bf666f668c37ecb3e4727c (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/**
 * 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
 */
/* trmm.c: this file is part of PolyBench/C */

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

/* Include polybench common header. */
#include<polybench.h>
# 1 "trmm.c"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 362 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "trmm.c" 2
# 1 "utilities/polybench.h" 1
# 30 "utilities/polybench.h"
# 1 "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/stdlib.h" 1 3 4
# 31 "utilities/polybench.h" 2
# 231 "utilities/polybench.h"
extern void* polybench_alloc_data(unsigned long long int n, int elt_size);
extern void polybench_free_data(void* ptr);




extern void polybench_flush_cache();
extern void polybench_prepare_instruments();
# 2 "trmm.c" 2


# 1 "./linear-algebra/blas/trmm/trmm.h" 1
# 5 "trmm.c" 2



static
void init_array(int m, int n,
  int *alpha,
  int A[ 20 + 0][20 + 0],
  int B[ 20 + 0][30 + 0])
{
  int i, j;

  *alpha = 1.5;
  for (i = 0; i < m; i++) {
    for (j = 0; j < i; j++) {
      A[i][j] = (int)((i+j) % m)/m;
    }
    A[i][i] = 1.0;
    for (j = 0; j < n; j++) {
      B[i][j] = (int)((n+(i-j)) % n)/n;
    }
 }

}




static
void print_array(int m, int n,
   int B[ 20 + 0][30 + 0])
{
  int i, j;

  fprintf(stderr, "==BEGIN DUMP_ARRAYS==\n");
  fprintf(stderr, "begin dump: %s", "B");
  for (i = 0; i < m; i++)
    for (j = 0; j < n; j++) {
 if ((i * m + j) % 20 == 0) fprintf (stderr, "\n");
 fprintf (stderr, "%d ", B[i][j]);
    }
  fprintf(stderr, "\nend   dump: %s\n", "B");
  fprintf(stderr, "==END   DUMP_ARRAYS==\n");
}




static
void kernel_trmm(int m, int n,
   int alpha,
   int A[ 20 + 0][20 + 0],
   int B[ 20 + 0][30 + 0])
{
  int i, j, k;
# 68 "trmm.c"
#pragma scop
 for (i = 0; i < m; i++)
     for (j = 0; j < n; j++) {
        for (k = i+1; k < m; k++)
           B[i][j] += A[k][i] * B[k][j];
        B[i][j] = alpha * B[i][j];
     }
#pragma endscop

}


int main(int argc, char** argv)
{

  int m = 20;
  int n = 30;


  int alpha;
  int (*A)[20 + 0][20 + 0]; A = (int(*)[20 + 0][20 + 0])polybench_alloc_data ((20 + 0) * (20 + 0), sizeof(int));;
  int (*B)[20 + 0][30 + 0]; B = (int(*)[20 + 0][30 + 0])polybench_alloc_data ((20 + 0) * (30 + 0), sizeof(int));;


  init_array (m, n, &alpha, *A, *B);


                             ;


  kernel_trmm (m, n, alpha, *A, *B);


                            ;
                             ;



  if (argc > 42 && ! strcmp(argv[0], "")) print_array(m, n, *B);


  free((void*)A);;
  free((void*)B);;

  return 0;
}