/[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 1223 - (show annotations)
Fri Aug 3 02:40:39 2007 UTC (11 years, 8 months ago) by gross
File MIME type: text/plain
File size: 7134 byte(s)
first attemt towards an improved MPI version.  

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 /* inserts row index row into the Finley_IndexList in if it does not exist */
79
80 void Finley_IndexList_insertIndex(Finley_IndexList* in, index_t index) {
81 dim_t i;
82 /* is index in in? */
83 for (i=0;i<in->n;i++) {
84 if (in->index[i]==index) return;
85 }
86 /* index could not be found */
87 if (in->n==INDEXLIST_LENGTH) {
88 /* if in->index is full check the extension */
89 if (in->extension==NULL) {
90 in->extension=TMPMEMALLOC(1,Finley_IndexList);
91 if (Finley_checkPtr(in->extension)) return;
92 in->extension->n=0;
93 in->extension->extension=NULL;
94 }
95 Finley_IndexList_insertIndex(in->extension,index);
96 } else {
97 /* insert index into in->index*/
98 in->index[in->n]=index;
99 in->n++;
100 }
101 }
102
103 /* counts the number of row indices in the Finley_IndexList in */
104
105 dim_t Finley_IndexList_count(Finley_IndexList* in, index_t range_min,index_t range_max) {
106 dim_t i;
107 dim_t out=0;
108 register index_t itmp;
109 if (in==NULL) {
110 return 0;
111 } else {
112 for (i=0;i<in->n;i++) {
113 itmp=in->index[i];
114 if ((itmp>=range_min) && (range_max>itmp)) ++out;
115 }
116 return out+Finley_IndexList_count(in->extension, range_min,range_max);
117 }
118 }
119
120 /* count the number of row indices in the Finley_IndexList in */
121
122 void Finley_IndexList_toArray(Finley_IndexList* in, index_t* array, index_t range_min,index_t range_max) {
123 dim_t i;
124 register index_t itmp;
125 if (in!=NULL) {
126 for (i=0;i<in->n;i++) {
127 itmp=in->index[i];
128 if ((itmp>=range_min) && (range_max>itmp)) array[i]=itmp;
129 }
130 Finley_IndexList_toArray(in->extension,&(array[in->n]), range_min, range_max);
131 }
132 }
133
134 /* deallocates the Finley_IndexList in by recursive calls */
135
136 void Finley_IndexList_free(Finley_IndexList* in) {
137 if (in!=NULL) {
138 Finley_IndexList_free(in->extension);
139 TMPMEMFREE(in);
140 }
141 }
142
143 /* creates a Paso_pattern from a range of indices */
144 Paso_Pattern* Finley_IndexList_createPattern(dim_t n,Finley_IndexList* index_list,index_t range_min,index_t range_max)
145 {
146 dim_t *ptr=NULL;
147 register dim_t s,i,itmp;
148 index_t *index=NULL;
149 Paso_Pattern* out=NULL;
150
151 ptr=MEMALLOC(n+1,index_t);
152 if (! Finley_checkPtr(ptr) ) {
153 /* get the number of connections per row */
154 #pragma omp parallel for schedule(static) private(i)
155 for(i=0;i<n;++i) {
156 ptr[i]=Finley_IndexList_count(&index_list[i],range_min,range_max);
157 }
158 /* accumulate ptr */
159 s=0;
160 for(i=0;i<n;++i) {
161 itmp=ptr[i];
162 ptr[i]=s;
163 s+=itmp;
164 }
165 ptr[n]=s;
166 /* fill index */
167 index=MEMALLOC(ptr[n],index_t);
168 if (! Finley_checkPtr(index)) {
169 #pragma omp parallel for schedule(static)
170 for(i=0;i<n;++i) Finley_IndexList_toArray(&index_list[i],&index[ptr[i]],range_min,range_max);
171
172 out=Paso_Pattern_alloc(PATTERN_FORMAT_DEFAULT,n,ptr,index);
173 }
174 }
175 if (! Finley_noError()) {
176 MEMFREE(ptr);
177 MEMFREE(index);
178 Paso_Pattern_free(out);
179 }
180 return out;
181 }
182
183 Paso_Coupler* Finley_IndexList_createCoupler(Finley_IndexList *index_list)
184 {
185 Paso_Coupler* out=NULL;
186 index_t *sharedInput=NULL, *offsetInSharedInput=NULL, *offsetInRemoteInput=NULL;
187 /*
188
189 if (! (rowMap->MPIInfo->comm == colMap->MPIInfo->comm ) ) {
190 Finley_setError(SYSTEM_ERROR,"Finley_IndexList_createCoupler: communicator for row and column DOFMap must be identical.");
191 return NULL;
192 }
193 if (! (rowMap->numNeighbours == colMap->numNeighbours ) ) {
194 Finley_setError(SYSTEM_ERROR,"Finley_IndexList_createCoupler: number of neighbours for row and column DOFMap must be identical.");
195 return NULL;
196 }
197
198
199 out=Paso_Coupler_alloc(rowMap->numNeighbours,
200 rowMap->neighbours,
201 sharedInput,
202 offsetInSharedInput,
203 offsetInRemoteInput,
204 rowMap->MPIInfo);
205 */
206 return out;
207 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26