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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1361 - (hide annotations)
Fri Dec 14 09:26:51 2007 UTC (11 years, 9 months ago) by gross
File MIME type: text/plain
File size: 7907 byte(s)
first steps towards a flux controlled transport solver.
1 ksteube 1312
2 jgs 150 /* $Id$ */
3    
4 ksteube 1312 /*******************************************************
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 dhawcroft 631
16 jgs 150 /**************************************************************/
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 gross 432
38 jgs 150 double time0;
39     Paso_SystemMatrix*out=NULL;
40 gross 1028 dim_t n_norm,i;
41 ksteube 1312 Paso_SystemMatrixType pattern_format_out;
42 gross 1028
43 jgs 150 Paso_resetError();
44     time0=Paso_timer();
45     out=MEMALLOC(1,Paso_SystemMatrix);
46     if (! Paso_checkPtr(out)) {
47 ksteube 1312 out->type=type;
48 jgs 150 out->pattern=NULL;
49 ksteube 1312 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 gross 425 out->solver_package=PASO_PASO;
57     out->solver=NULL;
58 ksteube 1312 out->trilinos_data=NULL;
59 jgs 150 out->reference_counter=1;
60 ksteube 1312
61     pattern_format_out= (type & MATRIX_FORMAT_OFFSET1)? PATTERN_FORMAT_OFFSET1: PATTERN_FORMAT_DEFAULT;
62     /* ====== compressed sparse columns === */
63 gross 415 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 gross 425 if ((type & MATRIX_FORMAT_BLK1) || row_block_size!=col_block_size || col_block_size>3) {
68 ksteube 1312 out->pattern=Paso_SystemMatrixPattern_unrollBlocks(pattern,pattern_format_out,col_block_size,row_block_size);
69 jgs 150 out->row_block_size=1;
70     out->col_block_size=1;
71 gross 415 } else {
72 ksteube 1312 out->pattern=Paso_SystemMatrixPattern_unrollBlocks(pattern,pattern_format_out,1,1);
73 jgs 150 out->row_block_size=row_block_size;
74     out->col_block_size=col_block_size;
75 gross 415 }
76     }
77 ksteube 1312 out->row_distribution=Paso_Distribution_getReference(out->pattern->input_distribution);
78     out->col_distribution=Paso_Distribution_getReference(out->pattern->output_distribution);
79 gross 415 } else {
80 ksteube 1312 /* ====== compressed sparse row === */
81 gross 415 if (type & MATRIX_FORMAT_SYM) {
82     Paso_setError(TYPE_ERROR,"Generation of matrix pattern for symmetric CSR is not implemented yet.");
83     } else {
84 gross 425 if ((type & MATRIX_FORMAT_BLK1) || row_block_size!=col_block_size || col_block_size>3) {
85 ksteube 1312 out->pattern=Paso_SystemMatrixPattern_unrollBlocks(pattern,pattern_format_out,row_block_size,col_block_size);
86 gross 415 out->row_block_size=1;
87     out->col_block_size=1;
88     } else {
89 ksteube 1312 out->pattern=Paso_SystemMatrixPattern_unrollBlocks(pattern,pattern_format_out,1,1);
90 gross 415 out->row_block_size=row_block_size;
91     out->col_block_size=col_block_size;
92     }
93     }
94 ksteube 1312 out->row_distribution=Paso_Distribution_getReference(out->pattern->output_distribution);
95     out->col_distribution=Paso_Distribution_getReference(out->pattern->input_distribution);
96 jgs 150 }
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 ksteube 1312 /* 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 jgs 150 }
124     /* all done: */
125     if (! Paso_noError()) {
126 ksteube 1312 Paso_SystemMatrix_free(out);
127 jgs 150 return NULL;
128     } else {
129     #ifdef Paso_TRACE
130     printf("timing: system matrix %.4e sec\n",Paso_timer()-time0);
131 ksteube 1312 printf("Paso_SystemMatrix_alloc: system matrix has been allocated.\n");
132 jgs 150 #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 ksteube 1312 void Paso_SystemMatrix_free(Paso_SystemMatrix* in) {
147 jgs 150 if (in!=NULL) {
148     in->reference_counter--;
149     if (in->reference_counter<=0) {
150 ksteube 1312 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 jgs 150 MEMFREE(in->normalizer);
157     Paso_solve_free(in);
158 ksteube 1312 #ifdef TRILINOS
159     Paso_TRILINOS_free(in->trilinos_data);
160     #endif
161 jgs 150 MEMFREE(in);
162     #ifdef Paso_TRACE
163 ksteube 1312 printf("Paso_SystemMatrix_free: system matrix as been deallocated.\n");
164 jgs 150 #endif
165     }
166     }
167     }
168 ksteube 1312 void Paso_SystemMatrix_allocBuffer(Paso_SystemMatrix* A) {
169     Paso_Coupler_allocBuffer(A->pattern->coupler,A->col_block_size);
170     }
171     void Paso_SystemMatrix_freeBuffer(Paso_SystemMatrix* A) {
172     Paso_Coupler_freeBuffer(A->pattern->coupler);
173     }
174     void Paso_SystemMatrix_startCollect(Paso_SystemMatrix* A, double* in)
175     {
176     Paso_Coupler_startCollect(A->pattern->coupler, in);
177     }
178     double* Paso_SystemMatrix_finishCollect(Paso_SystemMatrix* A)
179     {
180     Paso_Coupler_finishCollect(A->pattern->coupler);
181     return A->pattern->coupler->recv_buffer;
182     }
183    
184     dim_t Paso_SystemMatrix_getTotalNumRows(Paso_SystemMatrix* A){
185     return A->mainBlock->numRows * A->row_block_size;
186     }
187    
188     dim_t Paso_SystemMatrix_getTotalNumCols(Paso_SystemMatrix* A){
189     return A->mainBlock->numCols * A->col_block_size;
190     }
191     dim_t Paso_SystemMatrix_getGlobalNumRows(Paso_SystemMatrix* A) {
192     if (A->type & MATRIX_FORMAT_CSC) {
193     return Paso_Distribution_getGlobalNumComponents(A->pattern->input_distribution);
194     } else {
195     return Paso_Distribution_getGlobalNumComponents(A->pattern->output_distribution);
196     }
197     }
198     dim_t Paso_SystemMatrix_getGlobalNumCols(Paso_SystemMatrix* A) {
199     if (A->type & MATRIX_FORMAT_CSC) {
200     return Paso_Distribution_getGlobalNumComponents(A->pattern->output_distribution);
201     } else {
202     return Paso_Distribution_getGlobalNumComponents(A->pattern->input_distribution);
203     }
204    
205     }
206 gross 1361 dim_t Paso_SystemMatrix_getNumOutput(Paso_SystemMatrix* A) {
207     return Paso_SystemMatrixPattern_getNumOutput(A->pattern);
208     }
209 ksteube 1312

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26