source: CIVL/examples/amg/csr/seq/csr_add_spec.c@ 2e3b9a2

1.23 2.0 acw/focus-triggers main test-branch
Last change on this file since 2e3b9a2 was 2e3b9a2, checked in by Wenhao Wu <wuwenhao@…>, 10 years ago

Add the specification and implementation version of csr matrix addition

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@3756 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 1.4 KB
Line 
1#include <stdlib.h>
2
3/* = = = = = = = = TASS I/O = = = = = = = = */
4#pragma TASS input {N==1}
5int N;
6#pragma TASS input {M==4}
7int M;
8
9#pragma TASS input
10double A0[N*M];
11#pragma TASS input
12double B0[N*M];
13#pragma TASS output
14double OUTS[N*M];
15
16/* = = = = = = = = Dense Matrix Def = = = = = = = = */
17struct DM_struct{
18 double * data;
19 int num_rows;
20 int num_cols;
21};
22
23typedef struct DM_struct DenseMatrix;
24
25DenseMatrix * dense_create(int n, int m) {
26 DenseMatrix * mat;
27
28 mat = (DenseMatrix *) malloc (sizeof(DenseMatrix));
29 mat->num_rows = n;
30 mat->num_cols = m;
31 mat->data = (double*) malloc(n*m*sizeof(double));
32
33 return mat;
34}
35
36DenseMatrix * dense_add(DenseMatrix * X, DenseMatrix * Y) {
37 int i;
38 int j;
39 int n;
40 int m;
41 DenseMatrix * R;
42
43 n = X->num_rows;
44 m = X->num_cols;
45 R = dense_create(n,m);
46
47addLoop:
48 for (i=0; i<n; i++)
49 for (j=0; j<m; j++)
50 R->data[i*m + j] = X->data[i*m + j] + Y->data[i*m + j];
51 return R;
52}
53
54void free_dense(DenseMatrix * matrix) {
55 free(matrix->data);
56 free(matrix);
57}
58
59int main() {
60 int i;
61 DenseMatrix * X;
62 DenseMatrix * Y;
63 DenseMatrix * Z;
64
65 X = dense_create(N,M);
66 Y = dense_create(N,M);
67 for (i=0; i<N*M; i++)
68 X->data[i] = A0[i];
69 for (i=0; i<N*M; i++)
70 Y->data[i] = B0[i];
71 Z = dense_add(X,Y);
72 for (i=0; i<N*M; i++)
73 OUTS[i] = Z->data[i];
74 free_dense(X);
75 free_dense(Y);
76 free_dense(Z);
77 return 0;
78}
Note: See TracBrowser for help on using the repository browser.