File: Balance.cc

package info (click to toggle)
madlib 1.3.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,196 kB
  • sloc: cpp: 39,851; sh: 10,041; makefile: 473
file content (193 lines) | stat: -rw-r--r-- 6,351 bytes parent folder | download | duplicates (6)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// -------------------------------------------------------------------
// MAdLib - Copyright (C) 2008-2009 Universite catholique de Louvain
//
// See the Copyright.txt and License.txt files for license information. 
// You should have received a copy of these files along with MAdLib. 
// If not, see <http://www.madlib.be/license/>
//
// Please report all bugs and problems to <contrib@madlib.be>
//
// Authors: Cecile Dobrzynski, Jean-Francois Remacle, Gaetan Compere
// -------------------------------------------------------------------

#include "MeshDataBase.h"
#include "MeshDataBaseInterface.h"
#include "MeshDataBaseComm.h"
#include "MeshDataBaseParallelInterface.h"
#include "Mark.h"
#include "MAdMessage.h"

#ifdef PARALLEL
#include "mpi.h"
#include "autopack.h"
#ifdef _HAVE_PARMETIS_
#include "metisAdaptiveRepart.h"
#endif
#endif

#include <stdio.h>

using namespace MAd;

namespace MAd {

#ifdef PARALLEL
  // -------------------------------------------------------------------
  void Balance(pMesh mesh,MDB_DataExchanger &de) {

    int dim = (mesh->tets.empty()) ? 2 : 3;
    pMeshDataId tagElt= MD_newMeshDataId("EltDestination"); //dest = (int - 1)
  
    // --- Mark the elements to be moved and their destination ---
    if(dim==2) MarkTriangles (mesh, tagElt);
    else       MarkTets      (mesh, tagElt);
    //  if(dim==2) MarkTrianglesSmooth (mesh, tagElt);
    //  else       MarkTetsSmooth      (mesh, tagElt);

    // --- Move marked elements ---
    loadBalancing(mesh, tagElt, de);
  
    // --- Check that the mesh is not empty (debug) ---
    if ( dim==2 ) assert( !( mesh->triangles.empty() ) );
    if ( dim==3 ) assert( !( mesh->tets.empty() ) );

    // ----------------------------------------------
    // ------ Tagging inter-partition nodes
    // ----------------------------------------------

    pMeshDataId tag = MD_lookupMeshDataId("RemotePoint");
  
    V_createInfoInterface(mesh,tag);
    E_createInfoInterface(mesh,tag);
    F_createInfoInterface(mesh,tag);

    return;
  }
  // -------------------------------------------------------------------
  void Balance2(pMesh mesh,MDB_DataExchanger &de) {

    int dim = (mesh->tets.empty()) ? 2 : 3;
    pMeshDataId tagElt= MD_newMeshDataId("EltDestination"); //dest = (int - 1)

    // --- Mark the elements to be moved and their destination ---
    if(dim==2) MarkTriangles (mesh, tagElt);
    else       MarkTets      (mesh, tagElt);

    // --- Move marked elements ---
    loadBalancing2(mesh, tagElt, de);

    // --- Check that the mesh is not empty (debug) ---
    if ( dim==2 ) assert( !( mesh->triangles.empty() ) );
    if ( dim==3 ) assert( !( mesh->tets.empty() ) );
    // ----------------------------------------------
    // ------ Tagging inter-partition nodes
    // ----------------------------------------------

    pMeshDataId tag = MD_lookupMeshDataId("RemotePoint");
 
    V_createInfoInterface(mesh,tag);
    E_createInfoInterface(mesh,tag);
    F_createInfoInterface(mesh,tag);

    return;
  }

  // -------------------------------------------------------------------
  int BalanceManifold(pMesh mesh,MDB_DataExchanger &de) {
  
    int dim = (mesh->tets.empty()) ? 2 : 3;  
    pMeshDataId tagElt= MD_newMeshDataId("EltDestination"); //dest = (int - 1)
  
    int nmanifold = MarkTetsManifold(mesh,tagElt);
    
    loadBalancing(mesh,tagElt,de);

    if ( dim==3 ) assert( !(mesh->tets.empty()) );
 
    return(nmanifold);
  }

  // -------------------------------------------------------------------
  void BalanceRandom(pMesh mesh, MDB_DataExchanger &de) {

    int dim = (mesh->tets.empty()) ? 2 : 3;
    pMeshDataId tagElt = MD_newMeshDataId("EltDestination"); //dest = (int - 1)

    if(dim==2) MarkTrianglesRandom(mesh,tagElt);
    else       MarkTetsRandom(mesh,tagElt);

    loadBalancing(mesh,tagElt,de);

    if ( dim==3 ) assert( !(mesh->tets.empty()) );
  }

  // -------------------------------------------------------------------
#ifdef _HAVE_PARMETIS_
  void BalanceMetis(pMesh mesh,MDB_DataExchanger &de) {
  
    int dim = (mesh->tets.empty()) ? 2 : 3;
  
    //std::cout<<"metisAdaptiveRepart"<<mesh->nbPoints<<" "<<mesh->nbTets<<std::endl;
    pMeshDataId tagElt    = MD_newMeshDataId("EltDestination"); //dest = (int - 1)
    std::cout <<"USING PARMETIS"<<std::endl;
    metisAdaptiveRepart(mesh,tagElt);

    loadBalancing(mesh,tagElt,de);

    //std::cout<<"end metisAdaptiveRepart"<<mesh->nbPoints<<" "<<mesh->nbTets<<std::endl;
  
    if ( dim==3 ) assert( !(mesh->tets.empty()) );
  
    return;
  }
#endif

  // -------------------------------------------------------------------
#ifdef _HAVE_PARMETIS_
  void BalanceMetis2(pMesh mesh, MDB_DataExchanger &de) {
  
    int dim = M_dim(mesh);
  
    pMeshDataId tagElt = MD_newMeshDataId("EltDestination"); //dest = (int - 1)
    metisAdaptiveRepart(mesh,tagElt);
    loadBalancing2(mesh,tagElt,de);

    if ( M_dim(mesh) != dim ) {
      MAdMsgSgl::instance().error(__LINE__,__FILE__,
                                  "The dimension of the mesh has been reduced from %d to %d during a balancing operation",
                                  dim, M_dim(mesh));
    }

    pMeshDataId tag = MD_lookupMeshDataId("RemotePoint");
    V_createInfoInterface(mesh,tag);
    E_createInfoInterface(mesh,tag);
    F_createInfoInterface(mesh,tag);
  }
#endif

  // -------------------------------------------------------------------
#endif

  // -------------------------------------------------------------------
  void BalancePeriodic(pMesh mesh,int dim,MDB_DataExchanger &de,
                       MDB_DataExchangerPeriodic &deperiodic,std::vector<std::vector<int> >& transfo) {
    pMeshDataId tagMove = MD_newMeshDataId("TagMovePeriodic");
    pMeshDataId tagElt  = MD_newMeshDataId("EltDestination"); //dest = (int - 1)
    /*for 3-periodic cases*/
    pMeshDataId tagTransfo  = MD_newMeshDataId("Transformation"); 
  
    if(dim==2) MarkPeriodicTriangles(mesh,transfo,tagElt,tagMove,tagTransfo);
    else       MarkPeriodicTets(mesh,transfo,tagElt,tagMove,tagTransfo);  
  
    PeriodicInterfaceMigration(mesh,tagElt,tagMove,tagTransfo,de,deperiodic);
  
    MD_deleteMeshDataId(tagMove);
    MD_deleteMeshDataId(tagElt);
    MD_deleteMeshDataId(tagTransfo);
  
    return;
  }

  // -------------------------------------------------------------------

}