1 #ifndef DASH__SHIFT_TILE_PATTERN_H_ 2 #define DASH__SHIFT_TILE_PATTERN_H_ 11 #include <dash/Types.h> 12 #include <dash/Distribution.h> 13 #include <dash/Exception.h> 14 #include <dash/Dimensional.h> 15 #include <dash/Cartesian.h> 16 #include <dash/Team.h> 18 #include <dash/pattern/PatternProperties.h> 19 #include <dash/pattern/internal/PatternArguments.h> 21 #include <dash/internal/Math.h> 22 #include <dash/internal/Logging.h> 44 MemArrange Arrangement = ROW_MAJOR,
49 static constexpr
char const * PatternName =
"ShiftTilePattern";
79 typedef typename std::make_unsigned<IndexType>::type
100 typedef internal::PatternArguments<NumDimensions, IndexType>
104 typedef IndexType index_type;
105 typedef SizeType size_type;
113 std::array<index_type, NumDimensions>
coords;
120 DistributionSpec_t _distspec;
124 TeamSpec_t _teamspec;
127 MemoryLayout_t _memory_layout;
132 dim_t _major_tiled_dim{};
135 dim_t _minor_tiled_dim{};
137 BlockSizeSpec_t _blocksize_spec;
139 BlockSpec_t _blockspec;
141 BlockSpec_t _local_blockspec;
145 LocalMemoryLayout_t _local_memory_layout;
147 SizeType _local_capacity;
188 template<
typename ... Args>
199 DASH_LOG_TRACE(
"ShiftTilePattern()",
"Constructor with Argument list");
200 initialize_local_range();
242 DistributionSpec_t dist,
247 : _distspec(
std::move(dist))
256 _teamspec(
std::move(teamspec))
257 , _memory_layout(sizespec.
extents())
258 , _nunits(_teamspec.
size())
259 , _major_tiled_dim(initialize_major_tiled_dim(_distspec))
260 , _minor_tiled_dim((_major_tiled_dim + 1) % NumDimensions)
262 initialize_blocksizespec(sizespec, _distspec, _teamspec))
263 , _blockspec(initialize_blockspec(sizespec, _blocksize_spec, _teamspec))
265 initialize_local_blockspec(_blockspec, _major_tiled_dim, _nunits))
266 , _local_memory_layout(initialize_local_extents(_team->
myid()))
267 , _local_capacity(initialize_local_capacity())
269 DASH_LOG_TRACE(
"ShiftTilePattern()",
"(sizespec, dist, teamspec, team)");
270 initialize_local_range();
309 const SizeSpec_t &sizespec,
313 DistributionSpec_t dist = DistributionSpec_t(),
316 : _distspec(
std::move(dist))
318 , _teamspec(_distspec, *_team)
319 , _memory_layout(sizespec.
extents())
320 , _nunits(_teamspec.
size())
321 , _major_tiled_dim(initialize_major_tiled_dim(_distspec))
322 , _minor_tiled_dim((_major_tiled_dim + 1) % NumDimensions)
324 initialize_blocksizespec(sizespec, _distspec, _teamspec))
325 , _blockspec(initialize_blockspec(sizespec, _blocksize_spec, _teamspec))
327 initialize_local_blockspec(_blockspec, _major_tiled_dim, _nunits))
328 , _local_memory_layout(initialize_local_extents(_team->
myid()))
329 , _local_capacity(initialize_local_capacity())
331 DASH_LOG_TRACE(
"ShiftTilePattern()",
"(sizespec, dist, team)");
332 initialize_local_range();
339 : _distspec(other._distspec),
341 _teamspec(other._teamspec),
342 _memory_layout(other._memory_layout),
343 _nunits(other._nunits),
344 _major_tiled_dim(other._major_tiled_dim),
345 _minor_tiled_dim(other._minor_tiled_dim),
346 _blocksize_spec(other._blocksize_spec),
347 _blockspec(other._blockspec),
348 _local_blockspec(other._local_blockspec),
349 _local_memory_layout(other._local_memory_layout),
350 _local_capacity(other._local_capacity),
351 _lbegin(other._lbegin),
372 if (
this == &other) {
378 _distspec == other._distspec &&
379 _teamspec == other._teamspec &&
380 _memory_layout == other._memory_layout &&
381 _blockspec == other._blockspec &&
382 _blocksize_spec == other._blocksize_spec &&
383 _nunits == other._nunits
394 return !(*
this == other);
401 if (
this != &other) {
402 _distspec = other._distspec;
404 _teamspec = other._teamspec;
405 _memory_layout = other._memory_layout;
406 _local_memory_layout = other._local_memory_layout;
407 _blocksize_spec = other._blocksize_spec;
408 _blockspec = other._blockspec;
409 _local_blockspec = other._local_blockspec;
410 _local_capacity = other._local_capacity;
411 _nunits = other._nunits;
412 _minor_tiled_dim = other._minor_tiled_dim;
413 _major_tiled_dim = other._major_tiled_dim;
414 _lbegin = other._lbegin;
449 const std::array<IndexType, NumDimensions> &
coords,
451 const ViewSpec_t & viewspec)
const 453 DASH_LOG_TRACE(
"ShiftTilePattern.unit_at()",
455 "viewspec:", viewspec);
459 for (
auto d = 0; d < NumDimensions; ++d) {
460 auto vs_coord = coords[d] + viewspec.offset(d);
462 auto block_coord = vs_coord / _blocksize_spec.
extent(d);
463 unit_id += block_coord;
466 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.unit_at >", unit_id);
476 const std::array<IndexType, NumDimensions> &
coords)
const 478 DASH_LOG_TRACE(
"ShiftTilePattern.unit_at()",
480 "blocksize:", _blocksize_spec.
extents());
484 for (
auto d = 0; d < NumDimensions; ++d) {
486 auto block_coord = coords[d] / _blocksize_spec.
extent(d);
487 unit_id += block_coord;
490 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.unit_at >", unit_id);
501 IndexType global_pos,
503 const ViewSpec_t & viewspec)
const 505 auto global_coords = _memory_layout.
coords(global_pos);
506 return unit_at(global_coords, viewspec);
516 IndexType global_pos)
const 518 auto global_coords = _memory_layout.
coords(global_pos);
536 if (dim >= NumDimensions || dim < 0) {
539 "Wrong dimension for ShiftTilePattern::local_extent. " 540 <<
"Expected dimension between 0 and " << NumDimensions-1 <<
", " 543 return _memory_layout.
extent(dim);
558 if (dim >= NumDimensions || dim < 0) {
561 "Wrong dimension for ShiftTilePattern::local_extent. " 562 <<
"Expected dimension between 0 and " << NumDimensions-1 <<
", " 565 return _local_memory_layout.
extent(dim);
581 return _local_memory_layout.
extents();
596 const std::array<IndexType, NumDimensions> &
local_coords,
598 const ViewSpec_t & viewspec)
const 600 DASH_LOG_TRACE(
"ShiftTilePattern.local_at()", local_coords,
602 "local blocks:", _local_blockspec.
extents());
604 std::array<IndexType, NumDimensions> phase_coords{};
606 std::array<IndexType, NumDimensions> block_coords_l{};
607 for (
auto d = 0; d < NumDimensions; ++d) {
608 auto vs_offset_d = viewspec.offset(d);
609 auto vs_coord_d = local_coords[d] + vs_offset_d;
610 auto block_size_d = _blocksize_spec.
extent(d);
611 phase_coords[d] = vs_coord_d % block_size_d;
612 block_coords_l[d] = vs_coord_d / block_size_d;
614 DASH_LOG_TRACE(
"ShiftTilePattern.local_at",
615 "local block coords:", block_coords_l,
616 "phase coords:", phase_coords);
618 auto block_offset_l = _local_blockspec.
at(block_coords_l);
620 block_offset_l * _blocksize_spec.
size() +
621 _blocksize_spec.
at(phase_coords);
622 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.local_at >",
local_index);
633 const std::array<IndexType, NumDimensions> &
local_coords)
const 635 DASH_LOG_TRACE(
"ShiftTilePattern.local_at()", local_coords,
636 "local blocks:", _local_blockspec.
extents());
638 std::array<IndexType, NumDimensions> phase_coords{};
640 std::array<IndexType, NumDimensions> block_coords_l{};
641 for (
auto d = 0; d < NumDimensions; ++d) {
642 auto vs_coord_d = local_coords[d];
643 auto block_size_d = _blocksize_spec.
extent(d);
644 phase_coords[d] = vs_coord_d % block_size_d;
645 block_coords_l[d] = vs_coord_d / block_size_d;
647 DASH_LOG_TRACE(
"ShiftTilePattern.local_at",
648 "local block coords:", block_coords_l,
649 "phase coords:", phase_coords);
651 auto block_offset_l = _local_blockspec.
at(block_coords_l);
653 block_offset_l * _blocksize_spec.
size() +
654 _blocksize_spec.
at(phase_coords);
655 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.local_at >",
local_index);
668 const std::array<IndexType, NumDimensions> & global_coords)
const 672 l_coords.unit =
unit_at(global_coords);
684 IndexType g_index)
const 686 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.local()", g_index);
689 auto g_coords =
coords(g_index);
700 const std::array<IndexType, NumDimensions> & global_coords)
const 702 std::array<IndexType, NumDimensions>
local_coords = global_coords;
703 auto blocksize_d = _blocksize_spec.
extent(_major_tiled_dim);
704 auto coord_d = global_coords[_major_tiled_dim];
705 local_coords[_major_tiled_dim] =
707 (coord_d / (blocksize_d * _nunits)) * blocksize_d +
709 (coord_d % blocksize_d);
719 const std::array<IndexType, NumDimensions> & global_coords)
const 721 DASH_LOG_TRACE_VAR(
"Pattern.local_index()", global_coords);
724 auto unit =
unit_at(global_coords);
727 std::array<IndexType, NumDimensions> l_coords =
732 auto l_index =
at(global_coords);
733 DASH_LOG_TRACE_VAR(
"Pattern.local_index >", l_index);
747 std::array<IndexType, NumDimensions>
global(
749 const std::array<IndexType, NumDimensions> &
local_coords)
const {
750 DASH_LOG_DEBUG(
"ShiftTilePattern.global()",
752 "lcoords:", local_coords);
754 std::array<IndexType, NumDimensions> global_coords =
local_coords;
756 auto blocksize_maj = _blocksize_spec.
extent(_major_tiled_dim);
757 auto blocksize_min = _blocksize_spec.
extent(_minor_tiled_dim);
758 auto l_block_coord_maj = local_coords[_major_tiled_dim] /
760 auto l_block_coord_min = (NumDimensions > 1)
761 ? local_coords[_minor_tiled_dim] /
764 DASH_LOG_TRACE(
"ShiftTilePattern.global",
765 "minor tiled dim:", _minor_tiled_dim,
766 "major tiled dim:", _major_tiled_dim,
767 "l_block_coord_min:", l_block_coord_min,
768 "l_block_coord_maj:", l_block_coord_maj);
770 auto num_shift_blocks = (_nunits + unit -
771 (l_block_coord_min % _nunits))
773 num_shift_blocks += _nunits * l_block_coord_maj;
774 DASH_LOG_TRACE(
"ShiftTilePattern.global",
775 "num_shift_blocks:", num_shift_blocks,
776 "blocksize_maj:", blocksize_maj);
777 global_coords[_major_tiled_dim] =
778 (num_shift_blocks * blocksize_maj) +
779 local_coords[_major_tiled_dim] % blocksize_maj;
780 DASH_LOG_DEBUG_VAR(
"ShiftTilePattern.global >", global_coords);
781 return global_coords;
789 std::array<IndexType, NumDimensions>
global(
790 const std::array<IndexType, NumDimensions> &
local_coords)
const 806 DASH_LOG_TRACE(
"ShiftTilePattern.global()",
807 "local_index:", local_index,
809 auto block_size = _blocksize_spec.
size();
810 auto phase = local_index % block_size;
811 auto l_block_index = local_index / block_size;
813 auto l_block_coord = _local_blockspec.
coords(l_block_index);
815 auto phase_coord = _blocksize_spec.
coords(phase);
816 DASH_LOG_TRACE(
"ShiftTilePattern.global",
817 "local block index:", l_block_index,
818 "local block coords:", l_block_coord,
819 "phase coords:", phase_coord);
821 std::array<IndexType, NumDimensions> l_coords{};
822 for (
auto d = 0; d < NumDimensions; ++d) {
823 l_coords[d] = l_block_coord[d] * _blocksize_spec.
extent(d) +
826 std::array<IndexType, NumDimensions> g_coords =
829 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.global >", offset);
844 const std::array<IndexType, NumDimensions> &
local_coords)
const 846 DASH_LOG_TRACE(
"ShiftTilePattern.global_index()",
848 "local_coords:", local_coords);
849 std::array<IndexType, NumDimensions> global_coords =
850 global(unit, local_coords);
852 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.global_index >", g_index);
870 const std::array<IndexType, NumDimensions> & global_coords,
871 const ViewSpec_t & viewspec)
const 873 DASH_LOG_TRACE(
"ShiftTilePattern.global_at()",
874 "gcoords:", global_coords,
875 "viewspec:", viewspec);
877 std::array<IndexType, NumDimensions> phase_coords{};
879 std::array<IndexType, NumDimensions> block_coords{};
880 for (
auto d = 0; d < NumDimensions; ++d) {
881 auto vs_coord = global_coords[d] + viewspec.offset(d);
882 phase_coords[d] = vs_coord % _blocksize_spec.
extent(d);
883 block_coords[d] = vs_coord / _blocksize_spec.
extent(d);
885 DASH_LOG_TRACE(
"ShiftTilePattern.global_at",
886 "block coords:", block_coords,
887 "phase coords:", phase_coords);
890 auto block_index = _blockspec.
at(block_coords);
891 DASH_LOG_TRACE(
"ShiftTilePattern.global_at",
892 "block index:", block_index);
893 auto offset = block_index * _blocksize_spec.
size() +
894 _blocksize_spec.
at(phase_coords);
895 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.global_at >", offset);
912 const std::array<IndexType, NumDimensions> & global_coords)
const 914 DASH_LOG_TRACE(
"ShiftTilePattern.global_at()",
915 "gcoords:", global_coords);
917 std::array<IndexType, NumDimensions> phase_coords;
919 std::array<IndexType, NumDimensions> block_coords;
920 for (
auto d = 0; d < NumDimensions; ++d) {
921 auto vs_coord = global_coords[d];
922 phase_coords[d] = vs_coord % _blocksize_spec.
extent(d);
923 block_coords[d] = vs_coord / _blocksize_spec.
extent(d);
925 DASH_LOG_TRACE(
"ShiftTilePattern.global_at",
926 "block coords:", block_coords,
927 "phase coords:", phase_coords);
930 auto block_index = _blockspec.
at(block_coords);
931 DASH_LOG_TRACE(
"ShiftTilePattern.global_at",
932 "block index:", block_index);
933 auto offset = block_index * _blocksize_spec.
size() +
934 _blocksize_spec.
at(phase_coords);
935 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.global_at >", offset);
955 const std::array<IndexType, NumDimensions> & global_coords,
956 const ViewSpec_t & viewspec)
const 958 DASH_LOG_TRACE(
"ShiftTilePattern.at()",
959 "gcoords:", global_coords,
960 "viewspec:", viewspec);
962 std::array<IndexType, NumDimensions> phase_coords;
964 std::array<IndexType, NumDimensions> block_coords;
965 for (
auto d = 0; d < NumDimensions; ++d) {
966 auto vs_coord = global_coords[d] + viewspec.offset(d);
967 phase_coords[d] = vs_coord % _blocksize_spec.
extent(d);
968 block_coords[d] = vs_coord / _blocksize_spec.
extent(d);
970 DASH_LOG_TRACE(
"ShiftTilePattern.at",
971 "block_coords:", block_coords,
972 "phase_coords:", phase_coords);
975 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.at", _blockspec.
extents());
976 auto block_index = _blockspec.
at(block_coords);
977 auto block_index_l = block_index / _nunits;
978 DASH_LOG_TRACE(
"ShiftTilePattern.at",
979 "global block index:",block_index,
981 "local block index:", block_index_l);
982 auto offset = block_index_l * _blocksize_spec.
size() +
983 _blocksize_spec.
at(phase_coords);
984 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.at >", offset);
997 std::array<IndexType, NumDimensions> global_coords)
const 1002 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.at()", global_coords);
1004 std::array<IndexType, NumDimensions> phase_coords{};
1006 std::array<IndexType, NumDimensions> block_coords{};
1007 for (
auto d = 0; d < NumDimensions; ++d) {
1008 auto coord = global_coords[d];
1009 phase_coords[d] = coord % _blocksize_spec.
extent(d);
1010 block_coords[d] = coord / _blocksize_spec.
extent(d);
1012 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.at", block_coords);
1013 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.at", phase_coords);
1016 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.at", _blockspec.
extents());
1017 auto block_offset = _blockspec.
at(block_coords);
1018 auto block_offset_l = block_offset / _nunits;
1019 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.at", block_offset);
1020 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.at", _nunits);
1021 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.at", block_offset_l);
1022 return block_offset_l * _blocksize_spec.
size() +
1023 _blocksize_spec.
at(phase_coords);
1033 template<
typename ... Values>
1034 IndexType
at(Values ... values)
const 1037 sizeof...(values) == NumDimensions,
1038 "Wrong parameter number");
1039 std::array<IndexType, NumDimensions> inputindex = {
1040 (IndexType)values...
1042 return at(inputindex);
1059 IndexType dim_offset,
1063 const ViewSpec_t & viewspec)
const 1065 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.has_local_elements()", dim);
1066 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.has_local_elements()", dim_offset);
1067 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.has_local_elements()", unit);
1068 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.has_local_elements()", viewspec);
1070 dim_offset += viewspec.offset(dim);
1072 IndexType block_coord_d = dim_offset / _blocksize_spec.
extent(dim);
1073 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.has_local_elements", block_coord_d);
1075 IndexType teamspec_coord_d = block_coord_d % _teamspec.
extent(dim);
1076 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.has_local_elements",
1094 auto glob_coords =
coords(index);
1095 auto coords_unit =
unit_at(glob_coords);
1096 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.is_local >", (coords_unit == unit));
1097 return coords_unit == unit;
1107 IndexType
index)
const 1123 const std::array<index_type, NumDimensions> & g_coords)
const 1125 std::array<index_type, NumDimensions> block_coords;
1127 for (
auto d = 0; d < NumDimensions; ++d) {
1128 block_coords[d] = g_coords[d] / _blocksize_spec.
extent(d);
1131 auto block_idx = _blockspec.
at(block_coords);
1132 DASH_LOG_TRACE(
"ShiftTilePattern.block_at",
1134 "> block index", block_idx);
1145 const std::array<index_type, NumDimensions> & g_coords)
const 1149 "ShiftTilePattern.local_block_at is not implemented");
1157 index_type global_block_index)
const 1159 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.block()", global_block_index);
1161 auto block_coords = _blockspec.
coords(global_block_index);
1162 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.block", block_coords);
1163 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.block", _blocksize_spec.
extents());
1164 std::array<index_type, NumDimensions> offsets{};
1165 std::array<size_type, NumDimensions>
extents{};
1166 for (
auto d = 0; d < NumDimensions; ++d) {
1168 offsets[d] = block_coords[d] *
extents[d];
1170 DASH_LOG_TRACE(
"ShiftTilePattern.block",
1171 "offsets:", offsets,
1173 auto block_vs = ViewSpec_t(offsets,
extents);
1174 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.block >", block_vs);
1183 index_type local_block_index)
const {
1184 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.local_block()", local_block_index);
1186 auto l_block_coords = _local_blockspec.
coords(local_block_index);
1187 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.local_block()", l_block_coords);
1188 std::array<index_type, NumDimensions> l_elem_coords{};
1192 for (
auto d = 0; d < NumDimensions; ++d) {
1193 auto blocksize_d = _blocksize_spec.
extent(d);
1194 l_elem_coords[d] =
static_cast<index_type
>(
1195 l_block_coords[d] * blocksize_d);
1198 auto g_elem_coords =
global(l_elem_coords);
1199 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.local_block()", g_elem_coords);
1200 std::array<index_type, NumDimensions> offsets{};
1201 std::array<size_type, NumDimensions>
extents{};
1202 for (
auto d = 0; d < NumDimensions; ++d) {
1203 offsets[d] = g_elem_coords[d];
1206 ViewSpec_t block_vs(offsets,
extents);
1207 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.local_block >", block_vs);
1210 std::array<IndexType, NumDimensions> unit_ts_coord =
1212 for (
auto d = 0; d < NumDimensions; ++d) {
1214 auto blocksize_d = block_vs[d].extent;
1215 auto num_units_d = _teamspec.
extent(d);
1216 auto num_blocks_d = _blockspec.
extent(d);
1218 auto g_block_coord_d = (l_block_coords[d] + _myid) *
1220 block_vs[d].offset = g_block_coord_d * blocksize_d;
1231 index_type local_block_index)
const {
1232 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.local_block_local()", local_block_index);
1234 std::array<index_type, NumDimensions> offsets{};
1235 std::array<size_type, NumDimensions>
extents =
1238 auto l_block_coords = _local_blockspec.
coords(local_block_index);
1240 for (
auto d = 0; d < NumDimensions; ++d) {
1241 auto blocksize_d = extents[d];
1242 offsets[d] = l_block_coords[d] * blocksize_d;
1244 ViewSpec_t block_vs(offsets, extents);
1245 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.local_block >", block_vs);
1262 return _local_blockspec;
1274 dim_t dimension)
const {
1275 return _blocksize_spec.
extent(dimension);
1287 return _blocksize_spec.
size();
1315 return _local_memory_layout.
size();
1324 return _teamspec.
size();
1333 return _memory_layout.
size();
1342 return _memory_layout.
size();
1366 return SizeSpec_t(_memory_layout.
extents());
1374 const std::array<SizeType, NumDimensions> &
extents()
const {
1375 return _memory_layout.
extents();
1396 IndexType
index)
const {
1398 ::std::array<IndexType, NumDimensions> pos{};
1399 auto block_coords = _blockspec.
coords(index / _blocksize_spec.
size());
1400 auto phase_coords = _blocksize_spec.
coords(index % _blocksize_spec.
size());
1401 for (
auto d = 0; d < NumDimensions; ++d) {
1402 pos[d] = block_coords[d]*_blocksize_spec.
extent(d) + phase_coords[d];
1417 const ViewSpec_t & viewspec)
const {
1419 ::std::array<IndexType, NumDimensions> pos;
1420 auto block_coords = _blockspec.
coords(index / _blocksize_spec.
size(),
1422 auto phase_coords = _blocksize_spec.
coords(index % _blocksize_spec.
size(),
1424 for (
auto d = 0; d < NumDimensions; ++d) {
1425 pos[d] = block_coords[d]*_blocksize_spec.
extent(d) + phase_coords[d];
1441 return NumDimensions;
1447 : _distspec(arguments.distspec()),
1448 _team(&arguments.team()),
1449 _teamspec(arguments.teamspec()),
1450 _memory_layout(arguments.sizespec().extents()),
1451 _nunits(_teamspec.
size()),
1452 _major_tiled_dim(initialize_major_tiled_dim(_distspec)),
1453 _minor_tiled_dim((_major_tiled_dim + 1) % NumDimensions),
1454 _blocksize_spec(initialize_blocksizespec(
1455 arguments.sizespec(),
1458 _blockspec(initialize_blockspec(
1459 arguments.sizespec(),
1462 _local_blockspec(initialize_local_blockspec(
1466 _local_memory_layout(
1467 initialize_local_extents(_team->myid())),
1468 _local_capacity(initialize_local_capacity())
1474 BlockSizeSpec_t initialize_blocksizespec(
1475 const SizeSpec_t & sizespec,
1476 const DistributionSpec_t &
distspec,
1477 const TeamSpec_t & teamspec)
const {
1478 DASH_LOG_TRACE(
"ShiftTilePattern.init_blocksizespec()");
1480 std::array<SizeType, NumDimensions> s_blocks{};
1481 for (
auto d = 0; d < NumDimensions; ++d) {
1483 DASH_LOG_TRACE(
"ShiftTilePattern.init_blocksizespec d",
1484 "sizespec extent[d]:", sizespec.
extent(d),
1485 "teamspec extent[d]:", teamspec.
extent(d));
1489 s_blocks[d] = max_blocksize_d;
1491 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.init_blocksizespec >", s_blocks);
1492 return BlockSizeSpec_t(s_blocks);
1499 BlockSpec_t initialize_blockspec(
1500 const SizeSpec_t & sizespec,
1501 const BlockSizeSpec_t & blocksizespec,
1502 const TeamSpec_t & teamspec)
const 1504 DASH_LOG_TRACE(
"ShiftTilePattern.init_blockspec()",
1505 "pattern size:", sizespec.
extents(),
1506 "block size:", blocksizespec.
extents(),
1507 "team size:", teamspec.
extents());
1509 std::array<SizeType, NumDimensions> n_blocks{};
1510 for (
auto d = 0; d < NumDimensions; ++d) {
1511 SizeType max_blocksize_d = blocksizespec.
extent(d);
1512 SizeType max_blocks_d = dash::math::div_ceil(
1515 n_blocks[d] = max_blocks_d;
1518 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.init_blockspec >", n_blocks);
1526 BlockSpec_t initialize_local_blockspec(
1528 dim_t major_tiled_dim,
1529 size_t nunits)
const 1531 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.init_local_blockspec()",
1533 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.init_local_blockspec()",
1536 auto l_blocks = blockspec.
extents();
1537 l_blocks[major_tiled_dim] /= nunits;
1538 DASH_ASSERT_GT(l_blocks[major_tiled_dim], 0,
1539 "ShiftTilePattern: Size must be divisible by team size");
1540 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.init_local_blockspec >", l_blocks);
1541 return BlockSpec_t(l_blocks);
1551 SizeType initialize_local_capacity()
const 1555 auto l_capacity =
size() / _nunits;
1556 DASH_LOG_TRACE_VAR(
"ShiftTilePattern.init_local_capacity >", l_capacity);
1564 void initialize_local_range() {
1566 DASH_LOG_DEBUG_VAR(
"ShiftTilePattern.init_local_range()",
local_size);
1576 DASH_LOG_DEBUG_VAR(
"ShiftTilePattern.init_local_range >",
1577 _local_memory_layout.
extents());
1578 DASH_LOG_DEBUG_VAR(
"ShiftTilePattern.init_local_range >", _lbegin);
1579 DASH_LOG_DEBUG_VAR(
"ShiftTilePattern.init_local_range >", _lend);
1586 dim_t initialize_major_tiled_dim(
const DistributionSpec_t & ds)
1588 DASH_LOG_TRACE(
"ShiftTilePattern.init_major_tiled_dim()");
1589 if (Arrangement == dash::COL_MAJOR) {
1590 DASH_LOG_TRACE(
"ShiftTilePattern.init_major_tiled_dim",
"column major");
1591 for (
auto d = 0; d < NumDimensions; ++d) {
1592 if (ds[d].type == dash::internal::DIST_TILE) {
1593 DASH_LOG_TRACE(
"ShiftTilePattern.init_major_tiled_dim >", d);
1598 DASH_LOG_TRACE(
"ShiftTilePattern.init_major_tiled_dim",
"row major");
1599 for (
auto d = NumDimensions-1; d >= 0; --d) {
1600 if (ds[d].type == dash::internal::DIST_TILE) {
1601 DASH_LOG_TRACE(
"ShiftTilePattern.init_major_tiled_dim >", d);
1607 "Distribution is not tiled in any dimension");
1613 std::array<SizeType, NumDimensions> initialize_local_extents(
1616 #ifdef DASH_ENABLE_LOGGING 1617 auto unit_ts_coords = _teamspec.
coords(unit);
1618 DASH_LOG_DEBUG_VAR(
"ShiftTilePattern._local_extents()", unit);
1619 DASH_LOG_TRACE_VAR(
"ShiftTilePattern._local_extents", unit_ts_coords);
1621 ::std::array<SizeType, NumDimensions> l_extents{};
1622 for (
auto d = 0; d < NumDimensions; ++d) {
1624 auto num_units_d = _teamspec.
extent(d);
1626 auto num_blocks_d = _blockspec.
extent(d);
1628 auto blocksize_d = _blocksize_spec.
extent(d);
1630 auto min_local_blocks_d = num_blocks_d / num_units_d;
1635 l_extents[d] = min_local_blocks_d * blocksize_d;
1637 DASH_LOG_DEBUG_VAR(
"ShiftTilePattern._local_extents >", l_extents);
1644 #include <dash/pattern/ShiftTilePattern1D.h> 1646 #endif // DASH__SHIFT_TILE_PATTERN_H_ std::array< IndexType, NumDimensions > coords(IndexType index, const ViewSpec_t &viewspec) const
Convert given global linear offset (index) to global cartesian coordinates using viewspec.
IndexType at(std::array< IndexType, NumDimensions > global_coords) const
Global coordinates to local index.
constexpr team_unit_t UNDEFINED_TEAM_UNIT_ID
Invalid local unit ID.
IndexType global_at(const std::array< IndexType, NumDimensions > &global_coords, const ViewSpec_t &viewspec) const
Global coordinates and viewspec to global position in the pattern's iteration order.
All blocks have identical size.
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...
global_unit_t myid()
Shortcut to query the global unit ID of the calling unit.
SizeType 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...
ShiftTilePattern(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...
const BlockSpec_t & blockspec() const
Cartesian arrangement of pattern blocks.
constexpr std::enable_if< std::is_integral< IndexType >::value, IndexType >::type index(IndexType idx)
IndexType at(Values ... values) const
Global coordinates to local index.
SizeType extent(dim_t dim) const
extent
SizeType local_size(team_unit_t unit=UNDEFINED_TEAM_UNIT_ID) const
The actual number of elements in this pattern that are local to the calling unit in total...
This class is a simple memory pool which holds allocates elements of size ValueType.
std::array< SizeType, NumDimensions > local_extents() const
The actual number of elements in this pattern that are local to the given unit, by dimension...
Local element order corresponds to a logical linearization within single blocks (if blocked) or withi...
IndexType global_at(const std::array< IndexType, NumDimensions > &global_coords) const
Global coordinates to global position in the pattern's iteration order.
ShiftTilePattern(self_t &other)
Copy constructor using non-const lvalue reference parameter.
IndexType global(IndexType local_index) const
Resolve an element's linear global index from the calling unit's local index of that element...
team_unit_t unit_at(IndexType global_pos, const ViewSpec_t &viewspec) const
Convert given global linear index to its assigned unit id.
Specifies cartesian extents in a specific number of dimensions.
ShiftTilePattern(const SizeSpec_t &sizespec, DistributionSpec_t dist, TeamSpec_t teamspec, dash::Team &team=dash::Team::All())
Constructor, initializes a pattern from explicit instances of SizeSpec, DistributionSpec, TeamSpec and a Team.
Specifies view parameters for implementing submat, rows and cols.
static constexpr MemArrange memory_order()
Memory order followed by the pattern.
int dim_t
Scalar type for a dimension value, with 0 indicating the first dimension.
IndexType lend() const
Resolves the global index past the last local element in the pattern.
IndexType local_at(const std::array< IndexType, NumDimensions > &local_coords) const
Convert given local coordinates to linear local offset (index).
bool is_local(IndexType index, team_unit_t unit) const
Whether the given global index is local to the specified unit.
index_type block_at(const std::array< index_type, NumDimensions > &g_coords) const
block
SizeType blocksize(dim_t dimension) const
Maximum number of elements in a single block in the given dimension.
The number of blocks assigned to units may differ.
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...
bool operator!=(const self_t &other) const
Inquality comparison operator.
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.
bool operator==(const self_t &other) const
Equality comparison operator.
Block extents are constant for every dimension.
The number of assigned blocks is identical for every unit.
bool has_local_elements(dim_t dim, IndexType dim_offset, team_unit_t unit, const ViewSpec_t &viewspec) const
is_local
Units are mapped to blocks in diagonal chains in all hyperplanes.
IndexType local_at(const std::array< IndexType, NumDimensions > &local_coords, const ViewSpec_t &viewspec) const
local
size_t size() const
The number of units in this team.
IndexType size() const
The number of elements arranged in this pattern.
std::array< IndexType, NumDimensions > global(const std::array< IndexType, NumDimensions > &local_coords) const
Converts local coordinates of a active unit to global coordinates.
const DistributionSpec_t & distspec() const
Distribution specification of this pattern.
SizeType local_capacity() const
Maximum number of elements assigned to a single unit in total, equivalent to the local capacity of ev...
internal::default_signed_index default_index_t
Signed integer type used as default for index values.
std::array< IndexType, NumDimensions > global(team_unit_t unit, const std::array< IndexType, NumDimensions > &local_coords) const
global
A Team instance specifies a subset of all available units.
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...
ViewSpec_t block(index_type global_block_index) const
View spec (offset and extents) of block at global linear block index in global cartesian element spac...
constexpr const extents_type & extents() const noexcept
Extents of the cartesian space, by dimension.
IndexType at(const std::array< IndexType, NumDimensions > &global_coords, const ViewSpec_t &viewspec) const
at
std::array< IndexType, NumDimensions > coords(IndexType index) const
Convert given linear offset (index) to cartesian coordinates.
Elements are contiguous in local memory within a single block and thus indexed blockwise.
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.
const BlockSpec_t & local_blockspec() const
Cartesian arrangement of pattern blocks.
Defines a cartesian, totally-ordered index space by mapping linear indices to cartesian coordinates d...
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.
pattern_partitioning_properties< pattern_partitioning_tag::rectangular, pattern_partitioning_tag::balanced > partitioning_properties
Satisfiable properties in pattern property category Partitioning:
const TeamSpec_t & teamspec() const
Cartesian arrangement of the Team containing the units to which this pattern's elements are mapped...
const std::array< SizeType, NumDimensions > & extents() const
Size specification of the index space mapped by this pattern.
struct dash::unit_id< dash::local_unit, dart_team_unit_t > team_unit_t
Unit ID to use for team-local IDs.
SizeType max_blocksize() const
Maximum number of elements in a single block in all dimensions.
team_unit_t unit_at(const std::array< IndexType, NumDimensions > &coords) const
Convert given coordinate in pattern to its assigned unit id.
ShiftTilePattern(const self_t &other)
Copy constructor.
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.
pattern_mapping_properties< pattern_mapping_tag::balanced, pattern_mapping_tag::unbalanced, pattern_mapping_tag::diagonal > mapping_properties
Satisfiable properties in pattern property category Mapping:
local_index_t local_block_at(const std::array< index_type, NumDimensions > &g_coords) const
Unit and local block index at given global coordinates.
SizeType extent(dim_t dim) const
The extent of the cartesian space in the given dimension.
ShiftTilePattern(SizeType arg, Args &&... args)
Constructor, initializes a pattern from an argument list consisting of the pattern size (extent...
std::array< IndexType, NumDimensions > coords(IndexType index) const
Convert given global linear offset (index) to global cartesian coordinates.
local_index_t local(IndexType g_index) const
Converts global index to its associated unit and respective local index.
static constexpr dim_t ndim()
Number of dimensions of the cartesian space partitioned by the pattern.
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...
team_unit_t unit_at(IndexType global_pos) const
Convert given global linear index to its assigned unit id.
constexpr SizeType size() const noexcept
The number of discrete elements within the space spanned by the coordinate.
SizeSpec_t sizespec() const
Size specification of the index space mapped by this pattern.
local_coords_t local(const std::array< IndexType, NumDimensions > &global_coords) const
Converts global coordinates to their associated unit and its respective local coordinates.
ShiftTilePattern & operator=(const ShiftTilePattern &other)
Assignment operator.
dash::Team & team() const
The Team containing the units to which this pattern's elements are mapped.
pattern_layout_properties< pattern_layout_tag::blocked, pattern_layout_tag::linear > layout_properties
Satisfiable properties in pattern property category Layout:
static Team & All()
The invariant Team instance containing all available units.
see https://en.cppreference.com/w/cpp/feature_test for recommended feature tests
local_index_t local_index(const std::array< IndexType, NumDimensions > &global_coords) const
Resolves the unit and the local index from global coordinates.
team_unit_t unit_at(const std::array< IndexType, NumDimensions > &coords, const ViewSpec_t &viewspec) const
unit_at
IndexType num_units() const
The number of units to which this pattern's elements are mapped.
IndexType capacity() const
The maximum number of elements arranged in this pattern.
constexpr const extents_type & extents() const noexcept
Extents of the cartesian space, by dimension.
DistributionSpec describes distribution patterns of all dimensions,.
Generic type of mapping properties of a model satisfying the Pattern concept.
bool is_local(IndexType index) const
Whether the given global index is local to the unit that created this pattern instance.
IndexType lbegin() const
Resolves the global index of the first local element in the pattern.