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

Contents of /trunk-mpi-branch/paso/src/SystemMatrix.c

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26