Zoltan2
Loading...
Searching...
No Matches
paramToXML.cpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Zoltan2: A package of combinatorial algorithms for scientific computing
4//
5// Copyright 2012 NTESS and the Zoltan2 contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
15#include <Teuchos_ParameterList.hpp>
16#include <Teuchos_XMLObject.hpp>
17#include <Teuchos_XMLParameterListWriter.hpp>
18#include <Teuchos_ParameterXMLFileReader.hpp>
19#include <Teuchos_ValidatorXMLConverterDB.hpp>
20
21#include <Teuchos_StandardParameterEntryValidators.hpp>
22#include <Zoltan2_Standards.hpp>
25
26#include <iostream>
27#include <fstream>
28#include <sstream>
29#include <string>
30
31using std::string;
32using std::ostringstream;
33using std::endl;
34using std::cout;
35using std::cout;
36using Teuchos::RCP;
37using Teuchos::rcp;
38using Teuchos::Tuple;
39
40
41
42void createAllParameters(Teuchos::ParameterList &pList);
43
44int main(int argc, char *argv[])
45{
46 string xmlFile("initParams.xml");
47 Teuchos::XMLParameterListWriter plw;
48
49 // XML converter for Zoltan2::IntegerRangeListValidator must be added
50 // once to the validator database.
51
53 RCP<irlConverter_t > converter = rcp(new irlConverter_t);
55 RCP<const irl_t> intRangeValidatorP = rcp(new irl_t);
56
57 Teuchos::ValidatorXMLConverterDB::addConverter(
58 intRangeValidatorP, // can be a dummy of this type
59 converter);
60
61 Teuchos::ParameterList pl("zoltan2ValidatingParameters");
63
64 // Write out to XML
65 Teuchos::XMLObject obj = plw.toXML(pl);
66
67 cout << "Parameter list: " << endl;
68 cout << obj << endl;
69
70 std::ofstream of;
71 of.open(xmlFile.c_str());
72 of << obj << endl;
73 of.close();
74}
75
76void createAllParameters(Teuchos::ParameterList &pList)
77{
78 using Teuchos::tuple;
79 using std::string;
80
81 using Teuchos::AnyNumberParameterEntryValidator;
82 RCP<const AnyNumberParameterEntryValidator> anyNumValidatorP;
83
84 using Teuchos::EnhancedNumberValidator;
85 RCP<const EnhancedNumberValidator<int> > intValidatorP;
86
87 using Teuchos::StringValidator;
88 RCP<const StringValidator> strValidatorP;
89
90 using Teuchos::FileNameValidator;
91 RCP<const FileNameValidator > fnameValidatorP;
92
93 using Teuchos::StringToIntegralParameterEntryValidator;
94 typedef StringToIntegralParameterEntryValidator<int> str2intValidator;
95 RCP<const str2intValidator> str2intValidatorP;
96
97 Tuple<string,8> yesNoStrings =
98 tuple<string>( "true", "yes", "1", "on", "false", "no", "0", "off");
99
100 Tuple<int,8> yesNoIntegrals =
101 tuple<int>( 1, 1, 1, 1, 0, 0, 0, 0);
102
103 // allowed values for output streams
104
105 Tuple<string,8> ostreamStrings =
106 tuple<string>( "std::cout", "cout", "stdout",
107 "std::cerr", "cerr", "stderr",
108 "/dev/null", "null");
109
110 Tuple<int,8> ostreamIntegrals =
111 tuple<int>( 0, 0, 0, 1, 1, 1, 2, 2);
112
113 RCP<const Zoltan2::IntegerRangeListValidator<int> > intRangeValidatorP;
114
115 string parameterName;
116 std::ostringstream docString;
117
118 parameterName = string("error_check_level");
119
120 str2intValidatorP = rcp(new str2intValidator(
121
122 tuple<string>("no_assertions",
123 "basic_assertions",
124 "complex_assertions",
125 "debug_mode_assertions"),
126
127 tuple<string>(
128 "no assertions will be performed",
129 "typical checks of argument validity (fast, default)",
130 "additional checks, i.e. is input graph a valid graph)",
131 "check for everything including logic errors (slowest)"),
132
133 tuple<int>(Zoltan2::NO_ASSERTIONS,
137
138 parameterName));
139
140 string omitInfo("the amount of error checking performed\n");
141 omitInfo.append("(If the compile flag Z2_OMIT_ALL_ERROR_CHECKING was set,\n");
142 omitInfo.append("then error checking code is not executed at runtime.)\n");
143 docString.str("");
144 str2intValidatorP->printDoc(omitInfo, docString);
145
146 pList.set<string>(parameterName, "basic_assertions", docString.str(),
147 str2intValidatorP);
148
150 parameterName = string("debug_level");
151
152 str2intValidatorP = rcp(new str2intValidator(
153 tuple<string>("no_status",
154 "basic_status",
155 "detailed_status",
156 "verbose_detailed_status"),
157
158 tuple<string>(
159 "library outputs no status information",
160 "library outputs basic status information (default)",
161 "library outputs detailed information",
162 "library outputs very detailed information"),
163
164 tuple<int>(
169
170 parameterName));
171
172 omitInfo = string("the amount of status/warning/debugging info printed\n");
173 omitInfo.append("(If the compile flag Z2_OMIT_ALL_STATUS_MESSAGES was set,\n");
174 omitInfo.append("then message output code is not executed at runtime.)\n");
175 docString.str("");
176 str2intValidatorP->printDoc(
177 "the amount of status/debugging/warning information to print\n", docString);
178
179 pList.set<string>(parameterName, "basic_status", docString.str(),
180 str2intValidatorP);
181
183
184 parameterName = string("timer_type");
185
186 str2intValidatorP = rcp(new str2intValidator(
187 tuple<string>(
188 "no_timers", "macro_timers", "micro_timers", "both_timers", "test_timers"),
189
190 tuple<string>(
191 "No timing data will be collected (the default).",
192 "Time an algorithm (or other entity) as a whole.",
193 "Time the substeps of an entity.",
194 "Run both MACRO and MICRO timers.",
195 "Run timers added to code for testing, removed later"),
196
198
199 parameterName));
200
201 omitInfo = string("the type of timing information to collect\n");
202 omitInfo.append("(If the compile flag Z2_OMIT_ALL_PROFILING was set,\n");
203 omitInfo.append("then the timing code is not executed at runtime.)\n");
204 docString.str("");
205 str2intValidatorP->printDoc(omitInfo, docString);
206
207 pList.set<string>(parameterName, "no_timers", docString.str(),
208 str2intValidatorP);
209
211 parameterName = string("debug_output_stream");
212
213 str2intValidatorP =
214 rcp(new str2intValidator(ostreamStrings, ostreamIntegrals, parameterName));
215
216 docString.str("");
217 str2intValidatorP->printDoc(
218 "output stream for debug/status/warning messages (default cout)\n",
219 docString);
220
221 pList.set<string>(parameterName, "cout", docString.str(),
222 str2intValidatorP);
223
225 parameterName = string("timer_output_stream");
226
227 str2intValidatorP =
228 rcp(new str2intValidator(ostreamStrings, ostreamIntegrals, parameterName));
229
230 docString.str("");
231 str2intValidatorP->printDoc(
232 "output stream for timing report (default cout)\n",
233 docString);
234
235 pList.set<string>(parameterName, "cout", docString.str(),
236 str2intValidatorP);
237
239 parameterName = string("memory_output_stream");
240
241 str2intValidatorP =
242 rcp(new str2intValidator(ostreamStrings, ostreamIntegrals, parameterName));
243
244 docString.str("");
245 str2intValidatorP->printDoc(
246 "output stream for memory usage messages (default cout)\n",
247 docString);
248
249 pList.set<string>(parameterName, "cout", docString.str(),
250 str2intValidatorP);
251
252
254 parameterName = string("debug_output_file");
255
256 fnameValidatorP = rcp(new FileNameValidator(false));
257 docString.str("");
258 fnameValidatorP->printDoc(
259 "name of file to which debug/status messages should be written\n"
260 "(process rank will be included in file name)\n",
261 docString);
262
263 pList.set<string>(parameterName, "/dev/null", docString.str(), fnameValidatorP);
264
266 parameterName = string("timer_output_file");
267
268 docString.str("");
269 fnameValidatorP->printDoc(
270 "name of file to which timing information should be written\n"
271 "(process rank will be included in file name)\n",
272 docString);
273
274 pList.set<string>(parameterName, "/dev/null", docString.str(), fnameValidatorP);
275
277 parameterName = string("memory_output_file");
278
279 docString.str("");
280 fnameValidatorP->printDoc(
281 "name of file to which memory profiling information should be written\n"
282 "(process rank will be included in file name)\n",
283 docString);
284
285 pList.set<string>(parameterName, "/dev/null", docString.str(), fnameValidatorP);
286
288 parameterName = string("debug_procs");
289
290 RCP<const Zoltan2::IntegerRangeListValidator<int> > intRangeValidatorUnsertedP = rcp(new Zoltan2::IntegerRangeListValidator<int>(true));
291
292 docString.str("");
293 intRangeValidatorUnsertedP->printDoc(
294 "list of ranks that output debugging/status messages (default \"0\")\n",
295 docString);
296
297 pList.set<string>(parameterName, "0", docString.str(), intRangeValidatorUnsertedP);
298
300 parameterName = string("pqParts");
301
302 RCP<const Zoltan2::IntegerRangeListValidator<int> > pqRangeRangeValidatorP = rcp(new Zoltan2::IntegerRangeListValidator<int>(true));
303
304 docString.str("");
305 pqRangeRangeValidatorP->printDoc(
306 "list of parts for pqJagged partitioning algorithm. As many as the dimension count.\n",
307 docString);
308
309 pList.set<string>(parameterName, "0", docString.str(), pqRangeRangeValidatorP);
310
312 intRangeValidatorP = rcp(new Zoltan2::IntegerRangeListValidator<int>(true));
313 parameterName = string("memory_procs");
314
315 docString.str("");
316 intRangeValidatorP->printDoc(
317 "list of ranks that memory profiling information (default \"0\")\n",
318 docString);
319
320 pList.set<string>(parameterName, "0", docString.str(), intRangeValidatorP);
321
323 parameterName = string("speed_versus_quality");
324
325 strValidatorP = rcp(new StringValidator(
326 tuple<string>("speed", "balance", "quality")));
327
328 docString.str("");
329 strValidatorP->printDoc(
330 "When algorithm choices exist, opt for speed or solution quality?\n"
331 "(Default is a balance of speed and quality)\n",
332 docString);
333
334 pList.set<string>(parameterName, "balance", docString.str(), strValidatorP);
335
337 parameterName = string("memory_versus_speed");
338
339 strValidatorP = rcp(new StringValidator(
340 tuple<string>("memory", "balance", "speed")));
341
342 docString.str("");
343 strValidatorP->printDoc(
344 "When algorithm choices exist, opt for the use of less memory\n"
345 "at the expense of runtime\n"
346 "(Default is a balance of memory conservation and speed)\n",
347 docString);
348
349 pList.set<string>(parameterName, "balance", docString.str(), strValidatorP);
350
352 parameterName = string("random_seed");
353
354 anyNumValidatorP = rcp(new AnyNumberParameterEntryValidator);
355
356 docString.str("");
357 anyNumValidatorP->printDoc("random seed\n", docString);
358
359 pList.set<string>(parameterName, "0.5", docString.str(), anyNumValidatorP);
360
362 parameterName = string("order_method");
363 strValidatorP = rcp(new StringValidator(
364 tuple<string>("rcm", "minimum_degree", "method3")));
365
366 docString.str("");
367 strValidatorP->printDoc(
368 "Document the order_method parameter here\n"
369 "(Default is ?)\n",
370 docString);
371
372 pList.set<string>(parameterName, "rcm", docString.str(), strValidatorP);
373
375 parameterName = string("order_package");
376 strValidatorP = rcp(new StringValidator(
377 tuple<string>("amd", "package2", "package3")));
378
379 docString.str("");
380 strValidatorP->printDoc(
381 "Document the order_package parameter here\n"
382 "(Default is ?)\n",
383 docString);
384
385 pList.set<string>(parameterName, "amd", docString.str(), strValidatorP);
386
388 parameterName = string("compute_metrics");
389
390 str2intValidatorP =
391 rcp(new str2intValidator(yesNoStrings, yesNoIntegrals, parameterName));
392
393 docString.str("");
394 str2intValidatorP->printDoc("Compute metrics after computing solution\n",
395 docString);
396
397 pList.set<string>(parameterName, "no", docString.str(),
398 str2intValidatorP);
399
401 parameterName = string("topology");
402
403 strValidatorP = rcp(new StringValidator);
404
405 docString.str("");
406 docString << "Topology of node to be used in hierarchical partitioning\n";
407 docString << " \"2,4\" for dual-socket quad-core\n";
408 docString << " \"2,2,6\" for dual-socket, dual-die, six-core\n";
409 docString << " \"2,2,3\" for dual-socket, dual-die, six-core but\n";
410 docString << " with only three partitions per die\n";
411
412 pList.set<string>(parameterName, "", docString.str(), strValidatorP);
413
415 parameterName = string("randomize_input");
416
417 str2intValidatorP =
418 rcp(new str2intValidator(yesNoStrings, yesNoIntegrals, parameterName));
419
420 docString.str("");
421 str2intValidatorP->printDoc("randomize input prior to partitioning\n",
422 docString);
423
424 pList.set<string>(parameterName, "no", docString.str(),
425 str2intValidatorP);
426
428 parameterName = string("partitioning_objective"); // TODO
429
430 strValidatorP = rcp(new StringValidator(
431 tuple<string>(
432 "balance_object_count",
433 "balance_object_weight",
434 "multicriteria_minimize_total_weight",
435 "multicriteria_minimize_maximum_weight",
436 "multicriteria_balance_total_maximum",
437 "minimize_cut_edge_count",
438 "minimize_cut_edge_weight",
439 "minimize_neighboring_parts",
440 "minimize_boundary_vertices")));
441
442 docString.str("");
443 strValidatorP->printDoc(
444 "objective of partitioning (default depends on algorithm)\n",
445 docString);
446
447 pList.set<string>(parameterName, "balance_object_weight",
448 docString.str(), strValidatorP);
449
451 parameterName = string("imbalance_tolerance");
452
453 anyNumValidatorP = rcp(new AnyNumberParameterEntryValidator);
454
455 docString.str("");
456 anyNumValidatorP->printDoc(
457 "imbalance tolerance, ratio of maximum load over average load"
458 " (default 1.1)\n",
459 docString);
460
461 pList.set<string>(parameterName, "1.1", docString.str(),
462 anyNumValidatorP);
463
465 parameterName = string("num_global_parts");
466
467 anyNumValidatorP = rcp(new AnyNumberParameterEntryValidator);
468
469 docString.str("");
470 anyNumValidatorP->printDoc(
471 "global number of parts to compute (default is number of processes)\n",
472 docString);
473
474 pList.set<string>(parameterName, "0", docString.str(),
475 anyNumValidatorP);
476
478 parameterName = string("num_local_parts");
479
480 anyNumValidatorP = rcp(new AnyNumberParameterEntryValidator);
481
482 docString.str("");
483 anyNumValidatorP->printDoc(
484 "number of parts to compute for this process(default is one)\n",
485 docString);
486
487 pList.set<string>(parameterName, "0", docString.str(),
488 anyNumValidatorP);
489
491 parameterName = string("partitioning_approach"); // TODO
492
493 strValidatorP = rcp(new StringValidator(
494 tuple<string>("partition", "repartition", "maximize_overlap")));
495
496 docString.str("");
497 strValidatorP->printDoc(
498 "Partition from scratch, partition incrementally from current\n"
499 "partition, of partition from scratch but maximize overlap\n"
500 "with the current partition (default is \"partition\" from scratch)\n",
501 docString);
502
503 pList.set<string>(parameterName, "partition", docString.str(),
504 strValidatorP);
505
507 parameterName = string("objects_to_partition"); // TODO
508
509 strValidatorP = rcp(new StringValidator(
510 tuple<string>(
511 "matrix_rows",
512 "matrix_columns",
513 "matrix_nonzeros",
514 "mesh_elements",
515 "mesh_nodes",
516 "graph_edges",
517 "graph_vertices",
518 "coordinates",
519 "identifiers")));
520
521 docString.str("");
522 strValidatorP->printDoc(
523 "Objects to be partitioned (defaults are \"matrix_rows\" for\n"
524 "matrix input, \"mesh_nodes\" for mesh input, and \"graph_vertices\"\n"
525 "for graph input)\n",
526 docString);
527
528 pList.set<string>(parameterName, "graph_vertices", docString.str(),
529 strValidatorP);
530
532 parameterName = string("model");
533
534 strValidatorP = rcp(new StringValidator(
535 tuple<string>("hypergraph", "graph", "geometry", "ids")));
536
537 docString.str("");
538 strValidatorP->printDoc(
539 "This is a low level parameter. Normally the library will choose\n"
540 "a computational model based on the algorithm or objective specified\n"
541 "by the user.\n",
542 docString);
543
544 pList.set<string>(parameterName, "graph", docString.str(),
545 strValidatorP);
546
548 parameterName = string("algorithm");
549
550 strValidatorP = rcp(new StringValidator(
551 tuple<string>(
552 "rcb",
553 "multijagged",
554 "rib",
555 "hsfc",
556 "patoh",
557 "phg",
558 "metis",
559 "parmetis",
560 "scotch",
561 "ptscotch",
562 "block",
563 "cyclic",
564 "random")));
565
566 docString.str("");
567 strValidatorP->printDoc("partitioning algorithm\n", docString);
568
569 pList.set<string>(parameterName, "random", docString.str(),
570 strValidatorP);
571
573 parameterName = string("rectilinear");
574
575 str2intValidatorP =
576 rcp(new str2intValidator(yesNoStrings, yesNoIntegrals, parameterName));
577
578 docString.str("");
579 str2intValidatorP->printDoc(
580 "If true, then when a cut is made, all of the dots located on the cut\n"
581 "are moved to the same side of the cut. The resulting regions are then\n"
582 "rectilinear. The resulting load balance may not be as good as when\n"
583 "the group of dots is split by the cut. Default is false.\n",
584 docString);
585
586 pList.set<string>(parameterName, "no", docString.str(),
587 str2intValidatorP);
588
590 parameterName = string("average_cuts");
591
592 str2intValidatorP =
593 rcp(new str2intValidator(yesNoStrings, yesNoIntegrals, parameterName));
594
595 docString.str("");
596 str2intValidatorP->printDoc(
597 "When true, coordinates of RCB cutting planes are computed to be \n"
598 "the average of the coordinates of the closest object on each side \n"
599 "of the cut. Otherwise, coordinates of cutting planes may equal \n"
600 "those of one of the closest objects. Default is false.\n",
601 docString);
602
603 pList.set<string>(parameterName, "no", docString.str(),
604 str2intValidatorP);
605
607 parameterName = string("symmetrize_input");
608
609 strValidatorP = rcp(new StringValidator(
610 tuple<string>( "no", "transpose", "bipartite")));
611
612 docString.str("");
613 strValidatorP->printDoc(
614 "Symmetrize input prior to pList. If \"transpose\",\n"
615 "symmetrize A by computing A plus ATranspose. If \"bipartite\",\n"
616 "A becomes [[0 A][ATranspose 0]]. \n",
617 docString);
618
619 pList.set<string>(parameterName, "no", docString.str(),
620 strValidatorP);
621
623 parameterName = string("subset_graph");
624
625 str2intValidatorP =
626 rcp(new str2intValidator(yesNoStrings, yesNoIntegrals, parameterName));
627
628 docString.str("");
629 str2intValidatorP->printDoc(
630 "If \"yes\", the graph input is to be subsetted. If a vertex neighbor\n"
631 "is not a valid vertex, it will be omitted from the pList. Otherwise,\n"
632 "an invalid neighbor identifier is considered an error.\n",
633 docString);
634
635 pList.set<string>(parameterName, "no", docString.str(),
636 str2intValidatorP);
637}
Define IntegerRangeList validator.
Defines Parameter related enumerators, declares functions.
Gathering definitions used in software development.
int main()
XML conversion code for IntegerRangeListValidator.
A ParameterList validator for integer range lists.
@ NO_TIMERS
No timing data will be collected (the default).
@ MACRO_TIMERS
Time an algorithm (or other entity) as a whole.
@ TEST_TIMERS
Timers added while testing, removed later.
@ MICRO_TIMERS
Time the substeps of an entity.
@ BOTH_TIMERS
Run both MACRO and MICRO timers.
@ BASIC_STATUS
the status at each high level step
@ DETAILED_STATUS
sub-steps, each method's entry and exit
@ NO_STATUS
don't display status/debug messages
@ VERBOSE_DETAILED_STATUS
include more detail about sub-steps
@ BASIC_ASSERTION
fast typical checks for valid arguments
@ NO_ASSERTIONS
no assertion checks will be done
@ DEBUG_MODE_ASSERTION
checks for logic errors
@ COMPLEX_ASSERTION
more involved, like validate a graph
void createAllParameters(Teuchos::ParameterList &pList)