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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4803 - (show annotations)
Wed Mar 26 06:52:28 2014 UTC (5 years, 9 months ago) by caltinay
File size: 7527 byte(s)
Removed obsolete wrappers for malloc and friends.
Paso_Pattern -> paso::Pattern

1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2014 by University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Open Software License version 3.0
9 * http://www.opensource.org/licenses/osl-3.0.php
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development 2012-2013 by School of Earth Sciences
13 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 *
15 *****************************************************************************/
16
17 /************************************************************************************/
18
19 /* Dudley: Converting an element list into a matrix shape */
20
21 /************************************************************************************/
22
23 #include "IndexList.h"
24
25 /* Translate from distributed/local array indices to global indices */
26
27 /************************************************************************************/
28 /* inserts the contributions from the element matrices of elements
29 into the row index col. If symmetric is set, only the upper
30 triangle of the matrix is stored. */
31
32 void Dudley_IndexList_insertElements(Dudley_IndexList * index_list, Dudley_ElementFile * elements,
33 bool reduce_row_order, index_t * row_map,
34 bool reduce_col_order, index_t * col_map)
35 {
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;
38 dim_t e, kr, kc, NN_row, NN_col, icol, irow, NN;
39 if (elements != NULL)
40 {
41 NN = elements->numNodes;
42 NN_col = (elements->numShapes);
43 NN_row = (elements->numShapes);
44
45 for (color = elements->minColor; color <= elements->maxColor; color++)
46 {
47 #pragma omp for private(e,irow,kr,kc,icol) schedule(static)
48 for (e = 0; e < elements->numElements; e++)
49 {
50 if (elements->Color[e] == color)
51 {
52 for (kr = 0; kr < NN_row; kr++)
53 {
54 irow = row_map[elements->Nodes[INDEX2(kr, e, NN)]];
55 for (kc = 0; kc < NN_col; kc++)
56 {
57 icol = col_map[elements->Nodes[INDEX2(kc, e, NN)]];
58 Dudley_IndexList_insertIndex(&(index_list[irow]), icol);
59 }
60 }
61 }
62 }
63 }
64 }
65 return;
66 }
67
68 void Dudley_IndexList_insertElementsWithRowRange(Dudley_IndexList * index_list, index_t firstRow, index_t lastRow,
69 Dudley_ElementFile * elements, index_t * row_map, index_t * col_map)
70 {
71 /* this does not resolve macro elements */
72 index_t color;
73 dim_t e, kr, kc, icol, irow, NN;
74 if (elements != NULL)
75 {
76 NN = elements->numNodes;
77 for (color = elements->minColor; color <= elements->maxColor; color++)
78 {
79 #pragma omp for private(e,irow,kr,kc,icol) schedule(static)
80 for (e = 0; e < elements->numElements; e++)
81 {
82 if (elements->Color[e] == color)
83 {
84 for (kr = 0; kr < NN; kr++)
85 {
86 irow = row_map[elements->Nodes[INDEX2(kr, e, NN)]];
87 if ((firstRow <= irow) && (irow < lastRow))
88 {
89 irow -= firstRow;
90 for (kc = 0; kc < NN; kc++)
91 {
92 icol = col_map[elements->Nodes[INDEX2(kc, e, NN)]];
93 Dudley_IndexList_insertIndex(&(index_list[irow]), icol);
94 }
95 }
96 }
97 }
98 }
99 }
100 }
101 }
102
103 void Dudley_IndexList_insertElementsWithRowRangeNoMainDiagonal(Dudley_IndexList * index_list, index_t firstRow,
104 index_t lastRow, Dudley_ElementFile * elements,
105 index_t * row_map, index_t * col_map)
106 {
107 /* this does not resolve macro elements */
108 index_t color;
109 dim_t e, kr, kc, icol, irow, NN, irow_loc;
110 if (elements != NULL)
111 {
112 NN = elements->numNodes;
113 for (color = elements->minColor; color <= elements->maxColor; color++)
114 {
115 #pragma omp for private(e,irow,kr,kc,icol,irow_loc) schedule(static)
116 for (e = 0; e < elements->numElements; e++)
117 {
118 if (elements->Color[e] == color)
119 {
120 for (kr = 0; kr < NN; kr++)
121 {
122 irow = row_map[elements->Nodes[INDEX2(kr, e, NN)]];
123 if ((firstRow <= irow) && (irow < lastRow))
124 {
125 irow_loc = irow - firstRow;
126 for (kc = 0; kc < NN; kc++)
127 {
128 icol = col_map[elements->Nodes[INDEX2(kc, e, NN)]];
129 if (icol != irow)
130 Dudley_IndexList_insertIndex(&(index_list[irow_loc]), icol);
131 }
132 }
133 }
134 }
135 }
136 }
137 }
138 }
139
140 /* inserts row index row into the Dudley_IndexList in if it does not exist */
141
142 void Dudley_IndexList_insertIndex(Dudley_IndexList * in, index_t index)
143 {
144 dim_t i;
145 /* is index in in? */
146 for (i = 0; i < in->n; i++)
147 {
148 if (in->index[i] == index)
149 return;
150 }
151 /* index could not be found */
152 if (in->n == INDEXLIST_LENGTH)
153 {
154 /* if in->index is full check the extension */
155 if (in->extension == NULL)
156 {
157 in->extension = new Dudley_IndexList;
158 if (Dudley_checkPtr(in->extension))
159 return;
160 in->extension->n = 0;
161 in->extension->extension = NULL;
162 }
163 Dudley_IndexList_insertIndex(in->extension, index);
164 }
165 else
166 {
167 /* insert index into in->index */
168 in->index[in->n] = index;
169 in->n++;
170 }
171 }
172
173 /* counts the number of row indices in the Dudley_IndexList in */
174
175 dim_t Dudley_IndexList_count(Dudley_IndexList * in, index_t range_min, index_t range_max)
176 {
177 dim_t i;
178 dim_t out = 0;
179 register index_t itmp;
180 if (in == NULL)
181 {
182 return 0;
183 }
184 else
185 {
186 for (i = 0; i < in->n; i++)
187 {
188 itmp = in->index[i];
189 if ((itmp >= range_min) && (range_max > itmp))
190 ++out;
191 }
192 return out + Dudley_IndexList_count(in->extension, range_min, range_max);
193 }
194 }
195
196 /* count the number of row indices in the Dudley_IndexList in */
197
198 void Dudley_IndexList_toArray(Dudley_IndexList * in, index_t * array, index_t range_min, index_t range_max,
199 index_t index_offset)
200 {
201 dim_t i, ptr;
202 register index_t itmp;
203 if (in != NULL)
204 {
205 ptr = 0;
206 for (i = 0; i < in->n; i++)
207 {
208 itmp = in->index[i];
209 if ((itmp >= range_min) && (range_max > itmp))
210 {
211 array[ptr] = itmp + index_offset;
212 ptr++;
213 }
214
215 }
216 Dudley_IndexList_toArray(in->extension, &(array[ptr]), range_min, range_max, index_offset);
217 }
218 }
219
220 /* deallocates the Dudley_IndexList in by recursive calls */
221
222 void Dudley_IndexList_free(Dudley_IndexList * in)
223 {
224 if (in != NULL)
225 {
226 Dudley_IndexList_free(in->extension);
227 delete in;
228 }
229 }
230
231 /* creates a paso pattern from a range of indices */
232 paso::Pattern *Dudley_IndexList_createPattern(dim_t n0, dim_t n, Dudley_IndexList * index_list, index_t range_min,
233 index_t range_max, index_t index_offset)
234 {
235 dim_t *ptr = NULL;
236 register dim_t s, i, itmp;
237 index_t *index = NULL;
238 paso::Pattern *out = NULL;
239
240 ptr = new index_t[n + 1 - n0];
241 if (!Dudley_checkPtr(ptr))
242 {
243 /* get the number of connections per row */
244 #pragma omp parallel for schedule(static) private(i)
245 for (i = n0; i < n; ++i)
246 {
247 ptr[i - n0] = Dudley_IndexList_count(&index_list[i], range_min, range_max);
248 }
249 /* accumulate ptr */
250 s = 0;
251 for (i = n0; i < n; ++i)
252 {
253 itmp = ptr[i - n0];
254 ptr[i - n0] = s;
255 s += itmp;
256 }
257 ptr[n - n0] = s;
258 /* fill index */
259 index = new index_t[ptr[n - n0]];
260 if (!Dudley_checkPtr(index))
261 {
262 #pragma omp parallel for schedule(static)
263 for (i = n0; i < n; ++i)
264 {
265 Dudley_IndexList_toArray(&index_list[i], &index[ptr[i - n0]], range_min, range_max, index_offset);
266 }
267 out = paso::Pattern_alloc(MATRIX_FORMAT_DEFAULT, n - n0, range_max + index_offset, ptr, index);
268 }
269 }
270 if (!Dudley_noError())
271 {
272 delete[] ptr;
273 delete[] index;
274 paso::Pattern_free(out);
275 }
276 return out;
277 }

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision
svn:mergeinfo /branches/lapack2681/finley/src/IndexList.cpp:2682-2741 /branches/pasowrap/dudley/src/IndexList.cpp:3661-3674 /branches/py3_attempt2/dudley/src/IndexList.cpp:3871-3891 /branches/restext/finley/src/IndexList.cpp:2610-2624 /branches/ripleygmg_from_3668/dudley/src/IndexList.cpp:3669-3791 /branches/stage3.0/finley/src/IndexList.cpp:2569-2590 /branches/symbolic_from_3470/dudley/src/IndexList.cpp:3471-3974 /branches/symbolic_from_3470/ripley/test/python/dudley/src/IndexList.cpp:3517-3974 /release/3.0/finley/src/IndexList.cpp:2591-2601 /trunk/dudley/src/IndexList.cpp:4257-4344 /trunk/ripley/test/python/dudley/src/IndexList.cpp:3480-3515

  ViewVC Help
Powered by ViewVC 1.1.26