| 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_EpetraPartitioner_hpp_ |
| 41 |
#define _Isorropia_EpetraPartitioner_hpp_ |
| 42 |
|
| 43 |
|
| 44 |
/*! \file Isorropia_EpetraPartitioner.hpp |
| 45 |
* |
| 46 |
* \brief Contains functionality used for partitioning Epetra |
| 47 |
* matrices, maps, multivectors, etc. |
| 48 |
*/ |
| 49 |
|
| 50 |
/** \example matrix_1.cpp |
| 51 |
* |
| 52 |
* This example demonstrates creating a balanced copy of Epetra_CrsGraph and |
| 53 |
* Epetra_CrsMatrix objects using Isorropia::Epetra::createBalancedCopy functions. |
| 54 |
* |
| 55 |
*/ |
| 56 |
|
| 57 |
/** \example geometric/example_rcb.cpp |
| 58 |
* |
| 59 |
* This example shows how to use geometric partitioning methods with multivectors. |
| 60 |
* |
| 61 |
*/ |
| 62 |
|
| 63 |
/** \example vert_weights.cpp |
| 64 |
* |
| 65 |
* This example shows how to use graph partitioning methods with vertex weights. |
| 66 |
* |
| 67 |
*/ |
| 68 |
|
| 69 |
/** \example graphedge_weights.cpp |
| 70 |
* |
| 71 |
* This example shows how to use graph partitioning methods with edge weights. |
| 72 |
* |
| 73 |
*/ |
| 74 |
|
| 75 |
/** \example hgedge_weights.cpp |
| 76 |
* |
| 77 |
* This example shows how to use hypergraph partitioning methods with hyperedge weights. |
| 78 |
* |
| 79 |
*/ |
| 80 |
|
| 81 |
/** \example part_redist.cpp |
| 82 |
* |
| 83 |
* This example demonstrates repartitioning and redistributing the |
| 84 |
* contents of an Epetra_LinearProblem object, using the Isorropia::Partitioner |
| 85 |
* and Isorropia::Redistributor classes. This program does not use |
| 86 |
* user-specified weights/costs. |
| 87 |
* |
| 88 |
*/ |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
#include <Isorropia_ConfigDefs.hpp> |
| 93 |
#include <Teuchos_RCP.hpp> |
| 94 |
#include <Teuchos_ParameterList.hpp> |
| 95 |
|
| 96 |
#include <Isorropia_EpetraCostDescriber.hpp> |
| 97 |
#include <Isorropia_EpetraOperator.hpp> |
| 98 |
#include <Isorropia_Partitioner.hpp> |
| 99 |
|
| 100 |
#ifdef HAVE_EPETRA |
| 101 |
class Epetra_Map; |
| 102 |
class Epetra_BlockMap; |
| 103 |
class Epetra_Import; |
| 104 |
class Epetra_Vector; |
| 105 |
class Epetra_MultiVector; |
| 106 |
class Epetra_CrsGraph; |
| 107 |
class Epetra_CrsMatrix; |
| 108 |
class Epetra_RowMatrix; |
| 109 |
class Epetra_LinearProblem; |
| 110 |
|
| 111 |
namespace Isorropia { |
| 112 |
|
| 113 |
namespace Epetra { |
| 114 |
class CostDescriber; |
| 115 |
|
| 116 |
/** An implementation of the Partitioner interface that operates on |
| 117 |
Epetra matrices and linear systems. |
| 118 |
|
| 119 |
\ingroup partitioning_grp partitioning_rcp_grp partitioning_ptr_grp |
| 120 |
*/ |
| 121 |
|
| 122 |
class Partitioner : public Isorropia::Partitioner, public Isorropia::Epetra::Operator { |
| 123 |
public: |
| 124 |
|
| 125 |
/** @ingroup partitioning_rcp_grp |
| 126 |
*/ |
| 127 |
Partitioner(Teuchos::RCP<const Epetra_CrsGraph> inputGraph, |
| 128 |
const Teuchos::ParameterList& paramlist=Teuchos::ParameterList("EmptyParameterList"), |
| 129 |
bool compute_partitioning_now=true); |
| 130 |
|
| 131 |
/** |
| 132 |
\ingroup partitioning_ptr_grp |
| 133 |
*/ |
| 134 |
Partitioner(const Epetra_CrsGraph *inputGraph, |
| 135 |
const Teuchos::ParameterList& paramlist=Teuchos::ParameterList("EmptyParameterList"), |
| 136 |
bool compute_partitioning_now=true); |
| 137 |
|
| 138 |
/** |
| 139 |
\ingroup partitioning_rcp_grp |
| 140 |
*/ |
| 141 |
Partitioner(Teuchos::RCP<const Epetra_CrsGraph> inputGraph, |
| 142 |
Teuchos::RCP<CostDescriber> costs, |
| 143 |
const Teuchos::ParameterList& paramlist=Teuchos::ParameterList("EmptyParameterList"), |
| 144 |
bool compute_partitioning_now=true); |
| 145 |
|
| 146 |
/** |
| 147 |
\ingroup partitioning_ptr_grp |
| 148 |
*/ |
| 149 |
Partitioner(const Epetra_CrsGraph *inputGraph, |
| 150 |
CostDescriber* costs, |
| 151 |
const Teuchos::ParameterList& paramlist=Teuchos::ParameterList("EmptyParameterList"), |
| 152 |
bool compute_partitioning_now=true); |
| 153 |
|
| 154 |
/** |
| 155 |
\ingroup partitioning_rcp_grp |
| 156 |
*/ |
| 157 |
Partitioner(Teuchos::RCP<const Epetra_RowMatrix> inputMatrix, |
| 158 |
const Teuchos::ParameterList& paramlist=Teuchos::ParameterList("EmptyParameterList"), |
| 159 |
bool compute_partitioning_now=true); |
| 160 |
|
| 161 |
/** |
| 162 |
\ingroup partitioning_ptr_grp |
| 163 |
*/ |
| 164 |
Partitioner(const Epetra_RowMatrix *inputMatrix, |
| 165 |
const Teuchos::ParameterList& paramlist=Teuchos::ParameterList("EmptyParameterList"), |
| 166 |
bool compute_partitioning_now=true); |
| 167 |
|
| 168 |
/** |
| 169 |
\ingroup partitioning_rcp_grp |
| 170 |
*/ |
| 171 |
Partitioner(Teuchos::RCP<const Epetra_RowMatrix> inputMatrix, |
| 172 |
Teuchos::RCP<CostDescriber> costs, |
| 173 |
const Teuchos::ParameterList& paramlist=Teuchos::ParameterList("EmptyParameterList"), |
| 174 |
bool compute_partitioning_now=true); |
| 175 |
|
| 176 |
/** |
| 177 |
\ingroup partitioning_ptr_grp |
| 178 |
*/ |
| 179 |
Partitioner(const Epetra_RowMatrix *inputMatrix, |
| 180 |
CostDescriber *costs, |
| 181 |
const Teuchos::ParameterList& paramlist=Teuchos::ParameterList("EmptyParameterList"), |
| 182 |
bool compute_partitioning_now=true); |
| 183 |
|
| 184 |
/** |
| 185 |
\ingroup partitioning_rcp_grp |
| 186 |
*/ |
| 187 |
Partitioner(Teuchos::RCP<const Epetra_MultiVector> coords, |
| 188 |
const Teuchos::ParameterList& paramlist=Teuchos::ParameterList("EmptyParameterList"), |
| 189 |
bool compute_partitioning_now=true); |
| 190 |
|
| 191 |
/** |
| 192 |
\ingroup partitioning_ptr_grp |
| 193 |
*/ |
| 194 |
Partitioner(const Epetra_MultiVector *coords, |
| 195 |
const Teuchos::ParameterList& paramlist=Teuchos::ParameterList("EmptyParameterList"), |
| 196 |
bool compute_partitioning_now=true); |
| 197 |
|
| 198 |
/** |
| 199 |
\ingroup partitioning_rcp_grp |
| 200 |
*/ |
| 201 |
Partitioner(Teuchos::RCP<const Epetra_MultiVector> coords, |
| 202 |
Teuchos::RCP<const Epetra_MultiVector> weights, |
| 203 |
const Teuchos::ParameterList& paramlist=Teuchos::ParameterList("EmptyParameterList"), |
| 204 |
bool compute_partitioning_now=true); |
| 205 |
|
| 206 |
/** @ingroup partitioning_ptr_grp |
| 207 |
*/ |
| 208 |
Partitioner(const Epetra_MultiVector *coords, |
| 209 |
const Epetra_MultiVector *weights, |
| 210 |
const Teuchos::ParameterList& paramlist=Teuchos::ParameterList("EmptyParameterList"), |
| 211 |
bool compute_partitioning_now=true); |
| 212 |
|
| 213 |
/** @ingroup partitioning_rcp_grp |
| 214 |
*/ |
| 215 |
Partitioner(Teuchos::RCP<const Epetra_BlockMap> inputMap, |
| 216 |
const Teuchos::ParameterList& paramlist=Teuchos::ParameterList("EmptyParameterList"), |
| 217 |
bool compute_partitioning_now=true); |
| 218 |
|
| 219 |
/** @ingroup partitioning_ptr_grp |
| 220 |
*/ |
| 221 |
Partitioner(const Epetra_BlockMap *inputMap, |
| 222 |
const Teuchos::ParameterList& paramlist=Teuchos::ParameterList("EmptyParameterList"), |
| 223 |
bool compute_partitioning_now=true); |
| 224 |
|
| 225 |
/** @ingroup partitioning_rcp_grp |
| 226 |
*/ |
| 227 |
Partitioner(Teuchos::RCP<const Epetra_CrsGraph> inputGraph, |
| 228 |
Teuchos::RCP<const Epetra_MultiVector> coords, |
| 229 |
const Teuchos::ParameterList& paramlist=Teuchos::ParameterList("EmptyParameterList"), |
| 230 |
bool compute_partitioning_now=true); |
| 231 |
|
| 232 |
/** @ingroup partitioning_ptr_grp |
| 233 |
*/ |
| 234 |
Partitioner(const Epetra_CrsGraph *inputGraph, |
| 235 |
const Epetra_MultiVector *coords, |
| 236 |
const Teuchos::ParameterList& paramlist=Teuchos::ParameterList("EmptyParameterList"), |
| 237 |
bool compute_partitioning_now=true); |
| 238 |
|
| 239 |
|
| 240 |
/** @ingroup partitioning_rcp_grp |
| 241 |
*/ |
| 242 |
Partitioner(Teuchos::RCP<const Epetra_CrsGraph> inputGraph, |
| 243 |
Teuchos::RCP<CostDescriber> costs, |
| 244 |
Teuchos::RCP<const Epetra_MultiVector> coords, |
| 245 |
Teuchos::RCP<const Epetra_MultiVector> weights, |
| 246 |
const Teuchos::ParameterList& paramlist=Teuchos::ParameterList("EmptyParameterList"), |
| 247 |
bool compute_partitioning_now=true); |
| 248 |
|
| 249 |
/** @ingroup partitioning_ptr_grp |
| 250 |
*/ |
| 251 |
Partitioner(const Epetra_CrsGraph *inputGraph, |
| 252 |
CostDescriber *costs, |
| 253 |
const Epetra_MultiVector *coords, |
| 254 |
const Epetra_MultiVector *weights, |
| 255 |
const Teuchos::ParameterList& paramlist=Teuchos::ParameterList("EmptyParameterList"), |
| 256 |
bool compute_partitioning_now=true); |
| 257 |
|
| 258 |
/** @ingroup partitioning_rcp_grp |
| 259 |
*/ |
| 260 |
Partitioner(Teuchos::RCP<const Epetra_RowMatrix> inputMatrix, |
| 261 |
Teuchos::RCP<const Epetra_MultiVector> coords, |
| 262 |
const Teuchos::ParameterList& paramlist=Teuchos::ParameterList("EmptyParameterList"), |
| 263 |
bool compute_partitioning_now=true); |
| 264 |
|
| 265 |
/** @ingroup partitioning_ptr_grp |
| 266 |
*/ |
| 267 |
Partitioner(const Epetra_RowMatrix *inputMatrix, |
| 268 |
const Epetra_MultiVector *coords, |
| 269 |
const Teuchos::ParameterList& paramlist=Teuchos::ParameterList("EmptyParameterList"), |
| 270 |
bool compute_partitioning_now=true); |
| 271 |
|
| 272 |
/** @ingroup partitioning_rcp_grp |
| 273 |
*/ |
| 274 |
Partitioner(Teuchos::RCP<const Epetra_RowMatrix> inputMatrix, |
| 275 |
Teuchos::RCP<CostDescriber> costs, |
| 276 |
Teuchos::RCP<const Epetra_MultiVector> coords, |
| 277 |
Teuchos::RCP<const Epetra_MultiVector> weights, |
| 278 |
const Teuchos::ParameterList& paramlist=Teuchos::ParameterList("EmptyParameterList"), |
| 279 |
bool compute_partitioning_now=true); |
| 280 |
|
| 281 |
/** @ingroup partitioning_ptr_grp |
| 282 |
*/ |
| 283 |
Partitioner(const Epetra_RowMatrix *inputMatrix, |
| 284 |
CostDescriber *costs, |
| 285 |
const Epetra_MultiVector *coords, |
| 286 |
const Epetra_MultiVector *weights, |
| 287 |
const Teuchos::ParameterList& paramlist=Teuchos::ParameterList("EmptyParameterList"), |
| 288 |
bool compute_partitioning_now=true); |
| 289 |
|
| 290 |
|
| 291 |
/** @ingroup partitioning_grp |
| 292 |
Destructor |
| 293 |
*/ |
| 294 |
virtual ~Partitioner(); |
| 295 |
|
| 296 |
/* @ingroup partitioning_grp |
| 297 |
* Set the relative number of objects in each part. The default is to |
| 298 |
* evenly divide objects across parts. The numbers can be fractions of |
| 299 |
* one, or whole numbers. Zoltan adds the values supplied and takes the sizes |
| 300 |
* as proportional to that whole. |
| 301 |
* |
| 302 |
* We make a copy of id and size lists. |
| 303 |
* |
| 304 |
* Caller should supply either global part IDs or local part IDs. |
| 305 |
* Part IDs are integers beginning at zero for the first part. |
| 306 |
* |
| 307 |
* No communication is done during this call. One process can make the call |
| 308 |
* for all parts, or many processes can make the call. Zoltan checks the |
| 309 |
* consistency of the information provided. |
| 310 |
*/ |
| 311 |
|
| 312 |
void setPartSizes(int len, int *global_part_id, float *part_size); |
| 313 |
|
| 314 |
/* @ingroup partitioning_grp |
| 315 |
* Free the memory allocated to store part sizes. |
| 316 |
*/ |
| 317 |
void clearPartSizes(); |
| 318 |
|
| 319 |
/** @ingroup partitioning_grp |
| 320 |
partition is the method that computes |
| 321 |
a rebalanced partitioning for the data in the object |
| 322 |
that this class was constructed with. |
| 323 |
|
| 324 |
\param force_repartitioning Optional argument defaults to false. By |
| 325 |
default, compute_partitioning() only does anything the first time |
| 326 |
it is called, and subsequent repeated calls are no-ops. If the user's |
| 327 |
intent is to re-compute the partitioning (e.g., if parameters |
| 328 |
or other inputs have been changed), then setting this flag to |
| 329 |
true will force a new partitioning to be computed. |
| 330 |
*/ |
| 331 |
void partition(bool force_repartitioning=false); |
| 332 |
|
| 333 |
/** @ingroup partitioning_grp |
| 334 |
*/ |
| 335 |
virtual void compute(bool forceRecomputing=false); |
| 336 |
|
| 337 |
/** @ingroup partitioning_grp |
| 338 |
*/ |
| 339 |
int numElemsInPart(int part) const { |
| 340 |
return (numElemsWithProperty(part)); |
| 341 |
} |
| 342 |
|
| 343 |
/** @ingroup partitioning_grp |
| 344 |
*/ |
| 345 |
void elemsInPart(int part, int* elementList, int len) const { |
| 346 |
elemsWithProperty(part, elementList, len); |
| 347 |
} |
| 348 |
|
| 349 |
/** @ingroup partitioning_rcp_grp |
| 350 |
Create a new @c Epetra_Map corresponding to the new partition. |
| 351 |
|
| 352 |
This method is essentially used by the |
| 353 |
Isorropia::Epetra::Redistributor object. |
| 354 |
|
| 355 |
\return @c Epetra_Map that contains the new distribution of elements. |
| 356 |
|
| 357 |
\pre The number of parts might be the same or lower than the |
| 358 |
number of processors. |
| 359 |
*/ |
| 360 |
Teuchos::RCP<Epetra_Map> createNewMap(); |
| 361 |
|
| 362 |
/** @ingroup partitioning_ptr_grp |
| 363 |
Create a new @c Epetra_Map corresponding to the new partition. |
| 364 |
|
| 365 |
This method is essentially used by the |
| 366 |
Isorropia::Epetra::Redistributor object. |
| 367 |
|
| 368 |
\param[out] outputMap @c Epetra_Map that contains the new distribution of elements. |
| 369 |
|
| 370 |
\pre The number of parts might be the same or lower than the |
| 371 |
number of processors. |
| 372 |
*/ |
| 373 |
void createNewMap(Epetra_Map *&outputMap); |
| 374 |
|
| 375 |
int printZoltanMetrics() { return printMetrics; } |
| 376 |
|
| 377 |
private: |
| 378 |
int *partGIDs; |
| 379 |
float *partSizes; |
| 380 |
int numPartSizes; |
| 381 |
int printMetrics; |
| 382 |
|
| 383 |
};//class Partitioner |
| 384 |
|
| 385 |
}//namespace Epetra |
| 386 |
}//namespace Isorropia |
| 387 |
|
| 388 |
#endif //HAVE_EPETRA |
| 389 |
|
| 390 |
#endif |
| 391 |
|
| 392 |
|
| 393 |
#if defined(Isorropia_SHOW_DEPRECATED_WARNINGS) |
| 394 |
#ifdef __GNUC__ |
| 395 |
#warning "The Isorropia package is deprecated" |
| 396 |
#endif |
| 397 |
#endif |
| 398 |
|