/[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 1226 - (show annotations)
Fri Aug 3 08:00:07 2007 UTC (11 years, 8 months ago) by gross
File MIME type: text/plain
File size: 5374 byte(s)
hook for ParaMetis added. still needs some work
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
30 dim_t newGlobalNumDOFs=0;
31 Paso_MPI_rank* mpiRankOfDOF=NULL;
32 index_t* distribution=NULL;
33 if (in==NULL) return;
34 if (in->Nodes == NULL) return;
35
36 /* first step is to distribute the elements according to a global distribution of DOF */
37
38 mpiRankOfDOF=TMPMEMALLOC(in->Nodes->numNodes,Paso_MPI_rank);
39 distribution=TMPMEMALLOC(in->MPIInfo->size+1,index_t);
40 if (!(Finley_checkPtr(mpiRankOfDOF) || Finley_checkPtr(distribution))) {
41 /* first we create dense labeling for the DOFs */
42 newGlobalNumDOFs=Finley_NodeFile_createDenseDOFLabeling(in->Nodes);
43 /* create a distribution of the global DOFs and determine
44 the MPI_rank controling the DOFs on this processor */
45 Paso_MPIInfo_setDistribution(in->MPIInfo,0,newGlobalNumDOFs-1,distribution);
46 Finley_NodeFile_assignMPIRankToDOFs(in->Nodes,mpiRankOfDOF,distribution);
47
48 /* now the mesh is re-distributed according to the mpiRankOfDOF vector */
49 /* this will redistribute the Nodes and Elements including overlap and will create an element coloring
50 but will not create any mappings (see later in this function) */
51 if (Finley_noError()) Finley_Mesh_distributeByRankOfDOF(in,mpiRankOfDOF);
52 }
53 TMPMEMFREE(mpiRankOfDOF);
54
55 /* at this stage we are able to start an optimization of the DOF distribution using ParaMetis */
56 /* on return mpiRankOfDOF has been assigns a new rank to each node/DOF. It needs to include */
57 /* the overlap */
58 if (Finley_noError() && optimize && in->MPIInfo->size>1) {
59 mpiRankOfDOF=TMPMEMALLOC(in->Nodes->numNodes,Paso_MPI_rank);
60 if (!Finley_checkPtr(mpiRankOfDOF)) {
61
62 Finley_Mesh_optimizeDOFDistribution(in,distribution,mpiRankOfDOF);
63
64 if (Finley_noError()) Finley_Mesh_distributeByRankOfDOF(in,mpiRankOfDOF);
65 }
66 TMPMEMFREE(mpiRankOfDOF);
67 }
68 TMPMEMFREE(distribution);
69 /* now a local labeling of the DOF is introduced */
70 if (Finley_noError() && optimize) {
71 printf("Warning: no local node labeling optimization implemented yet.\n");
72 }
73 return;
74
75 /* set the labeling vectors in node files: */
76 Finley_Mesh_prepareNodes(in);
77
78 /* rearrange elements: */
79 Finley_Mesh_optimizeElementOrdering(in);
80 }
81
82 bool_t Finley_Mesh_isPrepared(Finley_Mesh* in) {
83 /* returns true if nodes and elements have been prepared for calculation */
84 index_t out = TRUE;
85 if ( in->Nodes != NULL) out = MIN(out , in->Nodes->isPrepared);
86 if ( in->Elements != NULL) out = MIN(out , in->Elements->isPrepared);
87 if ( in->FaceElements != NULL) out = MIN(out , in->FaceElements->isPrepared);
88 if ( in->ContactElements != NULL) out = MIN(out , in->ContactElements->isPrepared);
89 if ( in->Points != NULL) out = MIN(out , in->Points->isPrepared);
90
91 return out == FINLEY_PREPARED;
92 }
93 /* */
94 /* tries to reduce the coloring for all element files: */
95 /* */
96 void Finley_Mesh_createColoring(Finley_Mesh* in, index_t *node_localDOF_map) {
97 if (Finley_noError()) Finley_ElementFile_createColoring(in->Elements,in->Nodes->numNodes,node_localDOF_map);
98 if (Finley_noError()) Finley_ElementFile_createColoring(in->FaceElements,in->Nodes->numNodes,node_localDOF_map);
99 if (Finley_noError()) Finley_ElementFile_createColoring(in->Points,in->Nodes->numNodes,node_localDOF_map);
100 if (Finley_noError()) Finley_ElementFile_createColoring(in->ContactElements,in->Nodes->numNodes,node_localDOF_map);
101 }
102 /* */
103 /* redistribute elements to minimize communication during assemblage */
104 /* */
105 void Finley_Mesh_optimizeElementOrdering(Finley_Mesh* in) {
106 if (Finley_noError()) Finley_ElementFile_optimizeOrdering(&(in->Elements));
107 if (Finley_noError()) Finley_ElementFile_optimizeOrdering(&(in->FaceElements));
108 if (Finley_noError()) Finley_ElementFile_optimizeOrdering(&(in->Points));
109 if (Finley_noError()) Finley_ElementFile_optimizeOrdering(&(in->ContactElements));
110 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26