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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1087 - (hide annotations)
Thu Apr 12 10:01:47 2007 UTC (12 years, 3 months ago) by gross
File MIME type: text/plain
File size: 8357 byte(s)
the MPI version of PASO.PCG is running. 
There is a bug in the rectangular mesh generators but they need to be
revised in any case to clean up the code.


1 jgs 150 /* $Id$ */
2    
3 dhawcroft 631
4     /*
5     ********************************************************************************
6 dhawcroft 633 * Copyright 2006 by ACcESS MNRF *
7 dhawcroft 631 * *
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 jgs 150 /**************************************************************/
16    
17     /* Paso: SystemMatrix */
18    
19     /**************************************************************/
20    
21     /* Copyrights by ACcESS Australia 2003, 2004,2005 */
22     /* Author: gross@access.edu.au */
23    
24     /**************************************************************/
25    
26     #include "Paso.h"
27 gross 1011 #include "Paso_MPI.h"
28 jgs 150 #include "SystemMatrix.h"
29 gross 1011 #include "TRILINOS.h"
30 jgs 150
31     /**************************************************************/
32    
33     /* allocates a SystemMatrix of type type using the given matrix pattern
34     if type is UNKOWN CSR is used.
35     if CSC or CSC_BLK1 is used pattern has to give the CSC pattern.
36     if CSR or CSR_BLK1 is used pattern has to give the CSR pattern.
37     Values are initialized by zero. */
38    
39     Paso_SystemMatrix* Paso_SystemMatrix_alloc(Paso_SystemMatrixType type,Paso_SystemMatrixPattern *pattern, int row_block_size, int col_block_size) {
40 gross 432
41 jgs 150 double time0;
42     Paso_SystemMatrix*out=NULL;
43     Paso_resetError();
44     time0=Paso_timer();
45     dim_t n_norm,i;
46     out=MEMALLOC(1,Paso_SystemMatrix);
47     if (! Paso_checkPtr(out)) {
48     out->pattern=NULL;
49 gross 425 out->solver_package=PASO_PASO;
50     out->solver=NULL;
51 jgs 150 out->val=NULL;
52 gross 1011 out->trilinos_data=NULL;
53 jgs 150 out->reference_counter=1;
54 gross 415 out->type=type;
55 gross 1011 /* ====== compressed sparse columns === */
56 gross 415 if (type & MATRIX_FORMAT_CSC) {
57     if (type & MATRIX_FORMAT_SYM) {
58     Paso_setError(TYPE_ERROR,"Generation of matrix pattern for symmetric CSC is not implemented yet.");
59     return NULL;
60     } else {
61 gross 425 if ((type & MATRIX_FORMAT_BLK1) || row_block_size!=col_block_size || col_block_size>3) {
62 gross 415 if (type & MATRIX_FORMAT_OFFSET1) {
63     out->pattern=Paso_SystemMatrixPattern_unrollBlocks(pattern,PATTERN_FORMAT_OFFSET1,col_block_size,row_block_size);
64     } else {
65     out->pattern=Paso_SystemMatrixPattern_unrollBlocks(pattern,PATTERN_FORMAT_DEFAULT,col_block_size,row_block_size);
66     }
67 jgs 150 out->row_block_size=1;
68     out->col_block_size=1;
69 gross 415 } else {
70     if ( (type & MATRIX_FORMAT_OFFSET1) ==(pattern->type & PATTERN_FORMAT_OFFSET1)) {
71     out->pattern=Paso_SystemMatrixPattern_reference(pattern);
72     } else {
73     out->pattern=Paso_SystemMatrixPattern_unrollBlocks(pattern,(type & MATRIX_FORMAT_OFFSET1)? PATTERN_FORMAT_OFFSET1: PATTERN_FORMAT_DEFAULT,1,1);
74     }
75 jgs 150 out->row_block_size=row_block_size;
76     out->col_block_size=col_block_size;
77 gross 415 }
78     }
79 gross 1011 out->row_distribution=Paso_Distribution_getReference(out->pattern->input_distribution);
80     out->col_distribution=Paso_Distribution_getReference(out->pattern->output_distribution);
81 gross 415 } else {
82 gross 1011 /* ====== compressed sparse row === */
83 gross 415 if (type & MATRIX_FORMAT_SYM) {
84     Paso_setError(TYPE_ERROR,"Generation of matrix pattern for symmetric CSR is not implemented yet.");
85     return NULL;
86     } else {
87 gross 425 if ((type & MATRIX_FORMAT_BLK1) || row_block_size!=col_block_size || col_block_size>3) {
88 gross 415 if (type & MATRIX_FORMAT_OFFSET1) {
89     out->pattern=Paso_SystemMatrixPattern_unrollBlocks(pattern,PATTERN_FORMAT_OFFSET1,row_block_size,col_block_size);
90     } else {
91     out->pattern=Paso_SystemMatrixPattern_unrollBlocks(pattern,PATTERN_FORMAT_DEFAULT,row_block_size,col_block_size);
92     }
93     out->row_block_size=1;
94     out->col_block_size=1;
95     } else {
96     if ((type & MATRIX_FORMAT_OFFSET1)==(pattern->type & PATTERN_FORMAT_OFFSET1)) {
97     out->pattern=Paso_SystemMatrixPattern_reference(pattern);
98     } else {
99     out->pattern=Paso_SystemMatrixPattern_unrollBlocks(pattern,(type & MATRIX_FORMAT_OFFSET1)? PATTERN_FORMAT_OFFSET1: PATTERN_FORMAT_DEFAULT,1,1);
100     }
101     out->row_block_size=row_block_size;
102     out->col_block_size=col_block_size;
103     }
104     }
105 gross 1011 out->row_distribution=Paso_Distribution_getReference(out->pattern->output_distribution);
106     out->col_distribution=Paso_Distribution_getReference(out->pattern->input_distribution);
107 jgs 150 }
108     out->logical_row_block_size=row_block_size;
109     out->logical_col_block_size=col_block_size;
110     out->logical_block_size=out->logical_row_block_size*out->logical_block_size;
111     out->block_size=out->row_block_size*out->col_block_size;
112 gross 1011 out->myLen=(size_t)(out->pattern->myLen)*(size_t)(out->block_size);
113    
114 gross 1087 out->numRows = out->row_distribution->numComponents;
115     out->myNumRows = out->row_distribution->myNumComponents;
116     out->myFirstRow = out->row_distribution->myFirstComponent;
117     out->maxNumRows = out->row_distribution->maxNumComponents;
118     out->numCols = out->col_distribution->numComponents;
119     out->myNumCols = out->col_distribution->myNumComponents;
120     out->myFirstCol = out->col_distribution->myFirstComponent;
121     out->maxNumCols = out->col_distribution->maxNumComponents;
122 gross 1011 out->mpi_info = Paso_MPIInfo_getReference(out->pattern->mpi_info);
123 jgs 150 /* allocate memory for matrix entries */
124 gross 1011 if (type & MATRIX_FORMAT_TRILINOS_CRS) {
125     Paso_TRILINOS_alloc(out->trilinos_data, out->pattern,out->row_block_size,out->col_block_size);
126     } else {
127     if (type & MATRIX_FORMAT_CSC) {
128 gross 1087 n_norm = out->maxNumCols * out->col_block_size;
129 gross 1011 } else {
130 gross 1087 n_norm = out->maxNumRows * out->row_block_size;
131 gross 1011 }
132     out->val=MEMALLOC(out->myLen,double);
133     out->normalizer=MEMALLOC(n_norm,double);
134     out->normalizer_is_valid=FALSE;
135     if (! Paso_checkPtr(out->val)) Paso_SystemMatrix_setValues(out,DBLE(0));
136     if (! Paso_checkPtr(out->normalizer)) {
137     #pragma omp parallel for private(i) schedule(static)
138     for (i=0;i<n_norm;++i) out->normalizer[i]=0.;
139     }
140 jgs 150 }
141     }
142     /* all done: */
143     if (! Paso_noError()) {
144     Paso_SystemMatrix_dealloc(out);
145     return NULL;
146     } else {
147     #ifdef Paso_TRACE
148     printf("timing: system matrix %.4e sec\n",Paso_timer()-time0);
149 gross 1011 printf("Paso_SystemMatrix_alloc: %ld x %ld system matrix has been allocated.\n",(long)out->numRows,(long)out->numCols);
150 jgs 150 #endif
151     return out;
152     }
153     }
154    
155     /* returns a reference to Paso_SystemMatrix in */
156    
157     Paso_SystemMatrix* Paso_SystemMatrix_reference(Paso_SystemMatrix* in) {
158     if (in!=NULL) ++(in->reference_counter);
159     return NULL;
160     }
161    
162     /* deallocates a SystemMatrix: */
163    
164     void Paso_SystemMatrix_dealloc(Paso_SystemMatrix* in) {
165     if (in!=NULL) {
166     in->reference_counter--;
167     if (in->reference_counter<=0) {
168 gross 1011 Paso_SystemMatrixPattern_dealloc(in->pattern);
169 gross 1016 Paso_Distribution_free(in->row_distribution);
170     Paso_Distribution_free(in->col_distribution);
171 gross 1011 Paso_MPIInfo_dealloc(in->mpi_info);
172 jgs 150 MEMFREE(in->val);
173     MEMFREE(in->normalizer);
174 gross 1011 Paso_TRILINOS_free(in->trilinos_data);
175 jgs 150 Paso_solve_free(in);
176     MEMFREE(in);
177     #ifdef Paso_TRACE
178     printf("Paso_SystemMatrix_dealloc: system matrix as been deallocated.\n");
179     #endif
180     }
181     }
182     }
183     /*
184     * $Log$
185     * Revision 1.2 2005/09/15 03:44:38 jgs
186     * Merge of development branch dev-02 back to main trunk on 2005-09-15
187     *
188     * Revision 1.1.2.2 2005/09/07 00:59:08 gross
189     * some inconsistent renaming fixed to make the linking work.
190     *
191     * Revision 1.1.2.1 2005/09/05 06:29:47 gross
192     * These files have been extracted from finley to define a stand alone libray for iterative
193     * linear solvers on the ALTIX. main entry through Paso_solve. this version compiles but
194     * has not been tested yet.
195     *
196     *
197     */

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26