Liebe Gitlab-Nutzerin, lieber Gitlab-Nutzer,
es ist nun möglich sich mittels des ZIH-Logins/LDAP an unserem Dienst anzumelden. Die Konten der externen Nutzer:innen sind über den Reiter "Standard" erreichbar.
Die Administratoren


Dear Gitlab user,
it is now possible to log in to our service using the ZIH login/LDAP. The accounts of external users can be accessed via the "Standard" tab.
The administrators

ParMetisPartitioner.h 4.83 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  crystal growth group                                                  ==
// ==                                                                        ==
// ==  Stiftung caesar                                                       ==
// ==  Ludwig-Erhard-Allee 2                                                 ==
// ==  53175 Bonn                                                            ==
// ==  germany                                                               ==
// ==                                                                        ==
// ============================================================================
// ==                                                                        ==
// ==  http://www.caesar.de/cg/AMDiS                                         ==
// ==                                                                        ==
// ============================================================================

/** \file ParMetisPartitioner.h */

#ifndef AMDIS_PARMETISADAPTER_H
#define AMDIS_PARMETISADAPTER_H

#include <map>
#include <set>
Thomas Witkowski's avatar
Thomas Witkowski committed
27
#include "parmetis.h"
Naumann, Andreas's avatar
Naumann, Andreas committed
28
#include <Global.h>
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
namespace AMDiS {

  class FiniteElemSpace;

  enum PartitionMode {
    INITIAL = 0,          // initial partitioning of a unpartitioned mesh 
    ADAPTIVE_REPART = 1,  // repartitioning of a adaptively refined mesh
    REFINE_PART = 2       // quality improvement of the current partitioning
  };

  class ParMetisGraph;
  class Mesh;
  template<typename T > class DOFVector;

  class ParMetisMesh
  {
  public:
46
    ParMetisMesh(Mesh *mesh, MPI::Comm *comm);
47 48 49

    ~ParMetisMesh();

50
    inline void setParMetisIndex(int amdisIndex, int parMetisIndex) {
Thomas Witkowski's avatar
Thomas Witkowski committed
51
      elem_a2p[amdisIndex] = parMetisIndex + 1;
52
    }
53 54

    inline int getParMetisIndex(int amdisIndex) {
Thomas Witkowski's avatar
Thomas Witkowski committed
55
      int result = elem_a2p[amdisIndex];
56 57
      TEST_EXIT(result > 0)("invalid index\n");
      return result - 1;
58
    }
59

60
    inline void setAMDiSIndex(int parMetisIndex, int amdisIndex) {
Thomas Witkowski's avatar
Thomas Witkowski committed
61
      elem_p2a[parMetisIndex] = amdisIndex;
62
    }
63 64

    inline int getAMDiSIndex(int parMetisIndex) {
Thomas Witkowski's avatar
Thomas Witkowski committed
65
      return elem_p2a[parMetisIndex];
66
    }
67 68

    inline int *getAMDiSIndices() {
Thomas Witkowski's avatar
Thomas Witkowski committed
69
      return elem_p2a;
70
    }
71

72
    inline int *getElementPtr() { 
Thomas Witkowski's avatar
Thomas Witkowski committed
73
      return eptr; 
74
    }
75 76

    inline int *getElementInd() { 
Thomas Witkowski's avatar
Thomas Witkowski committed
77
      return eind; 
78
    }
79 80

    inline int *getElementDist() { 
81
      return elmdist; 
82
    }
83 84

    inline int getDim() { 
Thomas Witkowski's avatar
Thomas Witkowski committed
85
      return dim; 
86
    }
87 88

    inline float *getXYZ() { 
Thomas Witkowski's avatar
Thomas Witkowski committed
89
      return xyz; 
90
    }
91 92

    inline int getNumElements() { 
93
      return nElements; 
94
    }
95 96

  protected:
Thomas Witkowski's avatar
Thomas Witkowski committed
97
    int *eptr;
98

Thomas Witkowski's avatar
Thomas Witkowski committed
99
    int *eind;
100

101 102 103 104 105 106 107 108 109
    /* \brief
     * Array that specifies the distribution of the mesh elements.
     *
     * elmdist[0] = 0;
     * elmdist[1] = number of elements of proc 0;
     * elmdist[2] = elmdist[1] + number of elements of proc 1;
     *    ...
     */
    int *elmdist;
110

Thomas Witkowski's avatar
Thomas Witkowski committed
111
    int dim;
112

Thomas Witkowski's avatar
Thomas Witkowski committed
113
    float *xyz;
114

115
    int nElements;
116

Thomas Witkowski's avatar
Thomas Witkowski committed
117
    std::map<int, int> elem_a2p;
118

Thomas Witkowski's avatar
Thomas Witkowski committed
119
    int *elem_p2a;
120

121
    /// The MPI communicator that should be used for mesh partition.
122
    MPI::Comm *mpiComm;
123 124
  };

125

126 127 128 129
  class ParMetisGraph
  {
  public:
    ParMetisGraph(ParMetisMesh *parMetisMesh,
130
		  MPI::Comm *comm,
131 132 133 134
		  int ncommonnodes = -1);

    ~ParMetisGraph();

135
    inline int *getXAdj() { 
Thomas Witkowski's avatar
Thomas Witkowski committed
136
      return xadj; 
137
    }
138 139

    inline int *getAdjncy() { 
Thomas Witkowski's avatar
Thomas Witkowski committed
140
      return adjncy; 
141
    }
142 143

  protected:
144
    ParMetisMesh *parMetisMesh;
145

Thomas Witkowski's avatar
Thomas Witkowski committed
146 147 148
    int *xadj;

    int *adjncy;
149 150
  };

151

152 153 154
  class ParMetisPartitioner
  {
  public:
155
    ParMetisPartitioner(Mesh *mesh, MPI::Comm *comm)
156
      : mesh_(mesh),
157
        mpiComm(comm),
158
	parMetisMesh(NULL)
159
    {}
160 161 162 163 164

    void partition(std::map<int, double> *elemWeights,
		   PartitionMode mode = INITIAL,
		   float itr = 1000000.0);

165 166 167 168
    /* \brief 
     * Creates a map which stores for each element on partitioning level the 
     * rank the element corresponds to.
     */
169 170 171 172 173
    void fillCoarsePartitionVec(std::map<int, int> *partitionVec);

    void fillLeafPartitionVec(std::map<int, int> *coarseVec,
			      std::map<int, int> *fineVec);

174 175 176 177
    /* \brief
     * Creates an initial paritioning of the AMDiS mesh by seting the partition status
     * of all elements to either IN or UNDEFINED.
     */
178 179 180 181 182 183 184 185 186 187 188
    void createPartitionData();

    void deletePartitionData();

  protected:
    void distributePartitioning(int *part);

    void descendPartitionData(Element *element);

  protected:
    Mesh *mesh_;
189 190 191

    MPI::Comm *mpiComm;

192
    ParMetisMesh *parMetisMesh;
193 194 195 196
  };
}

#endif