| 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 |
#include <Isorropia_EpetraPartitioner.hpp> |
| 41 |
#ifdef HAVE_ISORROPIA_ZOLTAN |
| 42 |
#include <Isorropia_EpetraZoltanLib.hpp> |
| 43 |
#endif |
| 44 |
#include <Isorropia_Exception.hpp> |
| 45 |
#include <Isorropia_Epetra.hpp> |
| 46 |
#include <Isorropia_EpetraCostDescriber.hpp> |
| 47 |
|
| 48 |
#include <Teuchos_RCP.hpp> |
| 49 |
#include <Teuchos_ParameterList.hpp> |
| 50 |
|
| 51 |
#ifdef HAVE_EPETRA |
| 52 |
#include <Epetra_Comm.h> |
| 53 |
#include <Epetra_Map.h> |
| 54 |
#include <Epetra_Import.h> |
| 55 |
#include <Epetra_Vector.h> |
| 56 |
#include <Epetra_MultiVector.h> |
| 57 |
#include <Epetra_CrsGraph.h> |
| 58 |
#include <Epetra_CrsMatrix.h> |
| 59 |
#include <Epetra_LinearProblem.h> |
| 60 |
|
| 61 |
#endif |
| 62 |
|
| 63 |
#include <cstring> |
| 64 |
#include <iostream> |
| 65 |
#include <sstream> |
| 66 |
#include <string> |
| 67 |
#include <ctype.h> |
| 68 |
|
| 69 |
namespace Isorropia { |
| 70 |
|
| 71 |
#ifdef HAVE_EPETRA |
| 72 |
|
| 73 |
namespace Epetra { |
| 74 |
|
| 75 |
//////////////////////////////////////////////////////////////////////////////// |
| 76 |
//////////////////////////////////////////////////////////////////////////////// |
| 77 |
Partitioner::Partitioner(Teuchos::RCP<const Epetra_CrsGraph> input_graph, |
| 78 |
const Teuchos::ParameterList& paramlist, |
| 79 |
bool compute_partitioning_now): |
| 80 |
Operator (input_graph, paramlist, 0), |
| 81 |
partGIDs(NULL), partSizes(NULL), numPartSizes(0), printMetrics(0) |
| 82 |
{ |
| 83 |
if (compute_partitioning_now) |
| 84 |
partition(true); |
| 85 |
} |
| 86 |
//////////////////////////////////////////////////////////////////////////////// |
| 87 |
|
| 88 |
//////////////////////////////////////////////////////////////////////////////// |
| 89 |
//////////////////////////////////////////////////////////////////////////////// |
| 90 |
Partitioner::Partitioner(const Epetra_CrsGraph *input_graph, |
| 91 |
const Teuchos::ParameterList& paramlist, |
| 92 |
bool compute_partitioning_now): |
| 93 |
Operator (Teuchos::RCP<const Epetra_CrsGraph>(input_graph,false), paramlist, 0), |
| 94 |
partGIDs(NULL), partSizes(NULL), numPartSizes(0), printMetrics(0) |
| 95 |
{ |
| 96 |
if (compute_partitioning_now) |
| 97 |
partition(true); |
| 98 |
} |
| 99 |
//////////////////////////////////////////////////////////////////////////////// |
| 100 |
|
| 101 |
//////////////////////////////////////////////////////////////////////////////// |
| 102 |
//////////////////////////////////////////////////////////////////////////////// |
| 103 |
Partitioner::Partitioner(Teuchos::RCP<const Epetra_CrsGraph> input_graph, |
| 104 |
Teuchos::RCP<CostDescriber> costs, |
| 105 |
const Teuchos::ParameterList& paramlist, |
| 106 |
bool compute_partitioning_now): |
| 107 |
Operator (input_graph, costs, paramlist, 0) , |
| 108 |
partGIDs(NULL), partSizes(NULL), numPartSizes(0), printMetrics(0) |
| 109 |
{ |
| 110 |
if (compute_partitioning_now) |
| 111 |
partition(true); |
| 112 |
} |
| 113 |
//////////////////////////////////////////////////////////////////////////////// |
| 114 |
|
| 115 |
//////////////////////////////////////////////////////////////////////////////// |
| 116 |
//////////////////////////////////////////////////////////////////////////////// |
| 117 |
Partitioner::Partitioner(const Epetra_CrsGraph *input_graph, |
| 118 |
CostDescriber *costs, |
| 119 |
const Teuchos::ParameterList& paramlist, |
| 120 |
bool compute_partitioning_now): |
| 121 |
Operator (Teuchos::RCP<const Epetra_CrsGraph>(input_graph,false), |
| 122 |
Teuchos::RCP<CostDescriber>(costs,false), paramlist, 0), |
| 123 |
partGIDs(NULL), partSizes(NULL), numPartSizes(0), printMetrics(0) |
| 124 |
{ |
| 125 |
if (compute_partitioning_now) |
| 126 |
partition(true); |
| 127 |
} |
| 128 |
//////////////////////////////////////////////////////////////////////////////// |
| 129 |
|
| 130 |
//////////////////////////////////////////////////////////////////////////////// |
| 131 |
//////////////////////////////////////////////////////////////////////////////// |
| 132 |
Partitioner::Partitioner(Teuchos::RCP<const Epetra_RowMatrix> input_matrix, |
| 133 |
const Teuchos::ParameterList& paramlist, |
| 134 |
bool compute_partitioning_now): |
| 135 |
Operator (input_matrix, paramlist, 0) , |
| 136 |
partGIDs(NULL), partSizes(NULL), numPartSizes(0), printMetrics(0) |
| 137 |
{ |
| 138 |
if (compute_partitioning_now) |
| 139 |
partition(true); |
| 140 |
} |
| 141 |
//////////////////////////////////////////////////////////////////////////////// |
| 142 |
|
| 143 |
//////////////////////////////////////////////////////////////////////////////// |
| 144 |
//////////////////////////////////////////////////////////////////////////////// |
| 145 |
Partitioner::Partitioner(const Epetra_RowMatrix *input_matrix, |
| 146 |
const Teuchos::ParameterList& paramlist, |
| 147 |
bool compute_partitioning_now): |
| 148 |
Operator (Teuchos::RCP<const Epetra_RowMatrix>(input_matrix,false), paramlist, 0) , |
| 149 |
partGIDs(NULL), partSizes(NULL), numPartSizes(0), printMetrics(0) |
| 150 |
{ |
| 151 |
if (compute_partitioning_now) |
| 152 |
partition(true); |
| 153 |
} |
| 154 |
//////////////////////////////////////////////////////////////////////////////// |
| 155 |
|
| 156 |
//////////////////////////////////////////////////////////////////////////////// |
| 157 |
//////////////////////////////////////////////////////////////////////////////// |
| 158 |
Partitioner::Partitioner(Teuchos::RCP<const Epetra_RowMatrix> input_matrix, |
| 159 |
Teuchos::RCP<CostDescriber> costs, |
| 160 |
const Teuchos::ParameterList& paramlist, |
| 161 |
bool compute_partitioning_now): |
| 162 |
Operator (input_matrix, costs, paramlist, 0) , |
| 163 |
partGIDs(NULL), partSizes(NULL), numPartSizes(0), printMetrics(0) |
| 164 |
{ |
| 165 |
if (compute_partitioning_now) |
| 166 |
partition(true); |
| 167 |
} |
| 168 |
//////////////////////////////////////////////////////////////////////////////// |
| 169 |
|
| 170 |
//////////////////////////////////////////////////////////////////////////////// |
| 171 |
//////////////////////////////////////////////////////////////////////////////// |
| 172 |
Partitioner::Partitioner(const Epetra_RowMatrix *input_matrix, |
| 173 |
CostDescriber *costs, |
| 174 |
const Teuchos::ParameterList& paramlist, |
| 175 |
bool compute_partitioning_now): |
| 176 |
Operator (Teuchos::RCP<const Epetra_RowMatrix>(input_matrix,false), |
| 177 |
Teuchos::RCP<CostDescriber>(costs,false), paramlist, 0) , |
| 178 |
partGIDs(NULL), partSizes(NULL), numPartSizes(0), printMetrics(0) |
| 179 |
{ |
| 180 |
if (compute_partitioning_now) |
| 181 |
partition(true); |
| 182 |
} |
| 183 |
//////////////////////////////////////////////////////////////////////////////// |
| 184 |
|
| 185 |
//////////////////////////////////////////////////////////////////////////////// |
| 186 |
//////////////////////////////////////////////////////////////////////////////// |
| 187 |
Partitioner::Partitioner(Teuchos::RCP<const Epetra_MultiVector> coords, |
| 188 |
const Teuchos::ParameterList& paramlist, |
| 189 |
bool compute_partitioning_now): |
| 190 |
Operator (coords, paramlist, 0) , |
| 191 |
partGIDs(NULL), partSizes(NULL), numPartSizes(0), printMetrics(0) |
| 192 |
{ |
| 193 |
if (compute_partitioning_now) |
| 194 |
partition(true); |
| 195 |
} |
| 196 |
//////////////////////////////////////////////////////////////////////////////// |
| 197 |
|
| 198 |
//////////////////////////////////////////////////////////////////////////////// |
| 199 |
//////////////////////////////////////////////////////////////////////////////// |
| 200 |
Partitioner::Partitioner(const Epetra_MultiVector *coords, |
| 201 |
const Teuchos::ParameterList& paramlist, |
| 202 |
bool compute_partitioning_now): |
| 203 |
Operator (Teuchos::RCP<const Epetra_MultiVector>(coords,false), paramlist, 0) , |
| 204 |
partGIDs(NULL), partSizes(NULL), numPartSizes(0), printMetrics(0) |
| 205 |
{ |
| 206 |
if (compute_partitioning_now) |
| 207 |
partition(true); |
| 208 |
} |
| 209 |
//////////////////////////////////////////////////////////////////////////////// |
| 210 |
|
| 211 |
//////////////////////////////////////////////////////////////////////////////// |
| 212 |
//////////////////////////////////////////////////////////////////////////////// |
| 213 |
Partitioner::Partitioner(Teuchos::RCP<const Epetra_MultiVector> coords, |
| 214 |
Teuchos::RCP<const Epetra_MultiVector> weights, |
| 215 |
const Teuchos::ParameterList& paramlist, |
| 216 |
bool compute_partitioning_now): |
| 217 |
Operator (coords, weights, paramlist, 0) , |
| 218 |
partGIDs(NULL), partSizes(NULL), numPartSizes(0), printMetrics(0) |
| 219 |
{ |
| 220 |
if (compute_partitioning_now) |
| 221 |
partition(true); |
| 222 |
} |
| 223 |
//////////////////////////////////////////////////////////////////////////////// |
| 224 |
|
| 225 |
//////////////////////////////////////////////////////////////////////////////// |
| 226 |
//////////////////////////////////////////////////////////////////////////////// |
| 227 |
Partitioner::Partitioner(const Epetra_MultiVector *coords, |
| 228 |
const Epetra_MultiVector *weights, |
| 229 |
const Teuchos::ParameterList& paramlist, |
| 230 |
bool compute_partitioning_now): |
| 231 |
Operator (Teuchos::RCP<const Epetra_MultiVector>(coords,false), |
| 232 |
Teuchos::RCP<const Epetra_MultiVector>(weights,false), paramlist, 0) , |
| 233 |
partGIDs(NULL), partSizes(NULL), numPartSizes(0), printMetrics(0) |
| 234 |
{ |
| 235 |
if (compute_partitioning_now) |
| 236 |
partition(true); |
| 237 |
} |
| 238 |
//////////////////////////////////////////////////////////////////////////////// |
| 239 |
|
| 240 |
//////////////////////////////////////////////////////////////////////////////// |
| 241 |
//////////////////////////////////////////////////////////////////////////////// |
| 242 |
Partitioner::Partitioner(Teuchos::RCP<const Epetra_BlockMap> input_map, |
| 243 |
const Teuchos::ParameterList& paramlist, |
| 244 |
bool compute_partitioning_now): |
| 245 |
Operator (input_map, paramlist, 0), |
| 246 |
partGIDs(NULL), partSizes(NULL), numPartSizes(0), printMetrics(0) |
| 247 |
{ |
| 248 |
if (compute_partitioning_now) |
| 249 |
partition(true); |
| 250 |
} |
| 251 |
//////////////////////////////////////////////////////////////////////////////// |
| 252 |
|
| 253 |
//////////////////////////////////////////////////////////////////////////////// |
| 254 |
//////////////////////////////////////////////////////////////////////////////// |
| 255 |
Partitioner::Partitioner(const Epetra_BlockMap *input_map, |
| 256 |
const Teuchos::ParameterList& paramlist, |
| 257 |
bool compute_partitioning_now): |
| 258 |
Operator (Teuchos::RCP<const Epetra_BlockMap>(input_map,false), paramlist, 0), |
| 259 |
partGIDs(NULL), partSizes(NULL), numPartSizes(0), printMetrics(0) |
| 260 |
{ |
| 261 |
if (compute_partitioning_now) |
| 262 |
partition(true); |
| 263 |
} |
| 264 |
//////////////////////////////////////////////////////////////////////////////// |
| 265 |
|
| 266 |
//////////////////////////////////////////////////////////////////////////////// |
| 267 |
//////////////////////////////////////////////////////////////////////////////// |
| 268 |
Partitioner::Partitioner(Teuchos::RCP<const Epetra_CrsGraph> input_graph, |
| 269 |
Teuchos::RCP<const Epetra_MultiVector> coords, |
| 270 |
const Teuchos::ParameterList& paramlist, |
| 271 |
bool compute_partitioning_now): |
| 272 |
Operator (input_graph, coords, paramlist, 0), |
| 273 |
partGIDs(NULL), partSizes(NULL), numPartSizes(0), printMetrics(0) |
| 274 |
{ |
| 275 |
if (compute_partitioning_now) |
| 276 |
partition(true); |
| 277 |
} |
| 278 |
//////////////////////////////////////////////////////////////////////////////// |
| 279 |
|
| 280 |
//////////////////////////////////////////////////////////////////////////////// |
| 281 |
//////////////////////////////////////////////////////////////////////////////// |
| 282 |
Partitioner::Partitioner(const Epetra_CrsGraph *input_graph, |
| 283 |
const Epetra_MultiVector *coords, |
| 284 |
const Teuchos::ParameterList& paramlist, |
| 285 |
bool compute_partitioning_now): |
| 286 |
Operator (Teuchos::RCP<const Epetra_CrsGraph>(input_graph,false), |
| 287 |
Teuchos::RCP<const Epetra_MultiVector>(coords,false), paramlist, 0), |
| 288 |
partGIDs(NULL), partSizes(NULL), numPartSizes(0), printMetrics(0) |
| 289 |
{ |
| 290 |
if (compute_partitioning_now) |
| 291 |
partition(true); |
| 292 |
} |
| 293 |
//////////////////////////////////////////////////////////////////////////////// |
| 294 |
|
| 295 |
//////////////////////////////////////////////////////////////////////////////// |
| 296 |
//////////////////////////////////////////////////////////////////////////////// |
| 297 |
Partitioner::Partitioner(Teuchos::RCP<const Epetra_CrsGraph> input_graph, |
| 298 |
Teuchos::RCP<CostDescriber> costs, |
| 299 |
Teuchos::RCP<const Epetra_MultiVector> coords, |
| 300 |
Teuchos::RCP<const Epetra_MultiVector> weights, |
| 301 |
const Teuchos::ParameterList& paramlist, |
| 302 |
bool compute_partitioning_now): |
| 303 |
Operator (input_graph, costs, coords, weights, paramlist, 0) , |
| 304 |
partGIDs(NULL), partSizes(NULL), numPartSizes(0), printMetrics(0) |
| 305 |
{ |
| 306 |
if (compute_partitioning_now) |
| 307 |
partition(true); |
| 308 |
} |
| 309 |
//////////////////////////////////////////////////////////////////////////////// |
| 310 |
|
| 311 |
//////////////////////////////////////////////////////////////////////////////// |
| 312 |
//////////////////////////////////////////////////////////////////////////////// |
| 313 |
Partitioner::Partitioner(const Epetra_CrsGraph *input_graph, |
| 314 |
CostDescriber *costs, |
| 315 |
const Epetra_MultiVector *coords, |
| 316 |
const Epetra_MultiVector *weights, |
| 317 |
const Teuchos::ParameterList& paramlist, |
| 318 |
bool compute_partitioning_now): |
| 319 |
Operator (Teuchos::RCP<const Epetra_CrsGraph>(input_graph,false), |
| 320 |
Teuchos::RCP<CostDescriber>(costs,false), |
| 321 |
Teuchos::RCP<const Epetra_MultiVector>(coords,false), |
| 322 |
Teuchos::RCP<const Epetra_MultiVector>(weights,false), paramlist, 0) , |
| 323 |
partGIDs(NULL), partSizes(NULL), numPartSizes(0), printMetrics(0) |
| 324 |
{ |
| 325 |
if (compute_partitioning_now) |
| 326 |
partition(true); |
| 327 |
} |
| 328 |
//////////////////////////////////////////////////////////////////////////////// |
| 329 |
|
| 330 |
//////////////////////////////////////////////////////////////////////////////// |
| 331 |
//////////////////////////////////////////////////////////////////////////////// |
| 332 |
Partitioner::Partitioner(Teuchos::RCP<const Epetra_RowMatrix> input_matrix, |
| 333 |
Teuchos::RCP<const Epetra_MultiVector> coords, |
| 334 |
const Teuchos::ParameterList& paramlist, |
| 335 |
bool compute_partitioning_now): |
| 336 |
Operator (input_matrix, coords, paramlist, 0) , |
| 337 |
partGIDs(NULL), partSizes(NULL), numPartSizes(0), printMetrics(0) |
| 338 |
{ |
| 339 |
if (compute_partitioning_now) |
| 340 |
partition(true); |
| 341 |
} |
| 342 |
//////////////////////////////////////////////////////////////////////////////// |
| 343 |
|
| 344 |
//////////////////////////////////////////////////////////////////////////////// |
| 345 |
//////////////////////////////////////////////////////////////////////////////// |
| 346 |
Partitioner::Partitioner(const Epetra_RowMatrix *input_matrix, |
| 347 |
const Epetra_MultiVector *coords, |
| 348 |
const Teuchos::ParameterList& paramlist, |
| 349 |
bool compute_partitioning_now): |
| 350 |
Operator (Teuchos::RCP<const Epetra_RowMatrix>(input_matrix,false), |
| 351 |
Teuchos::RCP<const Epetra_MultiVector>(coords,false), paramlist, 0) , |
| 352 |
partGIDs(NULL), partSizes(NULL), numPartSizes(0), printMetrics(0) |
| 353 |
{ |
| 354 |
if (compute_partitioning_now) |
| 355 |
partition(true); |
| 356 |
} |
| 357 |
//////////////////////////////////////////////////////////////////////////////// |
| 358 |
|
| 359 |
//////////////////////////////////////////////////////////////////////////////// |
| 360 |
//////////////////////////////////////////////////////////////////////////////// |
| 361 |
Partitioner::Partitioner(Teuchos::RCP<const Epetra_RowMatrix> input_matrix, |
| 362 |
Teuchos::RCP<CostDescriber> costs, |
| 363 |
Teuchos::RCP<const Epetra_MultiVector> coords, |
| 364 |
Teuchos::RCP<const Epetra_MultiVector> weights, |
| 365 |
const Teuchos::ParameterList& paramlist, |
| 366 |
bool compute_partitioning_now): |
| 367 |
Operator (input_matrix, costs, coords, weights, paramlist, 0) , |
| 368 |
partGIDs(NULL), partSizes(NULL), numPartSizes(0), printMetrics(0) |
| 369 |
{ |
| 370 |
if (compute_partitioning_now) |
| 371 |
partition(true); |
| 372 |
} |
| 373 |
//////////////////////////////////////////////////////////////////////////////// |
| 374 |
|
| 375 |
//////////////////////////////////////////////////////////////////////////////// |
| 376 |
//////////////////////////////////////////////////////////////////////////////// |
| 377 |
Partitioner::Partitioner(const Epetra_RowMatrix *input_matrix, |
| 378 |
CostDescriber *costs, |
| 379 |
const Epetra_MultiVector *coords, |
| 380 |
const Epetra_MultiVector *weights, |
| 381 |
const Teuchos::ParameterList& paramlist, |
| 382 |
bool compute_partitioning_now): |
| 383 |
Operator (Teuchos::RCP<const Epetra_RowMatrix>(input_matrix,false), |
| 384 |
Teuchos::RCP<CostDescriber>(costs,false), |
| 385 |
Teuchos::RCP<const Epetra_MultiVector>(coords,false), |
| 386 |
Teuchos::RCP<const Epetra_MultiVector>(weights,false), paramlist, 0) , |
| 387 |
partGIDs(NULL), partSizes(NULL), numPartSizes(0), printMetrics(0) |
| 388 |
{ |
| 389 |
if (compute_partitioning_now) |
| 390 |
partition(true); |
| 391 |
} |
| 392 |
//////////////////////////////////////////////////////////////////////////////// |
| 393 |
|
| 394 |
Partitioner::~Partitioner(){} |
| 395 |
|
| 396 |
void Partitioner:: |
| 397 |
clearPartSizes() |
| 398 |
{ |
| 399 |
if (partGIDs){ |
| 400 |
delete [] partGIDs; |
| 401 |
partGIDs = NULL; |
| 402 |
} |
| 403 |
if (partSizes){ |
| 404 |
delete [] partSizes; |
| 405 |
partSizes = NULL; |
| 406 |
} |
| 407 |
numPartSizes = 0; |
| 408 |
} |
| 409 |
|
| 410 |
void Partitioner:: |
| 411 |
setPartSizes(int len, int *global_part_id, float *part_size) |
| 412 |
{ |
| 413 |
clearPartSizes(); |
| 414 |
|
| 415 |
if (len < 1) return; |
| 416 |
|
| 417 |
numPartSizes = len; |
| 418 |
|
| 419 |
partGIDs = new int [len]; |
| 420 |
memcpy(partGIDs, global_part_id, sizeof(int) * len); |
| 421 |
|
| 422 |
partSizes = new float [len]; |
| 423 |
memcpy(partSizes, part_size, sizeof(float) * len); |
| 424 |
} |
| 425 |
|
| 426 |
void Partitioner:: |
| 427 |
partition(bool force_repartitioning) |
| 428 |
{ |
| 429 |
int input_type = Library::unspecified_input_; |
| 430 |
|
| 431 |
std::string partitioning_method_str("PARTITIONING METHOD"); |
| 432 |
std::string partitioning_method = |
| 433 |
paramlist_.get(partitioning_method_str, "UNSPECIFIED"); |
| 434 |
|
| 435 |
std::string zoltan("ZOLTAN"); |
| 436 |
|
| 437 |
if (alreadyComputed() && !force_repartitioning) |
| 438 |
return; |
| 439 |
|
| 440 |
#ifdef HAVE_ISORROPIA_ZOLTAN |
| 441 |
if (partitioning_method == "SIMPLE_LINEAR") { |
| 442 |
throw Isorropia::Exception("Partitioner::partition - Only Zoltan Partitionner is now supported."); |
| 443 |
} |
| 444 |
|
| 445 |
if (input_graph_.get() != 0 && input_coords_.get() != 0) |
| 446 |
{ |
| 447 |
if (weights_.get()) |
| 448 |
{ |
| 449 |
lib_ = Teuchos::rcp(new ZoltanLibClass(input_graph_,costs_,input_coords_, weights_)); |
| 450 |
} |
| 451 |
else |
| 452 |
{ |
| 453 |
lib_ = Teuchos::rcp(new ZoltanLibClass(input_graph_,input_coords_)); |
| 454 |
} |
| 455 |
} |
| 456 |
else if (input_matrix_.get() != 0 && input_coords_.get() != 0) |
| 457 |
{ |
| 458 |
if (weights_.get()) |
| 459 |
{ |
| 460 |
lib_ = Teuchos::rcp(new ZoltanLibClass(input_matrix_,costs_,input_coords_, weights_)); |
| 461 |
} |
| 462 |
else |
| 463 |
{ |
| 464 |
lib_ = Teuchos::rcp(new ZoltanLibClass(input_matrix_,input_coords_)); |
| 465 |
} |
| 466 |
} |
| 467 |
else if (input_graph_.get() != 0) |
| 468 |
lib_ = Teuchos::rcp(new ZoltanLibClass(input_graph_, costs_)); |
| 469 |
else if (input_matrix_.get() != 0) |
| 470 |
lib_ = Teuchos::rcp(new ZoltanLibClass(input_matrix_, costs_)); |
| 471 |
else if (input_coords_.get() != 0) |
| 472 |
{ |
| 473 |
if (weights_.get()) |
| 474 |
{ |
| 475 |
lib_ = Teuchos::rcp(new ZoltanLibClass(input_coords_, weights_)); |
| 476 |
} |
| 477 |
else |
| 478 |
{ |
| 479 |
lib_ = Teuchos::rcp(new ZoltanLibClass(input_coords_)); |
| 480 |
} |
| 481 |
} |
| 482 |
else if (input_map_.get() != 0) |
| 483 |
{ |
| 484 |
lib_ = Teuchos::rcp(new ZoltanLibClass(input_map_)); |
| 485 |
} |
| 486 |
else |
| 487 |
{ |
| 488 |
throw Isorropia::Exception("Partitioner::partition - no input object."); |
| 489 |
} |
| 490 |
|
| 491 |
lib_->numPartSizes = numPartSizes; |
| 492 |
lib_->partGIDs = partGIDs; |
| 493 |
lib_->partSizes = partSizes; |
| 494 |
|
| 495 |
#endif /* HAVE_ISORROPIA_ZOLTAN */ |
| 496 |
Teuchos::ParameterList sublist = paramlist_.sublist(zoltan); |
| 497 |
// TODO: Add "block" and "random" partitioning. |
| 498 |
|
| 499 |
if (partitioning_method == "UNSPECIFIED" && sublist.isParameter("LB_METHOD")) |
| 500 |
{ |
| 501 |
throw Isorropia::Exception("Isorropia \"PARTITIONING METHOD\" as to be set\n" |
| 502 |
"ZOLTAN/LB_METHOD is no longer supported.\n" |
| 503 |
"See readme and release notes for details."); |
| 504 |
} |
| 505 |
|
| 506 |
if (input_coords_.get() != 0) |
| 507 |
{ |
| 508 |
if (partitioning_method == "UNSPECIFIED") |
| 509 |
{ |
| 510 |
sublist.set("LB_METHOD", "RCB"); |
| 511 |
input_type = Library::geometric_input_; |
| 512 |
} |
| 513 |
else if (partitioning_method == "BLOCK") |
| 514 |
{ |
| 515 |
input_type = Library::simple_input_; |
| 516 |
sublist.set("LB_METHOD", "BLOCK"); |
| 517 |
} |
| 518 |
else if (partitioning_method == "CYCLIC") |
| 519 |
{ |
| 520 |
input_type = Library::simple_input_; |
| 521 |
sublist.set("LB_METHOD", "CYCLIC"); |
| 522 |
} |
| 523 |
else if (partitioning_method == "RANDOM") |
| 524 |
{ |
| 525 |
input_type = Library::simple_input_; |
| 526 |
sublist.set("LB_METHOD", "RANDOM"); |
| 527 |
} |
| 528 |
else if (partitioning_method == "HIER_GRAPH_GEOM") // Can perhaps simply this partitioning method name by using another parameter |
| 529 |
{ |
| 530 |
sublist.set("LB_METHOD", "HIER"); |
| 531 |
input_type = Library::graph_geometric_input_; |
| 532 |
} |
| 533 |
else if (partitioning_method == "HIER_HGRAPH_GEOM") // Can perhaps simply this partitioning method name by using another parameter |
| 534 |
{ |
| 535 |
sublist.set("LB_METHOD", "HIER"); |
| 536 |
input_type = Library::hgraph_geometric_input_; |
| 537 |
} |
| 538 |
else if (partitioning_method == "HIER_HGRAPH_GRAPH_GEOM") // Can perhaps simply this partitioning method name by using another parameter |
| 539 |
{ |
| 540 |
sublist.set("LB_METHOD", "HIER"); |
| 541 |
input_type = Library::hgraph_graph_geometric_input_; |
| 542 |
} |
| 543 |
else // Default case: copy partitioning_method (e.g., RCB, RIB, HSFC) |
| 544 |
{ |
| 545 |
sublist.set("LB_METHOD", partitioning_method); |
| 546 |
input_type = Library::geometric_input_; |
| 547 |
} |
| 548 |
} |
| 549 |
else if (input_graph_.get() != 0 || input_matrix_.get() != 0) // graph or matrix input |
| 550 |
{ |
| 551 |
if (partitioning_method == "GRAPH") |
| 552 |
{ |
| 553 |
input_type = Library::graph_input_; |
| 554 |
sublist.set("LB_METHOD", "GRAPH"); |
| 555 |
} |
| 556 |
else if (partitioning_method == "BLOCK") |
| 557 |
{ |
| 558 |
input_type = Library::simple_input_; |
| 559 |
sublist.set("LB_METHOD", "BLOCK"); |
| 560 |
} |
| 561 |
else if (partitioning_method == "CYCLIC") |
| 562 |
{ |
| 563 |
input_type = Library::simple_input_; |
| 564 |
sublist.set("LB_METHOD", "CYCLIC"); |
| 565 |
} |
| 566 |
else if (partitioning_method == "RANDOM") |
| 567 |
{ |
| 568 |
input_type = Library::simple_input_; |
| 569 |
sublist.set("LB_METHOD", "RANDOM"); |
| 570 |
} |
| 571 |
else if (partitioning_method == "HIER_GRAPH") |
| 572 |
{ |
| 573 |
input_type = Library::graph_input_; |
| 574 |
sublist.set("LB_METHOD", "HIER"); |
| 575 |
} |
| 576 |
else if (partitioning_method == "HIER_HGRAPH_GRAPH") // Can perhaps simplify this partitioning method name by using another parameter |
| 577 |
{ |
| 578 |
sublist.set("LB_METHOD", "HIER"); |
| 579 |
input_type = Library::hgraph_graph_input_; |
| 580 |
} |
| 581 |
|
| 582 |
else //Hypergraph by default |
| 583 |
{ |
| 584 |
input_type = Library::hgraph_input_; |
| 585 |
sublist.set("LB_METHOD", "HYPERGRAPH"); |
| 586 |
} |
| 587 |
} |
| 588 |
else // BlockMap input |
| 589 |
{ |
| 590 |
if (partitioning_method == "CYCLIC") |
| 591 |
{ |
| 592 |
input_type = Library::simple_input_; |
| 593 |
sublist.set("LB_METHOD", "CYCLIC"); |
| 594 |
} |
| 595 |
else if (partitioning_method == "RANDOM") |
| 596 |
{ |
| 597 |
input_type = Library::simple_input_; |
| 598 |
sublist.set("LB_METHOD", "RANDOM"); |
| 599 |
} |
| 600 |
else // BLOCK by default |
| 601 |
{ |
| 602 |
input_type = Library::simple_input_; |
| 603 |
sublist.set("LB_METHOD", "BLOCK"); |
| 604 |
} |
| 605 |
} |
| 606 |
|
| 607 |
if (paramlist_.isParameter("NUM PARTS")) { |
| 608 |
sublist.set("NUM_GLOBAL_PARTS", paramlist_.get<std::string>("NUM PARTS")); |
| 609 |
} |
| 610 |
if (paramlist_.isParameter("IMBALANCE TOL")) { |
| 611 |
sublist.set("IMBALANCE_TOL", paramlist_.get<std::string>("IMBALANCE TOL")); |
| 612 |
} |
| 613 |
if (paramlist_.isParameter("BALANCE OBJECTIVE") |
| 614 |
&& paramlist_.get<std::string>("BALANCE OBJECTIVE") == "NONZEROS") { |
| 615 |
sublist.set("ADD_OBJ_WEIGHT", "NONZEROS"); |
| 616 |
} |
| 617 |
|
| 618 |
std::string print_metrics_str("PRINT ZOLTAN METRICS"); |
| 619 |
std::string print_metrics = |
| 620 |
paramlist_.get(print_metrics_str, "UNSPECIFIED"); |
| 621 |
|
| 622 |
if (print_metrics == ("UNSPECIFIED")){ |
| 623 |
printMetrics = 0; |
| 624 |
} |
| 625 |
else if (print_metrics == ("1")){ |
| 626 |
printMetrics = 1; |
| 627 |
} |
| 628 |
else if (print_metrics == ("2")){ |
| 629 |
printMetrics = 2; |
| 630 |
} |
| 631 |
else { |
| 632 |
printMetrics = 1; |
| 633 |
} |
| 634 |
|
| 635 |
lib_->input_type_ = input_type; |
| 636 |
lib_->repartition(sublist, properties_, exportsSize_, imports_); |
| 637 |
computeNumberOfProperties(); |
| 638 |
operation_already_computed_ = true; |
| 639 |
} |
| 640 |
|
| 641 |
//////////////////////////////////////////////////////////////////////////////// |
| 642 |
//////////////////////////////////////////////////////////////////////////////// |
| 643 |
void Partitioner:: |
| 644 |
compute(bool force_repartitioning) |
| 645 |
{ |
| 646 |
partition(force_repartitioning); |
| 647 |
} |
| 648 |
//////////////////////////////////////////////////////////////////////////////// |
| 649 |
|
| 650 |
//////////////////////////////////////////////////////////////////////////////// |
| 651 |
// Create a new RowMap |
| 652 |
//////////////////////////////////////////////////////////////////////////////// |
| 653 |
Teuchos::RCP<Epetra_Map> |
| 654 |
Partitioner::createNewMap() |
| 655 |
{ |
| 656 |
Epetra_Map *outputMap; |
| 657 |
|
| 658 |
createNewMap(outputMap); |
| 659 |
|
| 660 |
return( Teuchos::RCP<Epetra_Map>(outputMap) ); |
| 661 |
} |
| 662 |
//////////////////////////////////////////////////////////////////////////////// |
| 663 |
|
| 664 |
//////////////////////////////////////////////////////////////////////////////// |
| 665 |
// Create a new RowMap |
| 666 |
//////////////////////////////////////////////////////////////////////////////// |
| 667 |
void |
| 668 |
Partitioner::createNewMap(Epetra_Map * &outputMap) |
| 669 |
{ |
| 670 |
if (!alreadyComputed()) { |
| 671 |
partition(); |
| 672 |
} |
| 673 |
|
| 674 |
//Generate New Element List |
| 675 |
int myPID = input_map_->Comm().MyPID(); |
| 676 |
int numMyElements = input_map_->NumMyElements(); |
| 677 |
std::vector<int> elementList( numMyElements ); |
| 678 |
if (numMyElements > 0) |
| 679 |
input_map_->MyGlobalElements( &elementList[0] ); |
| 680 |
else |
| 681 |
input_map_->MyGlobalElements((int*)NULL); // disambiguate int/long long |
| 682 |
|
| 683 |
int newGIDSize = numMyElements - exportsSize_; |
| 684 |
|
| 685 |
std::vector<int> myNewGID; |
| 686 |
|
| 687 |
if (newGIDSize > 0){ |
| 688 |
myNewGID.resize(newGIDSize); |
| 689 |
std::vector<int>::iterator newElemsIter; |
| 690 |
std::vector<int>::const_iterator elemsIter; |
| 691 |
|
| 692 |
for (elemsIter = properties_.begin(), newElemsIter= myNewGID.begin() ; |
| 693 |
elemsIter != properties_.end() ; elemsIter ++) { |
| 694 |
if ((*elemsIter) == myPID) { |
| 695 |
(*newElemsIter) = elementList[elemsIter - properties_.begin()]; |
| 696 |
newElemsIter ++; |
| 697 |
} |
| 698 |
} |
| 699 |
} |
| 700 |
//Add imports to end of list |
| 701 |
myNewGID.insert(myNewGID.end(), imports_.begin(), imports_.end()); |
| 702 |
|
| 703 |
int *gidptr; |
| 704 |
if (myNewGID.size() > 0) |
| 705 |
gidptr = &myNewGID[0]; |
| 706 |
else |
| 707 |
gidptr = NULL; |
| 708 |
|
| 709 |
outputMap = new Epetra_Map(-1, myNewGID.size(), gidptr, 0, input_map_->Comm()); |
| 710 |
|
| 711 |
return; |
| 712 |
} |
| 713 |
//////////////////////////////////////////////////////////////////////////////// |
| 714 |
|
| 715 |
|
| 716 |
} // namespace EPETRA |
| 717 |
|
| 718 |
#endif //HAVE_EPETRA |
| 719 |
|
| 720 |
}//namespace Isorropia |
| 721 |
|