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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1267 - (show annotations)
Tue Aug 21 22:01:21 2007 UTC (12 years, 9 months ago) by gross
File MIME type: text/plain
File size: 5436 byte(s)
check for preperation status removed. is not really needed.
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: Mesh: prepares the mesh for further calculations */
16
17 /**************************************************************/
18
19 /* Author: gross@access.edu.au */
20 /* Version: $Id$ */
21
22 /**************************************************************/
23
24 #include "Mesh.h"
25
26 /**************************************************************/
27
28 void Finley_Mesh_prepare(Finley_Mesh* in, bool_t optimize) {
29 dim_t newGlobalNumDOFs=0, numReducedNodes=0,i;
30 index_t* distribution=NULL, *maskReducedNodes=NULL, *indexReducedNodes=NULL;
31 if (in==NULL) return;
32 if (in->Nodes == NULL) return;
33
34 /* first step is to distribute the elements according to a global distribution of DOF */
35
36 distribution=TMPMEMALLOC(in->MPIInfo->size+1,index_t);
37 if (! Finley_checkPtr(distribution)) {
38 /* first we create dense labeling for the DOFs */
39 newGlobalNumDOFs=Finley_NodeFile_createDenseDOFLabeling(in->Nodes);
40
41 /* 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
45 /* 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
51 /* 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
55 Finley_Mesh_optimizeDOFDistribution(in,distribution);
56
57 if (Finley_noError()) Finley_Mesh_distributeByRankOfDOF(in,distribution);
58
59 }
60 /* now a local labeling of the DOF is introduced */
61 if (Finley_noError() && optimize) {
62 printf("Warning: no local node labeling optimization implemented yet.\n");
63 }
64 /* rearrange elements with the attempt to bring elements closer to memory locations of the nodes (distributed shared memory!): */
65 if (Finley_noError()) Finley_Mesh_optimizeElementOrdering(in);
66
67
68 /* create the global indices */
69 if (Finley_noError()) {
70 maskReducedNodes=TMPMEMALLOC(in->Nodes->numNodes,index_t);
71 indexReducedNodes=TMPMEMALLOC(in->Nodes->numNodes,index_t);
72 if (! ( Finley_checkPtr(maskReducedNodes) || Finley_checkPtr(indexReducedNodes) ) ) {
73
74
75 #pragma omp parallel for private(i) schedule(static)
76 for (i=0;i<in->Nodes->numNodes;++i) maskReducedNodes[i]=-1;
77
78 Finley_Mesh_markNodes(maskReducedNodes,0,in,1);
79
80 numReducedNodes=Finley_Util_packMask(in->Nodes->numNodes,maskReducedNodes,indexReducedNodes);
81
82 Finley_NodeFile_createDenseNodeLabeling(in->Nodes);
83 Finley_NodeFile_createDenseReducedNodeLabeling(in->Nodes,maskReducedNodes);
84 Finley_NodeFile_createDenseReducedDOFLabeling(in->Nodes,maskReducedNodes);
85 /* create the missing mappings */
86 if (Finley_noError()) Finley_Mesh_createNodeFileMappings(in,numReducedNodes,indexReducedNodes,distribution);
87 }
88
89 TMPMEMFREE(maskReducedNodes);
90 TMPMEMFREE(indexReducedNodes);
91 }
92
93 TMPMEMFREE(distribution);
94
95 return;
96 }
97
98 /* */
99 /* tries to reduce the coloring for all element files: */
100 /* */
101 void Finley_Mesh_createColoring(Finley_Mesh* in, index_t *node_localDOF_map) {
102 if (Finley_noError()) Finley_ElementFile_createColoring(in->Elements,in->Nodes->numNodes,node_localDOF_map);
103 if (Finley_noError()) Finley_ElementFile_createColoring(in->FaceElements,in->Nodes->numNodes,node_localDOF_map);
104 if (Finley_noError()) Finley_ElementFile_createColoring(in->Points,in->Nodes->numNodes,node_localDOF_map);
105 if (Finley_noError()) Finley_ElementFile_createColoring(in->ContactElements,in->Nodes->numNodes,node_localDOF_map);
106 }
107 /* */
108 /* redistribute elements to minimize communication during assemblage */
109 /* */
110 void Finley_Mesh_optimizeElementOrdering(Finley_Mesh* in) {
111 if (Finley_noError()) Finley_ElementFile_optimizeOrdering(&(in->Elements));
112 if (Finley_noError()) Finley_ElementFile_optimizeOrdering(&(in->FaceElements));
113 if (Finley_noError()) Finley_ElementFile_optimizeOrdering(&(in->Points));
114 if (Finley_noError()) Finley_ElementFile_optimizeOrdering(&(in->ContactElements));
115 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26