Isorropia: Partitioning, Load Balancing and more
Isorropia_EpetraCostDescriber.hpp
Go to the documentation of this file.
1 //@HEADER
2 //************************************************************************
3 //
4 // Isorropia: Partitioning and Load Balancing Package
5 // Copyright (2006) Sandia Corporation
6 //
7 //Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 //license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 //************************************************************************
38 //@HEADER
39 
40 #ifndef _Isorropia_EpetraCostDescriber_hpp_
41 #define _Isorropia_EpetraCostDescriber_hpp_
42 
43 #include <Isorropia_ConfigDefs.hpp>
45 #include <Teuchos_RCP.hpp>
46 #include <Teuchos_ParameterList.hpp>
47 
48 #include <map>
49 #include <list>
50 #include <set>
51 #include <iostream>
52 
53 #ifdef HAVE_EPETRA
54 class Epetra_Vector;
55 class Epetra_CrsMatrix;
56 class Epetra_RowMatrix;
57 class Epetra_MultiVector;
58 class Epetra_Import;
59 class Epetra_CrsGraph;
60 
61 namespace Isorropia {
62 
100 class Operator;
101 
102 namespace Epetra {
103 
121 // Forward declarations of friends
122 
123 namespace ZoltanLib{
124  class QueryObject;
125 }
126 class ZoltanLibClass;
127 
129 
130  // public methods are part of API, private methods are used by different
131  // classes in isorropia
132 
133  friend class Isorropia::Operator;
136 
137 public:
139  CostDescriber();
140 
142  ~CostDescriber();
143 
145  CostDescriber(const CostDescriber &costs);
146 
149  friend std::ostream& operator <<(std::ostream &, const Isorropia::Epetra::CostDescriber &cd);
150 
159  void setVertexWeights(Teuchos::RCP<const Epetra_Vector> vwgts);
160 
172  void setGraphEdgeWeights(Teuchos::RCP<const Epetra_CrsMatrix> gewts);
173 
183  void setHypergraphEdgeWeights(Teuchos::RCP<const Epetra_Vector> hgewts);
184 
201  void setHypergraphEdgeWeights(int numHGedges, const int *hgGIDs, const float *hgEwgts);
202 
206  void setHypergraphEdgeWeights(int numHGedges, const int *hgGIDs, const double *hgEwgts);
207 
216  void getCosts(std::map<int, float > &vertexWeights,
217  std::map<int, std::map<int, float > > &graphEdgeWeights,
218  std::map<int, float > &hypergraphEdgeWeights) const;
219 
222  void show_cd(std::ostream &) const;
223 
224  // Add documentation
225 
226 #ifdef USE_UTILS
227  int compareBeforeAndAfterHypergraph( const Epetra_RowMatrix &in_m, const Epetra_RowMatrix &out_m,
228  const Epetra_Import &importer,
229  std::vector<double> &balance, std::vector<double> &cutn, std::vector<double> &cutl) const;
230 
231  int compareBeforeAndAfterGraph( const Epetra_RowMatrix &in_m, const Epetra_RowMatrix &out_m,
232  const Epetra_Import &importer,
233  std::vector<double> &balance, std::vector<int> &numCuts, std::vector<double> &cutWgt,
234  std::vector<double> &cutn, std::vector<double> &cutl) const;
235 
236  int compareBeforeAndAfterGraph( const Epetra_CrsGraph &in_g, const Epetra_CrsGraph &out_g,
237  const Epetra_Import &importer,
238  std::vector<double> &balance, std::vector<int> &numCuts, std::vector<double> &cutWgt,
239  std::vector<double> &cutn, std::vector<double> &cutl) const;
240 
241  int compareBeforeAndAfterImbalance(const Epetra_MultiVector &mv, const Epetra_Import &importer,
242  std::vector<double> &min, std::vector<double> &max, std::vector<double> &avg) const;
243 #endif
244 
245 private:
246 
247  void _transformWeights(const Epetra_Import &importer);
248 
249  int _compareBeforeAndAfterGraph( const Epetra_RowMatrix *in_m, const Epetra_RowMatrix *out_m,
250  const Epetra_CrsGraph *in_g, const Epetra_CrsGraph *out_g,
251  const Epetra_Import &importer,
252  std::vector<double> &balance, std::vector<int> &numCuts, std::vector<double> &cutWgt,
253  std::vector<double> &cutn, std::vector<double> &cutl) const;
254 
257  void setParameters(const Teuchos::ParameterList& paramlist);
258 
261  bool haveVertexWeights() const;
264  int getNumVertices() const;
267  void getVertexWeights(int numVertices,
268  int* global_ids, float* weights) const;
271  bool haveGraphEdgeWeights() const;
274  int getNumGraphEdges(int vertex_global_id) const;
275 
280  int getGraphEdgeVertices(std::set<int> &gids) const;
281 
282 
285  void getGraphEdgeWeights(int vertex_global_id,
286  int num_neighbors,
287  int* neighbor_global_ids,
288  float* weights) const;
291  bool haveHypergraphEdgeWeights() const;
294  int getNumHypergraphEdgeWeights() const;
297  void getHypergraphEdgeWeights(int numEdges,
298  int* global_ids,
299  float* weights) const;
300 
306  int getHypergraphEdgeWeights(std::map<int, float> &wgtMap) const;
307 
308 
314  int getVertexWeights(std::map<int, float> &wgtMap) const;
315 
316  // TODO documentation
317  const Epetra_Vector &getVertexWeights() { return *vertex_weights_;}
318 
319 
327  int getGraphEdgeWeights(int vertex_global_id, std::map<int, float> &wgtMap) const;
328 
329 
330 
334  bool haveGlobalVertexWeights() const;
335 
339  void setNumGlobalVertexWeights(int num);
340 
344  bool haveGlobalGraphEdgeWeights() const;
345 
349  void setNumGlobalGraphEdgeWeights(int num);
350 
354  bool haveGlobalHypergraphEdgeWeights() const;
355 
359  void setNumGlobalHypergraphEdgeWeights(int num);
360 
363  void allocate_hg_edge_weights_(int n);
364 
367  void free_hg_edge_weights_();
368 
369  Teuchos::RCP<const Epetra_Vector> vertex_weights_;
370  Teuchos::RCP<const Epetra_CrsMatrix> graph_edge_weights_;
371  std::set<int> graph_self_edges_;
372 
373  Teuchos::ParameterList paramlist_;
374 
378 
382 
395  int getEdges(int vertexGID, int len, int *nborGID, float *weights) const;
396 
397 };//class CostDescriber
398 
399 }//namespace Epetra
400 }//namespace Isorropia
401 
402 #endif //HAVE_EPETRA
403 
404 #endif
405 
float * hg_edge_weights_
Definition: Isorropia_EpetraCostDescriber.hpp:376
int * hg_edge_gids_
Definition: Isorropia_EpetraCostDescriber.hpp:375
int getNumHypergraphEdgeWeights() const
Get the number of Hypergraph edges.
void setHypergraphEdgeWeights(Teuchos::RCP< const Epetra_Vector > hgewts)
setHypergraphEdgeWeights is called by processes in an application to supply weights for the hyperedge...
friend std::ostream & operator<<(std::ostream &, const Isorropia::Epetra::CostDescriber &cd)
Overloaded &lt;&lt; operator for CostDescriber object.
void setGraphEdgeWeights(Teuchos::RCP< const Epetra_CrsMatrix > gewts)
setGraphEdgeWeights is called by a process to supply the weights for each of the edges of its vertice...
Teuchos::ParameterList paramlist_
Definition: Isorropia_EpetraCostDescriber.hpp:373
bool haveVertexWeights() const
Query whether vertex weights have been supplied by the application.
QueryObject is a class that contains the query functions required by the Zoltan library.
Definition: QueryObject.hpp:81
Interface (abstract base class) for describing the weights or costs associated with the vertices and/...
Definition: Isorropia_CostDescriber.hpp:61
void allocate_hg_edge_weights_(int n)
Dynamically allocate storage for hypergraph edge weights.
const Epetra_Vector & getVertexWeights()
Definition: Isorropia_EpetraCostDescriber.hpp:317
bool haveGlobalGraphEdgeWeights() const
haveGlobalGraphEdgeWeights returns true if any process in the application has supplied graph edge wei...
void setNumGlobalVertexWeights(int num)
setNumGlobalVertexWeights may be used to set the count of the global number of vertex weights supplie...
void setNumGlobalGraphEdgeWeights(int num)
setNumGlobalGraphEdgeWeights may be used to set the count of the global number of graph edge weights ...
int numGlobalHypergraphEdgeWeights_
Definition: Isorropia_EpetraCostDescriber.hpp:381
int numGlobalGraphEdgeWeights_
Definition: Isorropia_EpetraCostDescriber.hpp:380
int num_hg_edge_weights_
Definition: Isorropia_EpetraCostDescriber.hpp:377
Definition: Isorropia_EpetraZoltanLib.hpp:70
int _compareBeforeAndAfterGraph(const Epetra_RowMatrix *in_m, const Epetra_RowMatrix *out_m, const Epetra_CrsGraph *in_g, const Epetra_CrsGraph *out_g, const Epetra_Import &importer, std::vector< double > &balance, std::vector< int > &numCuts, std::vector< double > &cutWgt, std::vector< double > &cutn, std::vector< double > &cutl) const
bool haveHypergraphEdgeWeights() const
Query whether hypergraph edge weights have been supplied by the application.
void getGraphEdgeWeights(int vertex_global_id, int num_neighbors, int *neighbor_global_ids, float *weights) const
Get the graph edge weights for a specified vertex.
bool haveGlobalHypergraphEdgeWeights() const
haveGlobalHypergraphEdgeWeights returns true if any process in the application has supplied hyperedge...
int getNumVertices() const
Get the number of vertices for which this process supplied vertex weights.
Teuchos::RCP< const Epetra_CrsMatrix > graph_edge_weights_
Definition: Isorropia_EpetraCostDescriber.hpp:370
Interface (abstract base class) for computing a new partitioning/coloring/ ordering and exploiting th...
Definition: Isorropia_Operator.hpp:58
int numGlobalVertexWeights_
Definition: Isorropia_EpetraCostDescriber.hpp:379
void setVertexWeights(Teuchos::RCP< const Epetra_Vector > vwgts)
setVertexWeights is called by a process to supply the weight of each vertex (row) in the graph or hyp...
bool haveGraphEdgeWeights() const
Query whether graph edge weights have been supplied by the application.
void setParameters(const Teuchos::ParameterList &paramlist)
Set parameters for the CostDescriber instance.
void getHypergraphEdgeWeights(int numEdges, int *global_ids, float *weights) const
Get the hypergraph edge weights that were supplied by this process.
void free_hg_edge_weights_()
Free storage used by hypergraph edge weights.
bool haveGlobalVertexWeights() const
haveGlobalVertexWeights returns true if any process in the application has supplied vertex weights...
int getGraphEdgeVertices(std::set< int > &gids) const
Get the set of global IDs for the vertices that we have edge information for.
void show_cd(std::ostream &) const
Print out the contents of this CostDescriber.
std::set< int > graph_self_edges_
Definition: Isorropia_EpetraCostDescriber.hpp:371
void setNumGlobalHypergraphEdgeWeights(int num)
setNumGlobalHypergraphEdgeWeights may be used to set the count of the global number of hyperedge weig...
Definition: Isorropia_EpetraCostDescriber.hpp:128
Teuchos::RCP< const Epetra_Vector > vertex_weights_
Definition: Isorropia_EpetraCostDescriber.hpp:369
int getNumGraphEdges(int vertex_global_id) const
Get the number of graph edges for a specified vertex.
void _transformWeights(const Epetra_Import &importer)
int getEdges(int vertexGID, int len, int *nborGID, float *weights) const
getEdges creates an array of the neighbors and edge weights for given vertex.
void getCosts(std::map< int, float > &vertexWeights, std::map< int, std::map< int, float > > &graphEdgeWeights, std::map< int, float > &hypergraphEdgeWeights) const
Get the contents of this CostDescriber.