72 #ifdef HAVE_ZOLTAN2_INST_FLOAT_INT_LONG 77 #ifdef HAVE_ZOLTAN2_INST_DOUBLE_INT_LONG 82 #ifdef HAVE_ZOLTAN2_INST_FLOAT_INT_INT 87 #ifdef HAVE_ZOLTAN2_INST_DOUBLE_INT_INT 101 int main(
int argc,
char *argv[])
103 #ifdef HAVE_ZOLTAN2_MPI 104 MPI_Init(&argc, &argv);
106 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
107 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
109 int rank=0, nprocs=1;
121 size_t localCount = 40;
133 scalar_t scalingFactor = 10.0 / RAND_MAX;
135 for (
size_t i=0; i < localCount*dim; i++){
136 coords[i] =
scalar_t(rand()) * scalingFactor;
144 for (
size_t i=0; i < localCount; i++)
145 globalIds[i] = offset++;
150 double tolerance = 1.1;
153 std::cout <<
"Imbalance tolerance is " << tolerance << std::endl;
155 Teuchos::ParameterList params(
"test params");
156 params.set(
"debug_level",
"basic_status");
157 params.set(
"debug_procs",
"0");
158 params.set(
"error_check_level",
"debug_mode_assertions");
160 params.set(
"compute_metrics",
"true");
161 params.set(
"algorithm",
"rcb");
162 params.set(
"imbalance_tolerance", tolerance );
163 params.set(
"num_global_parts", nprocs);
165 params.set(
"bisection_num_test_cuts", 1);
175 inputAdapter_t ia1(localCount, globalIds, x, y, z, 1, 1, 1);
179 #ifdef HAVE_ZOLTAN2_MPI 199 if (imb <= tolerance)
200 std::cout <<
"pass: " << imb << std::endl;
202 std::cout <<
"fail: " << imb << std::endl;
203 std::cout << std::endl;
213 for (
size_t i=0; i < localCount; i++){
219 vector<const scalar_t *>coordVec(2);
220 vector<int> coordStrides(2);
222 coordVec[0] = x; coordStrides[0] = 1;
223 coordVec[1] = y; coordStrides[1] = 1;
225 vector<const scalar_t *>weightVec(1);
226 vector<int> weightStrides(1);
228 weightVec[0] = weights; weightStrides[0] = 1;
231 localCount, globalIds,
232 coordVec, coordStrides,
233 weightVec, weightStrides);
237 #ifdef HAVE_ZOLTAN2_MPI 257 if (imb <= tolerance)
258 std::cout <<
"pass: " << imb << std::endl;
260 std::cout <<
"fail: " << imb << std::endl;
261 std::cout << std::endl;
277 params.set(
"partitioning_objective",
"multicriteria_minimize_total_weight");
281 weights =
new scalar_t [localCount*3];
284 for (
size_t i=0; i < localCount*3; i+=3){
285 weights[i] = 1.0 + rank / nprocs;
286 weights[i+1] = rank<nprocs/2 ? 1 : 2;
287 weights[i+2] = rand()/RAND_MAX +.5;
293 weightStrides.resize(3);
295 weightVec[0] = weights; weightStrides[0] = 3;
296 weightVec[1] = weights+1; weightStrides[1] = 3;
297 weightVec[2] = weights+2; weightStrides[2] = 3;
300 localCount, globalIds,
301 coordVec, coordStrides,
302 weightVec, weightStrides);
306 #ifdef HAVE_ZOLTAN2_MPI 326 if (imb <= tolerance)
327 std::cout <<
"pass: " << imb << std::endl;
329 std::cout <<
"fail: " << imb << std::endl;
330 std::cout << std::endl;
336 bool dataHasChanged =
false;
338 params.set(
"partitioning_objective",
"multicriteria_minimize_maximum_weight");
340 problem3->
solve(dataHasChanged);
344 if (imb <= tolerance)
345 std::cout <<
"pass: " << imb << std::endl;
347 std::cout <<
"fail: " << imb << std::endl;
348 std::cout << std::endl;
351 params.set(
"partitioning_objective",
"multicriteria_balance_total_maximum");
353 problem3->
solve(dataHasChanged);
357 if (imb <= tolerance)
358 std::cout <<
"pass: " << imb << std::endl;
360 std::cout <<
"fail: " << imb << std::endl;
361 std::cout << std::endl;
378 params.set(
"num_global_parts", nprocs*2);
388 partIds[0] = rank*2; partSizes[0] = 0;
389 partIds[1] = rank*2+1; partSizes[1] = 1;
397 dataHasChanged =
false;
399 problem1->
solve(dataHasChanged);
410 int numInEmptyParts = 0;
411 for (
size_t i=0; i < localCount; i++){
412 if (partAssignments[i] % 2 == 0)
417 std::cout <<
"Request that " << nprocs <<
" parts be empty." <<std::endl;
426 if (imb <= tolerance)
427 std::cout <<
"pass: " << imb << std::endl;
429 std::cout <<
"fail: " << imb << std::endl;
430 std::cout << std::endl;
448 #ifdef HAVE_ZOLTAN2_MPI 453 std::cout <<
"PASS" << std::endl;
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.
int zoltan2_partId_t
a data type for part IDs
const zoltan2_partId_t * getPartList() const
Returns the part list corresponding to the global ID list.
A PartitioningSolution is a solution to a partitioning problem.
void printMetrics(ostream &os) const
Print the array of metrics.
const PartitioningSolution< Adapter > & getSolution()
Get the solution to the problem.
PartitioningProblem sets up partitioning problems for the user.
void setPartSizes(int len, partId_t *partIds, scalar_t *partSizes, bool makeCopy=true)
Set or reset relative sizes for the partitions that Zoltan2 will create.
Defines the PartitioningProblem class.
void solve(bool updateInputData=true)
Direct the problem to create a solution.
int main(int argc, char *argv[])
Zoltan2::BasicIdentifierInput< myTypes_t > inputAdapter_t
const scalar_t getImbalance(int dim=0) const
Returns the imbalance of the solution.