54 #include <Tpetra_Map.hpp> 65 int main(
int argc,
char *argv[])
67 #ifdef HAVE_ZOLTAN2_MPI 68 MPI_Init(&argc, &argv);
70 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
71 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
78 typedef Tpetra::Map<> Map_t;
79 typedef Map_t::local_ordinal_type localId_t;
80 typedef Map_t::global_ordinal_type globalId_t;
82 typedef double scalar_t;
87 typedef inputAdapter_t::part_t part_t;
92 size_t localCount = 40;
95 scalar_t *coords =
new scalar_t [dim * localCount];
98 scalar_t *y = x + localCount;
99 scalar_t *z = y + localCount;
104 scalar_t scalingFactor = 10.0 / RAND_MAX;
106 for (
size_t i=0; i < localCount*dim; i++){
107 coords[i] = scalar_t(rand()) * scalingFactor;
112 globalId_t *globalIds =
new globalId_t [localCount];
113 globalId_t offset = rank * localCount;
115 for (
size_t i=0; i < localCount; i++)
116 globalIds[i] = offset++;
121 double tolerance = 1.1;
124 std::cout <<
"Imbalance tolerance is " << tolerance << std::endl;
126 Teuchos::ParameterList params(
"test params");
127 params.set(
"debug_level",
"basic_status");
128 params.set(
"debug_procs",
"0");
129 params.set(
"error_check_level",
"debug_mode_assertions");
131 params.set(
"compute_metrics",
"true");
132 params.set(
"algorithm",
"rcb");
133 params.set(
"imbalance_tolerance", tolerance );
134 params.set(
"num_global_parts", nprocs);
136 params.set(
"bisection_num_test_cuts", 1);
146 inputAdapter_t ia1(localCount, globalIds, x, y, z, 1, 1, 1);
164 if (imb <= tolerance)
165 std::cout <<
"pass: " << imb << std::endl;
167 std::cout <<
"fail: " << imb << std::endl;
168 std::cout << std::endl;
177 scalar_t *
weights =
new scalar_t [localCount];
178 for (
size_t i=0; i < localCount; i++){
179 weights[i] = 1.0 + scalar_t(rank) / scalar_t(nprocs);
184 vector<const scalar_t *>coordVec(2);
185 vector<int> coordStrides(2);
187 coordVec[0] = x; coordStrides[0] = 1;
188 coordVec[1] = y; coordStrides[1] = 1;
190 vector<const scalar_t *>weightVec(1);
191 vector<int> weightStrides(1);
193 weightVec[0] =
weights; weightStrides[0] = 1;
196 localCount, globalIds,
197 coordVec, coordStrides,
198 weightVec, weightStrides);
216 if (imb <= tolerance)
217 std::cout <<
"pass: " << imb << std::endl;
219 std::cout <<
"fail: " << imb << std::endl;
220 std::cout << std::endl;
236 params.set(
"partitioning_objective",
"multicriteria_minimize_total_weight");
240 weights =
new scalar_t [localCount*3];
243 for (
size_t i=0; i < localCount*3; i+=3){
244 weights[i] = 1.0 + rank / nprocs;
245 weights[i+1] = rank<nprocs/2 ? 1 : 2;
246 weights[i+2] = rand()/RAND_MAX +.5;
252 weightStrides.resize(3);
254 weightVec[0] =
weights; weightStrides[0] = 3;
255 weightVec[1] = weights+1; weightStrides[1] = 3;
256 weightVec[2] = weights+2; weightStrides[2] = 3;
259 localCount, globalIds,
260 coordVec, coordStrides,
261 weightVec, weightStrides);
279 if (imb <= tolerance)
280 std::cout <<
"pass: " << imb << std::endl;
282 std::cout <<
"fail: " << imb << std::endl;
283 std::cout << std::endl;
289 bool dataHasChanged =
false;
291 params.set(
"partitioning_objective",
"multicriteria_minimize_maximum_weight");
293 problem3->
solve(dataHasChanged);
297 if (imb <= tolerance)
298 std::cout <<
"pass: " << imb << std::endl;
300 std::cout <<
"fail: " << imb << std::endl;
301 std::cout << std::endl;
304 params.set(
"partitioning_objective",
"multicriteria_balance_total_maximum");
306 problem3->
solve(dataHasChanged);
310 if (imb <= tolerance)
311 std::cout <<
"pass: " << imb << std::endl;
313 std::cout <<
"fail: " << imb << std::endl;
314 std::cout << std::endl;
331 params.set(
"num_global_parts", nprocs*2);
339 scalar_t partSizes[2];
341 partIds[0] = rank*2; partSizes[0] = 0;
342 partIds[1] = rank*2+1; partSizes[1] = 1;
350 dataHasChanged =
false;
352 problem1->
solve(dataHasChanged);
363 int numInEmptyParts = 0;
364 for (
size_t i=0; i < localCount; i++){
365 if (partAssignments[i] % 2 == 0)
370 std::cout <<
"Request that " << nprocs <<
" parts be empty." <<std::endl;
379 if (imb <= tolerance)
380 std::cout <<
"pass: " << imb << std::endl;
382 std::cout <<
"fail: " << imb << std::endl;
383 std::cout << std::endl;
396 #ifdef HAVE_ZOLTAN2_MPI 401 std::cout <<
"PASS" << std::endl;
const scalar_t getWeightImbalance(int idx=0) const
Returns the imbalance of the solution.
void setPartSizes(int len, part_t *partIds, scalar_t *partSizes, bool makeCopy=true)
Set or reset relative sizes for the parts that Zoltan2 will create.
A simple class that can be the User template argument for an InputAdapter.
Defines the PartitioningSolution class.
void resetParameters(ParameterList *params)
Reset the list of parameters.
A PartitioningSolution is a solution to a partitioning problem.
const part_t * getPartListView() const
Returns the part list corresponding to the global ID list.
void printMetrics(std::ostream &os) const
Print the array of metrics.
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.
Defines the BasicVectorAdapter class.
void solve(bool updateInputData=true)
Direct the problem to create a solution.
int main(int argc, char *argv[])