59 using Teuchos::ArrayRCP;
70 void doTest(RCP<
const Comm<int> > comm,
int numLocalObj,
71 int nWeights,
int numLocalParts,
bool givePartSizes);
73 int main(
int argc,
char *argv[])
75 Teuchos::GlobalMPISession session(&argc, &argv);
76 RCP<const Comm<int> > comm = Teuchos::DefaultComm<int>::getComm();
77 int rank = comm->getRank();
79 doTest(comm, 10, 0, -1,
false);
80 doTest(comm, 10, 0, 1,
false);
81 doTest(comm, 10, 0, 1,
true);
82 doTest(comm, 10, 1, 1,
false);
83 doTest(comm, 10, 1, 1,
true);
84 doTest(comm, 10, 2, 1,
false);
85 doTest(comm, 10, 2, 1,
true);
86 doTest(comm, 10, 1, 2,
true);
87 doTest(comm, 10, 1, 2,
false);
88 doTest(comm, 10, 1, -1,
false);
89 doTest(comm, 10, 1, -1,
true);
90 doTest(comm, 10, 2, -1,
false);
93 cout <<
"PASS" << endl;
98 void doTest(RCP<
const Comm<int> > comm,
int numLocalObj,
99 int nWeights,
int numLocalParts,
bool givePartSizes)
107 int rank = comm->getRank();
108 int nprocs = comm->getSize();
111 bool testEmptyParts = (numLocalParts < 1);
112 int numGlobalParts = 0;
115 numGlobalParts = nprocs / 2;
116 if (numGlobalParts >= 1)
117 numLocalParts = (rank < numGlobalParts ? 1 : 0);
120 testEmptyParts =
false;
124 numGlobalParts = nprocs * numLocalParts;
129 cout <<
"Test: number of weights " << nWeights;
130 cout <<
", desired number of parts " << numGlobalParts;
132 cout <<
", with differing part sizes." << endl;
134 cout <<
", with uniform part sizes." << endl;
135 cout <<
"Number of procs " << nprocs;
136 cout <<
", each with " << numLocalObj <<
" objects, part = rank." << endl;
141 Teuchos::ParameterList pl(
"test list");
142 pl.set(
"num_local_parts",
double(numLocalParts));
144 RCP<const Zoltan2::Environment> env =
150 for (
int i=0, x=rank*numLocalObj; i < numLocalObj; i++, x++){
157 int partSizeDim = (givePartSizes ? (nWeights ? nWeights : 1) : 0);
158 ArrayRCP<ArrayRCP<part_t> > ids(partSizeDim);
159 ArrayRCP<ArrayRCP<zscalar_t> > sizes(partSizeDim);
161 if (givePartSizes && numLocalParts > 0){
162 part_t *myParts =
new part_t [numLocalParts];
163 myParts[0] = rank * numLocalParts;
164 for (
int i=1; i < numLocalParts; i++)
165 myParts[i] = myParts[i-1] + 1;
166 ArrayRCP<part_t> partNums(myParts, 0, numLocalParts,
true);
169 if (sizeFactor < 0) sizeFactor *= -1;
172 for (
int dim=0; dim < partSizeDim; dim++){
174 for (
int i=0; i < numLocalParts; i++)
175 psizes[i] = sizeFactor;
176 sizes[dim] = arcp(psizes, 0, numLocalParts,
true);
184 std::vector<const zscalar_t *>
weights;
185 std::vector<int> strides;
187 int len = numLocalObj*nWeights;
188 ArrayRCP<zscalar_t> wgtBuf;
193 wgtBuf = arcp(wgts, 0, len,
true);
194 for (
int i=0; i < len; i++)
198 for (
int i=0; i < nWeights; i++, wgts+=numLocalObj)
199 weights.push_back(wgts);
201 RCP<const idInput_t> ia;
202 RCP<const base_adapter_t> bia;
205 ia = rcp(
new idInput_t(numLocalObj, myGids, weights, strides));
207 catch (std::exception &e){
213 bia = Teuchos::rcp_implicit_cast<
const base_adapter_t>(ia);
217 RCP<Zoltan2::PartitioningSolution<idInput_t> > solution;
223 ids.view(0,partSizeDim), sizes.view(0,partSizeDim)));
226 env, comm, nWeights));
228 catch (std::exception &e){
236 part_t *partNum =
new part_t [numLocalObj];
237 ArrayRCP<part_t> partAssignment(partNum, 0, numLocalObj,
true);
238 for (
int i=0; i < numLocalObj; i++)
241 solution->setParts(partAssignment);
242 RCP<const Zoltan2::PartitioningSolution<idInput_t> > solutionConst =
247 RCP<quality_t> metricObject;
250 metricObject = rcp(
new quality_t(env, comm, bia, solutionConst,
false));
252 catch (std::exception &e){
262 metricObject->getObjectCountImbalance(imb);
263 cout <<
"Object imbalance: " << imb << endl;
265 catch (std::exception &e){
272 if (rank==0 && nWeights > 0){
275 for (
int i=0; i < nWeights; i++){
276 metricObject->getWeightImbalance(imb, i);
277 cout <<
"Weight " << i <<
" imbalance: " << imb << endl;
280 catch (std::exception &e){
283 if (!fail && nWeights > 1){
285 metricObject->getNormedImbalance(imb);
286 cout <<
"Normed weight imbalance: " << imb << endl;
288 catch (std::exception &e){
298 metricObject->printMetrics(cout);
300 catch (std::exception &e){
IdentifierAdapter defines the interface for identifiers.
void doTest(RCP< const Comm< int > > comm, int numLocalObj, int nWeights, int numLocalParts, bool givePartSizes)
A simple class that can be the User template argument for an InputAdapter.
#define TEST_FAIL_AND_EXIT(comm, ok, s, code)
common code used by tests
int main(int argc, char *argv[])
This class represents a collection of global Identifiers and their associated weights, if any.
A PartitioningSolution is a solution to a partitioning problem.
Defines the EvaluatePartition class.
The user parameters, debug, timing and memory profiling output objects, and error checking methods...
static const std::string fail
InputTraits< User >::part_t part_t
Defines the BasicIdentifierAdapter class.
Zoltan2::BasicIdentifierAdapter< zzuser_t > idInput_t
A class that computes and returns quality metrics.