/[escript]/trunk/paso/src/SparseMatrix.c
ViewVC logotype

Contents of /trunk/paso/src/SparseMatrix.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1811 - (show annotations)
Thu Sep 25 23:11:13 2008 UTC (10 years, 9 months ago) by ksteube
File MIME type: text/plain
File size: 4579 byte(s)
Copyright updated in all files

1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2008 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
11 *
12 *******************************************************/
13
14
15 /**************************************************************/
16
17 /* Paso: SparseMatrix */
18
19 /**************************************************************/
20
21 /* Author: gross@access.edu.au */
22
23 /**************************************************************/
24
25 #include "Paso.h"
26 #include "SparseMatrix.h"
27 #include "TRILINOS.h"
28
29 /**************************************************************/
30
31 /* allocates a SparseMatrix of type type using the given matrix pattern
32 if type is UNKOWN CSR is used.
33 if CSC or CSC_BLK1 is used pattern has to give the CSC pattern.
34 if CSR or CSR_BLK1 is used pattern has to give the CSR pattern.
35 Values are initialized by zero. */
36
37 Paso_SparseMatrix* Paso_SparseMatrix_alloc(Paso_SparseMatrixType type,Paso_Pattern *pattern, int row_block_size, int col_block_size) {
38
39 double time0;
40 Paso_SparseMatrix*out=NULL;
41 Paso_SparseMatrixType pattern_format_out;
42
43 Paso_resetError();
44 time0=Paso_timer();
45 out=MEMALLOC(1,Paso_SparseMatrix);
46 if (! Paso_checkPtr(out)) {
47 out->pattern=NULL;
48 out->val=NULL;
49 out->reference_counter=1;
50 out->type=type;
51
52 pattern_format_out= (type & MATRIX_FORMAT_OFFSET1)? PATTERN_FORMAT_OFFSET1: PATTERN_FORMAT_DEFAULT;
53 /* ====== compressed sparse columns === */
54 if (type & MATRIX_FORMAT_CSC) {
55 if (type & MATRIX_FORMAT_SYM) {
56 Paso_setError(TYPE_ERROR,"Generation of matrix pattern for symmetric CSC is not implemented yet.");
57 return NULL;
58 } else {
59 if ((type & MATRIX_FORMAT_BLK1) || row_block_size!=col_block_size || col_block_size>3) {
60 out->pattern=Paso_Pattern_unrollBlocks(pattern,pattern_format_out,col_block_size,row_block_size);
61 out->row_block_size=1;
62 out->col_block_size=1;
63 } else {
64 out->pattern=Paso_Pattern_unrollBlocks(pattern,pattern_format_out,1,1);
65 out->row_block_size=row_block_size;
66 out->col_block_size=col_block_size;
67 }
68 out->numRows = out->pattern->numInput;
69 out->numCols = out->pattern->numOutput;
70 }
71 } else {
72 /* ====== compressed sparse row === */
73 if (type & MATRIX_FORMAT_SYM) {
74 Paso_setError(TYPE_ERROR,"Generation of matrix pattern for symmetric CSR is not implemented yet.");
75 return NULL;
76 } else {
77 if ((type & MATRIX_FORMAT_BLK1) || row_block_size!=col_block_size || col_block_size>3) {
78 out->pattern=Paso_Pattern_unrollBlocks(pattern,pattern_format_out,row_block_size,col_block_size);
79 out->row_block_size=1;
80 out->col_block_size=1;
81 } else {
82 out->pattern=Paso_Pattern_unrollBlocks(pattern,pattern_format_out,1,1);
83 out->row_block_size=row_block_size;
84 out->col_block_size=col_block_size;
85 }
86 out->numRows = out->pattern->numOutput;
87 out->numCols = out->pattern->numInput;
88 }
89 }
90 out->block_size=out->row_block_size*out->col_block_size;
91 out->len=(size_t)(out->pattern->len)*(size_t)(out->block_size);
92
93 out->val=MEMALLOC(out->len,double);
94 if (! Paso_checkPtr(out->val)) Paso_SparseMatrix_setValues(out,DBLE(0));
95 }
96 /* all done: */
97 if (! Paso_noError()) {
98 Paso_SparseMatrix_free(out);
99 return NULL;
100 } else {
101 #ifdef Paso_TRACE
102 printf("timing: system matrix %.4e sec\n",Paso_timer()-time0);
103 printf("Paso_SparseMatrix_alloc: %ld x %ld system matrix has been allocated.\n",(long)out->numRows,(long)out->numCols);
104 #endif
105 return out;
106 }
107 }
108
109 /* returns a reference to Paso_SparseMatrix in */
110
111 Paso_SparseMatrix* Paso_SparseMatrix_getReference(Paso_SparseMatrix* in) {
112 if (in!=NULL) ++(in->reference_counter);
113 return in;
114 }
115
116 /* deallocates a SparseMatrix: */
117
118 void Paso_SparseMatrix_free(Paso_SparseMatrix* in) {
119 if (in!=NULL) {
120 in->reference_counter--;
121 if (in->reference_counter<=0) {
122 Paso_Pattern_free(in->pattern);
123 MEMFREE(in->val);
124 MEMFREE(in);
125 #ifdef Paso_TRACE
126 printf("Paso_SparseMatrix_free: system matrix as been deallocated.\n");
127 #endif
128 }
129 }
130 }

  ViewVC Help
Powered by ViewVC 1.1.26