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

Annotation of /trunk/finley/src/Mesh_prepare.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1766 - (hide annotations)
Mon Sep 8 02:51:14 2008 UTC (11 years, 1 month ago) by gross
File MIME type: text/plain
File size: 6355 byte(s)
code formatting
1 jgs 150
2 ksteube 1312 /* $Id$ */
3 jgs 82
4 ksteube 1312 /*******************************************************
5     *
6     * Copyright 2003-2007 by ACceSS MNRF
7     * Copyright 2007 by University of Queensland
8     *
9     * http://esscc.uq.edu.au
10     * Primary Business: Queensland, Australia
11     * Licensed under the Open Software License version 3.0
12     * http://www.opensource.org/licenses/osl-3.0.php
13     *
14     *******************************************************/
15 jgs 82
16     /**************************************************************/
17    
18 ksteube 1312 /* Finley: Mesh: prepares the mesh for further calculations */
19 jgs 82
20     /**************************************************************/
21    
22     #include "Mesh.h"
23    
24     /**************************************************************/
25    
26 ksteube 1312 void Finley_Mesh_prepare(Finley_Mesh* in, bool_t optimize) {
27     dim_t newGlobalNumDOFs=0, numReducedNodes=0,i;
28 gross 1749 index_t* distribution=NULL, *maskReducedNodes=NULL, *indexReducedNodes=NULL, *node_distribution=NULL;
29 ksteube 1312 if (in==NULL) return;
30     if (in->Nodes == NULL) return;
31 jgs 82
32 ksteube 1312 /* first step is to distribute the elements according to a global distribution of DOF */
33 jgs 82
34 ksteube 1312 distribution=TMPMEMALLOC(in->MPIInfo->size+1,index_t);
35 gross 1749 node_distribution=TMPMEMALLOC(in->MPIInfo->size+1,index_t);
36     if (! (Finley_checkPtr(distribution) || Finley_checkPtr(node_distribution))) {
37 ksteube 1312 /* first we create dense labeling for the DOFs */
38 gross 1766
39 ksteube 1312 newGlobalNumDOFs=Finley_NodeFile_createDenseDOFLabeling(in->Nodes);
40 jgs 82
41 ksteube 1312 /* create a distribution of the global DOFs and determine
42     the MPI_rank controling the DOFs on this processor */
43     Paso_MPIInfo_setDistribution(in->MPIInfo,0,newGlobalNumDOFs-1,distribution);
44 gross 964
45 ksteube 1312 /* now the mesh is re-distributed according to the mpiRankOfDOF vector */
46     /* this will redistribute the Nodes and Elements including overlap and will create an element coloring
47     but will not create any mappings (see later in this function) */
48     if (Finley_noError()) Finley_Mesh_distributeByRankOfDOF(in,distribution);
49     }
50 gross 964
51 ksteube 1312 /* at this stage we are able to start an optimization of the DOF distribution using ParaMetis */
52     /* on return distribution is altered and new DOF ids have been assigned */
53     if (Finley_noError() && optimize && in->MPIInfo->size>1) {
54 gross 1766 Finley_Mesh_optimizeDOFDistribution(in,distribution);
55 ksteube 1312 if (Finley_noError()) Finley_Mesh_distributeByRankOfDOF(in,distribution);
56     }
57 gross 1766 /* the local labeling of the degrees of free is optimized */
58 ksteube 1312 if (Finley_noError() && optimize) {
59     Finley_Mesh_optimizeDOFLabeling(in,distribution);
60     }
61     /* rearrange elements with the attempt to bring elements closer to memory locations of the nodes (distributed shared memory!): */
62     if (Finley_noError()) Finley_Mesh_optimizeElementOrdering(in);
63    
64    
65     /* create the global indices */
66     if (Finley_noError()) {
67 gross 1766
68    
69 ksteube 1312 maskReducedNodes=TMPMEMALLOC(in->Nodes->numNodes,index_t);
70     indexReducedNodes=TMPMEMALLOC(in->Nodes->numNodes,index_t);
71     if (! ( Finley_checkPtr(maskReducedNodes) || Finley_checkPtr(indexReducedNodes) ) ) {
72    
73 gross 1766 /* useful DEBUG:
74     {index_t MIN_id,MAX_id;
75     printf("Mesh_prepare: global DOF : %d\n",newGlobalNumDOFs);
76     Finley_NodeFile_setGlobalIdRange(&MIN_id,&MAX_id,in->Nodes);
77     printf("Mesh_prepare: global node id range = %d :%d\n", MIN_id,MAX_id);
78     Finley_NodeFile_setIdRange(&MIN_id,&MAX_id,in->Nodes);
79     printf("Mesh_prepare: local node id range = %d :%d\n", MIN_id,MAX_id);
80     }
81     */
82 ksteube 1312 #pragma omp parallel for private(i) schedule(static)
83     for (i=0;i<in->Nodes->numNodes;++i) maskReducedNodes[i]=-1;
84    
85 gross 1766 Finley_Mesh_markNodes(maskReducedNodes,0,in,TRUE);
86 ksteube 1312
87     numReducedNodes=Finley_Util_packMask(in->Nodes->numNodes,maskReducedNodes,indexReducedNodes);
88    
89 gross 1749 Finley_NodeFile_createDenseNodeLabeling(in->Nodes, node_distribution, distribution);
90 ksteube 1312 Finley_NodeFile_createDenseReducedDOFLabeling(in->Nodes,maskReducedNodes);
91 gross 1749 Finley_NodeFile_createDenseReducedNodeLabeling(in->Nodes,maskReducedNodes);
92 ksteube 1312 /* create the missing mappings */
93 gross 1766
94 gross 1749 if (Finley_noError()) Finley_Mesh_createNodeFileMappings(in,numReducedNodes,indexReducedNodes,distribution, node_distribution);
95 ksteube 1312 }
96    
97     TMPMEMFREE(maskReducedNodes);
98     TMPMEMFREE(indexReducedNodes);
99     }
100    
101     TMPMEMFREE(distribution);
102 gross 1749 TMPMEMFREE(node_distribution);
103 ksteube 1312
104 gross 1716 Finley_Mesh_setTagsInUse(in);
105 ksteube 1312 return;
106 gross 964 }
107 ksteube 1312
108 jgs 82 /* */
109     /* tries to reduce the coloring for all element files: */
110     /* */
111 ksteube 1312 void Finley_Mesh_createColoring(Finley_Mesh* in, index_t *node_localDOF_map) {
112     if (Finley_noError()) Finley_ElementFile_createColoring(in->Elements,in->Nodes->numNodes,node_localDOF_map);
113     if (Finley_noError()) Finley_ElementFile_createColoring(in->FaceElements,in->Nodes->numNodes,node_localDOF_map);
114     if (Finley_noError()) Finley_ElementFile_createColoring(in->Points,in->Nodes->numNodes,node_localDOF_map);
115     if (Finley_noError()) Finley_ElementFile_createColoring(in->ContactElements,in->Nodes->numNodes,node_localDOF_map);
116 jgs 82 }
117     /* */
118     /* redistribute elements to minimize communication during assemblage */
119     /* */
120 ksteube 1312 void Finley_Mesh_optimizeElementOrdering(Finley_Mesh* in) {
121     if (Finley_noError()) Finley_ElementFile_optimizeOrdering(&(in->Elements));
122     if (Finley_noError()) Finley_ElementFile_optimizeOrdering(&(in->FaceElements));
123     if (Finley_noError()) Finley_ElementFile_optimizeOrdering(&(in->Points));
124     if (Finley_noError()) Finley_ElementFile_optimizeOrdering(&(in->ContactElements));
125 jgs 82 }
126 gross 1716
127     /* */
128     /* redistribute elements to minimize communication during assemblage */
129     void Finley_Mesh_setTagsInUse(Finley_Mesh* in)
130     {
131     if (Finley_noError()) Finley_NodeFile_setTagsInUse(in->Nodes);
132     if (Finley_noError()) Finley_ElementFile_setTagsInUse(in->Elements);
133     if (Finley_noError()) Finley_ElementFile_setTagsInUse(in->FaceElements);
134     if (Finley_noError()) Finley_ElementFile_setTagsInUse(in->Points);
135     if (Finley_noError()) Finley_ElementFile_setTagsInUse(in->ContactElements);
136     }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26