50 #include <Teuchos_GlobalMPISession.hpp> 51 #include <Teuchos_DefaultComm.hpp> 52 #include <Teuchos_CommandLineProcessor.hpp> 53 #include <Teuchos_ParameterList.hpp> 59 int main(
int narg,
char **arg)
62 Teuchos::GlobalMPISession session(&narg, &arg);
63 RCP<const Comm<int> > comm = Teuchos::DefaultComm<int>::getComm();
65 int rank = comm->getRank();
66 int nprocs = comm->getSize();
69 int numGlobalIdentifiers = 100;
70 int numMyIdentifiers = numGlobalIdentifiers / nprocs;
71 if (rank < numGlobalIdentifiers % nprocs)
72 numMyIdentifiers += 1;
79 if (!myIds || !myWeights){
87 std::cout <<
"Memory allocation failure" << std::endl;
88 std::cout <<
"FAIL" << std:: endl;
94 for (
int i=0; i < numMyIdentifiers; i++){
95 myIds[i] = myBaseId+i;
96 myWeights[i] = rank%3 + 1;
97 origsumwgts += myWeights[i];
101 int *origcnt =
new int[nprocs];
103 Teuchos::gather<int, int>(&numMyIdentifiers, 1, origcnt, 1, 0, *comm);
104 Teuchos::gather<int, zscalar_t>(&origsumwgts, 1, origwgts, 1, 0, *comm);
106 cout <<
"BEFORE PART CNTS: ";
107 for (
int i = 0; i < nprocs; i++)
108 cout << origcnt[i] <<
" ";
110 cout <<
"BEFORE PART WGTS: ";
111 for (
int i = 0; i < nprocs; i++)
112 cout << origwgts[i] <<
" ";
119 std::vector<const zscalar_t *> weightValues;
120 std::vector<int> weightStrides;
121 weightValues.push_back(const_cast<const zscalar_t *>(myWeights));
126 typedef adapter_t::part_t part_t;
130 new adapter_t(
zlno_t(numMyIdentifiers),myIds,weightValues,weightStrides);
133 bool useWeights =
true;
134 Teuchos::CommandLineProcessor cmdp (
false,
false);
135 cmdp.setOption(
"weights",
"no-weights", &useWeights,
136 "Indicated whether to use identifier weights in partitioning");
137 cmdp.parse(narg, arg);
139 Teuchos::ParameterList params(
"test parameters");
141 params.set(
"num_global_parts", nprocs);
142 params.set(
"algorithm",
"block");
143 params.set(
"partitioning_approach",
"partition");
144 if (!useWeights) params.set(
"partitioning_objective",
"balance_object_count");
154 quality_t *metricObject =
new quality_t(adapter, ¶ms, comm, &solution);
159 memset(totalWeight, 0, nprocs *
sizeof(
zscalar_t));
160 int *totalCnt =
new int [nprocs];
161 int *sumCnt =
new int [nprocs];
162 memset(totalCnt, 0, nprocs *
sizeof(
int));
165 zscalar_t libImbalance = metricObject->getWeightImbalance(0);
169 for (
int i=0; i < numMyIdentifiers; i++){
170 totalCnt[partList[i]]++;
171 totalWeight[partList[i]] += myWeights[i];
174 Teuchos::reduceAll<int, int>(*comm, Teuchos::REDUCE_SUM, nprocs,
176 Teuchos::reduceAll<int, zscalar_t>(*comm, Teuchos::REDUCE_SUM, nprocs,
177 totalWeight, sumWeight);
182 std::cout <<
"AFTER PART CNTS: ";
183 for (
int i=0; i < nprocs; i++)
184 std::cout << sumCnt[i] <<
" ";
185 std::cout << std::endl;
188 std::cout <<
"AFTER PART WGTS: ";
189 for (
int i=0; i < nprocs; i++){
190 std::cout << sumWeight[i] <<
" ";
191 total += sumWeight[i];
193 std::cout << std::endl;
199 for (
int i=0; i < nprocs; i++){
201 if (sumWeight[i] > avg)
202 imb = (sumWeight[i] - avg) / avg;
204 imb = (avg - sumWeight[i]) / avg;
211 std::cout <<
"Computed imbalance: " << imbalance << std::endl;
212 std::cout <<
"Library's imbalance: " << libImbalance << std::endl;
215 if (imbalance > libImbalance)
216 err = imbalance - libImbalance;
218 err = libImbalance - imbalance;
231 std::cout <<
"failure in solution's imbalance data" << std::endl;
232 std::cout <<
"FAIL" << std:: endl;
238 std::cout <<
"PASS" << std:: endl;
245 delete [] totalWeight;
Zoltan2::BaseAdapter< userTypes_t > base_adapter_t
int globalFail(const RCP< const Comm< int > > &comm, int fail)
int main(int narg, char **arg)
A simple class that can be the User template argument for an InputAdapter.
Defines the PartitioningSolution class.
common code used by tests
This class represents a collection of global Identifiers and their associated weights, if any.
A PartitioningSolution is a solution to a partitioning problem.
static const std::string fail
Defines the BasicIdentifierAdapter class.
const PartitioningSolution< Adapter > & getSolution()
Get the solution to the problem.
PartitioningProblem sets up partitioning problems for the user.
const part_t * getPartListView() const
Returns the part list corresponding to the global ID list.
Defines the PartitioningProblem class.
A class that computes and returns quality metrics.
void solve(bool updateInputData=true)
Direct the problem to create a solution.