~chaffra/+junk/trilinos

« back to all changes in this revision

Viewing changes to packages/isorropia/src/epetra/Isorropia_EpetraInternalPartitioner.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme, Christophe Prud'homme, Johannes Ring
  • Date: 2009-12-13 12:53:22 UTC
  • mfrom: (5.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20091213125322-in0nrdjc55deqsw9
Tags: 10.0.3.dfsg-1
[Christophe Prud'homme]
* New upstream release

[Johannes Ring]
* debian/patches/libname.patch: Add prefix 'libtrilinos_' to all
  libraries. 
* debian/patches/soname.patch: Add soversion to libraries.
* debian/watch: Update download URL.
* debian/control:
  - Remove python-numeric from Build-Depends (virtual package).
  - Remove automake and autotools from Build-Depends and add cmake to
    reflect switch to CMake.
  - Add python-support to Build-Depends.
* debian/rules: 
  - Cleanup and updates for switch to CMake.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//@HEADER
2
 
/*
3
 
************************************************************************
4
 
 
5
 
              Isorropia: Partitioning and Load Balancing Package
6
 
                Copyright (2006) Sandia Corporation
7
 
 
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.
10
 
 
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.
15
 
 
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.
20
 
 
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
24
 
USA
25
 
 
26
 
************************************************************************
27
 
*/
28
 
//@HEADER
29
 
 
30
 
#include <Isorropia_Exception.hpp>
31
 
#include <Isorropia_Epetra.hpp>
32
 
#include <Isorropia_EpetraCostDescriber.hpp>
33
 
 
34
 
#include <Teuchos_RCP.hpp>
35
 
#include <Teuchos_ParameterList.hpp>
36
 
 
37
 
#include <Isorropia_EpetraInternalPartitioner.hpp>
38
 
 
39
 
 
40
 
#ifdef HAVE_EPETRA
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>
49
 
#ifdef HAVE_MPI
50
 
#include <Epetra_MpiComm.h>
51
 
#endif
52
 
#endif
53
 
 
54
 
 
55
 
#include <cstring>
56
 
#include <iostream>
57
 
#include <sstream>
58
 
#include <string>
59
 
#include <ctype.h>
60
 
 
61
 
/* TODO: clean up the code */
62
 
 
63
 
namespace Isorropia {
64
 
 
65
 
#ifdef HAVE_EPETRA
66
 
 
67
 
namespace Epetra {
68
 
 
69
 
InternalPartitioner::InternalPartitioner(Teuchos::RCP<const Epetra_CrsGraph> input_graph):
70
 
  Library(input_graph)
71
 
 {
72
 
   setInputType("HYPERGRAPH");
73
 
 }
74
 
 
75
 
InternalPartitioner::InternalPartitioner(Teuchos::RCP<const Epetra_CrsGraph> input_graph,
76
 
                          Teuchos::RCP<CostDescriber> costs):
77
 
  Library(input_graph, costs)
78
 
{
79
 
   setInputType("HYPERGRAPH");
80
 
}
81
 
 
82
 
InternalPartitioner::InternalPartitioner(Teuchos::RCP<const Epetra_RowMatrix> input_matrix):
83
 
  Library(input_matrix)
84
 
{
85
 
   setInputType("HYPERGRAPH");
86
 
}
87
 
 
88
 
InternalPartitioner::InternalPartitioner(Teuchos::RCP<const Epetra_RowMatrix> input_matrix,
89
 
                          Teuchos::RCP<CostDescriber> costs):
90
 
  Library(input_matrix, costs)
91
 
{
92
 
   setInputType("HYPERGRAPH");
93
 
}
94
 
 
95
 
InternalPartitioner::~InternalPartitioner() {}
96
 
 
97
 
int InternalPartitioner::precompute()
98
 
{
99
 
  std::string str1("Isorropia::InternalPartitioner::precompute ");
100
 
  std::string str2;
101
 
 
102
 
 
103
 
  Library::precompute();
104
 
 
105
 
  return (0);
106
 
}
107
 
 
108
 
 
109
 
 
110
 
 
111
 
int InternalPartitioner::
112
 
repartition(Teuchos::ParameterList& paramList,
113
 
            std::vector<int>& myNewElements,
114
 
              int& exportsSize,
115
 
              std::vector<int>& imports)
116
 
//          std::map<int,int>& exports,
117
 
//          std::map<int,int>& imports)
118
 
{
119
 
  precompute();
120
 
 
121
 
  int nrows = input_map_->NumMyElements();
122
 
 
123
 
  if (nrows && costs_.get()){
124
 
    if (costs_->haveVertexWeights()){
125
 
      std::map<int, float> vwgts;
126
 
      costs_->getVertexWeights(vwgts);
127
 
 
128
 
      double *vals = new double [nrows];
129
 
 
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");
135
 
        }
136
 
        vals[i] = (double)iter->second;
137
 
      }
138
 
      weights_ = Teuchos::rcp(new Epetra_Vector(Copy, *input_map_, vals));
139
 
 
140
 
      delete [] vals;
141
 
    }
142
 
  }
143
 
 
144
 
  if (nrows && !weights_.get()){
145
 
    if (input_graph_.get() != 0) {
146
 
      weights_ = Teuchos::rcp(create_row_weights_nnz(*input_graph_));
147
 
    }
148
 
    else {
149
 
      weights_ = Teuchos::rcp(create_row_weights_nnz(*input_matrix_));
150
 
    }
151
 
  }
152
 
 
153
 
//   int err = Isorropia::Epetra::repartition(*input_map_,
154
 
//                                         *weights_,
155
 
//                                         myNewElements,
156
 
//                                         exports, imports);
157
 
  int err = Isorropia::Epetra::repartition(*input_map_,
158
 
                                           *weights_,
159
 
                                           myNewElements,
160
 
                                           exportsSize, imports);
161
 
 
162
 
  if (err != 0) {
163
 
    throw Isorropia::Exception("error 2 in simple linear repartitioning");
164
 
  }
165
 
 
166
 
  return (err);
167
 
}
168
 
 
169
 
int InternalPartitioner::
170
 
color(Teuchos::ParameterList& paramList,
171
 
      std::vector<int>& myNewElements)
172
 
{
173
 
  throw Isorropia::Exception("Coloring only available in Zoltan");
174
 
  return (-1);
175
 
}
176
 
 
177
 
int InternalPartitioner::
178
 
order(Teuchos::ParameterList& paramList,
179
 
      std::vector<int>& myNewElements)
180
 
{
181
 
  throw Isorropia::Exception("Ordering only available in Zoltan");
182
 
  return (-1);
183
 
}
184
 
 
185
 
 
186
 
int InternalPartitioner::postcompute()
187
 
{
188
 
  return (0);
189
 
}
190
 
 
191
 
 
192
 
 
193
 
} // namespace EPETRA
194
 
 
195
 
#endif //HAVE_EPETRA
196
 
 
197
 
}//namespace Isorropia
198