PandA-2024.02
spmv_test.c
Go to the documentation of this file.
1 //http://www.cs.berkeley.edu/~mhoemmen/matrix-seminar/slides/UCB_sparse_tutorial_1.pdf
2 #include "spmv.h"
3 
4 #define ran (TYPE)(((double) rand() / (MAX)) * (MAX-MIN) + MIN)
5 
6 void fillVal(TYPE A[NNZ]){
7  int j;
8  srand48(8650341L);
9  for (j = 0; j < NNZ; j++){
10  A[j] = ran;
11  }
12 }
13 
14 void fill(TYPE x[N])
15 {
16  int j;
17  srand48(8650341L);
18  for (j = 0; j < N; j++)
19  {
20  x[j] = ran;
21  }
22 }
23 
24 void initMat(int colind[NNZ], int rowDelimiters[N + 1])
25 {
26  int nnzAssigned = 0;
27  float prob = (float)NNZ / ((float)N * (float)N);
28 
29  srand48(8675307L);
30  int fillRemaining = 0;
31  int i, j;
32  for (i = 0; i < N; i++)
33  {
34  rowDelimiters[i] = nnzAssigned;
35  for (j = 0; j < N; j++)
36  {
37  int numEntriesLeft = (N * N) - ((i * N) + j);
38  int needToAssign = NNZ - nnzAssigned;
39  if (numEntriesLeft <= needToAssign) {
40  fillRemaining = 1;
41  }
42  if ((nnzAssigned < NNZ && drand48() <= prob) || fillRemaining == 1)
43  {
44  colind[nnzAssigned] = j;
45  nnzAssigned++;
46  }
47  }
48  }
49  rowDelimiters[N] = NNZ;
50 }
51 
52 void initOut(TYPE y[N]){
53  int i;
54  for (i=0; i<N; i++){
55  y[i] = 0;
56  }
57 }
58 
59 int main(){
60  TYPE nzval[NNZ];
61  TYPE x[N];
62  TYPE y[N];
63  int colind[NNZ];
64  int rowptr[N+1];
65  int i;
66 
67  srand48(8650341L);
68 
69  fillVal(nzval);
70  fill(x);
71  initMat(colind, rowptr);
72  initOut(y);
73 
74  spmv(nzval, colind, rowptr, x, y);
75 
76  printf("\n");
77  for(i = 0; i < N; i++){
78  printf("%d ", y[i]);
79  }
80  printf("\n");
81 
82  return 0;
83 }
void spmv(TYPE val[NNZ], int32_t cols[NNZ], int32_t rowDelimiters[N+1], TYPE vec[N], TYPE out[N])
Definition: spmv.c:8
void fillVal(TYPE A[NNZ])
Definition: spmv_test.c:6
#define TYPE
Definition: backprop.h:21
#define A
Definition: generate.c:13
#define ran
Definition: spmv_test.c:4
#define NNZ
Definition: spmv.h:11
int main()
Definition: spmv_test.c:59
void initMat(int colind[NNZ], int rowDelimiters[N+1])
Definition: spmv_test.c:24
#define N
Definition: dfdiv.c:60
#define L
Definition: spmv.h:13
void initOut(TYPE y[N])
Definition: spmv_test.c:52
void fill(TYPE x[N])
Definition: spmv_test.c:14
x
Return the smallest n such that 2^n >= _x.

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