/[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 1227 - (show annotations)
Fri Aug 3 10:34:23 2007 UTC (12 years, 10 months ago) by gross
File MIME type: text/plain
File size: 8255 byte(s)
final work on the ParaMetis hook. ParaMetis needs still to be put in there.


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) {
150 dim_t i;
151 register index_t itmp;
152 if (in!=NULL) {
153 for (i=0;i<in->n;i++) {
154 itmp=in->index[i];
155 if ((itmp>=range_min) && (range_max>itmp)) array[i]=itmp;
156 }
157 Finley_IndexList_toArray(in->extension,&(array[in->n]), range_min, range_max);
158 }
159 }
160
161 /* deallocates the Finley_IndexList in by recursive calls */
162
163 void Finley_IndexList_free(Finley_IndexList* in) {
164 if (in!=NULL) {
165 Finley_IndexList_free(in->extension);
166 TMPMEMFREE(in);
167 }
168 }
169
170 /* creates a Paso_pattern from a range of indices */
171 Paso_Pattern* Finley_IndexList_createPattern(dim_t n,Finley_IndexList* index_list,index_t range_min,index_t range_max)
172 {
173 dim_t *ptr=NULL;
174 register dim_t s,i,itmp;
175 index_t *index=NULL;
176 Paso_Pattern* out=NULL;
177
178 ptr=MEMALLOC(n+1,index_t);
179 if (! Finley_checkPtr(ptr) ) {
180 /* get the number of connections per row */
181 #pragma omp parallel for schedule(static) private(i)
182 for(i=0;i<n;++i) {
183 ptr[i]=Finley_IndexList_count(&index_list[i],range_min,range_max);
184 }
185 /* accumulate ptr */
186 s=0;
187 for(i=0;i<n;++i) {
188 itmp=ptr[i];
189 ptr[i]=s;
190 s+=itmp;
191 }
192 ptr[n]=s;
193 /* fill index */
194 index=MEMALLOC(ptr[n],index_t);
195 if (! Finley_checkPtr(index)) {
196 #pragma omp parallel for schedule(static)
197 for(i=0;i<n;++i) Finley_IndexList_toArray(&index_list[i],&index[ptr[i]],range_min,range_max);
198
199 out=Paso_Pattern_alloc(PATTERN_FORMAT_DEFAULT,n,ptr,index);
200 }
201 }
202 if (! Finley_noError()) {
203 MEMFREE(ptr);
204 MEMFREE(index);
205 Paso_Pattern_free(out);
206 }
207 return out;
208 }
209
210 Paso_Coupler* Finley_IndexList_createCoupler(Finley_IndexList *index_list)
211 {
212 Paso_Coupler* out=NULL;
213 index_t *sharedInput=NULL, *offsetInSharedInput=NULL, *offsetInRemoteInput=NULL;
214 /*
215
216 if (! (rowMap->MPIInfo->comm == colMap->MPIInfo->comm ) ) {
217 Finley_setError(SYSTEM_ERROR,"Finley_IndexList_createCoupler: communicator for row and column DOFMap must be identical.");
218 return NULL;
219 }
220 if (! (rowMap->numNeighbours == colMap->numNeighbours ) ) {
221 Finley_setError(SYSTEM_ERROR,"Finley_IndexList_createCoupler: number of neighbours for row and column DOFMap must be identical.");
222 return NULL;
223 }
224
225
226 out=Paso_Coupler_alloc(rowMap->numNeighbours,
227 rowMap->neighbours,
228 sharedInput,
229 offsetInSharedInput,
230 offsetInRemoteInput,
231 rowMap->MPIInfo);
232 */
233 return out;
234 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26