/[escript]/branches/domexper/dudley/src/Mesh_prepare.c
ViewVC logotype

Contents of /branches/domexper/dudley/src/Mesh_prepare.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3247 - (show annotations)
Wed Oct 6 05:53:06 2010 UTC (8 years, 6 months ago) by caltinay
File MIME type: text/plain
File size: 5991 byte(s)
Fixed name clashes between dudley and finley so both can be used
simultaneously.

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 /* Dudley: Mesh: prepares the mesh for further calculations */
17
18 /**************************************************************/
19
20 #include "Mesh.h"
21
22 /**************************************************************/
23
24 void Dudley_Mesh_prepare(Dudley_Mesh * in, bool_t optimize)
25 {
26 dim_t newGlobalNumDOFs = 0, numReducedNodes = 0, i;
27 index_t *distribution = NULL, *maskReducedNodes = NULL, *indexReducedNodes = NULL, *node_distribution = NULL;
28 if (in == NULL)
29 return;
30 if (in->Nodes == NULL)
31 return;
32
33 Dudley_Mesh_setOrders(in);
34
35 /* first step is to distribute the elements according to a global distribution of DOF */
36
37 distribution = TMPMEMALLOC(in->MPIInfo->size + 1, index_t);
38 node_distribution = TMPMEMALLOC(in->MPIInfo->size + 1, index_t);
39 if (!(Dudley_checkPtr(distribution) || Dudley_checkPtr(node_distribution)))
40 {
41 /* first we create dense labeling for the DOFs */
42
43 newGlobalNumDOFs = Dudley_NodeFile_createDenseDOFLabeling(in->Nodes);
44
45 /* create a distribution of the global DOFs and determine
46 the MPI_rank controling the DOFs on this processor */
47 Esys_MPIInfo_setDistribution(in->MPIInfo, 0, newGlobalNumDOFs - 1, distribution);
48
49 /* now the mesh is re-distributed according to the mpiRankOfDOF vector */
50 /* this will redistribute the Nodes and Elements including overlap and will create an element coloring
51 but will not create any mappings (see later in this function) */
52 if (Dudley_noError())
53 Dudley_Mesh_distributeByRankOfDOF(in, distribution);
54 }
55
56 /* at this stage we are able to start an optimization of the DOF distribution using ParaMetis */
57 /* on return distribution is altered and new DOF ids have been assigned */
58 if (Dudley_noError() && optimize && in->MPIInfo->size > 1)
59 {
60 Dudley_Mesh_optimizeDOFDistribution(in, distribution);
61 if (Dudley_noError())
62 Dudley_Mesh_distributeByRankOfDOF(in, distribution);
63 }
64 /* the local labeling of the degrees of free is optimized */
65 if (Dudley_noError() && optimize)
66 {
67 Dudley_Mesh_optimizeDOFLabeling(in, distribution);
68 }
69 /* rearrange elements with the attempt to bring elements closer to memory locations of the nodes (distributed shared memory!): */
70 if (Dudley_noError())
71 Dudley_Mesh_optimizeElementOrdering(in);
72
73 /* create the global indices */
74 if (Dudley_noError())
75 {
76
77 maskReducedNodes = TMPMEMALLOC(in->Nodes->numNodes, index_t);
78 indexReducedNodes = TMPMEMALLOC(in->Nodes->numNodes, index_t);
79 if (!(Dudley_checkPtr(maskReducedNodes) || Dudley_checkPtr(indexReducedNodes)))
80 {
81
82 /* useful DEBUG:
83 {index_t MIN_id,MAX_id;
84 printf("Mesh_prepare: global DOF : %d\n",newGlobalNumDOFs);
85 Dudley_NodeFile_setGlobalIdRange(&MIN_id,&MAX_id,in->Nodes);
86 printf("Mesh_prepare: global node id range = %d :%d\n", MIN_id,MAX_id);
87 Dudley_NodeFile_setIdRange(&MIN_id,&MAX_id,in->Nodes);
88 printf("Mesh_prepare: local node id range = %d :%d\n", MIN_id,MAX_id);
89 }
90 */
91 #pragma omp parallel for private(i) schedule(static)
92 for (i = 0; i < in->Nodes->numNodes; ++i)
93 maskReducedNodes[i] = -1;
94
95 Dudley_Mesh_markNodes(maskReducedNodes, 0, in, TRUE);
96
97 numReducedNodes = Dudley_Util_packMask(in->Nodes->numNodes, maskReducedNodes, indexReducedNodes);
98
99 Dudley_NodeFile_createDenseNodeLabeling(in->Nodes, node_distribution, distribution);
100 Dudley_NodeFile_createDenseReducedDOFLabeling(in->Nodes, maskReducedNodes);
101 Dudley_NodeFile_createDenseReducedNodeLabeling(in->Nodes, maskReducedNodes);
102 /* create the missing mappings */
103
104 if (Dudley_noError())
105 Dudley_Mesh_createNodeFileMappings(in, numReducedNodes, indexReducedNodes, distribution,
106 node_distribution);
107 }
108
109 TMPMEMFREE(maskReducedNodes);
110 TMPMEMFREE(indexReducedNodes);
111 }
112
113 TMPMEMFREE(distribution);
114 TMPMEMFREE(node_distribution);
115
116 Dudley_Mesh_setTagsInUse(in);
117 return;
118 }
119
120 /* */
121 /* tries to reduce the coloring for all element files: */
122 /* */
123 void Dudley_Mesh_createColoring(Dudley_Mesh * in, index_t * node_localDOF_map)
124 {
125 if (Dudley_noError())
126 Dudley_ElementFile_createColoring(in->Elements, in->Nodes->numNodes, node_localDOF_map);
127 if (Dudley_noError())
128 Dudley_ElementFile_createColoring(in->FaceElements, in->Nodes->numNodes, node_localDOF_map);
129 if (Dudley_noError())
130 Dudley_ElementFile_createColoring(in->Points, in->Nodes->numNodes, node_localDOF_map);
131 }
132
133 /* */
134 /* redistribute elements to minimize communication during assemblage */
135 /* */
136 void Dudley_Mesh_optimizeElementOrdering(Dudley_Mesh * in)
137 {
138 if (Dudley_noError())
139 Dudley_ElementFile_optimizeOrdering(&(in->Elements));
140 if (Dudley_noError())
141 Dudley_ElementFile_optimizeOrdering(&(in->FaceElements));
142 if (Dudley_noError())
143 Dudley_ElementFile_optimizeOrdering(&(in->Points));
144 }
145
146 /* */
147 /* redistribute elements to minimize communication during assemblage */
148 void Dudley_Mesh_setTagsInUse(Dudley_Mesh * in)
149 {
150 if (Dudley_noError())
151 Dudley_NodeFile_setTagsInUse(in->Nodes);
152 if (Dudley_noError())
153 Dudley_ElementFile_setTagsInUse(in->Elements);
154 if (Dudley_noError())
155 Dudley_ElementFile_setTagsInUse(in->FaceElements);
156 if (Dudley_noError())
157 Dudley_ElementFile_setTagsInUse(in->Points);
158 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26