/[escript]/trunk-mpi-branch/finley/src/IndexList.c
ViewVC logotype

Contents of /trunk-mpi-branch/finley/src/IndexList.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: 7486 byte(s)
solver starts now but there still seems to be a problem in the MVM
1 /*
2 ************************************************************
3 * Copyright 2006 by ACcESS MNRF *
4 * *
5 * http://www.access.edu.au *
6 * Primary Business: Queensland, Australia *
7 * Licensed under the Open Software License version 3.0 *
8 * http://www.opensource.org/licenses/osl-3.0.php *
9 * *
10 ************************************************************
11 */
12
13 /**************************************************************/
14
15 /* Finley: Converting an element list into a matrix shape */
16
17 /**************************************************************/
18
19 /* Author: gross@access.edu.au */
20 /* Version: $Id$ */
21
22 /**************************************************************/
23
24 #include "IndexList.h"
25
26 /* Translate from distributed/local array indices to global indices */
27
28 /**************************************************************/
29 /* inserts the contributions from the element matrices of elements
30 into the row index col. If symmetric is set, only the upper
31 triangle of the matrix is stored. */
32
33 void Finley_IndexList_insertElements(Finley_IndexList* index_list, Finley_ElementFile* elements,
34 bool_t reduce_row_order, index_t* row_map,
35 bool_t reduce_col_order, index_t* col_map) {
36 /* index_list is an array of linked lists. Each entry is a row (DOF) and contains the indices to the non-zero columns */
37 index_t color, *id=NULL;
38 dim_t e,kr,kc,NN_row,NN_col,i,icol,irow, NN, *row_node=NULL,*col_node=NULL;
39 if (elements!=NULL) {
40 NN=elements->numNodes;
41 id=TMPMEMALLOC(NN, index_t);
42 if (! Finley_checkPtr(id) ) {
43 for (i=0;i<NN;i++) id[i]=i;
44 if (reduce_col_order) {
45 col_node=elements->ReferenceElement->Type->linearNodes;
46 NN_col=elements->LinearReferenceElement->Type->numNodes;
47 } else {
48 col_node=id;
49 NN_col=elements->ReferenceElement->Type->numNodes;
50 }
51 if (reduce_row_order) {
52 row_node=elements->ReferenceElement->Type->linearNodes;
53 NN_row=elements->LinearReferenceElement->Type->numNodes;
54 } else {
55 row_node=id;
56 NN_row=elements->ReferenceElement->Type->numNodes;
57 }
58 for (color=elements->minColor;color<=elements->maxColor;color++) {
59 #pragma omp for private(e,irow,kr,kc,icol) schedule(static)
60 for (e=0;e<elements->numElements;e++) {
61 if (elements->Color[e]==color) {
62 for (kr=0;kr<NN_row;kr++) {
63 irow=row_map[elements->Nodes[INDEX2(row_node[kr],e,NN)]];
64 for (kc=0;kc<NN_col;kc++) {
65 icol=col_map[elements->Nodes[INDEX2(col_node[kc],e,NN)]];
66 Finley_IndexList_insertIndex(&(index_list[irow]),icol);
67 }
68 }
69 }
70 }
71 }
72 TMPMEMFREE(id);
73 }
74 }
75 return;
76 }
77
78 void Finley_IndexList_insertElementsWithRowRange(Finley_IndexList* index_list, index_t firstRow, index_t lastRow,
79 Finley_ElementFile* elements, index_t* row_map, index_t* col_map)
80 {
81 index_t color;
82 dim_t e,kr,kc,i,icol,irow, NN;
83 if (elements!=NULL) {
84 NN=elements->numNodes;
85 for (color=elements->minColor;color<=elements->maxColor;color++) {
86 #pragma omp for private(e,irow,kr,kc,icol) schedule(static)
87 for (e=0;e<elements->numElements;e++) {
88 if (elements->Color[e]==color) {
89 for (kr=0;kr<NN;kr++) {
90 irow=row_map[elements->Nodes[INDEX2(kr,e,NN)]];
91 if ((firstRow<=irow) && (irow < lastRow)) {
92 irow-=firstRow;
93 for (kc=0;kc<NN;kc++) {
94 icol=col_map[elements->Nodes[INDEX2(kc,e,NN)]];
95 Finley_IndexList_insertIndex(&(index_list[irow]),icol);
96 }
97 }
98 }
99 }
100 }
101 }
102 }
103 }
104
105 /* inserts row index row into the Finley_IndexList in if it does not exist */
106
107 void Finley_IndexList_insertIndex(Finley_IndexList* in, index_t index) {
108 dim_t i;
109 /* is index in in? */
110 for (i=0;i<in->n;i++) {
111 if (in->index[i]==index) return;
112 }
113 /* index could not be found */
114 if (in->n==INDEXLIST_LENGTH) {
115 /* if in->index is full check the extension */
116 if (in->extension==NULL) {
117 in->extension=TMPMEMALLOC(1,Finley_IndexList);
118 if (Finley_checkPtr(in->extension)) return;
119 in->extension->n=0;
120 in->extension->extension=NULL;
121 }
122 Finley_IndexList_insertIndex(in->extension,index);
123 } else {
124 /* insert index into in->index*/
125 in->index[in->n]=index;
126 in->n++;
127 }
128 }
129
130 /* counts the number of row indices in the Finley_IndexList in */
131
132 dim_t Finley_IndexList_count(Finley_IndexList* in, index_t range_min,index_t range_max) {
133 dim_t i;
134 dim_t out=0;
135 register index_t itmp;
136 if (in==NULL) {
137 return 0;
138 } else {
139 for (i=0;i<in->n;i++) {
140 itmp=in->index[i];
141 if ((itmp>=range_min) && (range_max>itmp)) ++out;
142 }
143 return out+Finley_IndexList_count(in->extension, range_min,range_max);
144 }
145 }
146
147 /* count the number of row indices in the Finley_IndexList in */
148
149 void Finley_IndexList_toArray(Finley_IndexList* in, index_t* array, index_t range_min,index_t range_max, index_t index_offset) {
150 dim_t i, ptr;
151 register index_t itmp;
152 if (in!=NULL) {
153 ptr=0;
154 for (i=0;i<in->n;i++) {
155 itmp=in->index[i];
156 if ((itmp>=range_min) && (range_max>itmp)) {
157 array[ptr]=itmp+index_offset;
158 ptr++;
159 }
160
161 }
162 Finley_IndexList_toArray(in->extension,&(array[ptr]), range_min, range_max, index_offset);
163 }
164 }
165
166 /* deallocates the Finley_IndexList in by recursive calls */
167
168 void Finley_IndexList_free(Finley_IndexList* in) {
169 if (in!=NULL) {
170 Finley_IndexList_free(in->extension);
171 TMPMEMFREE(in);
172 }
173 }
174
175 /* creates a Paso_pattern from a range of indices */
176 Paso_Pattern* Finley_IndexList_createPattern(dim_t n,Finley_IndexList* index_list,index_t range_min,index_t range_max,index_t index_offset)
177 {
178 dim_t *ptr=NULL;
179 register dim_t s,i,itmp;
180 index_t *index=NULL;
181 Paso_Pattern* out=NULL;
182
183 ptr=MEMALLOC(n+1,index_t);
184 if (! Finley_checkPtr(ptr) ) {
185 /* get the number of connections per row */
186 #pragma omp parallel for schedule(static) private(i)
187 for(i=0;i<n;++i) {
188 ptr[i]=Finley_IndexList_count(&index_list[i],range_min,range_max);
189 }
190 /* accumulate ptr */
191 s=0;
192 for(i=0;i<n;++i) {
193 itmp=ptr[i];
194 ptr[i]=s;
195 s+=itmp;
196 }
197 ptr[n]=s;
198 /* fill index */
199 index=MEMALLOC(ptr[n],index_t);
200 if (! Finley_checkPtr(index)) {
201 #pragma omp parallel for schedule(static)
202 for(i=0;i<n;++i) {
203 Finley_IndexList_toArray(&index_list[i],&index[ptr[i]],range_min,range_max,index_offset);
204 }
205 out=Paso_Pattern_alloc(PATTERN_FORMAT_DEFAULT,n,ptr,index);
206 }
207 }
208 if (! Finley_noError()) {
209 MEMFREE(ptr);
210 MEMFREE(index);
211 Paso_Pattern_free(out);
212 }
213 return out;
214 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26