1 #ifndef DASH__BLOCK_PATTERN_H_ 2 #define DASH__BLOCK_PATTERN_H_ 4 #include <dash/Types.h> 5 #include <dash/Distribution.h> 6 #include <dash/Exception.h> 7 #include <dash/Dimensional.h> 8 #include <dash/Cartesian.h> 11 #include <dash/pattern/PatternProperties.h> 12 #include <dash/pattern/internal/PatternArguments.h> 14 #include <dash/internal/Math.h> 15 #include <dash/internal/Logging.h> 19 #include <type_traits> 39 MemArrange Arrangement = ROW_MAJOR,
45 static constexpr
const char * PatternName =
"BlockPattern";
73 typedef typename std::make_unsigned<IndexType>::type
94 typedef internal::PatternArguments<NumDimensions, IndexType>
98 typedef IndexType index_type;
99 typedef SizeType size_type;
107 std::array<index_type, NumDimensions>
coords;
114 DistributionSpec_t _distspec;
118 TeamSpec_t _teamspec;
120 SizeType _nunits = 0;
123 MemoryLayout_t _memory_layout;
125 BlockSizeSpec_t _blocksize_spec;
127 BlockSpec_t _blockspec;
131 LocalMemoryLayout_t _local_memory_layout;
133 BlockSpec_t _local_blockspec;
135 SizeType _local_capacity;
179 template<
typename ... Args>
191 DASH_LOG_TRACE(
"BlockPattern()",
"Constructor with argument list");
192 initialize_local_range();
193 DASH_LOG_TRACE(
"BlockPattern()",
"BlockPattern initialized");
229 DistributionSpec_t dist,
234 : _distspec(
std::move(dist))
236 , _teamspec(teamspec, _distspec, *_team)
237 , _nunits(_teamspec.
size())
238 , _memory_layout(sizespec.
extents())
240 initialize_blocksizespec(sizespec, _distspec, _teamspec))
241 , _blockspec(initialize_blockspec(sizespec, _distspec, _blocksize_spec))
242 , _local_memory_layout(initialize_local_extents(_team->
myid()))
244 initialize_local_blockspec(_blocksize_spec, _local_memory_layout))
245 , _local_capacity(initialize_local_capacity())
247 DASH_LOG_TRACE(
"BlockPattern()",
"(sizespec, dist, teamspec, team)");
248 initialize_local_range();
249 DASH_LOG_TRACE(
"BlockPattern()",
"BlockPattern initialized");
288 const SizeSpec_t &sizespec,
292 DistributionSpec_t dist = DistributionSpec_t(),
295 : _distspec(
std::move(dist))
297 , _teamspec(_distspec, *_team)
298 , _nunits(_teamspec.
size())
299 , _memory_layout(sizespec.
extents())
301 initialize_blocksizespec(sizespec, _distspec, _teamspec))
302 , _blockspec(initialize_blockspec(sizespec, _distspec, _blocksize_spec))
303 , _local_memory_layout(initialize_local_extents(_team->
myid()))
305 initialize_local_blockspec(_blocksize_spec, _local_memory_layout))
306 , _local_capacity(initialize_local_capacity())
308 DASH_LOG_TRACE(
"BlockPattern()",
"(sizespec, dist, team)");
309 initialize_local_range();
310 DASH_LOG_TRACE(
"BlockPattern()",
"BlockPattern initialized");
317 : _distspec(other._distspec),
319 _teamspec(other._teamspec),
320 _nunits(other._nunits),
321 _memory_layout(other._memory_layout),
322 _blocksize_spec(other._blocksize_spec),
323 _blockspec(other._blockspec),
324 _local_memory_layout(other._local_memory_layout),
325 _local_blockspec(other._local_blockspec),
326 _local_capacity(other._local_capacity),
327 _lbegin(other._lbegin),
332 DASH_LOG_TRACE(
"BlockPattern(other)",
"BlockPattern copied");
350 const self_t & other)
const 352 if (
this == &other) {
358 _distspec == other._distspec &&
359 _teamspec == other._teamspec &&
360 _memory_layout == other._memory_layout &&
361 _blockspec == other._blockspec &&
362 _blocksize_spec == other._blocksize_spec &&
363 _nunits == other._nunits
372 const self_t & other)
const 374 return !(*
this == other);
382 DASH_LOG_TRACE(
"BlockPattern.=(other)");
383 if (
this != &other) {
384 _distspec = other._distspec;
386 _teamspec = other._teamspec;
387 _memory_layout = other._memory_layout;
388 _local_memory_layout = other._local_memory_layout;
389 _blocksize_spec = other._blocksize_spec;
390 _blockspec = other._blockspec;
391 _local_blockspec = other._local_blockspec;
392 _local_capacity = other._local_capacity;
393 _nunits = other._nunits;
394 _lbegin = other._lbegin;
396 DASH_LOG_TRACE(
"BlockPattern.=(other)",
"BlockPattern assigned");
432 const std::array<IndexType, NumDimensions> &
coords,
434 const ViewSpec_t & viewspec)
const 437 std::array<IndexType, NumDimensions> vs_coords;
438 for (
auto d = 0; d < NumDimensions; ++d) {
439 vs_coords[d] = coords[d] + viewspec.offset(0);
450 const std::array<IndexType, NumDimensions> &
coords)
const 452 std::array<IndexType, NumDimensions> unit_coords{};
454 for (
auto d = 0; d < NumDimensions; ++d) {
455 unit_coords[d] = (coords[d] / _blocksize_spec.
extent(d))
460 DASH_LOG_TRACE(
"BlockPattern.unit_at",
462 "> unit id", unit_id);
473 IndexType global_pos,
475 const ViewSpec_t & viewspec)
const 477 auto global_coords = _memory_layout.
coords(global_pos);
478 return unit_at(global_coords, viewspec);
492 IndexType global_pos)
const 494 auto global_coords = _memory_layout.
coords(global_pos);
513 if (dim >= NumDimensions || dim < 0) {
516 "Wrong dimension for Pattern::local_extent. " 517 <<
"Expected dimension between 0 and " << NumDimensions-1 <<
", " 520 return _memory_layout.
extent(dim);
536 if (dim >= NumDimensions || dim < 0) {
539 "Wrong dimension for Pattern::local_extent. " 540 <<
"Expected dimension between 0 and " << NumDimensions-1 <<
", " 543 return _local_memory_layout.
extent(dim);
557 constexpr std::array<SizeType, NumDimensions>
local_extents() const noexcept
559 return _local_memory_layout.
extents();
576 return ( unit == _team->myid()
577 ? _local_memory_layout.
extents()
578 : initialize_local_extents(unit)
594 const std::array<IndexType, NumDimensions> &
local_coords,
596 const ViewSpec_t & viewspec)
const 599 for (
auto d = 0; d < NumDimensions; ++d) {
600 coords[d] += viewspec.offset(d);
602 return _local_memory_layout.
at(
coords);
612 const std::array<IndexType, NumDimensions> &
local_coords)
const 614 return _local_memory_layout.
at(local_coords);
626 const std::array<IndexType, NumDimensions> & global_coords)
const 628 local_coords_t l_coords;
630 l_coords.unit =
unit_at(global_coords);
642 IndexType g_index)
const 644 DASH_LOG_TRACE_VAR(
"BlockPattern.local()", g_index);
647 auto l_coords =
coords(g_index);
658 const std::array<IndexType, NumDimensions> & global_coords)
const 661 for (
auto d = 0; d < NumDimensions; ++d) {
662 auto block_size_d = _blocksize_spec.
extent(d);
663 auto b_offset_d = global_coords[d] % block_size_d;
664 auto g_block_offset_d = global_coords[d] / block_size_d;
665 auto l_block_offset_d = g_block_offset_d / _teamspec.
extent(d);
667 (l_block_offset_d * block_size_d);
678 const std::array<IndexType, NumDimensions> & global_coords)
const 680 DASH_LOG_TRACE_VAR(
"BlockPattern.local_index()", global_coords);
681 auto unit =
unit_at(global_coords);
682 DASH_LOG_TRACE_VAR(
"BlockPattern.local_index", unit);
684 std::array<IndexType, NumDimensions> l_coords =
686 DASH_LOG_TRACE_VAR(
"BlockPattern.local_index", l_coords);
687 if (unit == _team->myid()) {
690 return local_index_t { unit, _local_memory_layout.
at(l_coords) };
696 LocalMemoryLayout_t(initialize_local_extents(unit));
697 return local_index_t { unit, l_mem_layout.at(l_coords) };
710 std::array<IndexType, NumDimensions>
global(
712 const std::array<IndexType, NumDimensions> &
local_coords)
const 714 DASH_LOG_DEBUG_VAR(
"BlockPattern.global()", local_coords);
715 if (_teamspec.
size() < 2) {
719 std::array<IndexType, NumDimensions> unit_ts_coord =
722 std::array<IndexType, NumDimensions> glob_index{};
723 for (
auto d = 0; d < NumDimensions; ++d) {
725 auto num_units_d = _teamspec.
extent(d);
726 auto blocksize_d = _blocksize_spec.
extent(d);
727 auto local_index_d = local_coords[d];
729 auto elem_block_offset_d = local_index_d % blocksize_d;
736 glob_index[d] = (block_index_d * blocksize_d) + elem_block_offset_d;
738 DASH_LOG_DEBUG_VAR(
"BlockPattern.global >", glob_index);
747 std::array<IndexType, NumDimensions>
global(
748 const std::array<IndexType, NumDimensions> &
local_coords)
const 765 _local_memory_layout.
coords(local_index);
766 DASH_LOG_TRACE_VAR(
"BlockPattern.local_to_global_idx()", local_coords);
767 std::array<IndexType, NumDimensions> global_coords =
769 DASH_LOG_TRACE_VAR(
"BlockPattern.local_to_global_idx >", global_coords);
770 return _memory_layout.
at(global_coords);
783 const std::array<IndexType, NumDimensions> &
local_coords)
const 785 std::array<IndexType, NumDimensions> global_coords =
786 global(unit, local_coords);
787 DASH_LOG_TRACE_VAR(
"BlockPattern.local_to_global_idx", global_coords);
788 return _memory_layout.
at(global_coords);
801 const std::array<IndexType, NumDimensions> & view_coords,
802 const ViewSpec_t & viewspec)
const 804 DASH_LOG_TRACE(
"BlockPattern.global_at()",
805 "view coords:",view_coords,
808 std::array<IndexType, NumDimensions> global_coords{};
809 for (
auto d = 0; d < NumDimensions; ++d) {
810 global_coords[d] = view_coords[d] + viewspec.offset(d);
812 DASH_LOG_TRACE(
"BlockPattern.global_at",
813 "global coords:", global_coords);
815 auto offset = _memory_layout.
at(global_coords);
816 DASH_LOG_TRACE_VAR(
"BlockPattern.global_at >", offset);
833 const std::array<IndexType, NumDimensions> & global_coords)
const 835 DASH_LOG_TRACE(
"BlockPattern.global_at()",
836 "gcoords:", global_coords);
838 auto offset = _memory_layout.
at(global_coords);
839 DASH_LOG_TRACE_VAR(
"BlockPattern.global_at >", offset);
856 const std::array<IndexType, NumDimensions> & global_coords)
const 858 auto unit =
unit_at(global_coords);
860 std::array<IndexType, NumDimensions> l_coords =
862 DASH_LOG_TRACE_VAR(
"BlockPattern.at", l_coords);
863 if (unit == _team->myid()) {
866 return _local_memory_layout.
at(l_coords);
872 LocalMemoryLayout_t(initialize_local_extents(unit));
873 return l_mem_layout.at(l_coords);
885 const std::array<IndexType, NumDimensions> & global_coords,
886 const ViewSpec_t & viewspec)
const 888 auto coords = global_coords;
889 for (
auto d = 0; d < NumDimensions; ++d) {
890 coords[d] += viewspec.offset(d);
892 DASH_LOG_TRACE_VAR(
"BlockPattern.at()",
coords);
893 DASH_LOG_TRACE_VAR(
"BlockPattern.at()", viewspec);
904 template<
typename ... Values>
905 IndexType
at(IndexType value, Values ... values)
const 908 sizeof...(values) == NumDimensions-1,
909 "Wrong parameter number");
910 std::array<IndexType, NumDimensions> inputindex = {
911 value, (IndexType)values...
913 return at(inputindex);
930 IndexType dim_offset,
934 const ViewSpec_t & viewspec)
const 936 DASH_LOG_TRACE_VAR(
"BlockPattern.has_local_elements()", dim);
937 DASH_LOG_TRACE_VAR(
"BlockPattern.has_local_elements()", dim_offset);
938 DASH_LOG_TRACE_VAR(
"BlockPattern.has_local_elements()", unit);
940 dim_offset += viewspec.offset(dim);
942 IndexType block_coord_d = dim_offset / _blocksize_spec.
extent(dim);
943 DASH_LOG_TRACE_VAR(
"BlockPattern.has_local_elements", block_coord_d);
945 IndexType teamspec_coord_d = block_coord_d % _teamspec.
extent(dim);
946 DASH_LOG_TRACE_VAR(
"BlockPattern.has_local_elements()",
964 auto glob_coords =
coords(index);
965 auto coords_unit =
unit_at(glob_coords);
966 DASH_LOG_TRACE_VAR(
"BlockPattern.is_local >", (coords_unit == unit));
967 return coords_unit == unit;
977 IndexType
index)
const noexcept
989 constexpr
const BlockSpec_t &
blockspec() const noexcept
999 return _local_blockspec;
1009 const std::array<index_type, NumDimensions> & g_coords)
const 1011 std::array<index_type, NumDimensions> block_coords{};
1013 for (
auto d = 0; d < NumDimensions; ++d) {
1014 block_coords[d] = g_coords[d] / _blocksize_spec.
extent(d);
1017 auto block_idx = _blockspec.
at(block_coords);
1018 DASH_LOG_TRACE(
"BlockPattern.block_at",
1020 "> block index", block_idx);
1031 const std::array<index_type, NumDimensions> & g_coords)
const 1033 local_index_t l_pos;
1035 std::array<IndexType, NumDimensions> l_block_coords{};
1036 std::array<IndexType, NumDimensions> unit_ts_coords{};
1037 for (
dim_t d = 0; d < NumDimensions; ++d) {
1038 auto nunits_d = _teamspec.
extent(d);
1039 auto blocksize_d = _blocksize_spec.
extent(d);
1040 auto block_coord_d = g_coords[d] / blocksize_d;
1041 l_block_coords[d] = block_coord_d / nunits_d;
1042 unit_ts_coords[d] = block_coord_d % nunits_d;
1044 l_pos.unit = _teamspec.
at(unit_ts_coords);
1045 l_pos.index = _local_blockspec.
at(l_block_coords);
1047 DASH_LOG_TRACE(
"BlockPattern.local_block_at >",
1049 "unit:", l_pos.unit,
1050 "local block index:", l_pos.index);
1059 index_type global_block_index)
const 1062 auto block_coords = _blockspec.
coords(global_block_index);
1063 std::array<index_type, NumDimensions> offsets{};
1064 std::array<size_type, NumDimensions>
extents{};
1066 for (
auto d = 0; d < NumDimensions; ++d) {
1067 auto num_blocks_d = _blockspec.
extent(d);
1069 if(block_coords[d] == (num_blocks_d - 1)){
1072 offsets[d] = block_coords[d] * _blocksize_spec.
extent(d);
1074 return ViewSpec_t(offsets,
extents);
1082 index_type local_block_index)
const 1085 std::array<SizeType, NumDimensions> block_vs_extents =
1087 std::array<IndexType, NumDimensions> block_vs_offsets {{ }};
1089 auto l_block_coords = _local_blockspec.
coords(local_block_index);
1090 auto l_elem_coords = l_block_coords;
1094 for (
auto d = 0; d < NumDimensions; ++d) {
1095 auto num_blocks_d =_local_blockspec.
extent(d);
1096 if(l_block_coords[d] == (num_blocks_d - 1)){
1097 size_type remaining =
local_extent(d) % block_vs_extents[d];
1098 block_vs_extents[d] = (remaining == 0)
1099 ? block_vs_extents[d]
1102 l_elem_coords[d] *= _blocksize_spec.
extent(d);
1104 l_elem_coords[d] *= block_vs_extents[d];
1108 auto g_elem_coords =
global(l_elem_coords);
1109 for (
auto d = 0; d < NumDimensions; ++d) {
1110 block_vs_offsets[d] = g_elem_coords[d];
1114 std::array<IndexType, NumDimensions> unit_ts_coord =
1116 for (
auto d = 0; d < NumDimensions; ++d) {
1118 auto blocksize_d = block_vs_extents[d];
1119 auto num_units_d = _teamspec.
extent(d);
1120 auto num_blocks_d = _blockspec.
extent(d);
1122 auto g_block_coord_d = (l_block_coords[d] + _myid) *
1124 block_vs_offsets[d] = g_block_coord_d * blocksize_d;
1127 ViewSpec_t block_vs(block_vs_offsets, block_vs_extents);
1136 index_type local_block_index)
const 1139 auto l_block_coords = _local_blockspec.
coords(local_block_index);
1140 std::array<index_type, NumDimensions> offsets;
1141 std::array<size_type, NumDimensions>
extents = _blocksize_spec.
extents();
1143 for(
dim_t d=0; d<NumDimensions; ++d){
1144 if(l_block_coords[d] == (_local_blockspec.
extent(d)-1)){
1146 extents[d] = (remaining == 0) ? extents[d] : remaining;
1148 offsets[d] = l_block_coords[d] * _blocksize_spec.
extent(d);
1150 offsets[d] = l_block_coords[d] * extents[d];
1153 return ViewSpec_t(offsets, extents);
1165 dim_t dimension)
const noexcept
1167 return _blocksize_spec.
extent(dimension);
1180 return _blocksize_spec.
size();
1191 return _local_capacity;
1208 ? _local_memory_layout.
size()
1209 : initialize_local_extents(unit).size();
1229 return _memory_layout.
size();
1237 constexpr IndexType
size() const noexcept
1239 return _memory_layout.
size();
1254 constexpr
const DistributionSpec_t &
distspec() const noexcept
1266 return SizeSpec_t(_memory_layout.
extents());
1274 constexpr
const std::array<SizeType, NumDimensions> &
1277 return _memory_layout.
extents();
1297 constexpr std::array<IndexType, NumDimensions>
coords(
1298 IndexType
index)
const noexcept
1309 constexpr std::array<IndexType, NumDimensions>
coords(
1313 const ViewSpec_t & viewspec)
const noexcept
1331 return NumDimensions;
1340 dim_t dimension)
const 1343 auto ovf_blocksize = _memory_layout.
extent(dimension) %
1345 if (ovf_blocksize == 0) {
1348 auto reg_blocksize =
blocksize(dimension);
1349 return reg_blocksize - ovf_blocksize;
1356 : _distspec(arguments.distspec()),
1357 _team(&arguments.team()),
1358 _teamspec(arguments.teamspec()),
1359 _nunits(_teamspec.
size()),
1360 _memory_layout(arguments.sizespec().extents()),
1361 _blocksize_spec(initialize_blocksizespec(
1362 arguments.sizespec(),
1365 _blockspec(initialize_blockspec(
1366 arguments.sizespec(),
1369 _local_memory_layout(
1370 initialize_local_extents(_team->myid())),
1371 _local_blockspec(initialize_local_blockspec(
1373 _local_memory_layout)),
1374 _local_capacity(initialize_local_capacity())
1381 BlockSizeSpec_t initialize_blocksizespec(
1382 const SizeSpec_t & sizespec,
1383 const DistributionSpec_t &
distspec,
1384 const TeamSpec_t & teamspec)
const 1386 DASH_LOG_TRACE_VAR(
"BlockPattern.init_blocksizespec", teamspec.
size());
1387 if (teamspec.
size() == 0) {
1388 return BlockSizeSpec_t();
1391 std::array<SizeType, NumDimensions> s_blocks{};
1392 for (
auto d = 0; d < NumDimensions; ++d) {
1397 s_blocks[d] = max_blocksize_d;
1399 return BlockSizeSpec_t(s_blocks);
1406 BlockSpec_t initialize_blockspec(
1407 const SizeSpec_t & sizespec,
1408 const DistributionSpec_t & distspec,
1409 const BlockSizeSpec_t & blocksizespec)
const 1411 if (blocksizespec.
size() == 0) {
1412 return BlockSpec_t();
1415 std::array<SizeType, NumDimensions> n_blocks{};
1416 for (
auto d = 0; d < NumDimensions; ++d) {
1417 DASH_LOG_TRACE_VAR(
"BlockPattern.init_blockspec", distspec[d].type);
1418 SizeType max_blocksize_d = blocksizespec.
extent(d);
1419 SizeType max_blocks_d = dash::math::div_ceil(
1422 n_blocks[d] = max_blocks_d;
1424 DASH_LOG_TRACE_VAR(
"BlockPattern.init_blockspec", n_blocks);
1425 return BlockSpec_t(n_blocks);
1431 BlockSpec_t initialize_local_blockspec(
1432 const BlockSizeSpec_t & blocksizespec,
1433 const LocalMemoryLayout_t & local_mem_layout)
const 1435 auto num_l_blocks = local_mem_layout.
extents();
1436 for (
auto d = 0; d < NumDimensions; ++d) {
1437 auto blocksize_d = blocksizespec.
extent(d);
1438 if (blocksize_d > 0) {
1439 num_l_blocks[d] = dash::math::div_ceil(
1441 blocksizespec.
extent(d));
1443 num_l_blocks[d] = 0;
1446 DASH_LOG_TRACE_VAR(
"BlockPattern.init_local_blockspec", num_l_blocks);
1447 return BlockSpec_t(num_l_blocks);
1457 SizeType initialize_local_capacity()
const 1459 SizeType l_capacity = 1;
1460 if (_teamspec.
size() == 0) {
1463 for (
auto d = 0; d < NumDimensions; ++d) {
1464 auto num_units_d = _teamspec.
extent(d);
1467 auto num_blocks_d = dash::math::div_ceil(
1468 _memory_layout.
extent(d),
1469 _blocksize_spec.
extent(d));
1470 auto max_l_blocks_d = dash::math::div_ceil(
1473 DASH_LOG_TRACE_VAR(
"BlockPattern.init_lcapacity.d", d);
1474 DASH_LOG_TRACE_VAR(
"BlockPattern.init_lcapacity.d", num_units_d);
1475 DASH_LOG_TRACE_VAR(
"BlockPattern.init_lcapacity.d", max_l_blocks_d);
1476 l_capacity *= max_l_blocks_d;
1478 l_capacity *= _blocksize_spec.
size();;
1479 DASH_LOG_DEBUG_VAR(
"BlockPattern.init_lcapacity >", l_capacity);
1487 void initialize_local_range()
1489 auto l_size = _local_memory_layout.
size();
1490 DASH_LOG_DEBUG_VAR(
"BlockPattern.init_local_range()", l_size);
1498 _lend =
global(l_size - 1) + 1;
1500 DASH_LOG_DEBUG_VAR(
"BlockPattern.init_local_range >", _lbegin);
1501 DASH_LOG_DEBUG_VAR(
"BlockPattern.init_local_range >", _lend);
1507 std::array<SizeType, NumDimensions> initialize_local_extents(
1510 DASH_LOG_DEBUG_VAR(
"BlockPattern.init_local_extents()", unit);
1511 DASH_LOG_DEBUG_VAR(
"BlockPattern.init_local_extents()", _nunits);
1513 return ::std::array<SizeType, NumDimensions> {{ }};
1516 auto unit_ts_coords = _teamspec.
coords(unit);
1517 DASH_LOG_TRACE_VAR(
"BlockPattern.init_local_extents", unit_ts_coords);
1518 ::std::array<SizeType, NumDimensions> l_extents{};
1519 for (
auto d = 0; d < NumDimensions; ++d) {
1520 auto num_elem_d = _memory_layout.
extent(d);
1522 auto num_units_d = _teamspec.
extent(d);
1524 auto num_blocks_d = _blockspec.
extent(d);
1526 auto blocksize_d = _blocksize_spec.
extent(d);
1528 auto min_local_blocks_d = num_blocks_d / num_units_d;
1530 auto unit_ts_coord = unit_ts_coords[d];
1531 DASH_LOG_TRACE_VAR(
"BlockPattern.init_local_extents.d", d);
1532 DASH_LOG_TRACE_VAR(
"BlockPattern.init_local_extents.d", unit_ts_coord);
1533 DASH_LOG_TRACE_VAR(
"BlockPattern.init_local_extents.d", num_elem_d);
1534 DASH_LOG_TRACE_VAR(
"BlockPattern.init_local_extents.d", num_units_d);
1535 DASH_LOG_TRACE_VAR(
"BlockPattern.init_local_extents.d", num_blocks_d);
1536 DASH_LOG_TRACE_VAR(
"BlockPattern.init_local_extents.d", blocksize_d);
1537 DASH_LOG_TRACE_VAR(
"BlockPattern.init_local_extents.d",
1538 min_local_blocks_d);
1541 l_extents[d] = min_local_blocks_d * blocksize_d;
1542 if (num_blocks_d == 1 && num_units_d == 1) {
1544 l_extents[d] = num_elem_d;
1547 auto num_add_blocks =
1548 static_cast<IndexType
>(num_blocks_d % num_units_d);
1550 team_unit_t last_block_unit_d((num_blocks_d % num_units_d == 0)
1552 : (num_blocks_d % num_units_d) - 1);
1553 DASH_LOG_TRACE_VAR(
"BlockPattern.init_local_extents.d",
1555 DASH_LOG_TRACE_VAR(
"BlockPattern.init_local_extents.d", num_add_blocks);
1556 if (unit_ts_coord < num_add_blocks) {
1558 l_extents[d] += blocksize_d;
1559 DASH_LOG_TRACE_VAR(
"BlockPattern.init_local_extents.d", l_extents[d]);
1561 if (unit_ts_coord == last_block_unit_d) {
1565 DASH_LOG_TRACE_VAR(
"BlockPattern.init_local_extents",
1566 undfill_blocksize_d);
1567 l_extents[d] -= undfill_blocksize_d;
1570 DASH_LOG_TRACE_VAR(
"BlockPattern.init_local_extents.d", l_extents[d]);
1572 DASH_LOG_DEBUG_VAR(
"BlockPattern.init_local_extents >", l_extents);
1579 #include <dash/pattern/BlockPattern1D.h> 1581 #endif // DASH__BLOCK_PATTERN_H_ bool operator==(const self_t &other) const
Equality comparison operator.
constexpr team_unit_t UNDEFINED_TEAM_UNIT_ID
Invalid local unit ID.
All blocks have identical size.
IndexType global(IndexType local_index) const
Resolve an element's linear global index from the calling unit's local index of that element...
bool includes_index(IndexType index, dim_t dimension, IndexType dim_offset) const
Whether the given index lies in the cartesian sub-space specified by a dimension and offset in the di...
constexpr std::array< SizeType, NumDimensions > local_extents() const noexcept
The actual number of elements in this pattern that are local to the active unit, by dimension...
global_unit_t myid()
Shortcut to query the global unit ID of the calling unit.
constexpr IndexType capacity() const noexcept
The maximum number of elements arranged in this pattern.
local_index_t local_block_at(const std::array< index_type, NumDimensions > &g_coords) const
Unit and local block index at given global coordinates.
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.
constexpr SizeType blocksize(dim_t dimension) const noexcept
Maximum number of elements in a single block in the given dimension.
constexpr const DistributionSpec_t & distspec() const noexcept
Distribution specification of this pattern.
This class is a simple memory pool which holds allocates elements of size ValueType.
Local element order corresponds to a logical linearization within single blocks (if blocked) or withi...
BlockPattern(SizeType arg, Args &&... args)
Constructor, initializes a pattern from an argument list consisting of the pattern size (extent...
Specifies cartesian extents in a specific number of dimensions.
IndexType at(IndexType value, Values ... values) const
Global coordinates to local index.
Specifies view parameters for implementing submat, rows and cols.
IndexType global_at(const std::array< IndexType, NumDimensions > &view_coords, const ViewSpec_t &viewspec) const
Global coordinates and viewspec to global position in the pattern's iteration order.
int dim_t
Scalar type for a dimension value, with 0 indicating the first dimension.
std::array< IndexType, NumDimensions > global(const std::array< IndexType, NumDimensions > &local_coords) const
Converts local coordinates of active unit to global coordinates.
constexpr SizeType max_blocksize() const noexcept
Maximum number of elements in a single block in all dimensions.
bool operator!=(const self_t &other) const
Inquality comparison operator.
constexpr const TeamSpec_t & teamspec() const noexcept
Cartesian arrangement of the Team containing the units to which this pattern's elements are mapped...
pattern_mapping_properties< pattern_mapping_tag::unbalanced > mapping_properties
Satisfiable properties in pattern property category Mapping:
All local indices are mapped to a single logical index domain and thus not indexed blockwise...
constexpr const BlockSpec_t & blockspec() const noexcept
block
std::array< IndexType, NumDimensions > local_coords(const std::array< IndexType, NumDimensions > &global_coords) const
Converts global coordinates to their associated unit's respective local coordinates.
constexpr SizeType local_capacity() const noexcept
Maximum number of elements assigned to a single unit in total, equivalent to the local capacity of ev...
constexpr IndexType local_at(const std::array< IndexType, NumDimensions > &local_coords) const
Convert given local coordinates to linear local offset (index).
pattern_partitioning_properties< pattern_partitioning_tag::rectangular, pattern_partitioning_tag::balanced, pattern_partitioning_tag::unbalanced > partitioning_properties
Satisfiable properties in pattern property category Partitioning:
local_index_t local_index(const std::array< IndexType, NumDimensions > &global_coords) const
Resolves the unit and the local index from global coordinates.
The number of blocks assigned to units may differ.
IndexType global_index(team_unit_t unit, const std::array< IndexType, NumDimensions > &local_coords) const
Resolve an element's linear global index from a given unit's local coordinates of that element...
pattern_layout_properties< pattern_layout_tag::canonical, pattern_layout_tag::linear > layout_properties
Satisfiable properties in pattern property category Layout:
Block extents are constant for every dimension.
SizeType underfilled_blocksize(dim_t dimension) const
Number of elements missing in the overflow block of given dimension compared to the regular blocksize...
std::array< IndexType, NumDimensions > global(team_unit_t unit, const std::array< IndexType, NumDimensions > &local_coords) const
global
local_coords_t local(const std::array< IndexType, NumDimensions > &global_coords) const
Converts global coordinates to their associated unit and its respective local coordinates.
team_unit_t unit_at(IndexType global_pos) const
Convert given global linear index to its assigned unit id.
constexpr SizeType local_size(team_unit_t unit=UNDEFINED_TEAM_UNIT_ID) const noexcept
The actual number of elements in this pattern that are local to the calling unit in total...
bool is_local(IndexType index, team_unit_t unit) const
Whether the given global index is local to the specified unit.
internal::default_signed_index default_index_t
Signed integer type used as default for index values.
A Team instance specifies a subset of all available units.
static constexpr dim_t ndim() noexcept
Number of dimensions of the cartesian space partitioned by the pattern.
ViewSpec_t local_block(index_type local_block_index) const
View spec (offset and extents) of block at local linear block index in global cartesian element space...
constexpr const extents_type & extents() const noexcept
Extents of the cartesian space, by dimension.
constexpr bool is_local(IndexType index) const noexcept
Whether the given global index is local to the unit that created this pattern instance.
team_unit_t unit_at(const std::array< IndexType, NumDimensions > &coords, const ViewSpec_t &viewspec) const
unit_at
constexpr SizeSpec_t sizespec() const noexcept
Size specification of the index space mapped by this pattern.
std::array< IndexType, NumDimensions > coords(IndexType index) const
Convert given linear offset (index) to cartesian coordinates.
SizeType extent(dim_t dim) const
The extent of the cartesian space in the given dimension.
IndexType local_index_to_block_coord(IndexType unit_teamspec_coord, IndexType local_index, SizeType num_units_in_dim) const
Resolve the block coordinate for a given local index in the distribution's dimension.
Defines a cartesian, totally-ordered index space by mapping linear indices to cartesian coordinates d...
constexpr std::array< IndexType, NumDimensions > coords(IndexType index, const ViewSpec_t &viewspec) const noexcept
Convert given global linear offset (index) and viewspec to global cartesian coordinates.
constexpr IndexType at(IndexType arg, Args... args) const
Convert the given coordinates to their respective linear index.
Specifies how a Pattern distributes elements to units in a specific dimension.
ViewSpec_t block(index_type global_block_index) const
View spec (offset and extents) of block at global linear block index in cartesian element space...
BlockPattern & operator=(const BlockPattern &other)
Assignment operator.
constexpr IndexType num_units() const noexcept
The number of units to which this pattern's elements are mapped.
BlockPattern(const SizeSpec_t &sizespec, DistributionSpec_t dist=DistributionSpec_t(), Team &team=dash::Team::All())
Constructor, initializes a pattern from explicit instances of SizeSpec, DistributionSpec and a Team...
bool has_local_elements(dim_t dim, IndexType dim_offset, team_unit_t unit, const ViewSpec_t &viewspec) const
is_local
BlockPattern(const SizeSpec_t &sizespec, DistributionSpec_t dist, const TeamSpec_t &teamspec, dash::Team &team=dash::Team::All())
Constructor, initializes a pattern from explicit instances of SizeSpec, DistributionSpec, TeamSpec and a Team.
constexpr const BlockSpec_t & local_blockspec() const noexcept
Cartesian arrangement of local pattern blocks.
Size of blocks may differ.
IndexType lbegin() const
Resolves the global index of the first local element in the pattern.
struct dash::unit_id< dash::local_unit, dart_team_unit_t > team_unit_t
Unit ID to use for team-local IDs.
constexpr std::array< SizeType, NumDimensions > local_extents(team_unit_t unit) const noexcept
The actual number of elements in this pattern that are local to the given unit, by dimension...
IndexType local_extent(dim_t dim) const
The actual number of elements in this pattern that are local to the calling unit in the given dimensi...
IndexType max_blocksize_in_range(IndexType range, SizeType num_units) const
The maximum size of a single block within an extent for a given total number of units.
SizeType extent(dim_t dim) const
The extent of the cartesian space in the given dimension.
IndexType global_at(const std::array< IndexType, NumDimensions > &global_coords) const
Global coordinates to global position in the pattern's iteration order.
IndexType local_at(const std::array< IndexType, NumDimensions > &local_coords, const ViewSpec_t &viewspec) const
local
local_index_t local(IndexType g_index) const
Converts global index to its associated unit and respective local index.
IndexType lend() const
Resolves the global index past the last local element in the pattern.
constexpr IndexType size() const noexcept
The number of elements arranged in this pattern.
constexpr SizeType size() const noexcept
The number of discrete elements within the space spanned by the coordinate.
static Team & All()
The invariant Team instance containing all available units.
see https://en.cppreference.com/w/cpp/feature_test for recommended feature tests
IndexType at(const std::array< IndexType, NumDimensions > &global_coords) const
at
team_unit_t unit_at(const std::array< IndexType, NumDimensions > &coords) const
Convert given coordinate in pattern to its assigned unit id.
IndexType at(const std::array< IndexType, NumDimensions > &global_coords, const ViewSpec_t &viewspec) const
Global coordinates and viewspec to local index.
index_type block_at(const std::array< index_type, NumDimensions > &g_coords) const
Index of block at given global coordinates.
constexpr const std::array< SizeType, NumDimensions > & extents() const noexcept
Size specification of the index space mapped by this pattern.
constexpr std::array< IndexType, NumDimensions > coords(IndexType index) const noexcept
Convert given global linear offset (index) to global cartesian coordinates.
IndexType extent(dim_t dim) const
extent
constexpr dash::Team & team() const noexcept
The Team containing the units to which this pattern's elements are mapped.
BlockPattern(const self_t &other)
Copy constructor.
BlockPattern(self_t &other)
Copy constructor using non-const lvalue reference parameter.
DistributionSpec describes distribution patterns of all dimensions,.
Generic type of mapping properties of a model satisfying the Pattern concept.
team_unit_t unit_at(IndexType global_pos, const ViewSpec_t &viewspec) const
Convert given global linear index to its assigned unit id.
ViewSpec_t local_block_local(index_type local_block_index) const
View spec (offset and extents) of block at local linear block index in local cartesian element space...
static constexpr MemArrange memory_order() noexcept
Memory order followed by the pattern.