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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1407 - (show annotations)
Mon Feb 4 06:45:48 2008 UTC (11 years, 6 months ago) by gross
File MIME type: text/plain
File size: 7997 byte(s)
new upwinding algorithm (still fails)
1
2 /* $Id$ */
3
4 /*******************************************************
5 *
6 * Copyright 2003-2007 by ACceSS MNRF
7 * Copyright 2007 by University of Queensland
8 *
9 * http://esscc.uq.edu.au
10 * Primary Business: Queensland, Australia
11 * Licensed under the Open Software License version 3.0
12 * http://www.opensource.org/licenses/osl-3.0.php
13 *
14 *******************************************************/
15
16 /**************************************************************/
17
18 /* Paso: SystemMatrix */
19
20 /**************************************************************/
21
22 /* Author: gross@access.edu.au */
23
24 /**************************************************************/
25
26 #include "SystemMatrix.h"
27
28 /**************************************************************/
29
30 /* allocates a SystemMatrix of type type using the given matrix pattern
31 if type is UNKOWN CSR is used.
32 if CSC or CSC_BLK1 is used pattern has to give the CSC pattern.
33 if CSR or CSR_BLK1 is used pattern has to give the CSR pattern.
34 Values are initialized by zero. */
35
36 Paso_SystemMatrix* Paso_SystemMatrix_alloc(Paso_SystemMatrixType type,Paso_SystemMatrixPattern *pattern, int row_block_size, int col_block_size) {
37
38 double time0;
39 Paso_SystemMatrix*out=NULL;
40 dim_t n_norm,i;
41 Paso_SystemMatrixType pattern_format_out;
42
43 Paso_resetError();
44 time0=Paso_timer();
45 out=MEMALLOC(1,Paso_SystemMatrix);
46 if (! Paso_checkPtr(out)) {
47 out->type=type;
48 out->pattern=NULL;
49 out->row_distribution=NULL;
50 out->col_distribution=NULL;
51 out->mpi_info=Paso_MPIInfo_getReference(pattern->mpi_info);
52 out->mainBlock=NULL;
53 out->coupleBlock=NULL;
54 out->normalizer_is_valid=FALSE;
55 out->normalizer=NULL;
56 out->solver_package=PASO_PASO;
57 out->solver=NULL;
58 out->trilinos_data=NULL;
59 out->reference_counter=1;
60
61 pattern_format_out= (type & MATRIX_FORMAT_OFFSET1)? PATTERN_FORMAT_OFFSET1: PATTERN_FORMAT_DEFAULT;
62 /* ====== compressed sparse columns === */
63 if (type & MATRIX_FORMAT_CSC) {
64 if (type & MATRIX_FORMAT_SYM) {
65 Paso_setError(TYPE_ERROR,"Generation of matrix pattern for symmetric CSC is not implemented yet.");
66 } else {
67 if ((type & MATRIX_FORMAT_BLK1) || row_block_size!=col_block_size || col_block_size>3) {
68 out->pattern=Paso_SystemMatrixPattern_unrollBlocks(pattern,pattern_format_out,col_block_size,row_block_size);
69 out->row_block_size=1;
70 out->col_block_size=1;
71 } else {
72 out->pattern=Paso_SystemMatrixPattern_unrollBlocks(pattern,pattern_format_out,1,1);
73 out->row_block_size=row_block_size;
74 out->col_block_size=col_block_size;
75 }
76 }
77 out->row_distribution=Paso_Distribution_getReference(out->pattern->input_distribution);
78 out->col_distribution=Paso_Distribution_getReference(out->pattern->output_distribution);
79 } else {
80 /* ====== compressed sparse row === */
81 if (type & MATRIX_FORMAT_SYM) {
82 Paso_setError(TYPE_ERROR,"Generation of matrix pattern for symmetric CSR is not implemented yet.");
83 } else {
84 if ((type & MATRIX_FORMAT_BLK1) || row_block_size!=col_block_size || col_block_size>3) {
85 out->pattern=Paso_SystemMatrixPattern_unrollBlocks(pattern,pattern_format_out,row_block_size,col_block_size);
86 out->row_block_size=1;
87 out->col_block_size=1;
88 } else {
89 out->pattern=Paso_SystemMatrixPattern_unrollBlocks(pattern,pattern_format_out,1,1);
90 out->row_block_size=row_block_size;
91 out->col_block_size=col_block_size;
92 }
93 }
94 out->row_distribution=Paso_Distribution_getReference(out->pattern->output_distribution);
95 out->col_distribution=Paso_Distribution_getReference(out->pattern->input_distribution);
96 }
97 out->logical_row_block_size=row_block_size;
98 out->logical_col_block_size=col_block_size;
99 out->logical_block_size=out->logical_row_block_size*out->logical_block_size;
100 out->block_size=out->row_block_size*out->col_block_size;
101 /* this should be bypassed if trilinos is used */
102 if (type & MATRIX_FORMAT_TRILINOS_CRS) {
103 #ifdef TRILINOS
104 out->trilinos_data=Paso_TRILINOS_alloc();
105 #endif
106 } else {
107 out->solver_package=PASO_PASO;
108 out->mainBlock=Paso_SparseMatrix_alloc(type,out->pattern->mainPattern,row_block_size,col_block_size);
109 out->coupleBlock=Paso_SparseMatrix_alloc(type,out->pattern->couplePattern,row_block_size,col_block_size);
110 /* allocate memory for matrix entries */
111 if (type & MATRIX_FORMAT_CSC) {
112 n_norm = out->mainBlock->numCols * out->col_block_size;
113 } else {
114 n_norm = out->mainBlock->numRows * out->row_block_size;
115 }
116 out->normalizer=MEMALLOC(n_norm,double);
117 out->normalizer_is_valid=FALSE;
118 if (! Paso_checkPtr(out->normalizer)) {
119 #pragma omp parallel for private(i) schedule(static)
120 for (i=0;i<n_norm;++i) out->normalizer[i]=0.;
121 }
122 }
123 }
124 /* all done: */
125 if (! Paso_noError()) {
126 Paso_SystemMatrix_free(out);
127 return NULL;
128 } else {
129 #ifdef Paso_TRACE
130 printf("timing: system matrix %.4e sec\n",Paso_timer()-time0);
131 printf("Paso_SystemMatrix_alloc: system matrix has been allocated.\n");
132 #endif
133 return out;
134 }
135 }
136
137 /* returns a reference to Paso_SystemMatrix in */
138
139 Paso_SystemMatrix* Paso_SystemMatrix_reference(Paso_SystemMatrix* in) {
140 if (in!=NULL) ++(in->reference_counter);
141 return NULL;
142 }
143
144 /* deallocates a SystemMatrix: */
145
146 void Paso_SystemMatrix_free(Paso_SystemMatrix* in) {
147 if (in!=NULL) {
148 in->reference_counter--;
149 if (in->reference_counter<=0) {
150 Paso_SystemMatrixPattern_free(in->pattern);
151 Paso_Distribution_free(in->row_distribution);
152 Paso_Distribution_free(in->col_distribution);
153 Paso_MPIInfo_free(in->mpi_info);
154 Paso_SparseMatrix_free(in->mainBlock);
155 Paso_SparseMatrix_free(in->coupleBlock);
156 MEMFREE(in->normalizer);
157 Paso_solve_free(in);
158 #ifdef TRILINOS
159 Paso_TRILINOS_free(in->trilinos_data);
160 #endif
161 MEMFREE(in);
162 #ifdef Paso_TRACE
163 printf("Paso_SystemMatrix_free: system matrix as been deallocated.\n");
164 #endif
165 }
166 }
167 }
168 void Paso_SystemMatrix_allocBuffer(Paso_SystemMatrix* A) {
169 if (! Paso_Coupler_bufferIsAllocated(A->pattern->coupler) ) {
170 Paso_Coupler_allocBuffer(A->pattern->coupler,A->col_block_size);
171 }
172 }
173 void Paso_SystemMatrix_freeBuffer(Paso_SystemMatrix* A) {
174 Paso_Coupler_freeBuffer(A->pattern->coupler);
175 }
176 void Paso_SystemMatrix_startCollect(Paso_SystemMatrix* A,const double* in)
177 {
178 Paso_Coupler_startCollect(A->pattern->coupler, in);
179 }
180 double* Paso_SystemMatrix_finishCollect(Paso_SystemMatrix* A)
181 {
182 Paso_Coupler_finishCollect(A->pattern->coupler);
183 return A->pattern->coupler->recv_buffer;
184 }
185
186 dim_t Paso_SystemMatrix_getTotalNumRows(const Paso_SystemMatrix* A){
187 return A->mainBlock->numRows * A->row_block_size;
188 }
189
190 dim_t Paso_SystemMatrix_getTotalNumCols(const Paso_SystemMatrix* A){
191 return A->mainBlock->numCols * A->col_block_size;
192 }
193 dim_t Paso_SystemMatrix_getGlobalNumRows(Paso_SystemMatrix* A) {
194 if (A->type & MATRIX_FORMAT_CSC) {
195 return Paso_Distribution_getGlobalNumComponents(A->pattern->input_distribution);
196 } else {
197 return Paso_Distribution_getGlobalNumComponents(A->pattern->output_distribution);
198 }
199 }
200 dim_t Paso_SystemMatrix_getGlobalNumCols(Paso_SystemMatrix* A) {
201 if (A->type & MATRIX_FORMAT_CSC) {
202 return Paso_Distribution_getGlobalNumComponents(A->pattern->output_distribution);
203 } else {
204 return Paso_Distribution_getGlobalNumComponents(A->pattern->input_distribution);
205 }
206
207 }
208 dim_t Paso_SystemMatrix_getNumOutput(Paso_SystemMatrix* A) {
209 return Paso_SystemMatrixPattern_getNumOutput(A->pattern);
210 }
211

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26