21 #include <Teuchos_CommandLineProcessor.hpp>
30 using Teuchos::ArrayView;
31 using Teuchos::ArrayRCP;
32 using Teuchos::CommandLineProcessor;
34 typedef Tpetra::MultiVector<zscalar_t, zlno_t, zgno_t, znode_t>
tMVector_t;
35 typedef Tpetra::Map<zlno_t, zgno_t, znode_t>
tMap_t;
45 const RCP<
const Teuchos::Comm<int> > & comm,
52 ArrayRCP<zscalar_t>
weights(wgts, 0, len,
true);
56 for (
zlno_t i=0; i < len; i++)
60 for (
int i=0; i < 10; i++){
62 for (
zlno_t j=i; j < len; j += 10)
68 for (
zlno_t i=0; i < len; i++)
80 const RCP<
const Teuchos::Comm<int> > & comm,
83 int rank = comm->getRank();
84 int nprocs = comm->getSize();
86 double k = log(numGlobalCoords) / 3;
87 double xdimf = exp(k) + 0.5;
88 ssize_t xdim =
static_cast<ssize_t
>(floor(xdimf));
90 ssize_t zdim = numGlobalCoords / (xdim*ydim);
91 ssize_t num=xdim*ydim*zdim;
92 ssize_t diff = numGlobalCoords - num;
96 if (zdim > xdim && zdim > ydim){
98 newdiff = diff - (xdim*ydim);
103 else if (ydim > xdim && ydim > zdim){
105 newdiff = diff - (xdim*zdim);
112 newdiff = diff - (ydim*zdim);
122 diff = numGlobalCoords - num;
124 diff /= -numGlobalCoords;
126 diff /= numGlobalCoords;
130 std::cout <<
"Warning: Difference " << diff*100 <<
" percent" << std::endl;
131 std::cout <<
"Mesh size: " << xdim <<
"x" << ydim <<
"x" <<
132 zdim <<
", " << num <<
" vertices." << std::endl;
137 ssize_t numLocalCoords = num / nprocs;
138 ssize_t leftOver = num % nprocs;
141 if (rank <= leftOver)
142 gid0 =
zgno_t(rank) * (numLocalCoords+1);
144 gid0 = (leftOver * (numLocalCoords+1)) +
145 ((
zgno_t(rank) - leftOver) * numLocalCoords);
150 ssize_t gid1 = gid0 + numLocalCoords;
155 ArrayRCP<zgno_t> idArray(ids, 0, numLocalCoords,
true);
157 for (ssize_t i=gid0; i < gid1; i++)
160 RCP<const tMap_t> idMap = rcp(
161 new tMap_t(num, idArray.view(0, numLocalCoords), 0, comm));
168 ArrayRCP<zscalar_t> coordArray(x, 0, numLocalCoords*3,
true);
175 zgno_t xyPlane = xdim*ydim;
176 zgno_t zStart = gid0 / xyPlane;
177 zgno_t rem = gid0 % xyPlane;
184 for (
zscalar_t zval=zStart; next < numLocalCoords && zval < zdim; zval++){
185 for (
zscalar_t yval=yStart; next < numLocalCoords && yval < ydim; yval++){
186 for (
zscalar_t xval=xStart; next < numLocalCoords && xval < xdim; xval++){
197 ArrayView<const zscalar_t> xArray(x, numLocalCoords);
198 ArrayView<const zscalar_t> yArray(y, numLocalCoords);
199 ArrayView<const zscalar_t> zArray(z, numLocalCoords);
200 ArrayRCP<ArrayView<const zscalar_t> >
coordinates =
201 arcp(
new ArrayView<const zscalar_t> [3], 0, 3);
202 coordinates[0] = xArray;
203 coordinates[1] = yArray;
204 coordinates[2] = zArray;
206 ArrayRCP<const ArrayView<const zscalar_t> > constCoords =
207 coordinates.getConst();
209 RCP<tMVector_t> meshCoords = rcp(
new tMVector_t(
210 idMap, constCoords.view(0,3), 3));
216 int main(
int narg,
char *arg[])
220 Tpetra::ScopeGuard tscope(&narg, &arg);
221 Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
223 int rank = comm->getRank();
224 int nprocs = comm->getSize();
229 std::cout <<
"Number of processes: " << nprocs << std::endl;
232 double numGlobalCoords = 1000;
235 string timingType(
"no_timers");
236 string debugLevel(
"basic_status");
237 string memoryOn(
"memoryOn");
238 string memoryOff(
"memoryOff");
239 string memoryProcs(
"0");
241 int numGlobalParts = nprocs;
243 CommandLineProcessor commandLine(
false,
true);
244 commandLine.setOption(
"size", &numGlobalCoords,
245 "Approximate number of global coordinates.");
246 commandLine.setOption(
"testCuts", &numTestCuts,
247 "Number of test cuts to make when looking for bisector.");
248 commandLine.setOption(
"numParts", &numGlobalParts,
249 "Number of parts (default is one per proc).");
250 commandLine.setOption(
"nWeights", &nWeights,
251 "Number of weights per coordinate, zero implies uniform weights.");
253 string balanceCount(
"balance_object_count");
254 string balanceWeight(
"balance_object_weight");
255 string mcnorm1(
"multicriteria_minimize_total_weight");
256 string mcnorm2(
"multicriteria_balance_total_maximum");
257 string mcnorm3(
"multicriteria_minimize_maximum_weight");
259 string objective(balanceWeight);
261 string doc(balanceCount); doc.append(
": ignore weights\n");
263 doc.append(balanceWeight); doc.append(
": balance on first weight\n");
266 doc.append(
": given multiple weights, balance their total.\n");
269 doc.append(
": given multiple weights, balance the maximum for each coordinate.\n");
272 doc.append(
": given multiple weights, balance the L2 norm of the weights.\n");
274 commandLine.setOption(
"objective", &objective, doc.c_str());
276 commandLine.setOption(
"timers", &timingType,
277 "no_timers, micro_timers, macro_timers, both_timers, test_timers");
279 commandLine.setOption(
"debug", &debugLevel,
280 "no_status, basic_status, detailed_status, verbose_detailed_status");
282 commandLine.setOption(memoryOn.c_str(), memoryOff.c_str(), &doMemory,
283 "do memory profiling");
285 commandLine.setOption(
"memoryProcs", &memoryProcs,
286 "list of processes that output memory usage");
288 CommandLineProcessor::EParseCommandLineReturn rc =
289 commandLine.parse(narg, arg);
291 if (rc != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL){
292 if (rc == Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED){
294 std::cout <<
"PASS" << std::endl;
299 std::cout <<
"FAIL" << std::endl;
306 zgno_t globalSize =
static_cast<zgno_t>(numGlobalCoords);
309 size_t numLocalCoords = coordinates->getLocalLength();
313 for (
int p=0; p < nprocs; p++){
315 std::cout <<
"Rank " << rank <<
", " << numLocalCoords <<
"coords" << std::endl;
316 const zscalar_t *x = coordinates->getData(0).getRawPtr();
317 const zscalar_t *y = coordinates->getData(1).getRawPtr();
318 const zscalar_t *z = coordinates->getData(2).getRawPtr();
319 for (
zlno_t i=0; i < numLocalCoords; i++)
320 std::cout <<
" " << x[i] <<
" " << y[i] <<
" " << z[i] << std::endl;
327 Array<ArrayRCP<zscalar_t> >
weights(nWeights);
332 for (
int i=0; i < nWeights; i++){
342 MEMORY_CHECK(doMemory && rank==0,
"After creating input");
345 const RCP<const tMap_t> &coordmap = coordinates->getMap();
346 ArrayView<const zgno_t> ids = coordmap->getLocalElementList();
347 const zgno_t *globalIds = ids.getRawPtr();
349 size_t localCount = coordinates->getLocalLength();
351 RCP<inputAdapter_t> ia;
354 ia = rcp(
new inputAdapter_t (localCount, globalIds,
355 coordinates->getData(0).getRawPtr(), coordinates->getData(1).getRawPtr(),
356 coordinates->getData(2).getRawPtr(), 1,1,1));
359 vector<const zscalar_t *> values(3);
360 for (
int i=0; i < 3; i++)
361 values[i] = coordinates->getData(i).getRawPtr();
362 vector<int> valueStrides(0);
363 vector<const zscalar_t *> weightPtrs(nWeights);
364 for (
int i=0; i < nWeights; i++)
365 weightPtrs[i] = weights[i].getRawPtr();
366 vector<int> weightStrides(0);
368 ia = rcp(
new inputAdapter_t (localCount, globalIds,
369 values, valueStrides, weightPtrs, weightStrides));
372 MEMORY_CHECK(doMemory && rank==0,
"After creating input adapter");
376 Teuchos::ParameterList params;
378 if (timingType !=
"no_timers"){
379 params.set(
"timer_output_stream" ,
"std::cout");
380 params.set(
"timer_type" , timingType);
384 params.set(
"memory_output_stream" ,
"std::cout");
385 params.set(
"memory_procs" , memoryProcs);
388 params.set(
"debug_output_stream" ,
"std::cerr");
389 params.set(
"debug_procs" ,
"0");
391 if (debugLevel !=
"basic_status"){
392 params.set(
"debug_level" , debugLevel);
395 params.set(
"algorithm",
"rcb");
396 params.set(
"partitioning_objective", objective);
397 double tolerance = 1.1;
398 params.set(
"imbalance_tolerance", tolerance );
400 if (numGlobalParts != nprocs)
401 params.set(
"num_global_parts" , numGlobalParts);
404 std::cout <<
"Number of parts: " << numGlobalParts << std::endl;
420 std::cout <<
"PASS" << std::endl;
int main(int narg, char **arg)
Defines the PartitioningSolution class.
common code used by tests
BasicVectorAdapter represents a vector (plus optional weights) supplied by the user as pointers to st...
void printTimers() const
Return the communicator passed to the problem.
Tpetra::Map::local_ordinal_type zlno_t
PartitioningProblem sets up partitioning problems for the user.
Defines the PartitioningProblem class.
Defines the BasicVectorAdapter class.
Tpetra::MultiVector< zscalar_t, zlno_t, zgno_t, znode_t > tMVector_t
Tpetra::Map::global_ordinal_type zgno_t
void solve(bool updateInputData=true)
Direct the problem to create a solution.
#define MEMORY_CHECK(iPrint, msg)