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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 432 - (hide annotations)
Fri Jan 13 07:38:54 2006 UTC (13 years, 8 months ago) by gross
File MIME type: text/plain
File size: 6437 byte(s)
some fixes for openmp
1 jgs 150 /* $Id$ */
2    
3     /**************************************************************/
4    
5     /* Paso: SystemMatrix */
6    
7     /**************************************************************/
8    
9     /* Copyrights by ACcESS Australia 2003, 2004,2005 */
10     /* Author: gross@access.edu.au */
11    
12     /**************************************************************/
13    
14     #include "Paso.h"
15     #include "SystemMatrix.h"
16    
17     /**************************************************************/
18    
19     /* allocates a SystemMatrix of type type using the given matrix pattern
20     if type is UNKOWN CSR is used.
21     if CSC or CSC_BLK1 is used pattern has to give the CSC pattern.
22     if CSR or CSR_BLK1 is used pattern has to give the CSR pattern.
23     Values are initialized by zero. */
24    
25     Paso_SystemMatrix* Paso_SystemMatrix_alloc(Paso_SystemMatrixType type,Paso_SystemMatrixPattern *pattern, int row_block_size, int col_block_size) {
26 gross 432
27 jgs 150 double time0;
28     Paso_SystemMatrix*out=NULL;
29     Paso_resetError();
30     time0=Paso_timer();
31     dim_t n_norm,i;
32     out=MEMALLOC(1,Paso_SystemMatrix);
33     if (! Paso_checkPtr(out)) {
34     out->pattern=NULL;
35 gross 425 out->solver_package=PASO_PASO;
36     out->solver=NULL;
37 jgs 150 out->val=NULL;
38     out->reference_counter=1;
39 gross 415 out->type=type;
40     if (type & MATRIX_FORMAT_CSC) {
41     if (type & MATRIX_FORMAT_SYM) {
42     Paso_setError(TYPE_ERROR,"Generation of matrix pattern for symmetric CSC is not implemented yet.");
43     return NULL;
44     } else {
45 gross 425 if ((type & MATRIX_FORMAT_BLK1) || row_block_size!=col_block_size || col_block_size>3) {
46 gross 415 if (type & MATRIX_FORMAT_OFFSET1) {
47     out->pattern=Paso_SystemMatrixPattern_unrollBlocks(pattern,PATTERN_FORMAT_OFFSET1,col_block_size,row_block_size);
48     } else {
49     out->pattern=Paso_SystemMatrixPattern_unrollBlocks(pattern,PATTERN_FORMAT_DEFAULT,col_block_size,row_block_size);
50     }
51 jgs 150 out->row_block_size=1;
52     out->col_block_size=1;
53 gross 415 } else {
54     if ( (type & MATRIX_FORMAT_OFFSET1) ==(pattern->type & PATTERN_FORMAT_OFFSET1)) {
55     out->pattern=Paso_SystemMatrixPattern_reference(pattern);
56     } else {
57     out->pattern=Paso_SystemMatrixPattern_unrollBlocks(pattern,(type & MATRIX_FORMAT_OFFSET1)? PATTERN_FORMAT_OFFSET1: PATTERN_FORMAT_DEFAULT,1,1);
58     }
59 jgs 150 out->row_block_size=row_block_size;
60     out->col_block_size=col_block_size;
61 gross 415 }
62     }
63     out->num_rows=out->pattern->n_index;
64     out->num_cols=out->pattern->n_ptr;
65     n_norm = out->num_cols * out->col_block_size;
66     } else {
67     if (type & MATRIX_FORMAT_SYM) {
68     Paso_setError(TYPE_ERROR,"Generation of matrix pattern for symmetric CSR is not implemented yet.");
69     return NULL;
70     } else {
71 gross 425 if ((type & MATRIX_FORMAT_BLK1) || row_block_size!=col_block_size || col_block_size>3) {
72 gross 415 if (type & MATRIX_FORMAT_OFFSET1) {
73     out->pattern=Paso_SystemMatrixPattern_unrollBlocks(pattern,PATTERN_FORMAT_OFFSET1,row_block_size,col_block_size);
74     } else {
75     out->pattern=Paso_SystemMatrixPattern_unrollBlocks(pattern,PATTERN_FORMAT_DEFAULT,row_block_size,col_block_size);
76     }
77     out->row_block_size=1;
78     out->col_block_size=1;
79     } else {
80     if ((type & MATRIX_FORMAT_OFFSET1)==(pattern->type & PATTERN_FORMAT_OFFSET1)) {
81     out->pattern=Paso_SystemMatrixPattern_reference(pattern);
82     } else {
83     out->pattern=Paso_SystemMatrixPattern_unrollBlocks(pattern,(type & MATRIX_FORMAT_OFFSET1)? PATTERN_FORMAT_OFFSET1: PATTERN_FORMAT_DEFAULT,1,1);
84     }
85     out->row_block_size=row_block_size;
86     out->col_block_size=col_block_size;
87     }
88     }
89     out->num_rows=out->pattern->n_index;
90     out->num_cols=out->pattern->n_ptr;
91     n_norm = out->num_cols * out->col_block_size;
92     out->num_rows=out->pattern->n_ptr;
93     out->num_cols=out->pattern->n_index;
94     n_norm = out->num_rows * out->row_block_size;
95 jgs 150 }
96     out->logical_row_block_size=row_block_size;
97     out->logical_col_block_size=col_block_size;
98     out->logical_block_size=out->logical_row_block_size*out->logical_block_size;
99     out->block_size=out->row_block_size*out->col_block_size;
100     out->len=(size_t)(out->pattern->len)*(size_t)(out->block_size);
101     /* allocate memory for matrix entries */
102     out->val=MEMALLOC(out->len,double);
103     out->normalizer=MEMALLOC(n_norm,double);
104     out->normalizer_is_valid=FALSE;
105     if (! Paso_checkPtr(out->val)) {
106     Paso_SystemMatrix_setValues(out,DBLE(0));
107     }
108     if (! Paso_checkPtr(out->normalizer)) {
109     #pragma omp parallel for private(i) schedule(static)
110     for (i=0;i<n_norm;++i) out->normalizer[i]=0.;
111     }
112     }
113     /* all done: */
114     if (! Paso_noError()) {
115     Paso_SystemMatrix_dealloc(out);
116     return NULL;
117     } else {
118     #ifdef Paso_TRACE
119     printf("timing: system matrix %.4e sec\n",Paso_timer()-time0);
120     printf("Paso_SystemMatrix_alloc: %ld x %ld system matrix has been allocated.\n",(long)out->num_rows,(long)out->num_cols);
121     #endif
122     return out;
123     }
124     }
125    
126     /* returns a reference to Paso_SystemMatrix in */
127    
128     Paso_SystemMatrix* Paso_SystemMatrix_reference(Paso_SystemMatrix* in) {
129     if (in!=NULL) ++(in->reference_counter);
130     return NULL;
131     }
132    
133     /* deallocates a SystemMatrix: */
134    
135     void Paso_SystemMatrix_dealloc(Paso_SystemMatrix* in) {
136     if (in!=NULL) {
137     in->reference_counter--;
138     if (in->reference_counter<=0) {
139     MEMFREE(in->val);
140     MEMFREE(in->normalizer);
141     Paso_SystemMatrixPattern_dealloc(in->pattern);
142     Paso_solve_free(in);
143     MEMFREE(in);
144     #ifdef Paso_TRACE
145     printf("Paso_SystemMatrix_dealloc: system matrix as been deallocated.\n");
146     #endif
147     }
148     }
149     }
150     /*
151     * $Log$
152     * Revision 1.2 2005/09/15 03:44:38 jgs
153     * Merge of development branch dev-02 back to main trunk on 2005-09-15
154     *
155     * Revision 1.1.2.2 2005/09/07 00:59:08 gross
156     * some inconsistent renaming fixed to make the linking work.
157     *
158     * Revision 1.1.2.1 2005/09/05 06:29:47 gross
159     * These files have been extracted from finley to define a stand alone libray for iterative
160     * linear solvers on the ALTIX. main entry through Paso_solve. this version compiles but
161     * has not been tested yet.
162     *
163     *
164     */

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26