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", 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)
206 catch (std::exception &e){
214 RCP<Zoltan2::PartitioningSolution<idInput_t> > solution;
220 ids.view(0,partSizeDim), sizes.view(0,partSizeDim)));
223 env, comm, nWeights));
225 catch (std::exception &e){
233 part_t *partNum =
new part_t [numLocalObj];
234 ArrayRCP<part_t> partAssignment(partNum, 0, numLocalObj,
true);
235 for (
int i=0; i < numLocalObj; i++)
238 solution->setParts(partAssignment);
242 RCP<quality_t> metricObject;
245 metricObject = rcp(
new quality_t(ia, &pl, comm, solution.getRawPtr()));
247 catch (std::exception &e){
257 zscalar_t imb = metricObject->getObjectCountImbalance();
258 cout <<
"Object imbalance: " << imb << endl;
260 catch (std::exception &e){
267 if (rank==0 && nWeights > 0){
269 for (
int i=0; i < nWeights; i++){
270 zscalar_t imb = metricObject->getWeightImbalance(i);
271 cout <<
"Weight " << i <<
" imbalance: " << imb << endl;
274 catch (std::exception &e){
277 if (!
fail && nWeights > 1){
279 zscalar_t imb = metricObject->getNormedImbalance();
280 cout <<
"Normed weight imbalance: " << imb << endl;
282 catch (std::exception &e){
292 metricObject->printMetrics(cout);
294 catch (std::exception &e){
Zoltan2::BaseAdapter< userTypes_t > base_adapter_t
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.