source: CIVL/examples/amg/csr/csr_add_spec.c@ 1aaefd4

main test-branch
Last change on this file since 1aaefd4 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

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

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