/[escript]/trunk/finley/src/Assemble_addToSystemMatrix.c
ViewVC logotype

Contents of /trunk/finley/src/Assemble_addToSystemMatrix.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1811 - (show annotations)
Thu Sep 25 23:11:13 2008 UTC (10 years, 9 months ago) by ksteube
File MIME type: text/plain
File size: 9441 byte(s)
Copyright updated in all files

1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2008 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
11 *
12 *******************************************************/
13
14
15 /**************************************************************/
16
17 /* Finley: SystemMatrix and SystemVector */
18
19 /* adds the matrix array[Equa,Sol,NN,NN] onto the matrix in. */
20 /* the rows/columns are given by */
21 /* i_Equa+Equa*Nodes_Equa[Nodes[j_Equa]] (i_Equa=0:Equa; j_Equa=0:NN_Equa). */
22 /* the routine has to be called from a parallel region */
23
24 /* This routine assumes that in->Equa=in->Sol=1, i.e. */
25 /* array is fully packed. */
26 /* TODO: the case in->Equa!=1 */
27
28 /**************************************************************/
29
30 #include "Assemble.h"
31 #include "IndexList.h"
32
33 /**************************************************************/
34
35 void Finley_Assemble_addToSystemMatrix(Paso_SystemMatrix* in,dim_t NN_Equa,index_t* Nodes_Equa, dim_t num_Equa,
36 dim_t NN_Sol,index_t* Nodes_Sol, dim_t num_Sol, double* array) {
37 index_t index_offset=(in->type & MATRIX_FORMAT_OFFSET1 ? 1:0);
38 dim_t k_Equa,j_Equa,j_Sol,k_Sol,i_Equa,i_Sol,l_col,l_row,ic,ir,k,i_row, i_col;
39 index_t *mainBlock_ptr, *mainBlock_index, *col_coupleBlock_ptr, *col_coupleBlock_index, *row_coupleBlock_ptr, *row_coupleBlock_index;
40 double *mainBlock_val, *row_coupleBlock_val, *col_coupleBlock_val;
41 dim_t row_block_size=in->row_block_size;
42 dim_t col_block_size=in->col_block_size;
43 dim_t block_size=in->block_size;
44 dim_t num_subblocks_Equa=num_Equa/row_block_size;
45 dim_t num_subblocks_Sol=num_Sol/col_block_size;
46 dim_t numMyCols=in->pattern->mainPattern->numInput;
47 dim_t numMyRows=in->pattern->mainPattern->numOutput;
48
49
50 if (in->type & MATRIX_FORMAT_CSC) {
51 /* MATRIX_FORMAT_CSC does not support MPI !!!!! */
52 mainBlock_ptr=in->mainBlock->pattern->ptr;
53 mainBlock_index=in->mainBlock->pattern->index;
54 mainBlock_val=in->mainBlock->val;
55 for (k_Sol=0;k_Sol<NN_Sol;k_Sol++) {
56 j_Sol=Nodes_Sol[k_Sol];
57 for (l_col=0;l_col<num_subblocks_Sol;++l_col) {
58 i_col=j_Sol*num_subblocks_Sol+l_col;
59 for (k_Equa=0;k_Equa<NN_Equa;k_Equa++) {
60 j_Equa=Nodes_Equa[k_Equa];
61 for (l_row=0;l_row<num_subblocks_Equa;++l_row) {
62 i_row=j_Equa*num_subblocks_Equa+index_offset+l_row;
63 for (k=mainBlock_ptr[i_col]-index_offset; k<mainBlock_ptr[i_col+1]-index_offset;++k) {
64 if (mainBlock_index[k] == i_row) {
65 for (ic=0;ic<col_block_size;++ic) {
66 i_Sol=ic+col_block_size*l_col;
67 for (ir=0;ir<row_block_size;++ir) {
68 i_Equa=ir+row_block_size*l_row;
69 mainBlock_val[k*block_size+ir+row_block_size*ic]+=
70 array[INDEX4(i_Equa,i_Sol,k_Equa,k_Sol,num_Equa,num_Sol,NN_Equa)];
71 }
72 }
73 break;
74 }
75 }
76 }
77 }
78 }
79 }
80 } else if (in->type & MATRIX_FORMAT_TRILINOS_CRS) {
81 /* this needs to be modified */
82 #ifdef TRILINOS
83 for (k_Equa=0;k_Equa<NN_Equa;++k_Equa) { /* Down columns of array */
84 j_Equa=Nodes_Equa[k_Equa];
85 if (j_Equa < in->mainBlock->pattern->output_node_distribution->numLocal) {
86 for (k_Sol=0;k_Sol<NN_Sol;++k_Sol) { /* Across rows of array */
87 j_Sol=Nodes_Sol[k_Sol];
88 for (l_row=0;l_row<num_subblocks_Equa;++l_row) {
89 irow=j_Equa*row_block_size+l_row;
90 for (l_col=0;l_col<col_block_size;++l_col) {
91 icol=j_Sol*col_block_size+index_offset+l_col;
92 /* irow is local and icol is global */
93 Trilinos_SumIntoMyValues(in->trilinos_data, irow, icol, array[INDEX4(l_row,l_col,k_Equa,k_Sol,num_Equa,num_Sol,NN_Equa)]);
94 }
95 }
96 }
97 }
98 }
99 #endif
100 } else {
101
102 mainBlock_ptr=in->mainBlock->pattern->ptr;
103 mainBlock_index=in->mainBlock->pattern->index;
104 mainBlock_val=in->mainBlock->val;
105 col_coupleBlock_ptr=in->col_coupleBlock->pattern->ptr;
106 col_coupleBlock_index=in->col_coupleBlock->pattern->index;
107 col_coupleBlock_val=in->col_coupleBlock->val;
108 row_coupleBlock_ptr=in->row_coupleBlock->pattern->ptr;
109 row_coupleBlock_index=in->row_coupleBlock->pattern->index;
110 row_coupleBlock_val=in->row_coupleBlock->val;
111
112 for (k_Equa=0;k_Equa<NN_Equa;++k_Equa) { /* Down columns of array */
113 j_Equa=Nodes_Equa[k_Equa];
114 for (l_row=0;l_row<num_subblocks_Equa;++l_row) {
115 i_row=j_Equa*num_subblocks_Equa+l_row;
116 /* only look at the matrix rows stored on this processor */
117 if (i_row < numMyRows) {
118 for (k_Sol=0;k_Sol<NN_Sol;++k_Sol) { /* Across rows of array */
119 j_Sol=Nodes_Sol[k_Sol];
120 for (l_col=0;l_col<num_subblocks_Sol;++l_col) {
121 /* only look at the matrix rows stored on this processor */
122 i_col=j_Sol*num_subblocks_Sol+index_offset+l_col;
123 if (i_col < numMyCols + index_offset ) {
124 for (k=mainBlock_ptr[i_row]-index_offset;k<mainBlock_ptr[i_row+1]-index_offset;++k) {
125 if (mainBlock_index[k]==i_col) {
126 /* Entry array(k_Sol, j_Equa) is a block (row_block_size x col_block_size) */
127 for (ic=0;ic<col_block_size;++ic) {
128 i_Sol=ic+col_block_size*l_col;
129 for (ir=0;ir<row_block_size;++ir) {
130 i_Equa=ir+row_block_size*l_row;
131 mainBlock_val[k*block_size+ir+row_block_size*ic]+=
132 array[INDEX4(i_Equa,i_Sol,k_Equa,k_Sol,num_Equa,num_Sol,NN_Equa)];
133 }
134 }
135 break;
136 }
137 }
138 } else {
139 for (k=col_coupleBlock_ptr[i_row]-index_offset;k<col_coupleBlock_ptr[i_row+1]-index_offset;++k) {
140 if (col_coupleBlock_index[k] == i_col-numMyCols) {
141 /* Entry array(k_Sol, j_Equa) is a block (row_block_size x col_block_size) */
142 for (ic=0;ic<col_block_size;++ic) {
143 i_Sol=ic+col_block_size*l_col;
144 for (ir=0;ir<row_block_size;++ir) {
145 i_Equa=ir+row_block_size*l_row;
146 col_coupleBlock_val[k*block_size+ir+row_block_size*ic]+=
147 array[INDEX4(i_Equa,i_Sol,k_Equa,k_Sol,num_Equa,num_Sol,NN_Equa)];
148 }
149 }
150 break;
151 }
152 }
153 }
154 }
155 }
156 } else {
157 for (k_Sol=0;k_Sol<NN_Sol;++k_Sol) { /* Across rows of array */
158 j_Sol=Nodes_Sol[k_Sol];
159 for (l_col=0;l_col<num_subblocks_Sol;++l_col) {
160 i_col=j_Sol*num_subblocks_Sol+index_offset+l_col;
161 if (i_col < numMyCols + index_offset ) {
162 for (k=row_coupleBlock_ptr[i_row-numMyRows]-index_offset;k<row_coupleBlock_ptr[i_row-numMyRows+1]-index_offset;++k) {
163 if (row_coupleBlock_index[k] == i_col) {
164 /* Entry array(k_Sol, j_Equa) is a block (row_block_size x col_block_size) */
165 for (ic=0;ic<col_block_size;++ic) {
166 i_Sol=ic+col_block_size*l_col;
167 for (ir=0;ir<row_block_size;++ir) {
168 i_Equa=ir+row_block_size*l_row;
169 row_coupleBlock_val[k*block_size+ir+row_block_size*ic]+=
170 array[INDEX4(i_Equa,i_Sol,k_Equa,k_Sol,num_Equa,num_Sol,NN_Equa)];
171 }
172 }
173 break;
174 }
175 }
176 }
177 }
178 }
179 }
180 }
181 }
182 }
183 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26