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.9 KB
|
| Line | |
|---|
| 1 | #include <stdlib.h>
|
|---|
| 2 |
|
|---|
| 3 | /* = = = = = = = = TASS I/O = = = = = = = = */
|
|---|
| 4 | #pragma TASS input
|
|---|
| 5 | int N;
|
|---|
| 6 | #pragma TASS input
|
|---|
| 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 * hypre_CSRMatrixAdd(DenseMatrix * A, DenseMatrix * B) {
|
|---|
| 37 | int i;
|
|---|
| 38 | int j;
|
|---|
| 39 | int nr;
|
|---|
| 40 | int nc;
|
|---|
| 41 | double * A_data;
|
|---|
| 42 | double * B_data;
|
|---|
| 43 | double * C_data;
|
|---|
| 44 | DenseMatrix * C;
|
|---|
| 45 |
|
|---|
| 46 | nr = A->num_rows;
|
|---|
| 47 | nc = B->num_cols;
|
|---|
| 48 | A_data = A->data;
|
|---|
| 49 | B_data = B->data;
|
|---|
| 50 | C = dense_create(nr,nc);
|
|---|
| 51 | C_data = C->data;
|
|---|
| 52 |
|
|---|
| 53 | #pragma TASS joint invariant LoopCondEquiv 0 <= i && i < nr && 0 <= j && j < nc;
|
|---|
| 54 | #pragma TASS joint invariant LoopMatAEquiv true;
|
|---|
| 55 | #pragma TASS joint invariant LoopMatBEquiv true;
|
|---|
| 56 | #pragma TASS joint invariant LoopMatCEquiv true;
|
|---|
| 57 | #pragma TASS joint invariant LoopCorrect true;
|
|---|
| 58 | for (i=0; i<nr; i++)
|
|---|
| 59 | for (j=0; j<nc; j++)
|
|---|
| 60 | C_data[i*nc + j] = A_data[i*nc + j] +B_data[i*nc + j];
|
|---|
| 61 | return C;
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | void free_dense(DenseMatrix * matrix) {
|
|---|
| 65 | free(matrix->data);
|
|---|
| 66 | free(matrix);
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | int main() {
|
|---|
| 70 | int i;
|
|---|
| 71 | DenseMatrix * X;
|
|---|
| 72 | DenseMatrix * Y;
|
|---|
| 73 | DenseMatrix * Z;
|
|---|
| 74 |
|
|---|
| 75 | X = dense_create(N,M);
|
|---|
| 76 | Y = dense_create(N,M);
|
|---|
| 77 | for (i=0; i<N*M; i++)
|
|---|
| 78 | X->data[i] = A0[i];
|
|---|
| 79 | for (i=0; i<N*M; i++)
|
|---|
| 80 | Y->data[i] = B0[i];
|
|---|
| 81 | Z = hypre_CSRMatrixAdd(X,Y);
|
|---|
| 82 | for (i=0; i<N*M; i++)
|
|---|
| 83 | OUTS[i] = Z->data[i];
|
|---|
| 84 | free_dense(X);
|
|---|
| 85 | free_dense(Y);
|
|---|
| 86 | free_dense(Z);
|
|---|
| 87 | return 0;
|
|---|
| 88 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.