45 #ifndef _ZOLTAN2_ALGPULP_HPP_ 46 #define _ZOLTAN2_ALGPULP_HPP_ 59 #ifndef HAVE_ZOLTAN2_PULP 65 template <
typename Adapter>
70 AlgPuLP(
const RCP<const Environment> &env,
71 const RCP<
const Comm<int> > &problemComm,
72 const RCP<const base_adapter_t> &adapter
75 throw std::runtime_error(
76 "BUILD ERROR: PuLP requested but not compiled into Zoltan2.\n" 77 "Please set CMake flag Zoltan2_ENABLE_PuLP:BOOL=ON.");
86 #ifdef HAVE_ZOLTAN2_PULP 101 template <
typename Adapter>
106 typedef typename Adapter::lno_t
lno_t;
107 typedef typename Adapter::gno_t
gno_t;
108 typedef typename Adapter::scalar_t
scalar_t;
109 typedef typename Adapter::part_t
part_t;
110 typedef typename Adapter::user_t user_t;
111 typedef typename Adapter::userCoord_t userCoord_t;
123 AlgPuLP(
const RCP<const Environment> &env__,
124 const RCP<
const Comm<int> > &problemComm__,
126 env(env__), problemComm(problemComm__), adapter(adapter__)
128 std::string errStr =
"cannot build GraphModel from IdentifierAdapter, ";
129 errStr +=
"PuLP requires Graph, Matrix, or Mesh Adapter";
130 throw std::runtime_error(errStr);
133 AlgPuLP(
const RCP<const Environment> &env__,
134 const RCP<
const Comm<int> > &problemComm__,
136 env(env__), problemComm(problemComm__), adapter(adapter__)
138 std::string errStr =
"cannot build GraphModel from VectorAdapter, ";
139 errStr +=
"PuLP requires Graph, Matrix, or Mesh Adapter";
140 throw std::runtime_error(errStr);
143 AlgPuLP(
const RCP<const Environment> &env__,
144 const RCP<
const Comm<int> > &problemComm__,
146 env(env__), problemComm(problemComm__), adapter(adapter__)
154 AlgPuLP(
const RCP<const Environment> &env__,
155 const RCP<
const Comm<int> > &problemComm__,
157 env(env__), problemComm(problemComm__), adapter(adapter__)
162 const ParameterList &pl = env->getParameters();
163 const Teuchos::ParameterEntry *pe;
165 std::string defString(
"default");
166 std::string objectOfInterest(defString);
167 pe = pl.getEntryPtr(
"objects_to_partition");
169 objectOfInterest = pe->getValue<std::string>(&objectOfInterest);
171 if (objectOfInterest == defString ||
172 objectOfInterest == std::string(
"matrix_rows") )
174 else if (objectOfInterest == std::string(
"matrix_columns"))
176 else if (objectOfInterest == std::string(
"matrix_nonzeros"))
182 AlgPuLP(
const RCP<const Environment> &env__,
183 const RCP<
const Comm<int> > &problemComm__,
185 env(env__), problemComm(problemComm__), adapter(adapter__)
190 const ParameterList &pl = env->getParameters();
191 const Teuchos::ParameterEntry *pe;
193 std::string defString(
"default");
194 std::string objectOfInterest(defString);
195 pe = pl.getEntryPtr(
"objects_to_partition");
197 objectOfInterest = pe->getValue<std::string>(&objectOfInterest);
199 if (objectOfInterest == defString ||
200 objectOfInterest == std::string(
"mesh_nodes") )
202 else if (objectOfInterest == std::string(
"mesh_elements"))
214 const RCP<const Environment> env;
215 const RCP<const Comm<int> > problemComm;
216 const RCP<const base_adapter_t> adapter;
217 RCP<const GraphModel<base_adapter_t> > model;
222 template <
typename Adapter>
225 const ParameterList &pl = env->getParameters();
226 const Teuchos::ParameterEntry *pe;
228 std::string defString(
"default");
229 std::string symParameter(defString);
230 pe = pl.getEntryPtr(
"symmetrize_graph");
232 symParameter = pe->getValue<std::string>(&symParameter);
233 if (symParameter == std::string(
"transpose"))
235 else if (symParameter == std::string(
"bipartite"))
239 pe = pl.getEntryPtr(
"subset_graph");
241 sgParameter = pe->getValue<
int>(&sgParameter);
242 if (sgParameter == 1)
250 this->problemComm, flags));
255 template <
typename Adapter>
262 size_t numGlobalParts = solution->getTargetGlobalNumberOfParts();
264 int num_parts = (int)numGlobalParts;
274 const size_t modelVerts = model->getLocalNumVertices();
275 const size_t modelEdges = model->getLocalNumEdges();
276 int num_verts = (int)modelVerts;
277 long num_edges = (long)modelEdges;
282 ArrayView<const gno_t> adjs;
283 ArrayView<const lno_t> offsets;
284 ArrayView<StridedData<lno_t, scalar_t> > ewgts;
285 model->getEdgeList(adjs, offsets, ewgts);
293 pulp_graph_t g = {num_verts, num_edges, out_edges, out_offsets};
297 ArrayRCP<part_t> partList(
new part_t[num_verts], 0, num_verts,
true);
299 if (num_verts && (
sizeof(
int) ==
sizeof(
part_t))) {
301 parts = (
int *) partList.getRawPtr();
305 parts =
new int[num_verts];
315 const Teuchos::ParameterList &pl = env->getParameters();
316 const Teuchos::ParameterEntry *pe;
326 int do_maxcut_min = 0;
327 int verbose_output = 0;
330 pe = pl.getEntryPtr(
"pulp_lp_init");
331 if (pe) do_lp_init = pe->getValue<
int>(&do_lp_init);
332 if (do_lp_init) do_bfs_init = 0;
335 pe = pl.getEntryPtr(
"pulp_minimize_maxcut");
337 do_maxcut_min = pe->getValue<
int>(&do_maxcut_min);
340 if (do_maxcut_min) do_edge_bal = 1;
344 double vert_imbalance = 1.1;
345 double edge_imbalance = 1.1;
347 pe = pl.getEntryPtr(
"pulp_vert_imbalance");
348 if (pe) vert_imbalance = pe->getValue<
double>(&vert_imbalance);
349 pe = pl.getEntryPtr(
"pulp_edge_imbalance");
351 edge_imbalance = pe->getValue<
double>(&edge_imbalance);
356 if (vert_imbalance < 1.0)
357 throw std::runtime_error(
"pulp_vert_imbalance must be '1.0' or greater.");
358 if (edge_imbalance < 1.0)
359 throw std::runtime_error(
"pulp_edge_imbalance must be '1.0' or greater.");
363 pe = pl.getEntryPtr(
"pulp_verbose");
364 if (pe) verbose_output = pe->getValue<
int>(&verbose_output);
367 pulp_part_control_t ppc = {vert_imbalance, edge_imbalance,
368 (bool)do_lp_init, (
bool)do_bfs_init,
369 (bool)do_edge_bal, (
bool)do_maxcut_min,
370 (bool)verbose_output};
372 if (verbose_output) {
373 printf(
"n: %i, m: %li, vb: %lf, eb: %lf, p: %i\n",
374 num_verts, num_edges, vert_imbalance, edge_imbalance, num_parts);
378 ierr = pulp_run(&g, &ppc, parts, num_parts);
380 env->globalInputAssertion(__FILE__, __LINE__,
"pulp_run",
384 if ((
sizeof(
int) !=
sizeof(
part_t)) || (num_verts == 0)) {
385 for (
int i = 0; i < num_verts; i++) partList[i] = parts[i];
389 solution->setParts(partList);
391 env->memory(
"Zoltan2-PuLP: After creating solution");
402 #endif // HAVE_ZOLTAN2_PULP use columns as graph vertices
IdentifierAdapter defines the interface for identifiers.
use mesh nodes as vertices
static void DELETE_TPL_T_ARRAY(tpl_t **a)
fast typical checks for valid arguments
MatrixAdapter defines the adapter interface for matrices.
Adapter::base_adapter_t base_adapter_t
GraphAdapter defines the interface for graph-based user data.
algorithm requires consecutive ids
MeshAdapter defines the interface for mesh input.
std::bitset< NUM_MODEL_FLAGS > modelFlag_t
model must symmetrize input
model must symmetrize input
Defines the PartitioningSolution class.
sub-steps, each method's entry and exit
use matrix rows as graph vertices
algorithm requires no self edges
Adapter::scalar_t scalar_t
A PartitioningSolution is a solution to a partitioning problem.
use nonzeros as graph vertices
VectorAdapter defines the interface for vector input.
Algorithm defines the base class for all algorithms.
static void ASSIGN_TPL_T_ARRAY(tpl_t **a, ArrayView< zno_t > &b)
virtual void partition(const RCP< PartitioningSolution< Adapter > > &solution)
Partitioning method.
Traits class to handle conversions between gno_t/lno_t and TPL data types (e.g., ParMETIS's idx_t...
use mesh elements as vertices
GraphModel defines the interface required for graph models.
Defines the GraphModel interface.
AlgPuLP(const RCP< const Environment > &env, const RCP< const Comm< int > > &problemComm, const RCP< const base_adapter_t > &adapter)
A gathering of useful namespace methods.
model represents graph within only one rank