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));
125 typedef adapter_t::part_t part_t;
127 adapter_t adapter(
zlno_t(numMyIdentifiers),myIds,weightValues,weightStrides);
130 bool useWeights =
true;
131 Teuchos::CommandLineProcessor cmdp (
false,
false);
132 cmdp.setOption(
"weights",
"no-weights", &useWeights,
133 "Indicated whether to use identifier weights in partitioning");
134 cmdp.parse(narg, arg);
136 Teuchos::ParameterList params(
"test parameters");
137 params.set(
"compute_metrics",
"true");
138 params.set(
"num_global_parts", nprocs);
139 params.set(
"algorithm",
"block");
140 params.set(
"partitioning_approach",
"partition");
141 if (!useWeights) params.set(
"partitioning_objective",
"balance_object_count");
152 memset(totalWeight, 0, nprocs *
sizeof(
zscalar_t));
153 int *totalCnt =
new int [nprocs];
154 int *sumCnt =
new int [nprocs];
155 memset(totalCnt, 0, nprocs *
sizeof(
int));
160 for (
int i=0; i < numMyIdentifiers; i++){
161 totalCnt[partList[i]]++;
162 totalWeight[partList[i]] += myWeights[i];
165 Teuchos::reduceAll<int, int>(*comm, Teuchos::REDUCE_SUM, nprocs,
167 Teuchos::reduceAll<int, zscalar_t>(*comm, Teuchos::REDUCE_SUM, nprocs,
168 totalWeight, sumWeight);
173 std::cout <<
"AFTER PART CNTS: ";
174 for (
int i=0; i < nprocs; i++)
175 std::cout << sumCnt[i] <<
" ";
176 std::cout << std::endl;
179 std::cout <<
"AFTER PART WGTS: ";
180 for (
int i=0; i < nprocs; i++){
181 std::cout << sumWeight[i] <<
" ";
182 total += sumWeight[i];
184 std::cout << std::endl;
190 for (
int i=0; i < nprocs; i++){
192 if (sumWeight[i] > avg)
193 imb = (sumWeight[i] - avg) / avg;
195 imb = (avg - sumWeight[i]) / avg;
202 std::cout <<
"Computed imbalance: " << imbalance << std::endl;
203 std::cout <<
"Library's imbalance: " << libImbalance << std::endl;
206 if (imbalance > libImbalance)
207 err = imbalance - libImbalance;
209 err = libImbalance - imbalance;
222 std::cout <<
"failure in solution's imbalance data" << std::endl;
223 std::cout <<
"FAIL" << std:: endl;
229 std::cout <<
"PASS" << std:: endl;
236 delete [] totalWeight;
const scalar_t getWeightImbalance(int idx=0) const
Returns the imbalance of the solution.
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.
const part_t * getPartListView() const
Returns the part list corresponding to the global ID list.
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.
Defines the PartitioningProblem class.
void solve(bool updateInputData=true)
Direct the problem to create a solution.