/[escript]/branches/trilinos_from_5897/dudley/src/Mesh_prepare.cpp
ViewVC logotype

Diff of /branches/trilinos_from_5897/dudley/src/Mesh_prepare.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 6078 by caltinay, Wed Mar 2 04:13:26 2016 UTC revision 6079 by caltinay, Mon Mar 21 12:22:38 2016 UTC
# Line 14  Line 14 
14  *  *
15  *****************************************************************************/  *****************************************************************************/
16    
 /****************************************************************************/  
   
 /*   Dudley: Mesh: prepares the mesh for further calculations  */  
   
 /****************************************************************************/  
   
17  #include "Mesh.h"  #include "Mesh.h"
18    
19  namespace dudley {  namespace dudley {
20    
21  void Dudley_Mesh_prepare(Dudley_Mesh* in, bool optimize)  /// prepares the mesh for further use
22    void Mesh::prepare(bool optimize)
23  {  {
24      dim_t newGlobalNumDOFs = 0, numReducedNodes = 0, i;      // first step is to distribute the elements according to a global
25      index_t *distribution = NULL, *maskReducedNodes = NULL, *indexReducedNodes = NULL, *node_distribution = NULL;      // distribution of DOF
26      if (in == NULL)      std::vector<index_t> distribution(MPIInfo->size+1);
27          return;  
28      if (in->Nodes == NULL)      // first we create dense labeling for the DOFs
29          return;      dim_t newGlobalNumDOFs = Nodes->createDenseDOFLabeling();
30    
31      Dudley_Mesh_setOrders(in);      // create a distribution of the global DOFs and determine the MPI rank
32        // controlling the DOFs on this processor
33      /* first step is to distribute the elements according to a global distribution of DOF */      MPIInfo->setDistribution(0, newGlobalNumDOFs - 1, &distribution[0]);
34    
35      distribution = new  index_t[in->MPIInfo->size + 1];      // now the mesh is re-distributed according to the distribution vector
36      node_distribution = new  index_t[in->MPIInfo->size + 1];      // this will redistribute the Nodes and Elements including overlap and
37      /* first we create dense labeling for the DOFs */      // will create an element colouring but will not create any mappings
38      newGlobalNumDOFs = Dudley_NodeFile_createDenseDOFLabeling(in->Nodes);      // (see later in this function)
39        distributeByRankOfDOF(distribution);
40      /* create a distribution of the global DOFs and determine  
41         the MPI_rank controlling the DOFs on this processor      */      // at this stage we are able to start an optimization of the DOF
42      in->MPIInfo->setDistribution(0, newGlobalNumDOFs - 1, distribution);      // distribution using ParaMetis. On return distribution is altered and
43        // new DOF IDs have been assigned
44      /* now the mesh is re-distributed according to the mpiRankOfDOF vector */      if (optimize && MPIInfo->size > 1) {
45      /* this will redistribute the Nodes and Elements including overlap and will create an element coloring          optimizeDOFDistribution(distribution);
46         but will not create any mappings (see later in this function) */          distributeByRankOfDOF(distribution);
     Dudley_Mesh_distributeByRankOfDOF(in, distribution);  
   
     /* at this stage we are able to start an optimization of the DOF distribution using ParaMetis */  
     /* on return distribution is altered and new DOF ids have been assigned */  
     if (optimize && in->MPIInfo->size > 1)  
     {  
         Dudley_Mesh_optimizeDOFDistribution(in, distribution);  
         Dudley_Mesh_distributeByRankOfDOF(in, distribution);  
47      }      }
48      /* the local labelling of the degrees of free is optimized */      // the local labelling of the degrees of freedom is optimized
49      if (optimize)      if (optimize) {
50          Dudley_Mesh_optimizeDOFLabeling(in, distribution);          optimizeDOFLabeling(distribution);
51        }
52      /* rearrange elements with the attempt to bring elements closer to memory locations of the nodes (distributed shared memory!): */  
53      Dudley_Mesh_optimizeElementOrdering(in);      // rearrange elements with the aim of bringing elements closer to memory
54        // locations of the nodes (distributed shared memory!):
55      /* create the global indices */      optimizeElementOrdering();
56      maskReducedNodes = new index_t[in->Nodes->numNodes];  
57      indexReducedNodes = new index_t[in->Nodes->numNodes];      // create the global indices
58        std::vector<index_t> node_distribution(MPIInfo->size + 1);
59  /* useful DEBUG:  
60  {index_t MIN_id,MAX_id;      Nodes->createDenseNodeLabeling(node_distribution, distribution);
61  printf("Mesh_prepare: global DOF : %d\n",newGlobalNumDOFs);      // create the missing mappings
62  Dudley_NodeFile_setGlobalIdRange(&MIN_id,&MAX_id,in->Nodes);      Nodes->createNodeMappings(distribution, node_distribution);
 printf("Mesh_prepare: global node id range = %d :%d\n", MIN_id,MAX_id);  
 Dudley_NodeFile_setIdRange(&MIN_id,&MAX_id,in->Nodes);  
 printf("Mesh_prepare: local node id range = %d :%d\n", MIN_id,MAX_id);  
 }  
 */  
 #pragma omp parallel for private(i) schedule(static)  
     for (i = 0; i < in->Nodes->numNodes; ++i)  
         maskReducedNodes[i] = -1;  
   
     Dudley_Mesh_markNodes(maskReducedNodes, 0, in, true);  
   
     numReducedNodes = Dudley_Util_packMask(in->Nodes->numNodes, maskReducedNodes, indexReducedNodes);  
   
     Dudley_NodeFile_createDenseNodeLabeling(in->Nodes, node_distribution, distribution);  
     Dudley_NodeFile_createDenseReducedDOFLabeling(in->Nodes, maskReducedNodes);  
     Dudley_NodeFile_createDenseReducedNodeLabeling(in->Nodes, maskReducedNodes);  
     /* create the missing mappings */  
     Dudley_Mesh_createNodeFileMappings(in, numReducedNodes, indexReducedNodes, distribution, node_distribution);  
   
     delete[] maskReducedNodes;  
     delete[] indexReducedNodes;  
     delete[] distribution;  
     delete[] node_distribution;  
63    
64      Dudley_Mesh_setTagsInUse(in);      updateTagList();
65  }  }
66    
67  /*                                                      */  /// tries to reduce the number of colours for all element files
68  /*  tries to reduce the coloring for all element files: */  void Mesh::createColoring(const index_t* node_localDOF_map)
 /*                                                      */  
 void Dudley_Mesh_createColoring(Dudley_Mesh* in, index_t* node_localDOF_map)  
69  {  {
70      Dudley_ElementFile_createColoring(in->Elements, in->Nodes->numNodes, node_localDOF_map);      Elements->createColoring(Nodes->getNumNodes(), node_localDOF_map);
71      Dudley_ElementFile_createColoring(in->FaceElements, in->Nodes->numNodes, node_localDOF_map);      FaceElements->createColoring(Nodes->getNumNodes(), node_localDOF_map);
72      Dudley_ElementFile_createColoring(in->Points, in->Nodes->numNodes, node_localDOF_map);      Points->createColoring(Nodes->getNumNodes(), node_localDOF_map);
73  }  }
74    
75  /*                                                                    */  /// redistributes elements to minimize communication during assemblage
76  /*  redistribute elements to minimize communication during assemblage */  void Mesh::optimizeElementOrdering()
 /*                                                                    */  
 void Dudley_Mesh_optimizeElementOrdering(Dudley_Mesh * in)  
77  {  {
78      Dudley_ElementFile_optimizeOrdering(&(in->Elements));      Elements->optimizeOrdering();
79      Dudley_ElementFile_optimizeOrdering(&(in->FaceElements));      FaceElements->optimizeOrdering();
80      Dudley_ElementFile_optimizeOrdering(&(in->Points));      Points->optimizeOrdering();
81  }  }
82    
83  /*                                                                    */  /// regenerates list of tags in use for node file and element files
84  /*  redistribute elements to minimize communication during assemblage */  void Mesh::updateTagList()
 void Dudley_Mesh_setTagsInUse(Dudley_Mesh * in)  
85  {  {
86      Dudley_NodeFile_setTagsInUse(in->Nodes);      Nodes->updateTagList();
87      Dudley_ElementFile_setTagsInUse(in->Elements);      Elements->updateTagList();
88      Dudley_ElementFile_setTagsInUse(in->FaceElements);      FaceElements->updateTagList();
89      Dudley_ElementFile_setTagsInUse(in->Points);      Points->updateTagList();
90  }  }
91    
92  } // namespace dudley  } // namespace dudley

Legend:
Removed from v.6078  
changed lines
  Added in v.6079

  ViewVC Help
Powered by ViewVC 1.1.26