55 #include <Tpetra_Map.hpp>
59 int main(
int narg,
char *arg[])
61 Tpetra::ScopeGuard scope(&narg, &arg);
62 const Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
63 int rank = comm->getRank();
64 int nprocs = comm->getSize();
67 typedef Tpetra::Map<> Map_t;
68 typedef Map_t::local_ordinal_type localId_t;
69 typedef Map_t::global_ordinal_type globalId_t;
70 typedef int int_scalar_t;
80 size_t localCount = 40;
84 int_scalar_t *coords =
new int_scalar_t [dim * localCount];
85 int_scalar_t *x = coords;
86 int_scalar_t *y = x + localCount;
87 int_scalar_t *z = y + localCount;
90 for (
size_t i=0; i < localCount*dim; i++)
91 coords[i] = int_scalar_t(rand() % 10);
94 globalId_t *globalIds =
new globalId_t [localCount];
95 globalId_t offset = rank * localCount;
96 for (
size_t i=0; i < localCount; i++) globalIds[i] = offset++;
101 Teuchos::ParameterList params(
"test params");
102 params.set(
"debug_level",
"basic_status");
103 params.set(
"error_check_level",
"debug_mode_assertions");
105 params.set(
"algorithm",
"multijagged");
106 params.set(
"num_global_parts", nprocs+1);
111 inputAdapter_t *ia1 =
new inputAdapter_t(localCount,globalIds,x,y,z,1,1,1);
118 quality_t *metricObject1 =
new quality_t(ia1, ¶ms, comm,
122 metricObject1->printMetrics(std::cout);
124 double imb = metricObject1->getObjectCountImbalance();
126 std::cout <<
"no weights -- balance satisfied: " << imb << std::endl;
128 std::cout <<
"no weights -- balance failure: " << imb << std::endl;
131 std::cout << std::endl;
133 delete metricObject1;
141 int_scalar_t *
weights =
new int_scalar_t [localCount];
142 for (
size_t i=0; i < localCount; i++) weights[i] = 1 + int_scalar_t(rank);
144 std::vector<const int_scalar_t *>coordVec(3);
145 std::vector<int> coordStrides(3);
147 coordVec[0] = x; coordStrides[0] = 1;
148 coordVec[1] = y; coordStrides[1] = 1;
149 coordVec[2] = z; coordStrides[2] = 1;
151 std::vector<const int_scalar_t *>weightVec(1);
152 std::vector<int> weightStrides(1);
154 weightVec[0] =
weights; weightStrides[0] = 1;
156 inputAdapter_t *ia2=
new inputAdapter_t(localCount, globalIds, coordVec,
157 coordStrides,weightVec,weightStrides);
164 quality_t *metricObject2 =
new quality_t(ia2, ¶ms, comm,
168 metricObject2->printMetrics(std::cout);
170 double imb = metricObject2->getWeightImbalance(0);
172 std::cout <<
"weighted -- balance satisfied " << imb << std::endl;
174 std::cout <<
"weighted -- balance failed " << imb << std::endl;
177 std::cout << std::endl;
179 delete metricObject2;
181 if (weights)
delete []
weights;
182 if (coords)
delete [] coords;
183 if (globalIds)
delete [] globalIds;
188 if (nFail == 0) std::cout <<
"PASS" << std::endl;
189 else std::cout <<
"FAIL: " << nFail <<
" tests failed" << std::endl;
int main(int narg, char *arg[])
A simple class that can be the User template argument for an InputAdapter.
Defines the PartitioningSolution class.
BasicVectorAdapter represents a vector (plus optional weights) supplied by the user as pointers to st...
const PartitioningSolution< Adapter > & getSolution()
Get the solution to the problem.
PartitioningProblem sets up partitioning problems for the user.
Defines the PartitioningProblem class.
A class that computes and returns quality metrics.
Defines the BasicVectorAdapter class.
void solve(bool updateInputData=true)
Direct the problem to create a solution.