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

Diff of /branches/trilinos_from_5897/dudley/src/Mesh_distributeByRankOfDOF.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: this will redistribute the Nodes and Elements including overlap */  
 /* according to the dof_distribution. It will create an element coloring but will not create any mappings. */  
   
 /****************************************************************************/  
   
17  #include "Mesh.h"  #include "Mesh.h"
18    
19  namespace dudley {  namespace dudley {
20    
21  void Dudley_Mesh_distributeByRankOfDOF(Dudley_Mesh* self, index_t* dof_distribution)  /// redistributes the Nodes and Elements including overlap
22    /// according to the DOF distribution. It will create an element colouring
23    /// but will not create any mappings.
24    void Mesh::distributeByRankOfDOF(const std::vector<index_t>& dofDistribution)
25  {  {
26      if (self == NULL)      const dim_t numNodes = Nodes->getNumNodes();
27          return;      int* mpiRankOfDOF = new int[numNodes];
28        Nodes->assignMPIRankToDOFs(mpiRankOfDOF, dofDistribution);
29    
30        // first, the elements are redistributed according to mpiRankOfDOF
31        // at the input the Node tables refer to a the local labeling of the nodes
32        // while at the output they refer to the global labeling which is rectified
33        // in the next step
34        Elements->distributeByRankOfDOF(mpiRankOfDOF, Nodes->Id);
35        FaceElements->distributeByRankOfDOF(mpiRankOfDOF, Nodes->Id);
36        Points->distributeByRankOfDOF(mpiRankOfDOF, Nodes->Id);
37    
38        resolveNodeIds();
39    
40        // create a local labeling of the DOFs
41        const std::pair<index_t,index_t> dofRange(Nodes->getDOFRange());
42        const dim_t len = dofRange.second - dofRange.first + 1;
43        // local mask for used nodes
44        index_t* localDOF_mask = new index_t[len];
45        index_t* localDOF_map = new index_t[numNodes];
46    
47    #pragma omp parallel for
48        for (index_t n = 0; n < len; n++)
49            localDOF_mask[n] = -1;
50    
51    #pragma omp parallel for
52        for (index_t n = 0; n < numNodes; n++)
53            localDOF_map[n] = -1;
54    
55      index_t min_dof_id, max_dof_id, *tmp_node_localDOF_map = NULL, *tmp_node_localDOF_mask = NULL;  #pragma omp parallel for
56      index_t k;      for (index_t n = 0; n < numNodes; n++) {
     dim_t len, n, numDOFs;  
   
     int* mpiRankOfDOF = new int[self->Nodes->numNodes];  
   
     Dudley_NodeFile_assignMPIRankToDOFs(self->Nodes, mpiRankOfDOF, dof_distribution);  
   
     /* first the elements are redistributed according to mpiRankOfDOF */  
     /* at the input the Node tables refering to a the local labeling of the nodes */  
     /* while at the output they refer to the global labeling which is rectified in the next step */  
     Dudley_ElementFile_distributeByRankOfDOF(self->Elements, mpiRankOfDOF, self->Nodes->Id);  
     Dudley_ElementFile_distributeByRankOfDOF(self->FaceElements, mpiRankOfDOF, self->Nodes->Id);  
     Dudley_ElementFile_distributeByRankOfDOF(self->Points, mpiRankOfDOF, self->Nodes->Id);  
   
     Dudley_Mesh_resolveNodeIds(self);  
   
     /* create a local labeling of the DOFs */  
     Dudley_NodeFile_setDOFRange(&min_dof_id, &max_dof_id, self->Nodes);  
     len = max_dof_id - min_dof_id + 1;  
     tmp_node_localDOF_mask = new  index_t[len];     /* local mask for used nodes */  
     tmp_node_localDOF_map = new  index_t[self->Nodes->numNodes];  
   
 #pragma omp parallel for private(n) schedule(static)  
     for (n = 0; n < len; n++)  
         tmp_node_localDOF_mask[n] = -1;  
   
 #pragma omp parallel for private (n) schedule(static)  
     for (n = 0; n < self->Nodes->numNodes; n++)  
         tmp_node_localDOF_map[n] = -1;  
   
 #pragma omp parallel for private(n) schedule(static)  
     for (n = 0; n < self->Nodes->numNodes; n++)  
     {  
57  #ifdef BOUNDS_CHECK  #ifdef BOUNDS_CHECK
58          if ((self->Nodes->globalDegreesOfFreedom[n] - min_dof_id) >= len          if ((Nodes->globalDegreesOfFreedom[n] - dofRange.first) >= len
59              || (self->Nodes->globalDegreesOfFreedom[n] - min_dof_id) < 0)              || (Nodes->globalDegreesOfFreedom[n] - dofRange.first) < 0) {
         {  
60              printf("BOUNDS_CHECK %s %d\n", __FILE__, __LINE__);              printf("BOUNDS_CHECK %s %d\n", __FILE__, __LINE__);
61              exit(1);              exit(1);
62          }          }
63  #endif  #endif
64          tmp_node_localDOF_mask[self->Nodes->globalDegreesOfFreedom[n] - min_dof_id] = n;          localDOF_mask[Nodes->globalDegreesOfFreedom[n] - dofRange.first] = n;
65      }      }
66    
67      numDOFs = 0;      dim_t numDOFs = 0;
68      for (n = 0; n < len; n++)      for (index_t n = 0; n < len; n++) {
69      {          const index_t k = localDOF_mask[n];
70          k = tmp_node_localDOF_mask[n];          if (k >= 0) {
71          if (k >= 0)              localDOF_mask[n] = numDOFs;
         {  
             tmp_node_localDOF_mask[n] = numDOFs;  
72              numDOFs++;              numDOFs++;
73          }          }
74      }      }
75  #pragma omp parallel for private (n,k)  #pragma omp parallel for
76      for (n = 0; n < self->Nodes->numNodes; n++)      for (index_t n = 0; n < numNodes; n++) {
77      {          localDOF_map[n] = localDOF_mask[
78          k = tmp_node_localDOF_mask[self->Nodes->globalDegreesOfFreedom[n] - min_dof_id];                              Nodes->globalDegreesOfFreedom[n] - dofRange.first];
         tmp_node_localDOF_map[n] = k;  
79      }      }
80      /* create element coloring */      // create element coloring
81      Dudley_Mesh_createColoring(self, tmp_node_localDOF_map);      createColoring(localDOF_map);
82    
83      delete[] tmp_node_localDOF_mask;      delete[] localDOF_mask;
84      delete[] tmp_node_localDOF_map;      delete[] localDOF_map;
85      delete[] mpiRankOfDOF;      delete[] mpiRankOfDOF;
86  }  }
87    

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

  ViewVC Help
Powered by ViewVC 1.1.26