1.23
2.0
acw/focus-triggers
main
test-branch
| Line | |
|---|
| 1 | #include <stdlib.h>
|
|---|
| 2 |
|
|---|
| 3 | /* = = = = = = = = TASS I/O = = = = = = = = */
|
|---|
| 4 | #pragma TASS input {N==1}
|
|---|
| 5 | int N;
|
|---|
| 6 | #pragma TASS input {M==4}
|
|---|
| 7 | int M;
|
|---|
| 8 |
|
|---|
| 9 | #pragma TASS input
|
|---|
| 10 | double A0[N*M];
|
|---|
| 11 | #pragma TASS input
|
|---|
| 12 | double B0[N*M];
|
|---|
| 13 | #pragma TASS output
|
|---|
| 14 | double OUTS[N*M];
|
|---|
| 15 |
|
|---|
| 16 | /* = = = = = = = = Dense Matrix Def = = = = = = = = */
|
|---|
| 17 | struct DM_struct{
|
|---|
| 18 | double * data;
|
|---|
| 19 | int num_rows;
|
|---|
| 20 | int num_cols;
|
|---|
| 21 | };
|
|---|
| 22 |
|
|---|
| 23 | typedef struct DM_struct DenseMatrix;
|
|---|
| 24 |
|
|---|
| 25 | DenseMatrix * 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 |
|
|---|
| 36 | DenseMatrix * 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 |
|
|---|
| 47 | addLoop:
|
|---|
| 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 |
|
|---|
| 54 | void free_dense(DenseMatrix * matrix) {
|
|---|
| 55 | free(matrix->data);
|
|---|
| 56 | free(matrix);
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | int 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.