Zoltan2
Loading...
Searching...
No Matches
partition_sarma.cpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Zoltan2: A package of combinatorial algorithms for scientific computing
4//
5// Copyright 2012 NTESS and the Zoltan2 contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10/*
11 * Created by mbenlioglu on Nov 10, 2020.
12 */
13
14#include <Zoltan2_config.h>
15
20
21using Teuchos::RCP;
22using Teuchos::rcp;
23
24typedef Zoltan2::BasicUserTypes <zscalar_t, zlno_t, zgno_t> myTypes_t;
25
26#ifdef HAVE_ZOLTAN2_SARMA
27
28struct Parameters {
29 std::string alg = "pal";
30 sarma::Order order_type = sarma::Order::NAT;
31 std::string order_str = "nat";
32 Ordinal row_parts = 8, col_parts = 0;
33 Value max_load = 0;
34 int seed = 2147483647;
35 double sparsify = 1.0;
36 bool triangular = false, use_data = false;
37};
38
39const static std::vector<std::pair<Parameters, std::vector<Ordinal> > > expected = {
40 {{.alg="opal"}, {0, 48, 94, 143, 175, 218, 257, 295, 332, 0, 48, 94, 143, 175, 218, 257, 295, 332}}
41};
42
43auto testFromFile(const RCP<const Teuchos::Comm<int> > &comm, int nparts, std::string &filename, bool doRemap,
44 const Parameters sarma) {
45 int me = comm->getRank();
46
47 UserInputForTests userInputForTests(testDataFilePath, filename, comm, false, true);
48 RCP<tcrsMatrix_t> matrix = userInputForTests.getUITpetraCrsMatrix();
49 RCP<const tcrsMatrix_t> matrixConst = rcp_const_cast<const tcrsMatrix_t>(matrix);
50
51
52 xCM_tCM_t matrixAdapter(matrixConst, 0);
53
54 #ifdef HAVE_ZOLTAN2_MPI
55 double begin = MPI_Wtime();
56 #endif
57
58 Teuchos::ParameterList params("test params");
59 params.set("debug_level", "basic_status");
60 params.set("num_global_parts", nparts);
61 params.set("algorithm", "sarma");
62 if (doRemap) params.set("remap_parts", true);
63 Teuchos::ParameterList &zparams = params.sublist("zoltan_parameters", false);
64 zparams.set("DEBUG_LEVEL", "0");
65
66 // Sarma params
67 Teuchos::ParameterList &sparams = params.sublist("sarma_parameters", false);
68 sparams.set("alg", sarma.alg);
69 sparams.set("order", sarma.order_str);
70 sparams.set("row_parts", sarma.row_parts);
71 sparams.set("col_parts", sarma.col_parts);
72 sparams.set("max_load", sarma.max_load);
73 sparams.set("sparsify", sarma.sparsify);
74 sparams.set("triangular", sarma.triangular);
75 sparams.set("use_data", sarma.use_data);
76 sparams.set("seed", sarma.seed);
77
78 #ifdef HAVE_ZOLTAN2_MPI
79 Zoltan2::PartitioningProblem<xCM_tCM_t> problem(&matrixAdapter, &params, comm);
80 #else
81 Zoltan2::PartitioningProblem<xCM_tCM_t> problem(&matrixAdapter, &params);
82 #endif
83 if (me == 0) std::cout << "Problem constructed" << std::endl;
84
85 problem.solve();
86
87 #ifdef HAVE_ZOLTAN2_MPI
88 if (me == 0)
89 std::cout << "Run-time:\t" << MPI_Wtime() - begin << std::endl;
90 #endif
91 return problem.getSolution();
92}
93#endif
94
95int main(int argc, char *argv[]) {
96 #ifdef HAVE_ZOLTAN2_SARMA
97 Tpetra::ScopeGuard tscope(&argc, &argv);
98 RCP<const Teuchos::Comm<int> > tcomm = Tpetra::getDefaultComm();
99
100 Parameters params;
101
102 int nParts = 8;
103 bool doRemap = false;
104 std::string filename = "USAir97";
105
106 // Run-time options
107
108 for (auto test : expected){
109
110 auto zsoln = testFromFile(tcomm, nParts, filename, doRemap, test.first);
111
112 // compare zoltan vs raw
113
114 const int *zparts = zsoln.getPartListView();
115 for (unsigned i = 0; i < test.second.size(); ++i) {
116 if (zparts[i] != (int) test.second[i]) {
117 std::cout << "FAIL" << std::endl;
118 return EXIT_FAILURE;
119 }
120 }
121 }
122 #endif
123 std::cout << "PASS" << std::endl;
124
125 return EXIT_SUCCESS;
126}
#define nParts
Defines the PartitioningProblem class.
Defines the PartitioningSolution class.
common code used by tests
std::string testDataFilePath(".")
Defines the XpetraCrsMatrixAdapter class.
int main()
PartitioningProblem sets up partitioning problems for the user.
Provides access for Zoltan2 to Xpetra::CrsMatrix data.
Zoltan2::BasicUserTypes< zscalar_t, zlno_t, zgno_t > myTypes_t