/[escript]/trunk/dudley/src/IndexList.cpp
ViewVC logotype

Contents of /trunk/dudley/src/IndexList.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3161 - (show annotations)
Tue Sep 7 04:17:03 2010 UTC (9 years ago) by jfenwick
Original Path: branches/domexper/dudley/src/IndexList.c
File MIME type: text/plain
File size: 7957 byte(s)
Switch to repository versions of required packages.
Fix some OpenMP problems

1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2010 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 /* Dudley: Converting an element list into a matrix shape */
18
19 /**************************************************************/
20
21 #include "IndexList.h"
22
23 /* Translate from distributed/local array indices to global indices */
24
25 /**************************************************************/
26 /* inserts the contributions from the element matrices of elements
27 into the row index col. If symmetric is set, only the upper
28 triangle of the matrix is stored. */
29
30 void Dudley_IndexList_insertElements(Dudley_IndexList* index_list, Dudley_ElementFile* elements,
31 bool_t reduce_row_order, index_t* row_map,
32 bool_t reduce_col_order, index_t* col_map)
33 {
34 /* index_list is an array of linked lists. Each entry is a row (DOF) and contains the indices to the non-zero columns */
35 index_t color;
36 Dudley_ReferenceElement*refElement;
37 dim_t e, kr, kc, NN_row, NN_col, icol, irow, NN;
38 if (elements!=NULL)
39 {
40 NN=elements->numNodes;
41 refElement= Dudley_ReferenceElementSet_borrowReferenceElement(elements->referenceElementSet, FALSE);
42 NN_col=(refElement->BasisFunctions->Type->numShapes);
43 NN_col=(refElement->BasisFunctions->Type->numShapes);
44 NN_row=(refElement->BasisFunctions->Type->numShapes) ;
45
46 for (color=elements->minColor;color<=elements->maxColor;color++)
47 {
48 #pragma omp for private(e,irow,kr,kc,icol) schedule(static)
49 for (e=0;e<elements->numElements;e++)
50 {
51 if (elements->Color[e]==color)
52 {
53 for (kr=0;kr<NN_row;kr++)
54 {
55 irow=row_map[elements->Nodes[INDEX2(kr,e,NN)]];
56 for (kc=0;kc<NN_col;kc++)
57 {
58 icol=col_map[elements->Nodes[INDEX2(kc,e,NN)]];
59 Dudley_IndexList_insertIndex(&(index_list[irow]),icol);
60 }
61 }
62 }
63 }
64 }
65 }
66 return;
67 }
68
69
70 void Dudley_IndexList_insertElementsWithRowRange(Dudley_IndexList* index_list, index_t firstRow, index_t lastRow,
71 Dudley_ElementFile* elements, index_t* row_map, index_t* col_map)
72 {
73 /* this does not resolve macro elements */
74 index_t color;
75 dim_t e,kr,kc,icol,irow, NN;
76 if (elements!=NULL) {
77 NN=elements->numNodes;
78 for (color=elements->minColor;color<=elements->maxColor;color++) {
79 #pragma omp for private(e,irow,kr,kc,icol) schedule(static)
80 for (e=0;e<elements->numElements;e++) {
81 if (elements->Color[e]==color) {
82 for (kr=0;kr<NN;kr++) {
83 irow=row_map[elements->Nodes[INDEX2(kr,e,NN)]];
84 if ((firstRow<=irow) && (irow < lastRow)) {
85 irow-=firstRow;
86 for (kc=0;kc<NN;kc++) {
87 icol=col_map[elements->Nodes[INDEX2(kc,e,NN)]];
88 Dudley_IndexList_insertIndex(&(index_list[irow]),icol);
89 }
90 }
91 }
92 }
93 }
94 }
95 }
96 }
97 void Dudley_IndexList_insertElementsWithRowRangeNoMainDiagonal(Dudley_IndexList* index_list, index_t firstRow, index_t lastRow,
98 Dudley_ElementFile* elements, index_t* row_map, index_t* col_map)
99 {
100 /* this does not resolve macro elements */
101 index_t color;
102 dim_t e,kr,kc,icol,irow, NN,irow_loc;
103 if (elements!=NULL) {
104 NN=elements->numNodes;
105 for (color=elements->minColor;color<=elements->maxColor;color++) {
106 #pragma omp for private(e,irow,kr,kc,icol,irow_loc) schedule(static)
107 for (e=0;e<elements->numElements;e++) {
108 if (elements->Color[e]==color) {
109 for (kr=0;kr<NN;kr++) {
110 irow=row_map[elements->Nodes[INDEX2(kr,e,NN)]];
111 if ((firstRow<=irow) && (irow < lastRow)) {
112 irow_loc=irow-firstRow;
113 for (kc=0;kc<NN;kc++) {
114 icol=col_map[elements->Nodes[INDEX2(kc,e,NN)]];
115 if (icol != irow) Dudley_IndexList_insertIndex(&(index_list[irow_loc]),icol);
116 }
117 }
118 }
119 }
120 }
121 }
122 }
123 }
124
125 /* inserts row index row into the Dudley_IndexList in if it does not exist */
126
127 void Dudley_IndexList_insertIndex(Dudley_IndexList* in, index_t index) {
128 dim_t i;
129 /* is index in in? */
130 for (i=0;i<in->n;i++) {
131 if (in->index[i]==index) return;
132 }
133 /* index could not be found */
134 if (in->n==INDEXLIST_LENGTH) {
135 /* if in->index is full check the extension */
136 if (in->extension==NULL) {
137 in->extension=TMPMEMALLOC(1,Dudley_IndexList);
138 if (Dudley_checkPtr(in->extension)) return;
139 in->extension->n=0;
140 in->extension->extension=NULL;
141 }
142 Dudley_IndexList_insertIndex(in->extension,index);
143 } else {
144 /* insert index into in->index*/
145 in->index[in->n]=index;
146 in->n++;
147 }
148 }
149
150 /* counts the number of row indices in the Dudley_IndexList in */
151
152 dim_t Dudley_IndexList_count(Dudley_IndexList* in, index_t range_min,index_t range_max) {
153 dim_t i;
154 dim_t out=0;
155 register index_t itmp;
156 if (in==NULL) {
157 return 0;
158 } else {
159 for (i=0;i<in->n;i++) {
160 itmp=in->index[i];
161 if ((itmp>=range_min) && (range_max>itmp)) ++out;
162 }
163 return out+Dudley_IndexList_count(in->extension, range_min,range_max);
164 }
165 }
166
167 /* count the number of row indices in the Dudley_IndexList in */
168
169 void Dudley_IndexList_toArray(Dudley_IndexList* in, index_t* array, index_t range_min,index_t range_max, index_t index_offset) {
170 dim_t i, ptr;
171 register index_t itmp;
172 if (in!=NULL) {
173 ptr=0;
174 for (i=0;i<in->n;i++) {
175 itmp=in->index[i];
176 if ((itmp>=range_min) && (range_max>itmp)) {
177 array[ptr]=itmp+index_offset;
178 ptr++;
179 }
180
181 }
182 Dudley_IndexList_toArray(in->extension,&(array[ptr]), range_min, range_max, index_offset);
183 }
184 }
185
186 /* deallocates the Dudley_IndexList in by recursive calls */
187
188 void Dudley_IndexList_free(Dudley_IndexList* in) {
189 if (in!=NULL) {
190 Dudley_IndexList_free(in->extension);
191 TMPMEMFREE(in);
192 }
193 }
194
195 /* creates a Paso_pattern from a range of indices */
196 Paso_Pattern* Dudley_IndexList_createPattern(dim_t n0, dim_t n,Dudley_IndexList* index_list,index_t range_min,index_t range_max,index_t index_offset)
197 {
198 dim_t *ptr=NULL;
199 register dim_t s,i,itmp;
200 index_t *index=NULL;
201 Paso_Pattern* out=NULL;
202
203 ptr=MEMALLOC(n+1-n0,index_t);
204 if (! Dudley_checkPtr(ptr) ) {
205 /* get the number of connections per row */
206 #pragma omp parallel for schedule(static) private(i)
207 for(i=n0;i<n;++i) {
208 ptr[i-n0]=Dudley_IndexList_count(&index_list[i],range_min,range_max);
209 }
210 /* accumulate ptr */
211 s=0;
212 for(i=n0;i<n;++i) {
213 itmp=ptr[i-n0];
214 ptr[i-n0]=s;
215 s+=itmp;
216 }
217 ptr[n-n0]=s;
218 /* fill index */
219 index=MEMALLOC(ptr[n-n0],index_t);
220 if (! Dudley_checkPtr(index)) {
221 #pragma omp parallel for schedule(static)
222 for(i=n0;i<n;++i) {
223 Dudley_IndexList_toArray(&index_list[i],&index[ptr[i-n0]],range_min,range_max,index_offset);
224 }
225 out=Paso_Pattern_alloc(PATTERN_FORMAT_DEFAULT,n-n0,range_max+index_offset,ptr,index);
226 }
227 }
228 if (! Dudley_noError()) {
229 MEMFREE(ptr);
230 MEMFREE(index);
231 Paso_Pattern_free(out);
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