/[escript]/trunk/dudley/src/Mesh_prepare.c
ViewVC logotype

Contents of /trunk/dudley/src/Mesh_prepare.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4286 - (show annotations)
Thu Mar 7 04:28:11 2013 UTC (6 years, 5 months ago) by caltinay
File MIME type: text/plain
File size: 6176 byte(s)
Assorted spelling fixes.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26