1.23
2.0
acw/focus-triggers
main
test-branch
| Line | |
|---|
| 1 |
|
|---|
| 2 | #include <stdlib.h>
|
|---|
| 3 |
|
|---|
| 4 | // Dense matrix spec...
|
|---|
| 5 |
|
|---|
| 6 | #pragma TASS input {N==3}
|
|---|
| 7 | int N;
|
|---|
| 8 | #pragma TASS input {M==3}
|
|---|
| 9 | int M;
|
|---|
| 10 |
|
|---|
| 11 | #pragma TASS input
|
|---|
| 12 | double A0[N*M];
|
|---|
| 13 | #pragma TASS input
|
|---|
| 14 | double B0[N*M];
|
|---|
| 15 | #pragma TASS output
|
|---|
| 16 | double C_OUT[N*M];
|
|---|
| 17 |
|
|---|
| 18 | /*
|
|---|
| 19 | struct DM_struct {
|
|---|
| 20 | double * data;
|
|---|
| 21 | int num_rows;
|
|---|
| 22 | int num_cols;
|
|---|
| 23 | };
|
|---|
| 24 | */
|
|---|
| 25 |
|
|---|
| 26 | typedef double DenseMatrix;
|
|---|
| 27 |
|
|---|
| 28 | //typedef struct DM_struct DenseMatrix;
|
|---|
| 29 | //typedef DenseMatrix * DM;
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 | double * dense_create(int n, int m) {
|
|---|
| 33 | double * mat;
|
|---|
| 34 |
|
|---|
| 35 | mat = (double*)malloc(n*m*sizeof(double));
|
|---|
| 36 | /*
|
|---|
| 37 | mat->num_rows = n;
|
|---|
| 38 | mat->num_cols = m;
|
|---|
| 39 | mat->data = (double*) malloc(n*m*sizeof(double));
|
|---|
| 40 | */
|
|---|
| 41 | return mat;
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 | DenseMatrix * dense_add(int n, int m, DenseMatrix *A, DenseMatrix *B) {
|
|---|
| 46 | int i;
|
|---|
| 47 | DenseMatrix * C;
|
|---|
| 48 |
|
|---|
| 49 | C = dense_create(n,m);
|
|---|
| 50 | for (i=0; i<n*m; i++)
|
|---|
| 51 | C[i] = A[i] + B[i];
|
|---|
| 52 | return C;
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | void free_dense(DenseMatrix *matrix) {
|
|---|
| 56 | //free(matrix->data);
|
|---|
| 57 | free(matrix);
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | int main() {
|
|---|
| 61 | int i;
|
|---|
| 62 | DenseMatrix * C;
|
|---|
| 63 |
|
|---|
| 64 | C = dense_add(N,M,&A0[0],&B0[0]);
|
|---|
| 65 | for (i=0; i<N*M; i++)
|
|---|
| 66 | C_OUT[i] = C[i];
|
|---|
| 67 | free_dense(C);
|
|---|
| 68 | return 0;
|
|---|
| 69 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.