17 #include <dash/tools/PatternVisualizer.h> 19 #include <dash/util/PatternMetrics.h> 21 #include <dash/pattern/internal/PatternLogging.h> 39 std::string type =
"summa";
40 extent_t size_x = 110;
41 extent_t size_y = 110;
42 extent_t units_x = 10;
43 extent_t units_y = 10;
46 bool blocked_display =
false;
47 bool balance_extents =
false;
54 template<
typename PatternType>
56 std::string pattern_to_string(
57 const PatternType & pattern);
59 template<
typename PatternType>
61 std::string pattern_to_filename(
62 const PatternType & pattern);
65 void print_usage(
char **argv);
68 cli_params parse_args(
int argc,
char * argv[]);
72 template<
typename PatternT>
74 void print_pattern_metrics(
const PatternT & pattern);
76 template<
typename PatternT>
79 const PatternT & pattern,
82 typedef typename PatternT::index_type index_t;
84 auto pattern_file = pattern_to_filename(pattern);
85 auto pattern_desc = pattern_to_string(pattern);
86 print_pattern_metrics(pattern);
91 cerr <<
"Generating visualization of " 93 <<
" " << pattern_desc
101 <<
" " << pattern_file
103 std::ofstream out(pattern_file);
123 if (params.tile_x >= 0 || params.tile_y >= 0) {
125 typedef decltype(pattern) pattern_t;
126 pattern_t custom_pattern(sizespec,
129 ? dash::TILE(params.tile_x)
132 ? dash::TILE(params.tile_y)
135 pattern = custom_pattern;
142 make_shift_tile_pattern(
149 pattern_t pattern(sizespec,
151 dash::TILE(params.tile_y),
152 dash::TILE(params.tile_x)),
159 make_seq_tile_pattern(
166 pattern_t pattern(sizespec,
168 dash::TILE(params.tile_y),
169 dash::TILE(params.tile_x)),
183 pattern_t pattern(sizespec,
185 dash::TILE(params.tile_y),
186 dash::TILE(params.tile_x)),
200 pattern_t pattern(sizespec,
203 ? dash::BLOCKCYCLIC(params.tile_y)
206 ? dash::BLOCKCYCLIC(params.tile_x)
212 int main(
int argc,
char* argv[])
216 auto params = parse_args(argc, argv);
217 print_params(params);
224 if(params.balance_extents) {
227 if (params.tile_x < 0 && params.tile_y < 0) {
228 auto max_team_extent = std::max(teamspec.
extent(0),
230 params.tile_y = sizespec.
extent(0) / max_team_extent;
231 params.tile_x = sizespec.
extent(1) / max_team_extent;
234 if (params.type ==
"summa") {
235 auto pattern = make_summa_pattern(params, sizespec, teamspec);
236 print_example(pattern, params);
237 }
else if (params.type ==
"block") {
238 auto pattern = make_block_pattern(params, sizespec, teamspec);
239 print_example(pattern, params);
240 }
else if (params.type ==
"tile") {
241 auto pattern = make_tile_pattern(params, sizespec, teamspec);
242 print_example(pattern, params);
243 }
else if (params.type ==
"shift") {
244 auto pattern = make_shift_tile_pattern(params, sizespec, teamspec);
245 print_example(pattern, params);
246 }
else if (params.type ==
"seq") {
247 auto pattern = make_seq_tile_pattern(params, sizespec, teamspec);
248 print_example(pattern, params);
254 }
catch (std::exception & excep) {
255 cerr << excep.what() << endl;
265 void print_usage(
char **argv)
269 << basename(argv[0]) <<
" " 277 cerr <<
"-s pattern: [summa|block|tile|seq|shift]\n" 278 <<
"-n size_spec: <size_y> <size_x> [ " 279 << default_params.size_y <<
" " << default_params.size_x <<
" ]\n" 280 <<
"-u unit_spec: <units_y> <units_x> [ " 281 << default_params.units_x <<
" " << default_params.units_x <<
" ]\n" 282 <<
"-t tile_spec: <tile_y> <tile_x> [ automatically determined ]\n" 283 <<
"-p : print to stdout instead of stderr\n" 284 <<
"-h : print help and exit" 290 cli_params parse_args(
int argc,
char * argv[])
294 for (
auto i = 1; i < argc; i += 3) {
295 std::string flag = argv[i];
301 params.type = argv[i+1];
303 }
else if (flag ==
"-n") {
304 params.size_y =
static_cast<extent_t
>(atoi(argv[i+1]));
305 params.size_x =
static_cast<extent_t
>(atoi(argv[i+2]));
306 }
else if (flag ==
"-u") {
307 params.units_y =
static_cast<extent_t
>(atoi(argv[i+1]));
308 params.units_x =
static_cast<extent_t
>(atoi(argv[i+2]));
309 }
else if (flag ==
"-t") {
310 params.tile_y =
static_cast<extent_t
>(atoi(argv[i+1]));
311 params.tile_x =
static_cast<extent_t
>(atoi(argv[i+2]));
312 }
else if (flag ==
"-p") {
315 }
else if (flag ==
"-e") {
316 params.balance_extents =
true;
318 }
else if (flag ==
"-b") {
319 params.blocked_display =
true;
333 int w_size = std::log10(std::max(params.size_x, params.size_y));
334 int w_units = std::log10(std::max(params.units_x, params.units_y));
335 int w_tile = std::log10(std::max(params.tile_x, params.tile_y));
336 int w = std::max({ w_size, w_units, w_tile }) + 1;
338 cerr <<
"Parameters:" 340 <<
" type (-s): " << params.type
342 <<
" size (-n <rows> <cols>): ( " 343 << std::fixed << std::setw(w) << params.size_y <<
", " 344 << std::fixed << std::setw(w) << params.size_x <<
" )" 346 <<
" team (-u <rows> <cols>): ( " 347 << std::fixed << std::setw(w) << params.units_y <<
", " 348 << std::fixed << std::setw(w) << params.units_x <<
" )" 350 <<
" balance extents (-e): " 351 << (params.balance_extents ?
"yes" :
"no")
353 <<
" tile (-t <rows> <cols>): ( " 354 << std::fixed << std::setw(w) << params.tile_y <<
", " 355 << std::fixed << std::setw(w) << params.tile_x <<
" )" 357 <<
" blocked display (-b): " 358 << (params.blocked_display ?
"yes" :
"no")
366 template<
typename PatternType>
368 std::string pattern_to_string(
369 const PatternType & pattern)
371 typedef typename PatternType::index_type index_t;
375 std::string storage_order = pattern.memory_order() == ROW_MAJOR
379 std::array<index_t, 2> blocksize;
380 blocksize[0] = pattern.blocksize(0);
381 blocksize[1] = pattern.blocksize(1);
383 std::ostringstream ss;
385 << PatternType::PatternName
388 << storage_order <<
"," 389 <<
typeid(index_t).name()
391 <<
" SizeSpec: " << pattern.sizespec().extents() <<
"," << endl
392 <<
" TeamSpec: " << pattern.teamspec().extents() <<
"," << endl
393 <<
" BlockSpec: " << pattern.blockspec().extents() <<
"," << endl
394 <<
" BlockSize: " << blocksize <<
" )";
402 template<
typename PatternType>
404 std::string pattern_to_filename(
405 const PatternType & pattern)
407 typedef typename PatternType::index_type index_t;
411 std::string storage_order = pattern.memory_order() == ROW_MAJOR
415 auto sspc = pattern.sizespec();
416 auto tspc = pattern.teamspec();
417 auto bspc = pattern.blockspec();
419 std::ostringstream ss;
420 ss << PatternType::PatternName
423 << storage_order <<
"-" 424 <<
typeid(index_t).name()
426 <<
"size-" << sspc.extent(0) <<
"x" << sspc.extent(1) <<
"--" 427 <<
"team-" << tspc.extent(0) <<
"x" << tspc.extent(1) <<
"--" 428 <<
"blocks-" << bspc.extent(0) <<
"x" << bspc.extent(1)
434 template<
typename PatternT>
436 void print_pattern_metrics(
const PatternT & pattern)
440 size_t block_kbytes = pattern.blocksize(0) * pattern.blocksize(1) *
444 cerr <<
"Pattern Metrics:" 448 <<
" block size: " << block_kbytes <<
" KB" 450 <<
" number of blocks: " << pm.num_blocks()
452 <<
" Mapping imbalance:" 460 <<
" imbalance factor: " << std::setprecision(4)
470 template<
typename PatternT>
472 void log_pattern_mapping(
const PatternT & pattern)
474 typedef PatternT pattern_t;
476 dash::internal::print_pattern_mapping(
477 "pattern.unit_at", pattern, 3,
478 [](
const pattern_t & _pattern,
int _x,
int _y) ->
dart_unit_t {
479 return _pattern.unit_at(std::array<index_t, 2> {{_x, _y}});
481 dash::internal::print_pattern_mapping(
482 "pattern.global_at", pattern, 3,
483 [](
const pattern_t & _pattern,
int _x,
int _y) -> index_t {
484 return _pattern.global_at(std::array<index_t, 2> {{_x, _y}});
486 dash::internal::print_pattern_mapping(
487 "pattern.local", pattern, 10,
488 [](
const pattern_t & _pattern,
int _x,
int _y) -> std::string {
489 auto lpos = _pattern.local(std::array<index_t, 2> {{_x, _y}});
490 std::ostringstream ss;
491 ss << lpos.unit <<
":" << lpos.coords;
494 dash::internal::print_pattern_mapping(
495 "pattern.at", pattern, 3,
496 [](
const pattern_t & _pattern,
int _x,
int _y) -> index_t {
497 return _pattern.at(std::array<index_t, 2> {{_x, _y}});
499 dash::internal::print_pattern_mapping(
500 "pattern.block_at", pattern, 3,
501 [](
const pattern_t & _pattern,
int _x,
int _y) -> index_t {
502 return _pattern.block_at(std::array<index_t, 2> {{_x, _y}});
504 dash::internal::print_pattern_mapping(
505 "pattern.block.offset", pattern, 5,
506 [](
const pattern_t & _pattern,
int _x,
int _y) -> std::string {
507 auto block_idx = _pattern.block_at(std::array<index_t, 2> {{_x, _y}});
508 auto block_vs = _pattern.block(block_idx);
509 std::ostringstream ss;
510 ss << block_vs.offset(0) <<
"," << block_vs.offset(1);
513 dash::internal::print_pattern_mapping(
514 "pattern.local_index", pattern, 3,
515 [](
const pattern_t & _pattern,
int _x,
int _y) -> index_t {
516 return _pattern.local_index(std::array<index_t, 2> {{_x, _y}}).
index;
internal::default_unsigned_index default_extent_t
Unsigned integer type used as default for extent values.
global_unit_t myid()
Shortcut to query the global unit ID of the calling unit.
constexpr std::enable_if< std::is_integral< IndexType >::value, IndexType >::type index(IndexType idx)
Defines how a list of global indices is mapped to single units within a Team.
This class is a simple memory pool which holds allocates elements of size ValueType.
Specifies cartesian extents in a specific number of dimensions.
dash::pattern_partitioning_properties< dash::pattern_partitioning_tag::rectangular, dash::pattern_partitioning_tag::balanced, dash::pattern_partitioning_tag::ndimensional > summa_pattern_partitioning_constraints
Constraints on pattern partitioning properties of matrix operands passed to dash::summa.
int32_t dart_unit_t
Data type for storing a unit ID.
int dim_t
Scalar type for a dimension value, with 0 indicating the first dimension.
constexpr double imbalance_factor() const noexcept
Relation of (max.
void balance_extents()
Tries to equally distribute the units across the dimensions.
void finalize()
Finalize the DASH library and the underlying runtime system.
std::enable_if< !MappingTags::diagonal &&PartitioningTags::rectangular &&PartitioningTags::balanced &&!PartitioningTags::unbalanced &&LayoutTags::blocked, TilePattern< SizeSpecType::ndim::value, dash::ROW_MAJOR, typename SizeSpecType::index_type >>::type make_pattern(const SizeSpecType &sizespec, const TeamSpecType &teamspec)
Generic Abstract Factory for models of the Pattern concept.
Defines how a list of global indices is mapped to single units within a Team.
internal::default_signed_index default_index_t
Signed integer type used as default for index values.
void draw_pattern(std::ostream &os, bool blocked_display=false, std::array< index_t, PatternT::ndim()> coords={}, int dimx=1, int dimy=0)
Outputs the pattern as a svg over the given output stream.
SizeType extent(dim_t dim) const
The extent of the cartesian space in the given dimension.
Defines how a list of global indices is mapped to single units within a Team.
Take a generic pattern instance and visualize it as an SVG image.
Defines how a list of global indices is mapped to single units within a Team.
constexpr dim_t ndim(const DimensionalType &d)
Specifies the arrangement of team units in a specified number of dimensions.
dash::pattern_mapping_properties< dash::pattern_mapping_tag::multiple, dash::pattern_mapping_tag::unbalanced > summa_pattern_mapping_constraints
Constraints on pattern mapping properties of matrix operands passed to dash::summa.
void set_title(const std::string &str)
Sets the title displayed above the pattern.
constexpr int num_imbalanced_units() const noexcept
Number of units mapped to maximum number of blocks per unit.
constexpr int max_blocks_per_unit() const noexcept
Maximum number of blocks mapped to any unit.
constexpr int max_elements_per_unit() const noexcept
Maximum number of elements mapped to any unit.
SizeType extent(dim_t dim) const
The extent of the cartesian space in the given dimension.
constexpr int min_elements_per_unit() const noexcept
Minimum number of elements mapped to any unit.
constexpr int num_balanced_units() const noexcept
Number of units mapped to minimum number of blocks per unit.
constexpr int min_blocks_per_unit() const noexcept
Minimum number of blocks mapped to any unit.
void init(int *argc, char ***argv)
Initialize the DASH library and the underlying runtime system.
DistributionSpec describes distribution patterns of all dimensions,.