Isorropia: Partitioning, Load Balancing and more
Isorropia_TpetraCostDescriber.hpp
Go to the documentation of this file.
00001 //@HEADER
00002 //************************************************************************
00003 //
00004 //              Isorropia: Partitioning and Load Balancing Package
00005 //                Copyright (2006) Sandia Corporation
00006 //
00007 //Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 //license for use of this work by or on behalf of the U.S. Government.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 //************************************************************************
00038 //@HEADER
00039 
00040 #ifndef _Isorropia_TpetraCostDescriber_hpp_
00041 #define _Isorropia_TpetraCostDescriber_hpp_
00042 
00043 #include <Isorropia_ConfigDefs.hpp>
00044 #include <Isorropia_CostDescriber.hpp>
00045 #include <Teuchos_RCP.hpp>
00046 #include <Teuchos_ParameterList.hpp>
00047 
00048 #include <map>
00049 #include <list>
00050 #include <set>
00051 #include <iostream>
00052 
00053 #ifdef HAVE_ISORROPIA_TPETRA
00054 
00055 #include <Kokkos_DefaultNode.hpp>
00056 #include <Tpetra_Vector_decl.hpp>
00057 #include <Tpetra_CrsMatrix_decl.hpp>
00058 
00059 
00060 namespace Isorropia {
00061 
00100 namespace Tpetra {
00101 
00119 // Forward declarations of friends
00120 
00121 
00122 template <typename Node=Kokkos::DefaultNode::DefaultNodeType>
00123 class CostDescriber : public Isorropia::CostDescriber {
00124 
00125   // public methods are part of API, private methods are used by different
00126   // classes in isorropia
00127 
00128   //friend class Isorropia::Operator;
00129   //friend class Isorropia::Tpetra::ZoltanLib::QueryObject;
00130   //friend class Isorropia::Tpetra::ZoltanLibClass;
00131 
00132 public:
00134   CostDescriber();
00135 
00137   ~CostDescriber();
00138 
00140   // */
00141   //friend std::ostream& operator << (std::ostream &, const Isorropia::Tpetra::CostDescriber<Node> &cd);
00142 
00151   void setVertexWeights(Teuchos::RCP<const ::Tpetra::Vector<double,int,int,Node> > vwgts);
00152 
00164   void setGraphEdgeWeights(Teuchos::RCP<const ::Tpetra::CrsMatrix<double,int,int,Node> > gewts);
00165 
00175   void setHypergraphEdgeWeights(Teuchos::RCP<const ::Tpetra::Vector<double,int,int,Node> > hgewts);
00176 
00193   void setHypergraphEdgeWeights(int numHGedges, const int *hgGIDs, const float *hgEwgts);
00194 
00195 
00196   void setHypergraphEdgeWeights(int numHGedges, const int *hgGIDs, const double *hgEwgts);
00197 
00206   void getCosts(std::map<int, float > &vertexWeights,
00207                 std::map<int, std::map<int, float > > &graphEdgeWeights,
00208                 std::map<int, float > &hypergraphEdgeWeights) const;
00209 
00212   void show_cd(std::ostream &) const;
00213 
00214 private:
00215 
00218   void setParameters(const Teuchos::ParameterList& paramlist);
00219 
00222   bool haveVertexWeights() const;
00225   int getNumVertices() const;
00228   void getVertexWeights(int numVertices,
00229                       int* global_ids, float* weights) const; 
00232   bool haveGraphEdgeWeights() const;
00235   int getNumGraphEdges(int vertex_global_id) const;
00236 
00241   int getGraphEdgeVertices(std::set<int> &gids) const;
00242 
00243 
00246   void getGraphEdgeWeights(int vertex_global_id,
00247                                    int num_neighbors,
00248                                    int* neighbor_global_ids,
00249                                    float* weights) const; 
00252   bool haveHypergraphEdgeWeights() const;
00255   int getNumHypergraphEdgeWeights() const;
00258   void getHypergraphEdgeWeights(int numEdges,
00259                                         int* global_ids,
00260                                         float* weights) const;
00261 
00267    int getHypergraphEdgeWeights(std::map<int, float> &wgtMap) const;
00268 
00269 
00275   int getVertexWeights(std::map<int, float> &wgtMap) const;
00276 
00277 
00278 
00286   int getGraphEdgeWeights(int vertex_global_id, std::map<int, float> &wgtMap) const;
00287 
00288 
00289 
00293   bool haveGlobalVertexWeights() const;
00294 
00298   void setNumGlobalVertexWeights(int num);
00299 
00303   bool haveGlobalGraphEdgeWeights() const;
00304 
00308   void setNumGlobalGraphEdgeWeights(int num);
00309 
00313   bool haveGlobalHypergraphEdgeWeights() const;
00314 
00318   void setNumGlobalHypergraphEdgeWeights(int num);
00319 
00322   void allocate_hg_edge_weights_(int n);
00323 
00326   void free_hg_edge_weights_();
00327 
00328   Teuchos::RCP<const ::Tpetra::Vector<double,int,int,Node> > vertex_weights_;
00329   Teuchos::RCP<const ::Tpetra::CrsMatrix<double,int,int,Node> > graph_edge_weights_;
00330   std::set<int> graph_self_edges_;
00331 
00332   Teuchos::ParameterList paramlist_;
00333 
00334   int *hg_edge_gids_;
00335   float *hg_edge_weights_;
00336   int num_hg_edge_weights_;
00337 
00338   int numGlobalVertexWeights_;
00339   int numGlobalGraphEdgeWeights_;
00340   int numGlobalHypergraphEdgeWeights_;
00341 
00354   int getEdges(int vertexGID, int len, int *nborGID, float *weights) const;
00355 
00356 
00357 };//class CostDescriber
00358 
00359 }//namespace Tpetra
00360 }//namespace Isorropia
00361 
00362 #endif //HAVE_TPETRA
00363 
00364 #endif
00365