| 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_EPETRA_ZOLTAN_QUERYOBJECT_H |
| 41 |
#define ISORROPIA_EPETRA_ZOLTAN_QUERYOBJECT_H |
| 42 |
|
| 43 |
#include "Isorropia_ConfigDefs.hpp" |
| 44 |
|
| 45 |
#include <Teuchos_RCP.hpp> |
| 46 |
|
| 47 |
#include <zoltan_cpp.h> |
| 48 |
|
| 49 |
#include <set> |
| 50 |
#include <map> |
| 51 |
|
| 52 |
class Epetra_BlockMap; |
| 53 |
class Epetra_CrsGraph; |
| 54 |
class Epetra_RowMatrix; |
| 55 |
class Epetra_MultiVector; |
| 56 |
|
| 57 |
namespace Isorropia { |
| 58 |
|
| 59 |
namespace Epetra { |
| 60 |
|
| 61 |
class CostDescriber; |
| 62 |
|
| 63 |
/** The ZoltanLib namespace within the Epetra namespace contains the |
| 64 |
classes and functions that use the Zoltan library to partition an |
| 65 |
Epetra object. |
| 66 |
*/ |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
namespace ZoltanLib { |
| 71 |
|
| 72 |
/** QueryObject is a class that contains the query functions required |
| 73 |
by the Zoltan library. |
| 74 |
|
| 75 |
These methods are not part of the Isorropia API (except to Zoltan). |
| 76 |
They are called by Isorropia itself and by Zoltan. |
| 77 |
|
| 78 |
For a better understanding of Zoltan's query functions, see the |
| 79 |
Zoltan User's Guide at http://www.cs.sandia.gov/zoltan |
| 80 |
*/ |
| 81 |
class QueryObject |
| 82 |
{ |
| 83 |
|
| 84 |
/** haveGraph is true if we have CrsGraph, and not a CrsMatrix or |
| 85 |
a MultiVector. |
| 86 |
*/ |
| 87 |
const bool haveGraph_; |
| 88 |
|
| 89 |
/** The CrsGraph. The QueryObject must be constructed with one of |
| 90 |
an Epetra_CrsGraph, an Epetra_RowMatrix or an Epetra_MultiVector. |
| 91 |
*/ |
| 92 |
Teuchos::RCP<const Epetra_CrsGraph> graph_; |
| 93 |
|
| 94 |
/** The CrsMatrix. |
| 95 |
The QueryObject must be constructed with one of |
| 96 |
an Epetra_CrsGraph, an Epetra_RowMatrix or an Epetra_MultiVector. |
| 97 |
*/ |
| 98 |
Teuchos::RCP<const Epetra_RowMatrix> matrix_; |
| 99 |
|
| 100 |
/** The MultiVector containing 1, 2 or 3 dimensional coordinates. If |
| 101 |
supplied, we will perform geometric partitioning. |
| 102 |
The QueryObject must be constructed with one of |
| 103 |
an Epetra_CrsGraph, an Epetra_RowMatrix or an Epetra_MultiVector. |
| 104 |
*/ |
| 105 |
Teuchos::RCP<const Epetra_MultiVector> coords_; |
| 106 |
|
| 107 |
/** The graph or matrix row map, or the MultiVector map |
| 108 |
*/ |
| 109 |
const Epetra_BlockMap *rowMap_; |
| 110 |
|
| 111 |
/** The graph or matrix column map |
| 112 |
*/ |
| 113 |
const Epetra_BlockMap *colMap_; |
| 114 |
|
| 115 |
/** The CostDescriber contains optional vertex and/or edge weights for |
| 116 |
graph and hypergraph partitioning. |
| 117 |
*/ |
| 118 |
|
| 119 |
Teuchos::RCP<const Isorropia::Epetra::CostDescriber> costs_; |
| 120 |
|
| 121 |
/** The MultiVector contains optional object (point) weights for |
| 122 |
geometric partitioning. Zoltan currently will use only the |
| 123 |
weights in the first vector (1 dimensional point weights). |
| 124 |
*/ |
| 125 |
|
| 126 |
Teuchos::RCP<const Epetra_MultiVector> weights_; |
| 127 |
|
| 128 |
std::map<int,int> procmap_; |
| 129 |
std::set<int> graph_self_edges_; |
| 130 |
|
| 131 |
unsigned int myProc_; |
| 132 |
unsigned int base_; |
| 133 |
|
| 134 |
void fill_procmap(); |
| 135 |
|
| 136 |
/** My_Number_Objects() returns the number of objects currently |
| 137 |
assigned to this process. (The objects are interpreted as |
| 138 |
graph vertices for Graph partitioning, as hypergraph |
| 139 |
vertices for hypergraph partitioning, or as coordinates for |
| 140 |
geometric partitioning.) |
| 141 |
*/ |
| 142 |
int My_Number_Objects(int *ierr); |
| 143 |
|
| 144 |
/** My_ObjectList() returns to Zoltan the global ID and weight of the |
| 145 |
objects currently assigned to this process. |
| 146 |
*/ |
| 147 |
void My_Object_List (int num_gid_entries, int num_lid_entries, |
| 148 |
ZOLTAN_ID_PTR global_ids, ZOLTAN_ID_PTR local_ids, |
| 149 |
int weight_dim, float * object_weights, int * ierr ); |
| 150 |
|
| 151 |
/** My_Number_Edges_Multi() is a query function used for graph partitioning |
| 152 |
only. It returns to Zoltan the number of edges (non-zeroes) that each |
| 153 |
vertex (row) has. |
| 154 |
*/ |
| 155 |
void My_Number_Edges_Multi (int num_gid_entries, int num_lid_entries, |
| 156 |
int num_obj, ZOLTAN_ID_PTR global_ids, ZOLTAN_ID_PTR local_ids, |
| 157 |
int *num_edges, int * ierr ); |
| 158 |
|
| 159 |
/** My_Edge_List_Multi() is a query function used for graph partitioning |
| 160 |
only. For each vertex (row), it returns a list of the global ID of |
| 161 |
each neighbor (non-zero) and the process owning that neighbor (that row). |
| 162 |
*/ |
| 163 |
void My_Edge_List_Multi(int num_gid_entries, int num_lid_entries, |
| 164 |
int num_obj, ZOLTAN_ID_PTR global_ids, ZOLTAN_ID_PTR local_ids, |
| 165 |
int *num_edges, ZOLTAN_ID_PTR neighbor_global_ids, int * neighbor_procs, |
| 166 |
int weight_dim, float * edge_weights, int * ierr ); |
| 167 |
|
| 168 |
/** My_HG_Size_CS() is a query function used for hypergraph partitioning |
| 169 |
only. Zoltan calls this query to get size of the non-zeros lists from the QueryObject. |
| 170 |
*/ |
| 171 |
void My_HG_Size_CS (int* num_lists, int* num_pins, int* format, |
| 172 |
int * ierr ); |
| 173 |
|
| 174 |
/** My_HG_CS() is a query function used for hypergraph partitioning |
| 175 |
only. Zoltan calls this query to get the non-zeros lists from the QueryObject. |
| 176 |
*/ |
| 177 |
void My_HG_CS (int num_gid_entries, int num_row_or_col, int num_pins, |
| 178 |
int format, ZOLTAN_ID_PTR vtxedge_GID, int* vtxedge_ptr, ZOLTAN_ID_PTR pin_GID, |
| 179 |
int * ierr ); |
| 180 |
|
| 181 |
|
| 182 |
/** My_FGHG_CS() is a query function used for fine-grain hypergraph partitioning |
| 183 |
only. Zoltan calls this query to get the non-zeros lists from the QueryObject. |
| 184 |
*/ |
| 185 |
void My_FGHG_CS (int num_gid_entries, int num_row_or_col, int num_pins, |
| 186 |
int format, ZOLTAN_ID_PTR vtxedge_GID, int* vtxedge_ptr, ZOLTAN_ID_PTR pin_GID, |
| 187 |
int * ierr ); |
| 188 |
|
| 189 |
/** My_HG_Size_Edge_Weights() is a query function used for hypergraph partitioning |
| 190 |
only. Zoltan calls this query to get number of hyperedge weights that this |
| 191 |
QueryObject will be providing. |
| 192 |
*/ |
| 193 |
void My_HG_Size_Edge_Weights(int* num_edges, int* ierr); |
| 194 |
|
| 195 |
/** My_HG_Edge_Weights() is a query function used for hypergraph partitioning |
| 196 |
only. Zoltan calls this query to get hyperedge weights from this |
| 197 |
QueryObject. |
| 198 |
*/ |
| 199 |
void My_HG_Edge_Weights(int num_gid_entries, int num_lid_entries, int num_edges, int edge_weight_dim, |
| 200 |
ZOLTAN_ID_PTR edge_GID, ZOLTAN_ID_PTR edge_LID, float* edge_weights, int* ierr); |
| 201 |
|
| 202 |
/** My_Number_Geom() is a query function used for geometric partitioning |
| 203 |
only. Zoltan calls this query to get the dimension of the geometric |
| 204 |
coordinates. |
| 205 |
*/ |
| 206 |
int My_Number_Geom(int *ierr); |
| 207 |
|
| 208 |
/** My_Geom_Multi() is a query function used for geometric partitioning |
| 209 |
only. Zoltan calls this query to get a list of coordinates from the QueryObject. |
| 210 |
*/ |
| 211 |
void My_Geom_Multi(int num_gid_entries, int num_lid_entries, |
| 212 |
int num_obj, ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids, int num_dim, |
| 213 |
double *geom_vec, int *ierr); |
| 214 |
|
| 215 |
public: |
| 216 |
|
| 217 |
/** Constructor |
| 218 |
*/ |
| 219 |
QueryObject( Teuchos::RCP<const Epetra_CrsGraph> graph, |
| 220 |
Teuchos::RCP<const Isorropia::Epetra::CostDescriber> costs, |
| 221 |
int inputType); |
| 222 |
|
| 223 |
|
| 224 |
/** Constructor |
| 225 |
*/ |
| 226 |
QueryObject( Teuchos::RCP<const Epetra_RowMatrix> matrix, |
| 227 |
Teuchos::RCP<const Isorropia::Epetra::CostDescriber> costs, |
| 228 |
int inputType); |
| 229 |
|
| 230 |
/** Constructor |
| 231 |
*/ |
| 232 |
QueryObject( Teuchos::RCP<const Epetra_MultiVector> coords, |
| 233 |
Teuchos::RCP<const Epetra_MultiVector> weights); |
| 234 |
|
| 235 |
|
| 236 |
/** Constructor |
| 237 |
*/ |
| 238 |
QueryObject(Teuchos::RCP<const Epetra_CrsGraph> graph, |
| 239 |
Teuchos::RCP<const Isorropia::Epetra::CostDescriber> costs, |
| 240 |
Teuchos::RCP<const Epetra_MultiVector> coords, |
| 241 |
Teuchos::RCP<const Epetra_MultiVector> weights, |
| 242 |
int inputType); |
| 243 |
|
| 244 |
|
| 245 |
/** Constructor |
| 246 |
*/ |
| 247 |
QueryObject(Teuchos::RCP<const Epetra_RowMatrix> matrix, |
| 248 |
Teuchos::RCP<const Isorropia::Epetra::CostDescriber> costs, |
| 249 |
Teuchos::RCP<const Epetra_MultiVector> coords, |
| 250 |
Teuchos::RCP<const Epetra_MultiVector> weights, |
| 251 |
int inputType); |
| 252 |
|
| 253 |
|
| 254 |
/** Constructor |
| 255 |
*/ |
| 256 |
QueryObject( Teuchos::RCP<const Epetra_BlockMap> inputMap, |
| 257 |
int inputType); |
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
/** Destructor |
| 263 |
*/ |
| 264 |
virtual ~QueryObject(); |
| 265 |
|
| 266 |
/** input_type_ == hgraph_input_. |
| 267 |
This indicates that the matrix or graph represents a hypergraph. Columns |
| 268 |
represent hyperedges, and row (vertex) partitioning is to be performed. |
| 269 |
*/ |
| 270 |
|
| 271 |
static const int hgraph_input_ = 1; |
| 272 |
|
| 273 |
/** input_type_ == hgraph2d_finegrain_input_. |
| 274 |
This indicates that the matrix or graph represents a hypergraph. Columns |
| 275 |
represent hyperedges, and non-zeroes are to be partitioned. |
| 276 |
*/ |
| 277 |
static const int hgraph2d_finegrain_input_ = 2; |
| 278 |
|
| 279 |
/** input_type_ == graph_input_. |
| 280 |
This indicates that the square symmetric matrix or graph represents a graph |
| 281 |
in the sense that row/column IDs are vertices and non-zeroes represent |
| 282 |
edges. The vertices are to be partitioned. |
| 283 |
*/ |
| 284 |
static const int graph_input_ = 3; |
| 285 |
|
| 286 |
/** input_type_ == geometric_input_. |
| 287 |
This indicates that the Epetra_MultiVector represents geometric |
| 288 |
coordinates. The MultiVector should have 1, 2 or 3 vectors, |
| 289 |
representing 1, 2 or 3 dimensional coordinates. The coordinates |
| 290 |
are to be partitioned. |
| 291 |
*/ |
| 292 |
static const int geometric_input_ = 4; |
| 293 |
|
| 294 |
/** input_type_ == hgraph_graph_input_ |
| 295 |
This indicates that the Epetra_MultiVector represents a hypergraph |
| 296 |
and graph (see above). This is necessary for hierarchical partitioning |
| 297 |
with both hypergraph and graph methods. |
| 298 |
*/ |
| 299 |
static const int hgraph_graph_input_ = 5; |
| 300 |
|
| 301 |
/** input_type_ == hgraph_geometric_input_ |
| 302 |
This indicates that the Epetra_MultiVector represents a hypergraph |
| 303 |
and graph (see above). This is necessary for hierarchical partitioning |
| 304 |
with both hypergraph and geometric methods. |
| 305 |
*/ |
| 306 |
static const int hgraph_geometric_input_ = 6; |
| 307 |
|
| 308 |
/** input_type_ == graph_geometric_input_ |
| 309 |
This indicates that the Epetra_MultiVector represents graph and |
| 310 |
has geometric coordinates (see above). |
| 311 |
This is necessary for hierarchical partitioning |
| 312 |
with both graph and geometric methods. |
| 313 |
*/ |
| 314 |
static const int graph_geometric_input_ = 7; |
| 315 |
|
| 316 |
/** input_type_ == hgraph_graph_geometric_input_ |
| 317 |
This indicates that the Epetra_MultiVector represents a hypergraph |
| 318 |
and graph and has geometric coordinates(see above). This is necessary for |
| 319 |
hierarchical partitioning using hypergraph, graph, and geometric methods. |
| 320 |
*/ |
| 321 |
static const int hgraph_graph_geometric_input_ = 8; |
| 322 |
|
| 323 |
/** input_type_ == simple_input_ |
| 324 |
This indicates that a simple method (block, cyclic, or random) will be used. |
| 325 |
*/ |
| 326 |
static const int simple_input_ = 9; |
| 327 |
|
| 328 |
|
| 329 |
/** input_type_ == unspecified_input_. |
| 330 |
This value is the "unset" state for the input_type_ instance variable. |
| 331 |
*/ |
| 332 |
static const int unspecified_input_ = 10; |
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
/** The input_type_ indicates how the object to be partitioned is to |
| 337 |
be interpreted - as a graph or a hypergraph for row partitioning, |
| 338 |
as a hypergraph for fine-grain partitioning, or as a list of coordinates for geometric |
| 339 |
partitioning. |
| 340 |
*/ |
| 341 |
int input_type_; |
| 342 |
|
| 343 |
/** Return the map associated with the object to be partitioned. |
| 344 |
*/ |
| 345 |
const Epetra_BlockMap &RowMap(void){ return *rowMap_;}; |
| 346 |
|
| 347 |
/** Return true if any of the processes in the application have defined |
| 348 |
vertex weights. |
| 349 |
*/ |
| 350 |
bool haveVertexWeights(); |
| 351 |
|
| 352 |
/** Return true if any of the processes in the application have defined |
| 353 |
graph edge weights. |
| 354 |
*/ |
| 355 |
bool haveGraphEdgeWeights(); |
| 356 |
|
| 357 |
/** Return true if any of the processes in the application have defined |
| 358 |
hypergraph edge weights. |
| 359 |
*/ |
| 360 |
bool haveHypergraphEdgeWeights(); |
| 361 |
|
| 362 |
// General query functions |
| 363 |
|
| 364 |
/** The interface to a particular QueryObject's My_Number_Objects query function. |
| 365 |
*/ |
| 366 |
static int Number_Objects(void *data, int *ierr); |
| 367 |
|
| 368 |
/** The interface to a particular QueryObject's My_Object_List query function. |
| 369 |
*/ |
| 370 |
static void Object_List ( void * data, int num_gid_entries, int num_lid_entries, |
| 371 |
ZOLTAN_ID_PTR global_ids, ZOLTAN_ID_PTR local_ids, |
| 372 |
int weight_dim, float * object_weights, int * ierr ); |
| 373 |
|
| 374 |
// Query functions for graph partitioning only |
| 375 |
|
| 376 |
/** The interface to a particular QueryObject's My_Number_Edges_Multi query function. |
| 377 |
*/ |
| 378 |
static void Number_Edges_Multi ( void * data, int num_gid_entries, int num_lid_entries, |
| 379 |
int num_obj, ZOLTAN_ID_PTR global_ids, ZOLTAN_ID_PTR local_ids, |
| 380 |
int *num_edges, int * ierr ); |
| 381 |
|
| 382 |
/** The interface to a particular QueryObject's My_Edges_Multi query function. |
| 383 |
*/ |
| 384 |
static void Edge_List_Multi( void * data, int num_gid_entries, int num_lid_entries, |
| 385 |
int num_obj, ZOLTAN_ID_PTR global_ids, ZOLTAN_ID_PTR local_ids, |
| 386 |
int *num_edges, ZOLTAN_ID_PTR neighbor_global_ids, int * neighbor_procs, |
| 387 |
int weight_dim, float * edge_weights, int * ierr ); |
| 388 |
|
| 389 |
// Query functions for hypergraph partitioning only |
| 390 |
|
| 391 |
/** The interface to a particular QueryObject's My_HG_Size_CS query function. |
| 392 |
*/ |
| 393 |
static void HG_Size_CS ( void * data, int* num_lists, int* num_pins, int* format, |
| 394 |
int * ierr ); |
| 395 |
/** The interface to a particular QueryObject's My_HG_CS query function. |
| 396 |
*/ |
| 397 |
static void HG_CS ( void * data, int num_gid_entries, int num_row_or_col, int num_pins, |
| 398 |
int format, ZOLTAN_ID_PTR vtxedge_GID, int* vtxedge_ptr, ZOLTAN_ID_PTR pin_GID, |
| 399 |
int * ierr ); |
| 400 |
/** The interface to a particular QueryObject's My_HG_Size_Edge_Weights query function. |
| 401 |
*/ |
| 402 |
static void HG_Size_Edge_Weights(void * data, int* num_edges, int* ierr); |
| 403 |
|
| 404 |
/** The interface to a particular QueryObject's My_HG_Edge_Weights query function. |
| 405 |
*/ |
| 406 |
static void HG_Edge_Weights(void * data, |
| 407 |
int num_gid_entries, int num_lid_entries, int num_edges, int edge_weight_dim, |
| 408 |
ZOLTAN_ID_PTR edge_GID, ZOLTAN_ID_PTR edge_LID, float* edge_weights, int* ierr); |
| 409 |
|
| 410 |
/** The interface to a particular QueryObject's My_Number_Geom query function. |
| 411 |
*/ |
| 412 |
static int Number_Geom(void *data, int *ierr); |
| 413 |
|
| 414 |
/** The interface to a particular QueryObject's My_Geom_Multi query function. |
| 415 |
*/ |
| 416 |
static void Geom_Multi(void *data, int num_gid_entries, int num_lid_entries, |
| 417 |
int num_obj, ZOLTAN_ID_PTR gids, ZOLTAN_ID_PTR lids, int num_dim, |
| 418 |
double *geom_vec, int *ierr); |
| 419 |
|
| 420 |
|
| 421 |
//M.M.W. need to add hierarchical query functions |
| 422 |
|
| 423 |
}; |
| 424 |
|
| 425 |
} //namespace ZoltanLib |
| 426 |
} //namespace Epetra |
| 427 |
} //namespace Isorropia |
| 428 |
|
| 429 |
#endif //ISORROPIA_EPETRA_ZOLTAN_QUERYOBJECT_H |
| 430 |
|
| 431 |
#if defined(Isorropia_SHOW_DEPRECATED_WARNINGS) |
| 432 |
#ifdef __GNUC__ |
| 433 |
#warning "The Isorropia package is deprecated" |
| 434 |
#endif |
| 435 |
#endif |
| 436 |
|