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

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

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

revision 6008 by caltinay, Mon Feb 22 06:59:27 2016 UTC revision 6009 by caltinay, Wed Mar 2 04:13:26 2016 UTC
# Line 14  Line 14 
14  *  *
15  *****************************************************************************/  *****************************************************************************/
16    
17  /**********************************************************************************************/  /****************************************************************************/
18    
19  /*   Dudley: Mesh: optimizes the labeling of the DOFs on each processor */  /*   Dudley: Mesh: optimizes the labeling of the DOFs on each processor */
20    
21  /**********************************************************************************************/  /****************************************************************************/
   
 #define ESNEEDPYTHON  
 #include "esysUtils/first.h"  
22    
23  #include "Mesh.h"  #include "Mesh.h"
24  #include "IndexList.h"  #include "IndexList.h"
25    
26  #include <boost/scoped_array.hpp>  #include <boost/scoped_array.hpp>
27    
28  /************************************************************************************/  namespace dudley {
29    
30  void Dudley_Mesh_optimizeDOFLabeling(Dudley_Mesh * in, dim_t * distribution)  void Dudley_Mesh_optimizeDOFLabeling(Dudley_Mesh* in, dim_t* distribution)
31  {  {
32        if (in == NULL)
33            return;
34        if (in->Nodes == NULL)
35            return;
36    
37      index_t myFirstVertex, myLastVertex, *newGlobalDOFID = NULL, firstVertex, lastVertex;      index_t myFirstVertex, myLastVertex, *newGlobalDOFID = NULL, firstVertex, lastVertex;
38      index_t k;      index_t k;
39      dim_t mpiSize, myNumVertices, len, p, i;      dim_t mpiSize, myNumVertices, len, p, i;
40      paso::Pattern_ptr pattern;      paso::Pattern_ptr pattern;
41      Esys_MPI_rank myRank, current_rank;      int myRank, current_rank;
42  #ifdef ESYS_MPI  #ifdef ESYS_MPI
43      Esys_MPI_rank dest, source;      int dest, source;
44      MPI_Status status;      MPI_Status status;
45  #endif  #endif
46    
     if (in == NULL)  
     return;  
     if (in->Nodes == NULL)  
     return;  
   
47      myRank = in->MPIInfo->rank;      myRank = in->MPIInfo->rank;
48      mpiSize = in->MPIInfo->size;      mpiSize = in->MPIInfo->size;
49      myFirstVertex = distribution[myRank];      myFirstVertex = distribution[myRank];
# Line 55  void Dudley_Mesh_optimizeDOFLabeling(Dud Line 51  void Dudley_Mesh_optimizeDOFLabeling(Dud
51      myNumVertices = myLastVertex - myFirstVertex;      myNumVertices = myLastVertex - myFirstVertex;
52      len = 0;      len = 0;
53      for (p = 0; p < mpiSize; ++p)      for (p = 0; p < mpiSize; ++p)
54      len = MAX(len, distribution[p + 1] - distribution[p]);          len = std::max(len, distribution[p + 1] - distribution[p]);
55    
56      boost::scoped_array<IndexList> index_list(new IndexList[myNumVertices]);      boost::scoped_array<IndexList> index_list(new IndexList[myNumVertices]);
57      newGlobalDOFID = new  index_t[len];      newGlobalDOFID = new index_t[len];
58    
59      /* create the adjacency structure xadj and adjncy */      /* create the adjacency structure xadj and adjncy */
     {  
60  #pragma omp parallel private(i)  #pragma omp parallel private(i)
61      {      {
62          /*  insert contributions from element matrices into columns index index_list: */          /*  insert contributions from element matrices into columns index index_list: */
63          Dudley_IndexList_insertElementsWithRowRangeNoMainDiagonal(index_list.get(),          Dudley_IndexList_insertElementsWithRowRangeNoMainDiagonal(index_list.get(),
64                  myFirstVertex, myLastVertex, in->Elements,              myFirstVertex, myLastVertex, in->Elements,
65                  in->Nodes->globalDegreesOfFreedom, in->Nodes->globalDegreesOfFreedom);              in->Nodes->globalDegreesOfFreedom, in->Nodes->globalDegreesOfFreedom);
66          Dudley_IndexList_insertElementsWithRowRangeNoMainDiagonal(index_list.get(),          Dudley_IndexList_insertElementsWithRowRangeNoMainDiagonal(index_list.get(),
67                  myFirstVertex, myLastVertex, in->FaceElements,              myFirstVertex, myLastVertex, in->FaceElements,
68                  in->Nodes->globalDegreesOfFreedom,              in->Nodes->globalDegreesOfFreedom,
69                  in->Nodes->globalDegreesOfFreedom);              in->Nodes->globalDegreesOfFreedom);
70          Dudley_IndexList_insertElementsWithRowRangeNoMainDiagonal(index_list.get(),          Dudley_IndexList_insertElementsWithRowRangeNoMainDiagonal(index_list.get(),
71                  myFirstVertex, myLastVertex, in->Points,              myFirstVertex, myLastVertex, in->Points,
72                  in->Nodes->globalDegreesOfFreedom,              in->Nodes->globalDegreesOfFreedom,
73                  in->Nodes->globalDegreesOfFreedom);              in->Nodes->globalDegreesOfFreedom);
74      }      }
75      /* create the local matrix pattern */      /* create the local matrix pattern */
76      pattern = paso::Pattern::fromIndexListArray(0, myNumVertices, index_list.get(),      pattern = paso::Pattern::fromIndexListArray(0, myNumVertices, index_list.get(),
77              myFirstVertex, myLastVertex, -myFirstVertex);          myFirstVertex, myLastVertex, -myFirstVertex);
78    
79      if (Dudley_noError())      pattern->reduceBandwidth(newGlobalDOFID);
         pattern->reduceBandwidth(newGlobalDOFID);  
80    
81      }      /* shift new labeling to create a global id */
     esysUtils::Esys_MPIInfo_noError(in->MPIInfo);  
     if (Dudley_noError())  
     {  
     /* shift new labeling to create a global id */  
82  #pragma omp parallel for private(i)  #pragma omp parallel for private(i)
83      for (i = 0; i < myNumVertices; ++i)      for (i = 0; i < myNumVertices; ++i)
84          newGlobalDOFID[i] += myFirstVertex;          newGlobalDOFID[i] += myFirstVertex;
85    
86      /* distribute new labeling to other processors */      /* distribute new labeling to other processors */
87  #ifdef ESYS_MPI  #ifdef ESYS_MPI
88      dest = esysUtils::mod_rank(mpiSize, myRank + 1);      dest = in->MPIInfo->mod_rank(myRank + 1);
89      source = esysUtils::mod_rank(mpiSize, myRank - 1);      source = in->MPIInfo->mod_rank(myRank - 1);
90  #endif  #endif
91      current_rank = myRank;      current_rank = myRank;
92      for (p = 0; p < mpiSize; ++p)      for (p = 0; p < mpiSize; ++p) {
93      {          firstVertex = distribution[current_rank];
94          firstVertex = distribution[current_rank];          lastVertex = distribution[current_rank + 1];
         lastVertex = distribution[current_rank + 1];  
95  #pragma omp parallel for private(i,k)  #pragma omp parallel for private(i,k)
96          for (i = 0; i < in->Nodes->numNodes; ++i)          for (i = 0; i < in->Nodes->numNodes; ++i) {
97          {              k = in->Nodes->globalDegreesOfFreedom[i];
98          k = in->Nodes->globalDegreesOfFreedom[i];              if ((firstVertex <= k) && (k < lastVertex)) {
99          if ((firstVertex <= k) && (k < lastVertex))                  in->Nodes->globalDegreesOfFreedom[i] = newGlobalDOFID[k - firstVertex];
100          {              }
101              in->Nodes->globalDegreesOfFreedom[i] = newGlobalDOFID[k - firstVertex];          }
         }  
         }  
102    
103          if (p < mpiSize - 1)          if (p < mpiSize - 1) { /* the final send can be skipped */
         {           /* the final send can be skipped */  
104  #ifdef ESYS_MPI  #ifdef ESYS_MPI
105          MPI_Sendrecv_replace(newGlobalDOFID, len, MPI_INT,              MPI_Sendrecv_replace(newGlobalDOFID, len, MPI_INT,
106                       dest, in->MPIInfo->msg_tag_counter,                                   dest, in->MPIInfo->counter(),
107                       source, in->MPIInfo->msg_tag_counter, in->MPIInfo->comm, &status);                                   source, in->MPIInfo->counter(), in->MPIInfo->comm, &status);
108                in->MPIInfo->incCounter();
109  #endif  #endif
110          in->MPIInfo->msg_tag_counter++;              current_rank = in->MPIInfo->mod_rank(current_rank - 1);
111          current_rank = esysUtils::mod_rank(mpiSize, current_rank - 1);          }
         }  
     }  
112      }      }
113      delete[] newGlobalDOFID;      delete[] newGlobalDOFID;
114  #if 0  #if 0
115      for (i = 0; i < in->Nodes->numNodes; ++i)      for (i = 0; i < in->Nodes->numNodes; ++i)
116      printf("%d ", in->Nodes->globalDegreesOfFreedom[i]);          printf("%d ", in->Nodes->globalDegreesOfFreedom[i]);
117      printf("\n");      printf("\n");
118  #endif  #endif
     return;  
119  }  }
120    
121    } // namespace dudley
122    

Legend:
Removed from v.6008  
changed lines
  Added in v.6009

  ViewVC Help
Powered by ViewVC 1.1.26