Zoltan2
Loading...
Searching...
No Matches
Sphynx_Research_Driver.cpp
Go to the documentation of this file.
1// @HEADER
2//
3// ***********************************************************************
4//
5// Zoltan2: A package of combinatorial algorithms for scientific computing
6// Copyright 2012 Sandia Corporation
7//
8// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9// the U.S. Government retains certain rights in this software.
10//
11// Redistribution and use in source and binary forms, with or without
12// modification, are permitted provided that the following conditions are
13// met:
14//
15// 1. Redistributions of source code must retain the above copyright
16// notice, this list of conditions and the following disclaimer.
17//
18// 2. Redistributions in binary form must reproduce the above copyright
19// notice, this list of conditions and the following disclaimer in the
20// documentation and/or other materials provided with the distribution.
21//
22// 3. Neither the name of the Corporation nor the names of the
23// contributors may be used to endorse or promote products derived from
24// this software without specific prior written permission.
25//
26// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37//
38// Questions? Contact Seher Acer (sacer@sandia.gov)
39// Erik Boman (egboman@sandia.gov)
40// Siva Rajamanickam (srajama@sandia.gov)
41// Jennifer Loe (jloe@sandia.gov)
42//
43// ***********************************************************************
44//
45// @HEADER
46#include "Teuchos_CommandLineProcessor.hpp"
47#include "Tpetra_CrsMatrix.hpp"
48#include "Tpetra_Core.hpp"
49#include "Tpetra_KokkosCompat_DefaultNode.hpp"
51
54
55#include "Teuchos_TimeMonitor.hpp"
56#include "Teuchos_StackedTimer.hpp"
58
59#include <Galeri_MultiVectorTraits.hpp>
60#include <Galeri_XpetraProblemFactory.hpp>
61#include <Galeri_XpetraParameters.hpp>
62#include <MatrixMarket_Tpetra.hpp>
63
65// This is a driver with many available options that can be used to test
66// a variety of features of Sphynx.
67// Note: This is research code. We do not guarantee it is without bugs.
69
70template <typename lno_t, typename gno_t, typename scalar_t, typename nod_t>
71int buildCrsMatrix(int xdim, int ydim, int zdim, std::string problemType,
72 const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
73 Teuchos::RCP<Tpetra::CrsMatrix<scalar_t, lno_t, gno_t, nod_t>> &M_)
74{
75 if (comm->getRank() == 0){
76 std::cout << "Create matrix with " << problemType;
77 std::cout << " (and " << xdim;
78 if (zdim > 0)
79 std::cout << " x " << ydim << " x " << zdim << " ";
80 else if (ydim > 0)
81 std::cout << " x" << ydim << " x 1 ";
82 else
83 std::cout << "x 1 x 1 ";
84 std::cout << " mesh)" << std::endl;
85 }
86
87 Teuchos::CommandLineProcessor tclp;
88 Galeri::Xpetra::Parameters<gno_t> params(tclp, xdim, ydim, zdim, problemType);
89
90 Teuchos::RCP<const Tpetra::Map<lno_t, gno_t> > map =
91 Teuchos::rcp(new Tpetra::Map<lno_t, gno_t>(params.GetNumGlobalElements(), 0, comm));
92
93 try{
94 Teuchos::RCP<Galeri::Xpetra::Problem<Tpetra::Map<lno_t, gno_t>,
95 Tpetra::CrsMatrix<scalar_t, lno_t, gno_t, nod_t>,
96 Tpetra::MultiVector<scalar_t, lno_t, gno_t> > > Pr=
97 Galeri::Xpetra::BuildProblem<scalar_t, lno_t, gno_t,
98 Tpetra::Map<lno_t, gno_t>,
99 Tpetra::CrsMatrix<scalar_t, lno_t, gno_t, nod_t>,
100 Tpetra::MultiVector<scalar_t, lno_t, gno_t, nod_t> >
101 (params.GetMatrixType(), map, params.GetParameterList());
102
103 M_ = Pr->BuildMatrix();
104 }
105 catch (std::exception &e) { // Probably not enough memory
106 std::cout << "Error returned from Galeri " << e.what() << std::endl;
107 exit(-1);
108 }
109 if (M_.is_null())
110 return 1;
111 else
112 return 0;
113}
114
115template <typename adapter_type>
116void
117compute_edgecut(Teuchos::RCP<adapter_type> &adapter,
119{
120 typedef typename adapter_type::user_t graph_type;
121 typedef typename graph_type::global_ordinal_type GO;
122 typedef typename graph_type::local_ordinal_type LO;
123 typedef typename graph_type::node_type NO;
124 typedef typename adapter_type::part_t PT;
125
126 using ordinal_view_t = Kokkos::View<GO*, typename NO::device_type>;
127 using part_view_t = Kokkos::View<PT*, typename NO::device_type>;
128
129 auto graph = adapter->getUserGraph();
130 auto rowMap = graph->getRowMap();
131 auto colMap = graph->getColMap();
132
133 size_t numLclRows = rowMap->getLocalNumElements();
134 size_t numGblRows = rowMap->getGlobalNumElements();
135 size_t numLclCols = colMap->getLocalNumElements();
136
137
138 ordinal_view_t colLocalToGlobal(Kokkos::view_alloc("colLocalToGlobal", Kokkos::WithoutInitializing), numLclCols);
139 auto colMapHost = Kokkos::create_mirror_view (Kokkos::HostSpace (), colLocalToGlobal);
140 for(size_t i = 0; i < numLclCols; ++i)
141 colMapHost[i] = colMap->getGlobalElement(i);
142 Kokkos::deep_copy (colLocalToGlobal, colMapHost);
143
144 ordinal_view_t rowLocalToGlobal(Kokkos::view_alloc("rowLocalToGlobal", Kokkos::WithoutInitializing), numLclRows);
145 auto rowMapHost = Kokkos::create_mirror_view (Kokkos::HostSpace (), rowLocalToGlobal);
146 for(size_t i = 0; i < numLclRows; ++i)
147 rowMapHost[i] = rowMap->getGlobalElement(i);
148 Kokkos::deep_copy (rowLocalToGlobal, rowMapHost);
149
150 part_view_t localParts("localParts", numGblRows);
151 part_view_t globalParts("globalParts", numGblRows);
152 auto localPartsHost = Kokkos::create_mirror_view(Kokkos::HostSpace(), localParts);
153
154 auto parts = solution.getPartListView();
155 for(size_t i = 0; i < numLclRows; i++){
156 GO gi = rowMap->getGlobalElement(i);
157 localPartsHost(gi) = parts[i];
158 }
159 Kokkos::deep_copy(localParts, localPartsHost);
160
161 auto comm = graph->getComm();
162 Teuchos::reduceAll<int, PT> (*comm, Teuchos::REDUCE_SUM, numGblRows, localParts.data(), globalParts.data());
163
164 auto rowPtr = graph->getLocalGraphHost().row_map;
165 auto colInd = graph->getLocalGraphHost().entries;
166
167 size_t localtotalcut = 0, totalcut = 0;
168
169 using execution_space = typename NO::device_type::execution_space;
170 using range_policy = Kokkos::RangePolicy<execution_space, Kokkos::IndexType<LO>>;
171 Kokkos::parallel_reduce("Compute cut", range_policy(0, numLclRows),
172 KOKKOS_LAMBDA(const LO i, size_t &cut){
173
174 const GO gRid = rowLocalToGlobal(i);
175 const PT gi = globalParts(gRid);
176
177 const size_t start = rowPtr(i);
178 const size_t end = rowPtr(i+1);
179 for(size_t j = start; j < end; ++j) {
180
181 const GO gCid = colLocalToGlobal(colInd(j));
182 PT gj = globalParts(gCid);
183 if(gi != gj)
184 cut += 1;
185 }
186 }, localtotalcut);
187
188 Teuchos::reduceAll (*comm, Teuchos::REDUCE_SUM, 1, &localtotalcut, &totalcut);
189
190 // compute imbalance
191 auto rowPtr_h = Kokkos::create_mirror_view(rowPtr);
192 Kokkos::deep_copy(rowPtr_h, rowPtr);
193 int nparts = (int)solution.getTargetGlobalNumberOfParts();
194
195 size_t *partw = new size_t[nparts];
196 size_t *partc = new size_t[nparts];
197
198 size_t *gpartw = new size_t[nparts];
199 size_t *gpartc = new size_t[nparts];
200
201 for(int i = 0; i < nparts; i++){
202 partw[i] = 0; partc[i] = 0;
203 gpartw[i] = 0; gpartc[i] = 0;
204 }
205
206 for(size_t i = 0; i < numLclRows; i++){
207 partw[parts[i]] += rowPtr_h(i+1) - rowPtr_h(i) - 1;
208 partc[parts[i]] ++;
209 }
210
211 Teuchos::reduceAll (*comm, Teuchos::REDUCE_SUM, nparts, partw, gpartw);
212 Teuchos::reduceAll (*comm, Teuchos::REDUCE_SUM, nparts, partc, gpartc);
213
214 size_t maxc = 0, totc = 0;
215 size_t maxw = 0, totw = 0;
216
217 for(int i = 0; i < nparts; i++){
218 if(gpartw[i] > maxw)
219 maxw = gpartw[i];
220 if(gpartc[i] > maxc)
221 maxc = gpartc[i];
222 totw += gpartw[i];
223 totc += gpartc[i];
224 }
225
226 double imbw = (double)maxw/((double)totw/nparts);
227 double imbc = (double)maxc/((double)totc/nparts);
228
229 if(comm->getRank() == 0) {
230
231 std::cout << "\n\n************************************************" << std::endl;
232 std::cout << " EDGECUT: " << totalcut << std::endl;
233 std::cout << " MAX/AVG WEIGHT: " << imbw << std::endl;
234 std::cout << " MAX/AVG COUNT: " << imbc << std::endl;
235 std::cout << "************************************************\n\n" << std::endl;
236
237 }
238}
239
240template <typename adapter_type>
241void
242compute_edgecut_old(Teuchos::RCP<adapter_type> &adapter,
244{
245 typedef typename adapter_type::user_t graph_type;
246 typedef typename graph_type::global_ordinal_type GO;
247 typedef typename graph_type::local_ordinal_type LO;
248 typedef typename graph_type::node_type NO;
249 typedef typename adapter_type::part_t PT;
250
251 using ordinal_view_t = Kokkos::View<GO*, typename NO::device_type>;
252 using part_view_t = Kokkos::View<PT*, typename NO::device_type>;
253
254 auto graph = adapter->getUserGraph();
255 auto rowMap = graph->getRowMap();
256 auto colMap = graph->getColMap();
257
258 size_t numLclRows = rowMap->getNodeNumElements();
259 size_t numGblRows = rowMap->getGlobalNumElements();
260 size_t numLclCols = colMap->getNodeNumElements();
261
262
263 ordinal_view_t colLocalToGlobal(Kokkos::view_alloc("colLocalToGlobal", Kokkos::WithoutInitializing), numLclCols);
264 auto colMapHost = Kokkos::create_mirror_view (Kokkos::HostSpace (), colLocalToGlobal);
265 for(size_t i = 0; i < numLclCols; ++i)
266 colMapHost[i] = colMap->getGlobalElement(i);
267 Kokkos::deep_copy (colLocalToGlobal, colMapHost);
268
269 ordinal_view_t rowLocalToGlobal(Kokkos::view_alloc("rowLocalToGlobal", Kokkos::WithoutInitializing), numLclRows);
270 auto rowMapHost = Kokkos::create_mirror_view (Kokkos::HostSpace (), rowLocalToGlobal);
271 for(size_t i = 0; i < numLclRows; ++i)
272 rowMapHost[i] = rowMap->getGlobalElement(i);
273 Kokkos::deep_copy (rowLocalToGlobal, rowMapHost);
274
275
276 part_view_t localParts(Kokkos::view_alloc("localParts", Kokkos::WithoutInitializing), numGblRows);
277 part_view_t globalParts("globalParts", numGblRows);
278 auto localPartsHost = Kokkos::create_mirror_view(Kokkos::HostSpace(), localParts);
279
280 auto parts = solution.getPartListView();
281 for(LO i = 0; i < numLclRows; i++){
282
283 GO gi = rowMap->getGlobalElement(i);
284 localPartsHost(gi) = parts[i];
285 }
286 Kokkos::deep_copy(localParts, localPartsHost);
287
288 auto comm = graph->getComm();
289 Teuchos::reduceAll<int, PT> (*comm, Teuchos::REDUCE_SUM, numGblRows, localParts.data(), globalParts.data());
290
291 auto rowPtr = graph->getLocalGraphHost().row_map;
292 auto colInd = graph->getLocalGraphHost().entries;
293
294 size_t localtotalcut = 0, totalcut = 0;
295
296 using execution_space = typename NO::device_type::execution_space;
297 using range_policy = Kokkos::RangePolicy<execution_space, Kokkos::IndexType<LO>>;
298 Kokkos::parallel_reduce("Compute cut", range_policy(0, numLclRows),
299 KOKKOS_LAMBDA(const LO i, size_t &cut){
300
301 const GO gRid = rowLocalToGlobal(i);
302 const PT gi = globalParts(gRid);
303
304 const size_t start = rowPtr(i);
305 const size_t end = rowPtr(i+1);
306 for(size_t j = start; j < end; ++j) {
307
308 const GO gCid = colLocalToGlobal(colInd(j));
309 PT gj = globalParts(gCid);
310 if(gi != gj)
311 cut += 1;
312 }
313 }, localtotalcut);
314
315 Teuchos::reduceAll (*comm, Teuchos::REDUCE_SUM, 1, &localtotalcut, &totalcut);
316
317 if(comm->getRank() == 0) {
318 std::cout << "\n\n************************************************" << std::endl;
319 std::cout << " EDGECUT: " << totalcut << std::endl;
320 std::cout << "************************************************\n\n" << std::endl;
321
322 }
323
324}
325
326
327int main(int narg, char *arg[])
328{
329
330 Tpetra::ScopeGuard tpetraScope (&narg, &arg);
331 {
332
333 const Teuchos::RCP<const Teuchos::Comm<int>> pComm= Tpetra::getDefaultComm();
334
335 int me = pComm->getRank();
336
337 // Parameters
338 int nparts = 64;
339 int max_iters = 1000;
340 int block_size = -1;
341 int rand_seed = 1;
342 std::string matrix_file = "";
343 std::string vector_file = "";
344 std::string eigensolve = "LOBPCG";
345 bool parmetis = false;
346 bool pulp = false;
347
348 int verbosity = 1;
349
350 std::string ptype = "";
351 std::string prec = "";
352 std::string init = "";
353 double tol = -1;
354
355 // Echo the command line
356 if (me == 0) {
357 for (int i = 0; i < narg; i++){
358 std::cout << arg[i] << " ";
359 }
360 std::cout << std::endl;
361 }
362
363 Teuchos::CommandLineProcessor cmdp(false,true);
364 cmdp.setOption("matrix_file",&matrix_file,
365 "Path and filename of the matrix to be read.");
366 cmdp.setOption("vector_file",&vector_file,
367 "Path and filename of the vector to be read.");
368 cmdp.setOption("nparts",&nparts,
369 "Number of global parts desired in the resulting partition.");
370 cmdp.setOption("rand_seed",&rand_seed,
371 "Seed for the random multivector.");
372 cmdp.setOption("max_iters",&max_iters,
373 "Maximum iters (LOBPCG) or mulitplies by A (randomized).");
374 cmdp.setOption("block_size",&block_size,
375 "Block size (LOBPCG) or number of vectors l (randomized).");
376 cmdp.setOption("verbosity", &verbosity,
377 "Verbosity level");
378 cmdp.setOption("parmetis", "sphynx", &parmetis,
379 "Whether to use parmetis.");
380 cmdp.setOption("pulp", "sphynx", &pulp,
381 "Whether to use pulp.");
382 cmdp.setOption("prec", &prec,
383 "Prec type to use.");
384 //cmdp.setOption("eigensolve", &eigensolve,
385 // "Eigensolver to use: LOBPCG or randomized."); //TODO: Uncomment when randomized eigensolver in Anasazi.
386 cmdp.setOption("prob", &ptype,
387 "Problem type to use. Options are combinatorial, normalized or generalized.");
388 cmdp.setOption("tol", &tol,
389 "Tolerance to use.");
390 cmdp.setOption("init", &init,
391 "Sphynx Initial guess. Options: random or constants. Default: random if randomized solver is used.");
392
393 if (cmdp.parse(narg,arg)!=Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL) {
394 return -1;
395 }
396
397 // Print the most essential options (not in the MyPL parameters later)
398 if (me==0){
399 std::cout << "matrix file = " << matrix_file << std::endl;
400 std::cout << "vector file = " << vector_file << std::endl;
401 std::cout << "nparts = " << nparts << std::endl;
402 std::cout << "verbosity = " << verbosity << std::endl;
403 std::cout << "parmetis = " << parmetis << std::endl;
404 std::cout << "pulp = " << pulp << std::endl;
405 std::cout << "prec = " << prec << std::endl;
406 std::cout << "eigensolver = " << eigensolve << std::endl;
407 std::cout << "prob = " << ptype << std::endl;
408 std::cout << "tol = " << tol << std::endl;
409 std::cout << "init = " << init << std::endl;
410 }
411
412 using scalar_type = Tpetra::Details::DefaultTypes::scalar_type;
413 using local_ordinal_type = Tpetra::Details::DefaultTypes::local_ordinal_type;
414 using global_ordinal_type = Tpetra::Details::DefaultTypes::global_ordinal_type;
415 using node_type = Tpetra::Details::DefaultTypes::node_type;
416
417 using crs_matrix_type = Tpetra::CrsMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type>;
418 using map_type = Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type>;
419 using mv_type = Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type>;
421 using solution_type = Zoltan2::PartitioningSolution<adapter_type>;
422
423 // Set the random seed.
424 std::srand(rand_seed);
425
426 // Read the input matrix
427 Teuchos::RCP<adapter_type> adapter;
428 Teuchos::RCP<crs_matrix_type> tmatrix;
429
430 std::string mtx = ".mtx", lc = ".largestComp";
431 if(std::equal(lc.rbegin(), lc.rend(), matrix_file.rbegin())) {
432 tmatrix = readMatrixFromBinaryFile<crs_matrix_type>(matrix_file, pComm, true, verbosity>0);
433 if (me==0){
434 std::cout << "Used reader for Largest Comp." << std::endl;
435 }
436 }
437 else if(std::equal(mtx.rbegin(), mtx.rend(), matrix_file.rbegin())) {
438 typedef Tpetra::MatrixMarket::Reader<crs_matrix_type> reader_type;
439 reader_type r;
440 tmatrix = r.readSparseFile(matrix_file, pComm);
441 if (me==0){
442 std::cout << "Used standard Matrix Market reader." << std::endl;
443 }
444 }
445 else {
446 int meshdim = 100;
447 if(matrix_file == "200")
448 meshdim = 200;
449 else if(matrix_file == "400")
450 meshdim = 400;
452 (meshdim, meshdim, meshdim, "Brick3D", pComm, tmatrix);
453 //Tpetra::MatrixMarket::Writer<crs_matrix_type>::writeSparseFile(matrix_file+".mtx", tmatrix);
454 if(me == 0){
455 std::cout << "Generated Brick3D matrix." << std::endl;
456 }
457 }
458 if(me == 0){
459 std::cout << "Done with reading/creating the matrix." << std::endl;
460 }
461
462 Teuchos::RCP<const map_type> map = tmatrix->getMap();
463
464 Teuchos::RCP<mv_type> V;
465 if (vector_file !=""){
466 V = Tpetra::MatrixMarket::Reader<mv_type >::readDenseFile(vector_file,pComm,map);
467 if(me == 0){
468 std::cout << "Done with reading user-provided eigenvectors." << std::endl;
469 }
470 }
471 adapter = Teuchos::rcp(new adapter_type(tmatrix->getCrsGraph(), 1));
472 adapter->setVertexWeightIsDegree(0);
473
474 // Set the parameters
475 Teuchos::RCP<Teuchos::ParameterList> params = Teuchos::rcp(new Teuchos::ParameterList());
476 Teuchos::RCP<Teuchos::ParameterList> sphynxParams(new Teuchos::ParameterList);
477 params->set("num_global_parts", nparts);
478
479 Teuchos::RCP<Teuchos::StackedTimer> stacked_timer;
480 stacked_timer = Teuchos::rcp(new Teuchos::StackedTimer("SphynxDriver"));
481 Teuchos::TimeMonitor::setStackedTimer(stacked_timer);
482 if(parmetis || pulp) {
483
484 params->set("partitioning_approach", "partition");
485 params->set("imbalance_tolerance", 1.01);
486 if(parmetis) {
487 params->set("algorithm", "parmetis");
488 params->set("imbalance_tolerance", 1.01);
489 }
490 else {
491 params->set("algorithm", "pulp");
492 params->set("pulp_vert_imbalance", 1.01);
493 }
494
495 using problem_type = Zoltan2::SphynxProblem<adapter_type>;
496 Teuchos::RCP<problem_type> problem;
497 pComm->barrier();
498 {
499 Teuchos::TimeMonitor t1(*Teuchos::TimeMonitor::getNewTimer("Partitioning::All"));
500 {
501 Teuchos::TimeMonitor t2(*Teuchos::TimeMonitor::getNewTimer("Partitioning::Problem"));
502 problem = Teuchos::rcp(new problem_type(adapter.getRawPtr(), params.getRawPtr(), sphynxParams, Tpetra::getDefaultComm()));
503 }
504 {
505 Teuchos::TimeMonitor t3(*Teuchos::TimeMonitor::getNewTimer("Partitioning::Solve"));
506 problem->solve();
507 }
508 }
509 pComm->barrier();
510
511 solution_type solution = problem->getSolution();
512 compute_edgecut<adapter_type>(adapter, solution);
513
514 }
515 else {
516
517 sphynxParams->set("sphynx_verbosity", verbosity);
518 sphynxParams->set("sphynx_max_iterations", max_iters);
519 if(block_size > 0){
520 sphynxParams->set("sphynx_block_size", block_size);
521 }
522 sphynxParams->set("sphynx_skip_preprocessing", true);
523 //sphynxParams->set("sphynx_eigensolver", eigensolve); //TODO: Uncomment when randomized solver in Anasazi.
524 if (ptype != "") sphynxParams->set("sphynx_problem_type", ptype);
525 if (init != "") sphynxParams->set("sphynx_initial_guess", init);
526 if (prec != "") sphynxParams->set("sphynx_preconditioner_type", prec);
527 if (tol != -1) sphynxParams->set("sphynx_tolerance", tol);
528
529 using problem_type = Zoltan2::SphynxProblem<adapter_type>; //We found sphynx
530 Teuchos::RCP<problem_type> problem;
531 pComm->barrier();
532 {
533 Teuchos::TimeMonitor t1b(*Teuchos::TimeMonitor::getNewTimer("Partitioning::All"));
534 {
535 Teuchos::TimeMonitor t2b(*Teuchos::TimeMonitor::getNewTimer("Partitioning::Problem"));
536 problem = Teuchos::rcp(new problem_type(adapter.get(), params.get(), sphynxParams, Tpetra::getDefaultComm()));
537 }
538 {
539 Teuchos::TimeMonitor t3b(*Teuchos::TimeMonitor::getNewTimer("Partitioning::Solve"));
540 if (vector_file ==""){
541 if(me == 0)
542 std::cout << eigensolve << "will be used to solve the partitioning problem." << std::endl;
543 problem->solve();
544 }
545 else{
546 std::cout << "Problem to be partitioned with user-provided eigenvectors." << std::endl;
547 problem->setUserEigenvectors(V);
548 problem->solve();
549 }
550 }
551 pComm->barrier();
552 }
553 solution_type solution = problem->getSolution();
554 compute_edgecut<adapter_type>(adapter, solution);
555 /*
556 const int *SolArray = solution.getPartListView();
557 std::cout << "Pointer is: " << SolArray << std::endl;
558 int numparts = int(V->getGlobalLength());
559 for(int i=0;i<numparts;i++)
560 std::cout << *(SolArray+i) << std::endl;
561 */
562 // TODO: Uncomment the above lines and use >> out.txt to isolate the solution array file
563 }
564 stacked_timer->stopBaseTimer();
565
566 Teuchos::RCP<Teuchos::FancyOStream> fancy2 = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
567 Teuchos::FancyOStream& out2 = *fancy2;
568 Teuchos::StackedTimer::OutputOptions options;
569 options.output_fraction = options.output_histogram = options.output_minmax = true;
570 stacked_timer->report(out2, pComm, options);
571
572 Teuchos::TimeMonitor::summarize();
573
574 } //End Tpetra scope guard
575 return 0;
576}
int buildCrsMatrix(int xdim, int ydim, int zdim, std::string problemType, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, Teuchos::RCP< Tpetra::CrsMatrix< scalar_t, lno_t, gno_t, nod_t > > &M_)
void compute_edgecut_old(Teuchos::RCP< adapter_type > &adapter, Zoltan2::PartitioningSolution< adapter_type > &solution)
void compute_edgecut(Teuchos::RCP< adapter_type > &adapter, Zoltan2::PartitioningSolution< adapter_type > &solution)
Defines the PartitioningProblem class.
Defines XpetraCrsGraphAdapter class.
int main()
A PartitioningSolution is a solution to a partitioning problem.
const part_t * getPartListView() const
Returns the part list corresponding to the global ID list.
size_t getTargetGlobalNumberOfParts() const
Returns the global number of parts desired in the solution.
const PartitioningSolution< Adapter > & getSolution()
Provides access for Zoltan2 to Xpetra::CrsGraph data.
map_t::local_ordinal_type lno_t
map_t::global_ordinal_type gno_t
Teuchos::RCP< crs_matrix_type > readMatrixFromBinaryFile(std::string filename, const Teuchos::RCP< const Teuchos::Comm< int > > pComm, bool binary=true, bool debug=false)