3
************************************************************************
5
Isorropia: Partitioning and Load Balancing Package
6
Copyright (2006) Sandia Corporation
8
Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
9
license for use of this work by or on behalf of the U.S. Government.
11
This library is free software; you can redistribute it and/or modify
12
it under the terms of the GNU Lesser General Public License as
13
published by the Free Software Foundation; either version 2.1 of the
14
License, or (at your option) any later version.
16
This library is distributed in the hope that it will be useful, but
17
WITHOUT ANY WARRANTY; without even the implied warranty of
18
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19
Lesser General Public License for more details.
21
You should have received a copy of the GNU Lesser General Public
22
License along with this library; if not, write to the Free Software
23
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26
************************************************************************
30
#include <Isorropia_Exception.hpp>
31
#include <Isorropia_Epetra.hpp>
32
#include <Isorropia_EpetraCostDescriber.hpp>
34
#include <Teuchos_RCP.hpp>
35
#include <Teuchos_ParameterList.hpp>
37
#include <Isorropia_EpetraInternalPartitioner.hpp>
41
#include <Epetra_Comm.h>
42
#include <Epetra_Map.h>
43
#include <Epetra_Import.h>
44
#include <Epetra_Vector.h>
45
#include <Epetra_MultiVector.h>
46
#include <Epetra_CrsGraph.h>
47
#include <Epetra_CrsMatrix.h>
48
#include <Epetra_LinearProblem.h>
50
#include <Epetra_MpiComm.h>
61
/* TODO: clean up the code */
69
InternalPartitioner::InternalPartitioner(Teuchos::RCP<const Epetra_CrsGraph> input_graph):
72
setInputType("HYPERGRAPH");
75
InternalPartitioner::InternalPartitioner(Teuchos::RCP<const Epetra_CrsGraph> input_graph,
76
Teuchos::RCP<CostDescriber> costs):
77
Library(input_graph, costs)
79
setInputType("HYPERGRAPH");
82
InternalPartitioner::InternalPartitioner(Teuchos::RCP<const Epetra_RowMatrix> input_matrix):
85
setInputType("HYPERGRAPH");
88
InternalPartitioner::InternalPartitioner(Teuchos::RCP<const Epetra_RowMatrix> input_matrix,
89
Teuchos::RCP<CostDescriber> costs):
90
Library(input_matrix, costs)
92
setInputType("HYPERGRAPH");
95
InternalPartitioner::~InternalPartitioner() {}
97
int InternalPartitioner::precompute()
99
std::string str1("Isorropia::InternalPartitioner::precompute ");
103
Library::precompute();
111
int InternalPartitioner::
112
repartition(Teuchos::ParameterList& paramList,
113
std::vector<int>& myNewElements,
115
std::vector<int>& imports)
116
// std::map<int,int>& exports,
117
// std::map<int,int>& imports)
121
int nrows = input_map_->NumMyElements();
123
if (nrows && costs_.get()){
124
if (costs_->haveVertexWeights()){
125
std::map<int, float> vwgts;
126
costs_->getVertexWeights(vwgts);
128
double *vals = new double [nrows];
130
for (int i=0; i<nrows; i++){
131
int gid = input_map_->GID(i);
132
std::map<int, float>::iterator iter = vwgts.find(gid);
133
if (iter == vwgts.end()){
134
throw Isorropia::Exception("error 1 in simple linear repartitioning");
136
vals[i] = (double)iter->second;
138
weights_ = Teuchos::rcp(new Epetra_Vector(Copy, *input_map_, vals));
144
if (nrows && !weights_.get()){
145
if (input_graph_.get() != 0) {
146
weights_ = Teuchos::rcp(create_row_weights_nnz(*input_graph_));
149
weights_ = Teuchos::rcp(create_row_weights_nnz(*input_matrix_));
153
// int err = Isorropia::Epetra::repartition(*input_map_,
156
// exports, imports);
157
int err = Isorropia::Epetra::repartition(*input_map_,
160
exportsSize, imports);
163
throw Isorropia::Exception("error 2 in simple linear repartitioning");
169
int InternalPartitioner::
170
color(Teuchos::ParameterList& paramList,
171
std::vector<int>& myNewElements)
173
throw Isorropia::Exception("Coloring only available in Zoltan");
177
int InternalPartitioner::
178
order(Teuchos::ParameterList& paramList,
179
std::vector<int>& myNewElements)
181
throw Isorropia::Exception("Ordering only available in Zoltan");
186
int InternalPartitioner::postcompute()
193
} // namespace EPETRA
197
}//namespace Isorropia