Zoltan2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Zoltan2_MatchingProblem.hpp
Go to the documentation of this file.
1 #if 0
2 // @HEADER
3 //
4 // ***********************************************************************
5 //
6 // Zoltan2: A package of combinatorial algorithms for scientific computing
7 // Copyright 2012 Sandia Corporation
8 //
9 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
10 // the U.S. Government retains certain rights in this software.
11 //
12 // Redistribution and use in source and binary forms, with or without
13 // modification, are permitted provided that the following conditions are
14 // met:
15 //
16 // 1. Redistributions of source code must retain the above copyright
17 // notice, this list of conditions and the following disclaimer.
18 //
19 // 2. Redistributions in binary form must reproduce the above copyright
20 // notice, this list of conditions and the following disclaimer in the
21 // documentation and/or other materials provided with the distribution.
22 //
23 // 3. Neither the name of the Corporation nor the names of the
24 // contributors may be used to endorse or promote products derived from
25 // this software without specific prior written permission.
26 //
27 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
28 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
31 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 //
39 // Questions? Contact Karen Devine (kddevin@sandia.gov)
40 // Erik Boman (egboman@sandia.gov)
41 // Siva Rajamanickam (srajama@sandia.gov)
42 //
43 // ***********************************************************************
44 //
45 // @HEADER
46 
51 #ifndef _ZOLTAN2_MATCHINGPROBLEM_HPP_
52 #define _ZOLTAN2_MATCHINGPROBLEM_HPP_
53 
54 #include <Zoltan2_Standards.hpp>
55 
56 #include <Zoltan2_Problem.hpp>
57 #include <Zoltan2_MatchingAlgorithms.hpp>
59 
60 #include <Zoltan2_GraphModel.hpp>
61 #include <string>
62 
63 #include <bitset>
64 
65 using Teuchos::rcp_dynamic_cast;
66 
67 namespace Zoltan2{
68 
70 
90 template<typename Adapter>
91 class MatchingProblem : public Problem<Adapter>
92 {
93 public:
94 
95  typedef typename Adapter::scalar_t scalar_t;
96  typedef typename Adapter::gno_t gno_t;
97  typedef typename Adapter::lno_t lno_t;
98  typedef typename Adapter::user_t user_t;
99  typedef typename Adapter::base_adapter_t base_adapter_t;
100 
101 #ifdef HAVE_ZOLTAN2_MPI
102  typedef Teuchos::OpaqueWrapper<MPI_Comm> mpiWrapper_t;
103 #endif
104 
107  virtual ~MatchingProblem() {};
108 
109 
110 #ifdef HAVE_ZOLTAN2_MPI
111 
113  MatchingProblem(Adapter *A, ParameterList *p, MPI_Comm comm)
114  : Problem<Adapter>(A, p, comm)
115  {
116  HELLO;
117  createMatchingProblem();
118  };
119 #endif
120 
123  MatchingProblem(Adapter *A, ParameterList *p) : Problem<Adapter>(A, p)
124  {
125  HELLO;
126  createMatchingProblem();
127  };
128 
130  //
131  // \param updateInputData If true this indicates that either
132  // this is the first attempt at solution, or that we
133  // are computing a new solution and the input data has
134  // changed since the previous solution was computed.
135  // If false, this indicates that we are computing a
136  // new solution using the same input data was used for
137  // the previous solution, even though the parameters
138  // may have been changed.
139  //
140  // For the sake of performance, we ask the caller to set \c updateInputData
141  // to false if he/she is computing a new solution using the same input data,
142  // but different problem parameters, than that which was used to compute
143  // the most recent solution.
144 
145  void solve(bool updateInputData=true);
146 
148  //
149  // \return a reference to the solution to the most recent solve().
150 
151  MatchingSolution<Adapter> *getSolution() {
152  // Get the raw ptr from the rcp
153  return solution_.getRawPtr();
154  };
155 
156 private:
157  void createMatchingProblem();
158 
159  RCP<MatchingSolution<Adapter> > solution_;
160 
161 };
162 
163 
165 template <typename Adapter>
166 void MatchingProblem<Adapter>::solve(bool newData)
167 {
168  HELLO;
169 
170  size_t nVtx = this->baseModel_->getLocalNumObjects();
171 
172  try
173  {
174  this->solution_ = rcp(new MatchingSolution<Adapter>(nVtx));
175  }
177 
178  // Determine which algorithm to use based on defaults and parameters.
179  // Need some exception handling here, too.
180 
181  std::string method = this->params_->template get<std::string>("color_method", "SerialGreedy");
182 
183  try
184  {
185  // TODO: Ignore case
186  if (method.compare("SerialGreedy") == 0)
187  {
188  AlgSerialGreedy<Adapter> alg(this->graphModel_, this->params_,
189  this->env_, this->comm_);
190  alg.color(this->solution_);
191  }
192 #if 0 // TODO later
193  else if (method.compare("speculative") == 0) // Gebremedhin-Manne
194  {
195  AlgGM<base_adapter_t> alg(this->graphModel_, this->comm_);
196  alg.color(this->solution_, this->params_);
197  }
198 #endif
199  }
201 
202 }
203 
205 //template <typename Adapter>
206 //void MatchingProblem<Adapter>::redistribute()
207 //{
208 // HELLO;
209 //}
210 
213 // Method with common functionality for creating a MatchingProblem.
214 // Individual constructors do appropriate conversions of input, etc.
215 // This method does everything that all constructors must do.
216 
217 template <typename Adapter>
218 void MatchingProblem<Adapter>::createMatchingProblem()
219 {
220  HELLO;
221  using Teuchos::ParameterList;
222 
223 // std::cout << __func__zoltan2__ << " input adapter type "
224 // << this->inputAdapter_->inputAdapterType() << " "
225 // << this->inputAdapter_->inputAdapterName() << std::endl;
226 
227  // Create a copy of the user's communicator.
228 
229  // Only graph model supported.
230  // TODO: Allow hypergraph later?
231 
232  ModelType modelType = GraphModelType;
233 
234  // Select Model based on parameters and InputAdapter type
235 
236  std::bitset<NUM_MODEL_FLAGS> graphFlags;
237  std::bitset<NUM_MODEL_FLAGS> idFlags;
238 
239  switch (modelType) {
240 
241  case GraphModelType:
242  graphFlags.set(REMOVE_SELF_EDGES);
243  graphFlags.set(BUILD_LOCAL_GRAPH);
244  this->graphModel_ = rcp(new GraphModel<base_adapter_t>(
245  this->baseInputAdapter_, this->envConst_, this->comm_, graphFlags));
246 
247  this->baseModel_ = rcp_implicit_cast<const Model<base_adapter_t> >(
248  this->graphModel_);
249 
250  break;
251 
252 
253  case IdentifierModelType:
254  case HypergraphModelType:
255  case CoordinateModelType:
256  std::cout << __func__zoltan2__ << " Model type " << modelType << " not yet supported."
257  << std::endl;
258  break;
259 
260  default:
261  std::cout << __func__zoltan2__ << " Invalid model" << modelType << std::endl;
262  break;
263  }
264 }
265 } //namespace Zoltan2
266 
267 #endif
268 #endif
#define HELLO
Zoltan2::BaseAdapter< userTypes_t > base_adapter_t
ModelType
An identifier for the general type of model.
#define Z2_FORWARD_EXCEPTIONS
Forward an exception back through call stack.
map_t::global_ordinal_type gno_t
Definition: mapRemotes.cpp:18
algorithm requires no self edges
Defines the Problem base class.
map_t::local_ordinal_type lno_t
Definition: mapRemotes.cpp:17
Gathering definitions used in software development.
Defines the GraphModel interface.
model represents graph within only one rank
#define __func__zoltan2__
Zoltan2::BasicUserTypes< zscalar_t, zlno_t, zgno_t > user_t
Definition: Metric.cpp:74