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