Zoltan2
Loading...
Searching...
No Matches
Zoltan2_MatchingProblem.hpp
Go to the documentation of this file.
1#if 0
2// @HEADER
3// *****************************************************************************
4// Zoltan2: A package of combinatorial algorithms for scientific computing
5//
6// Copyright 2012 NTESS and the Zoltan2 contributors.
7// SPDX-License-Identifier: BSD-3-Clause
8// *****************************************************************************
9// @HEADER
10
15#ifndef _ZOLTAN2_MATCHINGPROBLEM_HPP_
16#define _ZOLTAN2_MATCHINGPROBLEM_HPP_
17
18#include <Zoltan2_Standards.hpp>
19
20#include <Zoltan2_Problem.hpp>
21#include <Zoltan2_MatchingAlgorithms.hpp>
23
25#include <string>
26
27#include <bitset>
28
29using Teuchos::rcp_dynamic_cast;
30
31namespace Zoltan2{
32
34
54template<typename Adapter>
55class MatchingProblem : public Problem<Adapter>
56{
57public:
58
59 typedef typename Adapter::scalar_t scalar_t;
60 typedef typename Adapter::gno_t gno_t;
61 typedef typename Adapter::lno_t lno_t;
62 typedef typename Adapter::user_t user_t;
63 typedef typename Adapter::base_adapter_t base_adapter_t;
64
65#ifdef HAVE_ZOLTAN2_MPI
66 typedef Teuchos::OpaqueWrapper<MPI_Comm> mpiWrapper_t;
67#endif
68
71 virtual ~MatchingProblem() {};
72
73
74#ifdef HAVE_ZOLTAN2_MPI
77 MatchingProblem(Adapter *A, ParameterList *p, MPI_Comm comm)
78 : Problem<Adapter>(A, p, comm)
79 {
80 HELLO;
81 createMatchingProblem();
82 };
83#endif
84
87 MatchingProblem(Adapter *A, ParameterList *p) : Problem<Adapter>(A, p)
88 {
89 HELLO;
90 createMatchingProblem();
91 };
92
94 //
95 // \param updateInputData If true this indicates that either
96 // this is the first attempt at solution, or that we
97 // are computing a new solution and the input data has
98 // changed since the previous solution was computed.
99 // If false, this indicates that we are computing a
100 // new solution using the same input data was used for
101 // the previous solution, even though the parameters
102 // may have been changed.
103 //
104 // For the sake of performance, we ask the caller to set \c updateInputData
105 // to false if he/she is computing a new solution using the same input data,
106 // but different problem parameters, than that which was used to compute
107 // the most recent solution.
108
109 void solve(bool updateInputData=true);
110
112 //
113 // \return a reference to the solution to the most recent solve().
114
115 MatchingSolution<Adapter> *getSolution() {
116 // Get the raw ptr from the rcp
117 return solution_.getRawPtr();
118 };
119
120private:
121 void createMatchingProblem();
122
123 RCP<MatchingSolution<Adapter> > solution_;
124
125};
126
127
129template <typename Adapter>
130void MatchingProblem<Adapter>::solve(bool newData)
131{
132 HELLO;
133
134 size_t nVtx = this->baseModel_->getLocalNumObjects();
135
136 try
137 {
138 this->solution_ = rcp(new MatchingSolution<Adapter>(nVtx));
139 }
141
142 // Determine which algorithm to use based on defaults and parameters.
143 // Need some exception handling here, too.
144
145 std::string method = this->params_->template get<std::string>("color_method", "SerialGreedy");
146
147 try
148 {
149 // TODO: Ignore case
150 if (method.compare("SerialGreedy") == 0)
151 {
152 AlgSerialGreedy<Adapter> alg(this->graphModel_, this->params_,
153 this->env_, this->comm_);
154 alg.color(this->solution_);
155 }
156#if 0 // TODO later
157 else if (method.compare("speculative") == 0) // Gebremedhin-Manne
158 {
159 AlgGM<base_adapter_t> alg(this->graphModel_, this->comm_);
160 alg.color(this->solution_, this->params_);
161 }
162#endif
163 }
165
166}
167
169//template <typename Adapter>
170//void MatchingProblem<Adapter>::redistribute()
171//{
172// HELLO;
173//}
174
177// Method with common functionality for creating a MatchingProblem.
178// Individual constructors do appropriate conversions of input, etc.
179// This method does everything that all constructors must do.
180
181template <typename Adapter>
182void MatchingProblem<Adapter>::createMatchingProblem()
183{
184 HELLO;
185 using Teuchos::ParameterList;
186
187// std::cout << __func__zoltan2__ << " input adapter type "
188// << this->inputAdapter_->inputAdapterType() << " "
189// << this->inputAdapter_->inputAdapterName() << std::endl;
190
191 // Create a copy of the user's communicator.
192
193 // Only graph model supported.
194 // TODO: Allow hypergraph later?
195
196 ModelType modelType = GraphModelType;
197
198 // Select Model based on parameters and InputAdapter type
199
200 std::bitset<NUM_MODEL_FLAGS> graphFlags;
201 std::bitset<NUM_MODEL_FLAGS> idFlags;
202
203 switch (modelType) {
204
205 case GraphModelType:
206 graphFlags.set(REMOVE_SELF_EDGES);
207 graphFlags.set(BUILD_LOCAL_GRAPH);
208 this->graphModel_ = rcp(new GraphModel<base_adapter_t>(
209 this->baseInputAdapter_, this->envConst_, this->comm_, graphFlags));
210
211 this->baseModel_ = rcp_implicit_cast<const Model<base_adapter_t> >(
212 this->graphModel_);
213
214 break;
215
216
220 std::cout << __func__zoltan2__ << " Model type " << modelType << " not yet supported."
221 << std::endl;
222 break;
223
224 default:
225 std::cout << __func__zoltan2__ << " Invalid model" << modelType << std::endl;
226 break;
227 }
228}
229} //namespace Zoltan2
230
231#endif
232#endif
Zoltan2::BasicUserTypes< zscalar_t, zlno_t, zgno_t > user_t
Definition Metric.cpp:39
#define Z2_FORWARD_EXCEPTIONS
Forward an exception back through call stack.
#define __func__zoltan2__
Defines the GraphModel interface.
Defines the Problem base class.
Gathering definitions used in software development.
#define HELLO
map_t::local_ordinal_type lno_t
map_t::global_ordinal_type gno_t
Zoltan2::BaseAdapter< userTypes_t > base_adapter_t
Created by mbenlioglu on Aug 31, 2020.
ModelType
An identifier for the general type of model.
@ IdentifierModelType
@ HypergraphModelType
@ CoordinateModelType
@ REMOVE_SELF_EDGES
algorithm requires no self edges
@ BUILD_LOCAL_GRAPH
model represents graph within only one rank