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

Contents of /trunk-mpi-branch/finley/src/Mesh_createNodeFileMappings.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1272 - (show annotations)
Fri Aug 24 00:40:43 2007 UTC (12 years, 1 month ago) by gross
File MIME type: text/plain
File size: 15884 byte(s)
some bugs in the node-node interpolation fixed
1 /*
2 ************************************************************
3 * Copyright 2007 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: NodeFile : creates the mappings using the indexReducedNodes */
16 /* no distribution is happening */
17
18 /**************************************************************/
19
20 /* Author: gross@access.edu.au */
21 /* Version: $Id:$ */
22
23 /**************************************************************/
24
25 #include "Mesh.h"
26 #define UNUSED -1
27
28 /**************************************************************/
29
30 void Mesh_createDOFMappingAndCoupling(Finley_Mesh* in, bool_t use_reduced_elements)
31 {
32 index_t min_DOF, max_DOF, *shared=NULL, *offsetInShared=NULL, *locDOFMask=NULL, i, k, myFirstDOF, myLastDOF, *nodeMask=NULL, firstDOF, lastDOF, *globalDOFIndex;
33 dim_t mpiSize, len_loc_dof, numNeighbors, n, lastn, numNodes;
34 Paso_MPI_rank myRank,p,p_min,p_max, *neighbor=NULL;
35 Paso_SharedComponents *rcv_shcomp=NULL, *snd_shcomp=NULL;
36 Finley_NodeMapping *this_mapping=NULL;
37 Paso_Coupler* this_coupler=NULL;
38 Paso_Distribution* dof_distribution;
39
40 numNodes=in->Nodes->numNodes;
41 if (use_reduced_elements) {
42 dof_distribution=in->Nodes->reducedDegreesOfFreedomDistribution;
43 globalDOFIndex=in->Nodes->globalReducedDOFIndex;
44 Finley_NodeFile_setReducedDOFRange(&min_DOF, &max_DOF,in->Nodes);
45 } else {
46 dof_distribution=in->Nodes->degreesOfFreedomDistribution;
47 globalDOFIndex=in->Nodes->globalDegreesOfFreedom;
48 Finley_NodeFile_setDOFRange(&min_DOF, &max_DOF,in->Nodes);
49 }
50
51 mpiSize=dof_distribution->mpi_info->size;
52 myRank=dof_distribution->mpi_info->rank;
53
54 min_DOF=Finley_Util_getFlaggedMinInt(1,numNodes,globalDOFIndex,-1);
55 max_DOF=Finley_Util_getFlaggedMaxInt(1,numNodes,globalDOFIndex,-1);
56
57 len_loc_dof=max_DOF-min_DOF+1;
58
59 p_min=mpiSize;
60 p_max=-1;
61
62 for (p=0; p<mpiSize; ++p) {
63 if (dof_distribution->first_component[p]<=min_DOF) p_min=p;
64 if (dof_distribution->first_component[p]<=max_DOF) p_max=p;
65 }
66
67 myFirstDOF=Paso_Distribution_getFirstComponent(dof_distribution);
68 myLastDOF=Paso_Distribution_getLastComponent(dof_distribution);
69
70
71 nodeMask=TMPMEMALLOC(numNodes,index_t);
72 neighbor=TMPMEMALLOC(mpiSize,Paso_MPI_rank);
73 shared=TMPMEMALLOC(numNodes*(p_max-p_min+1),index_t);
74 offsetInShared=TMPMEMALLOC(mpiSize+1,index_t);
75 locDOFMask=TMPMEMALLOC(len_loc_dof, index_t);
76 if (! ( Finley_checkPtr(neighbor) || Finley_checkPtr(shared) || Finley_checkPtr(offsetInShared) || Finley_checkPtr(locDOFMask) || Finley_checkPtr(nodeMask) )) {
77
78
79 #pragma omp parallel for private(i) schedule(static)
80 for (i=0;i<len_loc_dof;++i) locDOFMask[i]=UNUSED;
81 #pragma omp parallel for private(i) schedule(static)
82 for (i=0;i<numNodes;++i) nodeMask[i]=UNUSED;
83
84 for (i=0;i<numNodes;++i) {
85 k=globalDOFIndex[i];
86 #ifdef BOUNDS_CHECK
87 if ((k-min_DOF) >= len_loc_dof) { printf("BOUNDS_CHECK %s:%i i=%i k=%i min_DOF=%i\n", __FILE__, __LINE__, i, k, min_DOF); exit(1); }
88 #endif
89 if (k>-1) locDOFMask[k-min_DOF]=UNUSED-1;
90 }
91 for (i=myFirstDOF-min_DOF;i<myLastDOF-min_DOF;++i) {
92 #ifdef BOUNDS_CHECK
93 if (i < 0 || i >= len_loc_dof) { printf("BOUNDS_CHECK %s:%i i=%i\n", __FILE__, __LINE__, i); exit(1); }
94 #endif
95 locDOFMask[i]=i-myFirstDOF+min_DOF;
96 }
97
98 numNeighbors=0;
99 n=0;
100 lastn=n;
101 for (p=p_min;p<=p_max;++p) {
102 firstDOF=dof_distribution->first_component[p];
103 lastDOF=dof_distribution->first_component[p+1];
104 if (p != myRank) {
105 for (i=firstDOF-min_DOF;i<lastDOF-min_DOF;++i) {
106 if (locDOFMask[i] == UNUSED-1) {
107 #ifdef BOUNDS_CHECK
108 if (i < 0 || i >= len_loc_dof) { printf("BOUNDS_CHECK %s:%i p=%i i=%i\n", __FILE__, __LINE__, p, i); exit(1); }
109 #endif
110 locDOFMask[i]=myLastDOF-myFirstDOF+n;
111 ++n;
112 }
113 }
114 if (n>lastn) {
115 neighbor[numNeighbors]=p;
116 #ifdef BOUNDS_CHECK
117 if (numNeighbors < 0 || numNeighbors >= mpiSize+1) { printf("BOUNDS_CHECK %s:%i p=%i numNeighbors=%i n=%i\n", __FILE__, __LINE__, p, numNeighbors, n); exit(1); }
118 #endif
119 offsetInShared[numNeighbors]=lastn;
120 numNeighbors++;
121 lastn=n;
122 }
123 }
124 }
125 #ifdef BOUNDS_CHECK
126 if (numNeighbors < 0 || numNeighbors >= mpiSize+1) { printf("BOUNDS_CHECK %s:%i numNeighbors=%i\n", __FILE__, __LINE__, numNeighbors); exit(1); }
127 #endif
128 offsetInShared[numNeighbors]=lastn;
129
130 /* assign new DOF labels to nodes */
131 #pragma omp parallel for private(i) schedule(static)
132 for (i=0;i<numNodes;++i) {
133 k=globalDOFIndex[i];
134 if (k>-1) nodeMask[i]=locDOFMask[k-min_DOF];
135 }
136
137 /* now we can set the mapping from nodes to local DOFs */
138 this_mapping=Finley_NodeMapping_alloc(numNodes,nodeMask,UNUSED);
139
140 /* define how to get DOF values for controlled bu other processors */
141 #pragma omp parallel for private(i) schedule(static)
142 #ifdef BOUNDS_CHECK
143 for (i=0;i<offsetInShared[numNeighbors];++i) {
144 if (i < 0 || i >= numNodes*(p_max-p_min+1)) { printf("BOUNDS_CHECK %s:%i i=%i\n", __FILE__, __LINE__, i); exit(1); }
145 }
146 #endif
147 for (i=0;i<offsetInShared[numNeighbors];++i) shared[i]=myLastDOF-myFirstDOF+i;
148
149 rcv_shcomp=Paso_SharedComponents_alloc(numNeighbors,neighbor,shared,offsetInShared,1,0,dof_distribution->mpi_info);
150
151 /* now it is determined which DOFs needs to be send off:*/
152 #pragma omp parallel for private(i) schedule(static)
153 for (i=0;i<len_loc_dof;++i) locDOFMask[i]=UNUSED;
154 n=0;
155 numNeighbors=0;
156 lastn=n;
157 for (p=p_min;p<=p_max;++p) {
158 firstDOF=dof_distribution->first_component[p];
159 lastDOF=dof_distribution->first_component[p+1];
160 if (p != myRank) {
161 /* mark a DOF by p if it will be requested by processor p */
162 Finley_Mesh_markDOFsConnectedToRange(locDOFMask,min_DOF,p,firstDOF,lastDOF,in,use_reduced_elements);
163
164 for (i=myFirstDOF-min_DOF;i<myLastDOF-min_DOF;++i) {
165 if (locDOFMask[i] == p) {
166 #ifdef BOUNDS_CHECK
167 if (n < 0 || n >= numNodes*(p_max-p_min+1)) { printf("BOUNDS_CHECK %s:%i p=%i i=%i n=%i\n", __FILE__, __LINE__, p, i, n); exit(1); }
168 #endif
169 shared[n]=i-myFirstDOF+min_DOF;
170 ++n;
171 }
172 }
173 if (n>lastn) {
174 neighbor[numNeighbors]=p;
175 #ifdef BOUNDS_CHECK
176 if (numNeighbors < 0 || numNeighbors >= mpiSize+1) { printf("BOUNDS_CHECK %s:%i p=%i n=%i numNeighbors=%i\n", __FILE__, __LINE__, p, n, numNeighbors); exit(1); }
177 #endif
178 offsetInShared[numNeighbors]=lastn;
179 numNeighbors++;
180 lastn=n;
181 }
182 }
183 }
184 #ifdef BOUNDS_CHECK
185 if (numNeighbors < 0 || numNeighbors >= mpiSize+1) { printf("BOUNDS_CHECK %s:%i numNeighbors=%i\n", __FILE__, __LINE__, numNeighbors); exit(1); }
186 #endif
187 offsetInShared[numNeighbors]=lastn;
188 snd_shcomp=Paso_SharedComponents_alloc(numNeighbors,neighbor,shared,offsetInShared,1,0,dof_distribution->mpi_info);
189
190 if (Finley_noError()) this_coupler=Paso_Coupler_alloc(snd_shcomp,rcv_shcomp);
191 /* assign new DOF labels to nodes */
192 Paso_SharedComponents_free(rcv_shcomp);
193 Paso_SharedComponents_free(snd_shcomp);
194 }
195 TMPMEMFREE(nodeMask);
196 TMPMEMFREE(neighbor);
197 TMPMEMFREE(shared);
198 TMPMEMFREE(offsetInShared);
199 TMPMEMFREE(locDOFMask);
200 if (Finley_noError()) {
201 if (use_reduced_elements) {
202 in->Nodes->reducedDegreesOfFreedomMapping=this_mapping;
203 in->Nodes->reducedDegreesOfFreedomCoupler=this_coupler;
204 } else {
205 in->Nodes->degreesOfFreedomMapping=this_mapping;
206 in->Nodes->degreesOfFreedomCoupler=this_coupler;
207 }
208 } else {
209
210 Finley_NodeMapping_free(this_mapping);
211 Paso_Coupler_free(this_coupler);
212
213 }
214
215 }
216 void Finley_Mesh_createNodeFileMappings(Finley_Mesh* in, dim_t numReducedNodes, index_t* indexReducedNodes, index_t* dof_first_component) {
217
218
219 index_t myFirstDOF, myLastDOF, myFirstNode, myLastNode, *reduced_dof_first_component=NULL, *nodeMask=NULL,
220 *reduced_nodes_first_component=NULL, *nodes_first_component=NULL,k,
221 *maskMyReducedDOF=NULL, *indexMyReducedDOF=NULL, *maskMyReducedNodes=NULL, *indexMyReducedNodes=NULL;
222 dim_t myNumDOF, myNumNodes, myNumReducedNodes, myNumReducedDOF, globalNumReducedNodes, globalNumReducedDOF,i,mpiSize, globalNumNodes, n, lastn,n0, numNeighbors;
223 Paso_MPI_rank myRank;
224
225 mpiSize=in->Nodes->MPIInfo->size;
226 myRank=in->Nodes->MPIInfo->rank;
227 /* mark the nodes used by the reduced mesh */
228
229 reduced_dof_first_component=TMPMEMALLOC(mpiSize+1,index_t);
230 reduced_nodes_first_component=TMPMEMALLOC(mpiSize+1,index_t);
231 nodes_first_component=TMPMEMALLOC(mpiSize+1,index_t);
232
233 if (! ( Finley_checkPtr(reduced_dof_first_component) || Finley_checkPtr(reduced_nodes_first_component) || Finley_checkPtr(nodes_first_component) ) ) {
234
235 globalNumNodes=Finley_NodeFile_maxGlobalNodeIDIndex(in->Nodes)+1;
236 Paso_MPIInfo_setDistribution(in->Nodes->MPIInfo,0,globalNumNodes-1,nodes_first_component);
237
238 myFirstDOF=dof_first_component[myRank];
239 myLastDOF=dof_first_component[myRank+1];
240 myNumDOF=myLastDOF-myFirstDOF;
241 myFirstNode=nodes_first_component[myRank];
242 myLastNode=nodes_first_component[myRank+1];
243 myNumNodes=myLastNode-myFirstNode;
244
245 maskMyReducedDOF=TMPMEMALLOC(myNumDOF,index_t);
246 indexMyReducedDOF=TMPMEMALLOC(myNumDOF,index_t);
247 maskMyReducedNodes=TMPMEMALLOC(myNumNodes,index_t);
248 indexMyReducedNodes=TMPMEMALLOC(myNumNodes,index_t);
249
250 if (! ( Finley_checkPtr(maskMyReducedDOF) || Finley_checkPtr(indexMyReducedDOF) || Finley_checkPtr(maskMyReducedNodes) || Finley_checkPtr(indexMyReducedNodes) ) ) {
251
252 #pragma omp parallel private(i)
253 {
254 #pragma omp for schedule(static)
255 for (i=0;i<myNumNodes;++i) maskMyReducedNodes[i]=-1;
256 #pragma omp for schedule(static)
257 for (i=0;i<myNumDOF;++i) maskMyReducedDOF[i]=-1;
258 #pragma omp for private(k) schedule(static)
259 for (i=0;i<numReducedNodes;++i) {
260 k=in->Nodes->globalNodesIndex[indexReducedNodes[i]];
261 if ( (k>=myFirstNode) && (myLastNode>k) ) maskMyReducedNodes[k-myFirstNode]=i;
262 k=in->Nodes->globalDegreesOfFreedom[indexReducedNodes[i]];
263 if ( (k>=myFirstDOF) && (myLastDOF>k) ) maskMyReducedDOF[k-myFirstDOF]=i;
264 }
265 }
266 myNumReducedNodes=Finley_Util_packMask(myNumNodes,maskMyReducedNodes,indexMyReducedNodes);
267 myNumReducedDOF=Finley_Util_packMask(myNumDOF,maskMyReducedDOF,indexMyReducedDOF);
268
269 #ifdef PASO_MPI
270 MPI_Allgather(&myNumReducedNodes,1,MPI_INT,reduced_nodes_first_component,1,MPI_INT,in->Nodes->MPIInfo->comm);
271 MPI_Allgather(&myNumReducedDOF,1,MPI_INT,reduced_dof_first_component,1,MPI_INT,in->Nodes->MPIInfo->comm);
272 #else
273 reduced_nodes_first_component[0]=myNumReducedNodes;
274 reduced_dof_first_component[0]=myNumReducedDOF;
275 #endif
276 globalNumReducedNodes=0;
277 globalNumReducedDOF=0;
278 for (i=0;i<mpiSize;++i) {
279 k=reduced_nodes_first_component[i];
280 reduced_nodes_first_component[i]=globalNumReducedNodes;
281 globalNumReducedNodes+=k;
282
283 k=reduced_dof_first_component[i];
284 reduced_dof_first_component[i]=globalNumReducedDOF;
285 globalNumReducedDOF+=k;
286 }
287 reduced_nodes_first_component[mpiSize]=globalNumReducedNodes;
288 reduced_dof_first_component[mpiSize]=globalNumReducedDOF;
289 /* ==== distribution of Nodes ===============================*/
290 Paso_MPIInfo_setDistribution(in->Nodes->MPIInfo,0,globalNumNodes-1,nodes_first_component);
291 in->Nodes->nodesDistribution=Paso_Distribution_alloc(in->Nodes->MPIInfo,nodes_first_component,1,0);
292
293 /* ==== distribution of Nodes ===============================*/
294 in->Nodes->degreesOfFreedomDistribution=Paso_Distribution_alloc(in->Nodes->MPIInfo,dof_first_component,1,0);
295
296 /* ==== distribution of reduced Nodes ===============================*/
297 reduced_nodes_first_component[mpiSize]=globalNumReducedNodes;
298 in->Nodes->reducedNodesDistribution=Paso_Distribution_alloc(in->Nodes->MPIInfo,reduced_nodes_first_component,1,0);
299
300 /* ==== distribution of reduced DOF ===============================*/
301 in->Nodes->reducedDegreesOfFreedomDistribution=Paso_Distribution_alloc(in->Nodes->MPIInfo,reduced_dof_first_component,1,0);
302 }
303 TMPMEMFREE(maskMyReducedDOF);
304 TMPMEMFREE(indexMyReducedDOF);
305 TMPMEMFREE(maskMyReducedNodes);
306 TMPMEMFREE(indexMyReducedNodes);
307 }
308 TMPMEMFREE(reduced_dof_first_component);
309 TMPMEMFREE(reduced_nodes_first_component);
310 TMPMEMFREE(nodes_first_component);
311
312 nodeMask=TMPMEMALLOC(in->Nodes->numNodes,index_t);
313 if (! Finley_checkPtr(nodeMask) && Finley_noError()) {
314
315 /* ==== nodes mapping which is a dummy structure ======== */
316 #pragma omp parallel for private(i) schedule(static)
317 for (i=0;i<in->Nodes->numNodes;++i) nodeMask[i]=i;
318 in->Nodes->nodesMapping=Finley_NodeMapping_alloc(in->Nodes->numNodes,nodeMask,UNUSED);
319
320 /* ==== mapping between nodes and reduced nodes ========== */
321 #pragma omp parallel for private(i) schedule(static)
322 for (i=0;i<in->Nodes->numNodes;++i) nodeMask[i]=UNUSED;
323 #pragma omp parallel for private(i) schedule(static)
324 for (i=0;i<numReducedNodes;++i) nodeMask[indexReducedNodes[i]]=i;
325 in->Nodes->reducedNodesMapping=Finley_NodeMapping_alloc(in->Nodes->numNodes,nodeMask,UNUSED);
326
327 }
328 TMPMEMFREE(nodeMask);
329 /* ==== mapping between nodes and DOFs + DOF coupler ========== */
330 if ( Finley_noError()) Mesh_createDOFMappingAndCoupling(in,FALSE);
331 /* ==== mapping between nodes and reduced DOFs + reduced DOF coupler ========== */
332 if ( Finley_noError()) Mesh_createDOFMappingAndCoupling(in,TRUE);
333
334 /* get the Ids for DOFs and reduced nodes */
335 if (Finley_noError()) {
336 #pragma omp parallel private(i)
337 {
338 #pragma omp for
339 for (i=0;i<in->Nodes->reducedNodesMapping->numTargets;++i) in->Nodes->reducedNodesId[i]=in->Nodes->Id[in->Nodes->reducedNodesMapping->map[i]];
340 #pragma omp for
341 for (i=0;i<in->Nodes->degreesOfFreedomMapping->numTargets;++i) in->Nodes->degreesOfFreedomId[i]=in->Nodes->Id[in->Nodes->degreesOfFreedomMapping->map[i]];
342 #pragma omp for
343 for (i=0;i<in->Nodes->reducedDegreesOfFreedomMapping->numTargets;++i) in->Nodes->reducedDegreesOfFreedomId[i]=in->Nodes->Id[in->Nodes->reducedDegreesOfFreedomMapping->map[i]];
344 }
345 } else {
346 Finley_NodeMapping_free(in->Nodes->nodesMapping);
347 Finley_NodeMapping_free(in->Nodes->reducedNodesMapping);
348 Finley_NodeMapping_free(in->Nodes->degreesOfFreedomMapping);
349 Finley_NodeMapping_free(in->Nodes->reducedDegreesOfFreedomMapping);
350 Paso_Distribution_free(in->Nodes->nodesDistribution);
351 Paso_Distribution_free(in->Nodes->reducedNodesDistribution);
352 Paso_Distribution_free(in->Nodes->degreesOfFreedomDistribution);
353 Paso_Distribution_free(in->Nodes->reducedDegreesOfFreedomDistribution);
354 Paso_Coupler_free(in->Nodes->degreesOfFreedomCoupler);
355 Paso_Coupler_free(in->Nodes->reducedDegreesOfFreedomCoupler);
356 }
357 }
358

  ViewVC Help
Powered by ViewVC 1.1.26