1 #ifndef DASH__SEQ_TILE_PATTERN_H_ 2 #define DASH__SEQ_TILE_PATTERN_H_ 13 #include <dash/Types.h> 14 #include <dash/Distribution.h> 15 #include <dash/Exception.h> 16 #include <dash/Dimensional.h> 17 #include <dash/Cartesian.h> 18 #include <dash/Team.h> 20 #include <dash/pattern/PatternProperties.h> 21 #include <dash/pattern/internal/PatternArguments.h> 23 #include <dash/internal/Math.h> 24 #include <dash/internal/Logging.h> 46 MemArrange Arrangement = ROW_MAJOR,
51 static constexpr
char const * PatternName =
"SeqTilePattern";
88 typedef typename std::make_unsigned<IndexType>::type
106 typedef internal::PatternArguments<NumDimensions, IndexType>
110 typedef IndexType index_type;
111 typedef SizeType size_type;
119 std::array<index_type, NumDimensions>
coords;
126 DistributionSpec_t _distspec;
132 TeamSpec_t _teamspec;
135 MemoryLayout_t _memory_layout;
139 BlockSizeSpec_t _blocksize_spec;
141 BlockSpec_t _blockspec;
143 BlockSpec_t _local_blockspec;
147 LocalMemoryLayout_t _local_memory_layout;
149 SizeType _local_capacity;
190 template<
typename ... Args>
202 DASH_LOG_TRACE(
"SeqTilePattern()",
"Constructor with Argument list");
203 initialize_local_range();
245 DistributionSpec_t dist,
250 : _distspec(
std::move(dist))
252 , _myid(_team->
myid())
253 , _teamspec(teamspec, _distspec, *_team)
254 , _memory_layout(sizespec.
extents())
255 , _nunits(_teamspec.
size())
257 initialize_blocksizespec(sizespec, _distspec, _teamspec))
258 , _blockspec(initialize_blockspec(sizespec, _blocksize_spec, _teamspec))
259 , _local_blockspec(initialize_local_blockspec(_blockspec))
260 , _local_memory_layout(initialize_local_extents(_myid))
261 , _local_capacity(initialize_local_capacity(_local_memory_layout))
263 DASH_LOG_TRACE(
"SeqTilePattern()",
"(sizespec, dist, teamspec, team)");
264 initialize_local_range();
302 const SizeSpec_t & sizespec,
306 const DistributionSpec_t & dist = DistributionSpec_t(),
311 _myid(_team->
myid()),
312 _teamspec(_distspec, *_team),
313 _memory_layout(sizespec.
extents()),
314 _nunits(_teamspec.
size()),
315 _blocksize_spec(initialize_blocksizespec(
319 _blockspec(initialize_blockspec(
323 _local_blockspec(initialize_local_blockspec(
325 _local_memory_layout(
326 initialize_local_extents(_myid)),
328 initialize_local_capacity(_local_memory_layout)) {
329 DASH_LOG_TRACE(
"SeqTilePattern()",
"(sizespec, dist, team)");
330 initialize_local_range();
337 : _distspec(other._distspec),
339 _myid(_team->
myid()),
340 _teamspec(other._teamspec),
341 _memory_layout(other._memory_layout),
342 _nunits(other._nunits),
343 _blocksize_spec(other._blocksize_spec),
344 _blockspec(other._blockspec),
345 _local_blockspec(other._local_blockspec),
346 _local_memory_layout(other._local_memory_layout),
347 _local_capacity(other._local_capacity),
348 _lbegin(other._lbegin),
367 const self_t & other)
const 369 if (
this == &other) {
375 _distspec == other._distspec &&
376 _teamspec == other._teamspec &&
377 _memory_layout == other._memory_layout &&
378 _blockspec == other._blockspec &&
379 _blocksize_spec == other._blocksize_spec &&
380 _nunits == other._nunits
391 return !(*
this == other);
398 if (
this != &other) {
399 _distspec = other._distspec;
401 _teamspec = other._teamspec;
402 _memory_layout = other._memory_layout;
403 _local_memory_layout = other._local_memory_layout;
404 _blocksize_spec = other._blocksize_spec;
405 _blockspec = other._blockspec;
406 _local_blockspec = other._local_blockspec;
407 _local_capacity = other._local_capacity;
408 _nunits = other._nunits;
409 _lbegin = other._lbegin;
444 const std::array<IndexType, NumDimensions> &
coords,
446 const ViewSpec_t & viewspec)
const 448 DASH_LOG_TRACE(
"SeqTilePattern.unit_at()",
450 "viewspec:", viewspec);
451 std::array<IndexType, NumDimensions> block_coords;
452 for (
auto d = 0; d < NumDimensions; ++d) {
453 auto vs_coord = coords[d] + viewspec.offset(d);
455 block_coords[d] = vs_coord / _blocksize_spec.
extent(d);
457 auto block_idx = _blockspec.
at(block_coords);
460 DASH_LOG_TRACE_VAR(
"SeqTilePattern.unit_at", block_coords);
461 DASH_LOG_TRACE_VAR(
"SeqTilePattern.unit_at", block_idx);
462 DASH_LOG_TRACE_VAR(
"SeqTilePattern.unit_at >", unit_id);
472 const std::array<IndexType, NumDimensions> &
coords)
const 474 DASH_LOG_TRACE(
"SeqTilePattern.unit_at()",
476 std::array<IndexType, NumDimensions> block_coords{};
479 for (
auto d = 0; d < NumDimensions; ++d) {
481 block_coords[d] = coords[d] / _blocksize_spec.
extent(d);
483 auto block_idx = _blockspec.
at(block_coords);
485 DASH_LOG_TRACE_VAR(
"SeqTilePattern.unit_at", block_coords);
486 DASH_LOG_TRACE_VAR(
"SeqTilePattern.unit_at", block_idx);
487 DASH_LOG_TRACE_VAR(
"SeqTilePattern.unit_at >", unit_id);
498 IndexType global_pos,
500 const ViewSpec_t & viewspec)
const 502 auto global_coords = _memory_layout.
coords(global_pos);
503 return unit_at(global_coords, viewspec);
513 IndexType global_pos)
const 515 auto global_coords = _memory_layout.
coords(global_pos);
533 if (dim >= NumDimensions || dim < 0) {
536 "Wrong dimension for SeqTilePattern::local_extent. " 537 <<
"Expected dimension between 0 and " << NumDimensions-1 <<
", " 540 return _memory_layout.
extent(dim);
556 if (dim >= NumDimensions || dim < 0) {
559 "Wrong dimension for SeqTilePattern::local_extent. " 560 <<
"Expected dimension between 0 and " << NumDimensions-1 <<
", " 563 return _local_memory_layout.
extent(dim);
584 return _local_memory_layout.
extents();
586 return initialize_local_extents(unit);
601 const std::array<IndexType, NumDimensions> &
local_coords,
603 const ViewSpec_t & viewspec)
const 605 DASH_LOG_TRACE(
"SeqTilePattern.local_at()",
606 "local_coords:", local_coords,
608 "local blocks:", _local_blockspec.
extents());
610 std::array<IndexType, NumDimensions> phase_coords{};
612 std::array<IndexType, NumDimensions> block_coords_l{};
613 for (
auto d = 0; d < NumDimensions; ++d) {
614 auto vs_offset_d = viewspec.offset(d);
615 auto vs_coord_d = local_coords[d] + vs_offset_d;
616 auto block_size_d = _blocksize_spec.
extent(d);
617 phase_coords[d] = vs_coord_d % block_size_d;
618 block_coords_l[d] = vs_coord_d / block_size_d;
620 DASH_LOG_TRACE(
"SeqTilePattern.local_at",
621 "local_coords:", local_coords,
623 "local blocks:", _local_blockspec.
extents(),
624 "local block coords:", block_coords_l,
625 "phase coords:", phase_coords);
627 auto block_offset_l = _local_blockspec.
at(block_coords_l);
629 block_offset_l * _blocksize_spec.
size() +
630 _blocksize_spec.
at(phase_coords);
631 DASH_LOG_TRACE_VAR(
"SeqTilePattern.local_at >",
local_index);
642 const std::array<IndexType, NumDimensions> &
local_coords)
const 644 DASH_LOG_TRACE(
"SeqTilePattern.local_at()",
645 "local coords:", local_coords,
646 "local blocks:", _local_blockspec.
extents());
648 std::array<IndexType, NumDimensions> phase_coords;
650 std::array<IndexType, NumDimensions> block_coords_l;
651 for (
auto d = 0; d < NumDimensions; ++d) {
652 auto gcoord_d = local_coords[d];
653 auto block_size_d = _blocksize_spec.
extent(d);
654 phase_coords[d] = gcoord_d % block_size_d;
655 block_coords_l[d] = gcoord_d / block_size_d;
657 DASH_LOG_TRACE(
"SeqTilePattern.local_at",
658 "local_coords:", local_coords,
659 "local blocks:", _local_blockspec.
extents(),
660 "local block coords:", block_coords_l,
661 "block size:", _blocksize_spec.
extents(),
662 "phase coords:", phase_coords);
664 auto block_offset_l = _local_blockspec.
at(block_coords_l);
666 block_offset_l * _blocksize_spec.
size() +
667 _blocksize_spec.
at(phase_coords);
668 DASH_LOG_TRACE_VAR(
"SeqTilePattern.local_at >",
local_index);
679 const std::array<IndexType, NumDimensions> & global_coords)
const 683 std::array<IndexType, NumDimensions> g_block_coords;
684 std::array<IndexType, NumDimensions> phase;
685 for (
dim_t d = 0; d < NumDimensions; ++d) {
686 auto blocksize_d = _blocksize_spec.
extent(d);
687 g_block_coords[d] = global_coords[d] / blocksize_d;
688 phase[d] = global_coords[d] % blocksize_d;
690 auto g_block_index = _blockspec.
at(g_block_coords);
691 l_coords.unit = g_block_index % _nunits;
692 auto l_block_index = g_block_index / _nunits;
693 local_coords[0] = l_block_index * _blocksize_spec.
extent(0) +
695 for (
dim_t d = 1; d < NumDimensions; ++d) {
696 local_coords[d] = phase[d];
711 IndexType g_index)
const 713 DASH_LOG_TRACE_VAR(
"SeqTilePattern.local()", g_index);
726 const std::array<IndexType, NumDimensions> & global_coords)
const 729 for (
dim_t d = 0; d < NumDimensions; ++d) {
730 auto nunits_d = _teamspec.
extent(d);
731 auto blocksize_d = _blocksize_spec.
extent(d);
732 auto block_coord_d = global_coords[d] / blocksize_d;
733 auto phase_d = global_coords[d] % blocksize_d;
734 auto l_block_coord_d = block_coord_d / nunits_d;
735 local_coords[d] = (l_block_coord_d * blocksize_d) + phase_d;
746 const std::array<IndexType, NumDimensions> & global_coords)
const 748 DASH_LOG_TRACE_VAR(
"SeqTilePattern.local_index()", global_coords);
751 std::array<IndexType, NumDimensions> phase_coords{};
753 std::array<IndexType, NumDimensions> block_coords{};
755 std::array<IndexType, NumDimensions> l_block_coords{};
756 for (
auto d = 0; d < NumDimensions; ++d) {
757 auto vs_coord = global_coords[d];
758 phase_coords[d] = vs_coord % _blocksize_spec.
extent(d);
759 block_coords[d] = vs_coord / _blocksize_spec.
extent(d);
761 index_type g_block_index = _blockspec.
at(block_coords);
763 auto l_block_index = g_block_index / _nunits;
764 DASH_LOG_TRACE(
"SeqTilePattern.at",
765 "block_coords:", block_coords,
766 "g_block_index:", g_block_index,
767 "phase_coords:", phase_coords,
768 "l_block_index:", l_block_index,
770 index_type l_index = l_block_index * _blocksize_spec.
size() +
771 _blocksize_spec.
at(phase_coords);
772 DASH_LOG_TRACE_VAR(
"SeqTilePattern.local_index >", l_index);
786 std::array<IndexType, NumDimensions>
global(
788 const std::array<IndexType, NumDimensions> &
local_coords)
const 792 DASH_LOG_DEBUG(
"SeqTilePattern.global()",
794 "lcoords:", local_coords);
795 auto l_block_index = local_coords[0] / _blocksize_spec.
extent(0);
796 auto g_block_index = l_block_index * _nunits + unit;
797 auto g_block_coords = _blockspec.
coords(g_block_index);
798 DASH_LOG_DEBUG(
"SeqTilePattern.global()",
799 "l_block_index:", l_block_index,
800 "g_block_index:", g_block_index,
801 "g_block_coords:", g_block_coords);
803 std::array<IndexType, NumDimensions> global_coords{};
804 for (
dim_t d = 0; d < NumDimensions; ++d) {
805 auto blocksize_d = _blocksize_spec.
extent(d);
806 auto phase = local_coords[d] % blocksize_d;
807 auto g_block_coord_d = g_block_coords[d];
808 global_coords[d] = (g_block_coord_d * blocksize_d) + phase;
810 DASH_LOG_DEBUG_VAR(
"SeqTilePattern.global >", global_coords);
811 return global_coords;
819 std::array<IndexType, NumDimensions>
global(
820 const std::array<IndexType, NumDimensions> &
local_coords)
const {
821 return global(_myid, local_coords);
837 DASH_LOG_TRACE(
"SeqTilePattern.global()",
838 "local_index:", local_index,
840 auto block_size = _blocksize_spec.
size();
841 auto phase = local_index % block_size;
842 auto l_block_index = local_index / block_size;
844 auto l_block_coord = _local_blockspec.
coords(l_block_index);
846 auto phase_coord = _blocksize_spec.
coords(phase);
847 DASH_LOG_TRACE(
"SeqTilePattern.global",
848 "local block index:", l_block_index,
849 "local block coords:", l_block_coord,
850 "phase coords:", phase_coord);
852 std::array<IndexType, NumDimensions> l_coords{};
853 for (
auto d = 0; d < NumDimensions; ++d) {
854 l_coords[d] = l_block_coord[d] * _blocksize_spec.
extent(d) +
857 std::array<IndexType, NumDimensions> g_coords =
859 auto offset = _memory_layout.
at(g_coords);
860 DASH_LOG_TRACE_VAR(
"SeqTilePattern.global >", offset);
875 const std::array<IndexType, NumDimensions> &
local_coords)
const 877 DASH_LOG_TRACE(
"SeqTilePattern.global_index()",
879 "local_coords:", local_coords);
880 std::array<IndexType, NumDimensions> global_coords =
881 global(unit, local_coords);
882 auto g_index = _memory_layout.
at(global_coords);
883 DASH_LOG_TRACE_VAR(
"SeqTilePattern.global_index >", g_index);
901 const std::array<IndexType, NumDimensions> & global_coords,
902 const ViewSpec_t & viewspec)
const 904 DASH_LOG_TRACE(
"SeqTilePattern.global_at()",
905 "gcoords:", global_coords,
906 "viewspec:", viewspec);
908 std::array<IndexType, NumDimensions> phase_coords{};
910 std::array<IndexType, NumDimensions> block_coords{};
911 for (
auto d = 0; d < NumDimensions; ++d) {
912 auto vs_coord = global_coords[d] + viewspec.offset(d);
913 phase_coords[d] = vs_coord % _blocksize_spec.
extent(d);
914 block_coords[d] = vs_coord / _blocksize_spec.
extent(d);
916 DASH_LOG_TRACE(
"SeqTilePattern.global_at",
917 "block coords:", block_coords,
918 "phase coords:", phase_coords);
921 auto block_index = _blockspec.
at(block_coords);
922 DASH_LOG_TRACE(
"SeqTilePattern.global_at",
923 "block index:", block_index);
924 auto offset = block_index * _blocksize_spec.
size() +
925 _blocksize_spec.
at(phase_coords);
926 DASH_LOG_TRACE_VAR(
"SeqTilePattern.global_at >", offset);
944 const std::array<IndexType, NumDimensions> & global_coords)
const 946 DASH_LOG_TRACE(
"SeqTilePattern.global_at()",
947 "gcoords:", global_coords);
949 std::array<IndexType, NumDimensions> phase_coords;
951 std::array<IndexType, NumDimensions> block_coords;
952 for (
auto d = 0; d < NumDimensions; ++d) {
953 auto vs_coord = global_coords[d];
954 phase_coords[d] = vs_coord % _blocksize_spec.
extent(d);
955 block_coords[d] = vs_coord / _blocksize_spec.
extent(d);
957 DASH_LOG_TRACE(
"SeqTilePattern.global_at",
958 "block coords:", block_coords,
959 "phase coords:", phase_coords);
962 auto block_index = _blockspec.
at(block_coords);
963 DASH_LOG_TRACE(
"SeqTilePattern.global_at",
964 "block index:", block_index);
965 auto offset = block_index * _blocksize_spec.
size() +
966 _blocksize_spec.
at(phase_coords);
967 DASH_LOG_TRACE_VAR(
"SeqTilePattern.global_at >", offset);
983 const std::array<IndexType, NumDimensions> & global_coords,
984 const ViewSpec_t & viewspec)
const 986 DASH_LOG_TRACE(
"SeqTilePattern.at()",
987 "gcoords:", global_coords,
988 "viewspec:", viewspec);
990 std::array<IndexType, NumDimensions> phase_coords;
992 std::array<IndexType, NumDimensions> block_coords;
994 std::array<IndexType, NumDimensions> l_block_coords;
995 for (
auto d = 0; d < NumDimensions; ++d) {
996 auto vs_coord = global_coords[d] + viewspec.offset(d);
997 phase_coords[d] = vs_coord % _blocksize_spec.
extent(d);
998 block_coords[d] = vs_coord / _blocksize_spec.
extent(d);
1000 index_type g_block_index = _blockspec.
at(block_coords);
1001 auto l_block_index = g_block_index / _nunits;
1002 DASH_LOG_TRACE(
"SeqTilePattern.at",
1003 "block_coords:", block_coords,
1004 "g_block_index:", g_block_index,
1005 "phase_coords:", phase_coords,
1006 "l_block_index:", l_block_index);
1007 auto offset = l_block_index * _blocksize_spec.
size() +
1008 _blocksize_spec.
at(phase_coords);
1009 DASH_LOG_TRACE_VAR(
"SeqTilePattern.at >", offset);
1022 std::array<IndexType, NumDimensions> global_coords)
const 1024 DASH_LOG_TRACE(
"SeqTilePattern.at()",
1025 "gcoords:", global_coords);
1027 std::array<IndexType, NumDimensions> phase_coords{};
1029 std::array<IndexType, NumDimensions> block_coords{};
1031 std::array<IndexType, NumDimensions> l_block_coords{};
1032 for (
auto d = 0; d < NumDimensions; ++d) {
1033 auto vs_coord = global_coords[d];
1034 phase_coords[d] = vs_coord % _blocksize_spec.
extent(d);
1035 block_coords[d] = vs_coord / _blocksize_spec.
extent(d);
1037 index_type g_block_index = _blockspec.
at(block_coords);
1038 auto l_block_index = g_block_index / _nunits;
1039 DASH_LOG_TRACE(
"SeqTilePattern.at",
1040 "block_coords:", block_coords,
1041 "g_block_index:", g_block_index,
1042 "phase_coords:", phase_coords,
1043 "l_block_index:", l_block_index);
1044 auto offset = l_block_index * _blocksize_spec.
size() +
1045 _blocksize_spec.
at(phase_coords);
1046 DASH_LOG_TRACE_VAR(
"SeqTilePattern.at >", offset);
1057 template<
typename ... Values>
1058 IndexType
at(Values ... values)
const 1061 sizeof...(values) == NumDimensions,
1062 "Wrong parameter number");
1063 std::array<IndexType, NumDimensions> inputindex = {
1064 (IndexType)values...
1066 return at(inputindex);
1083 IndexType dim_offset,
1087 const ViewSpec_t & viewspec)
const 1089 DASH_LOG_TRACE_VAR(
"SeqTilePattern.has_local_elements()", dim);
1090 DASH_LOG_TRACE_VAR(
"SeqTilePattern.has_local_elements()", dim_offset);
1091 DASH_LOG_TRACE_VAR(
"SeqTilePattern.has_local_elements()", unit);
1092 DASH_LOG_TRACE_VAR(
"SeqTilePattern.has_local_elements()", viewspec);
1094 dim_offset += viewspec.offset(dim);
1096 IndexType block_coord_d = dim_offset / _blocksize_spec.
extent(dim);
1097 DASH_LOG_TRACE_VAR(
"SeqTilePattern.has_local_elements", block_coord_d);
1099 IndexType teamspec_coord_d = block_coord_d % _teamspec.
extent(dim);
1100 DASH_LOG_TRACE_VAR(
"SeqTilePattern.has_local_elements",
1118 auto glob_coords =
coords(index);
1119 auto coords_unit =
unit_at(glob_coords);
1120 DASH_LOG_TRACE_VAR(
"SeqTilePattern.is_local >", (coords_unit == unit));
1121 return coords_unit == unit;
1131 IndexType
index)
const 1147 const std::array<index_type, NumDimensions> & g_coords)
const 1149 std::array<index_type, NumDimensions> block_coords;
1151 for (
auto d = 0; d < NumDimensions; ++d) {
1152 block_coords[d] = g_coords[d] / _blocksize_spec.
extent(d);
1155 auto block_idx = _blockspec.
at(block_coords);
1156 DASH_LOG_TRACE(
"SeqTilePattern.block_at",
1158 "> block index", block_idx);
1169 index_type global_block_index)
const 1171 DASH_LOG_TRACE_VAR(
"SeqTilePattern.block()", global_block_index);
1173 auto g_block_coords = _blockspec.
coords(global_block_index);
1174 DASH_LOG_TRACE_VAR(
"SeqTilePattern.block", g_block_coords);
1175 DASH_LOG_TRACE_VAR(
"SeqTilePattern.block", _blocksize_spec.
extents());
1176 std::array<index_type, NumDimensions> offsets{};
1177 std::array<size_type, NumDimensions>
extents{};
1178 for (
auto d = 0; d < NumDimensions; ++d) {
1179 auto blocksize_d = _blocksize_spec.
extent(d);
1181 offsets[d] = g_block_coords[d] * blocksize_d;
1183 DASH_LOG_TRACE(
"SeqTilePattern.block",
1184 "offsets:", offsets,
1186 auto block_vs = ViewSpec_t(offsets,
extents);
1187 DASH_LOG_TRACE_VAR(
"SeqTilePattern.block >", block_vs);
1198 index_type local_block_index)
const 1211 index_type local_block_index)
const 1213 DASH_LOG_TRACE(
"SeqTilePattern.local_block()",
1215 "lblock_idx:", local_block_index);
1216 auto g_block_index = local_block_index * _nunits + unit;
1217 auto g_block_coords = _blockspec.
coords(g_block_index);
1219 DASH_LOG_TRACE_VAR(
"SeqTilePattern.local_block", g_block_coords);
1220 std::array<index_type, NumDimensions> offsets{};
1221 std::array<size_type, NumDimensions>
extents{};
1222 for (
auto d = 0; d < NumDimensions; ++d) {
1223 auto blocksize_d = _blocksize_spec.
extent(d);
1224 offsets[d] = g_block_coords[d] * blocksize_d;
1227 ViewSpec_t block_vs(offsets,
extents);
1228 DASH_LOG_TRACE_VAR(
"SeqTilePattern.local_block >", block_vs);
1239 index_type local_block_index)
const 1241 DASH_LOG_TRACE_VAR(
"SeqTilePattern.local_block_local()",
1244 std::array<index_type, NumDimensions> offsets{};
1245 std::array<size_type, NumDimensions>
extents =
1248 auto l_block_coords = _local_blockspec.
coords(local_block_index);
1250 for (
auto d = 0; d < NumDimensions; ++d) {
1251 offsets[d] = l_block_coords[d] * extents[d];
1253 ViewSpec_t block_vs(offsets, extents);
1254 DASH_LOG_TRACE_VAR(
"SeqTilePattern.local_block_local >", block_vs);
1271 return _local_blockspec;
1279 if (unit == _myid) {
1282 return initialize_local_blockspec( _blockspec, unit);
1294 dim_t dimension)
const 1296 return _blocksize_spec.
extent(dimension);
1308 return _blocksize_spec.
size();
1333 return _local_memory_layout.
size();
1337 return LocalMemoryLayout_t(initialize_local_extents(unit)).size();
1346 return _teamspec.
size();
1355 return _memory_layout.
size();
1364 return _memory_layout.
size();
1388 return SizeSpec_t(_memory_layout.
extents());
1396 const std::array<SizeType, NumDimensions> &
extents()
const {
1397 return _memory_layout.
extents();
1417 IndexType
index)
const {
1418 return _memory_layout.
coords(index);
1429 const ViewSpec_t & viewspec)
const {
1430 return _memory_layout.
coords(index, viewspec);
1445 return NumDimensions;
1451 : _distspec(arguments.distspec()),
1452 _team(&arguments.team()),
1453 _myid(_team->myid()),
1454 _teamspec(arguments.teamspec()),
1455 _memory_layout(arguments.sizespec().extents()),
1456 _nunits(_teamspec.
size()),
1457 _blocksize_spec(initialize_blocksizespec(
1458 arguments.sizespec(),
1461 _blockspec(initialize_blockspec(
1462 arguments.sizespec(),
1465 _local_blockspec(initialize_local_blockspec(
1467 _local_memory_layout(
1468 initialize_local_extents(_myid)),
1470 initialize_local_capacity(_local_memory_layout))
1477 BlockSizeSpec_t initialize_blocksizespec(
1478 const SizeSpec_t & sizespec,
1479 const DistributionSpec_t &
distspec,
1480 const TeamSpec_t & teamspec)
const {
1481 DASH_LOG_TRACE(
"SeqTilePattern.init_blocksizespec()");
1483 std::array<SizeType, NumDimensions> s_blocks{};
1484 for (
auto d = 0; d < NumDimensions; ++d) {
1486 DASH_LOG_TRACE(
"SeqTilePattern.init_blocksizespec d",
1487 "sizespec extent[d]:", sizespec.
extent(d),
1488 "teamspec extent[d]:", teamspec.
extent(d));
1492 s_blocks[d] = max_blocksize_d;
1494 DASH_LOG_TRACE_VAR(
"SeqTilePattern.init_blocksizespec >", s_blocks);
1495 return BlockSizeSpec_t(s_blocks);
1502 BlockSpec_t initialize_blockspec(
1503 const SizeSpec_t & sizespec,
1504 const BlockSizeSpec_t & blocksizespec,
1505 const TeamSpec_t & teamspec)
const 1507 DASH_LOG_TRACE(
"SeqTilePattern.init_blockspec()",
1508 "pattern size:", sizespec.
extents(),
1509 "block size:", blocksizespec.
extents(),
1510 "team size:", teamspec.
extents());
1512 std::array<SizeType, NumDimensions> n_blocks{};
1513 for (
auto d = 0; d < NumDimensions; ++d) {
1514 SizeType max_blocksize_d = blocksizespec.
extent(d);
1515 SizeType max_blocks_d = dash::math::div_ceil(
1518 n_blocks[d] = max_blocks_d;
1521 DASH_LOG_TRACE_VAR(
"SeqTilePattern.init_blockspec >", n_blocks);
1532 BlockSpec_t initialize_local_blockspec(
1536 DASH_LOG_TRACE_VAR(
"SeqTilePattern.init_local_blockspec()",
1542 auto num_blocks_total = blockspec.
size();
1544 std::array<SizeType, NumDimensions> l_blocks{};
1545 auto min_local_blocks = num_blocks_total / _nunits;
1546 l_blocks[0] = min_local_blocks;
1547 if (unit_id < num_blocks_total % _nunits) {
1550 for (
auto d = 1; d < NumDimensions; ++d) {
1553 DASH_LOG_TRACE_VAR(
"SeqTilePattern.init_local_blockspec >", l_blocks);
1554 return BlockSpec_t(l_blocks);
1564 SizeType initialize_local_capacity(
1567 auto l_capacity = local_extents.
size();
1568 DASH_LOG_TRACE_VAR(
"SeqTilePattern.init_local_capacity >", l_capacity);
1575 void initialize_local_range()
1578 DASH_LOG_DEBUG_VAR(
"SeqTilePattern.init_local_range()",
local_size);
1588 DASH_LOG_DEBUG_VAR(
"SeqTilePattern.init_local_range >",
1589 _local_memory_layout.
extents());
1590 DASH_LOG_DEBUG_VAR(
"SeqTilePattern.init_local_range >", _lbegin);
1591 DASH_LOG_DEBUG_VAR(
"SeqTilePattern.init_local_range >", _lend);
1597 std::array<SizeType, NumDimensions> initialize_local_extents(
1600 DASH_LOG_DEBUG_VAR(
"SeqTilePattern.init_local_extents()", unit);
1601 auto l_blockspec = initialize_local_blockspec(
1604 DASH_LOG_DEBUG_VAR(
"SeqTilePattern.init_local_extents()",
1605 l_blockspec.extents());
1606 ::std::array<SizeType, NumDimensions> l_extents{};
1607 for (
auto d = 0; d < NumDimensions; ++d) {
1608 l_extents[d] = _blocksize_spec.
extent(d) * l_blockspec.extent(d);
1610 DASH_LOG_DEBUG_VAR(
"SeqTilePattern.init_local_extents >", l_extents);
1619 std::ostream & operator<<(
1623 typedef Index index_t;
1627 std::string storage_order = pattern.
memory_order() == ROW_MAJOR
1635 std::ostringstream ss;
1640 << storage_order <<
"," 1641 <<
typeid(index_t).name()
1647 <<
"BlockSize:" << blocksize
1650 return operator<<(os, ss.str());
1657 #endif // DASH__SEQ_TILE_PATTERN_H_ constexpr team_unit_t UNDEFINED_TEAM_UNIT_ID
Invalid local unit ID.
All blocks have identical size.
team_unit_t unit_at(const std::array< IndexType, NumDimensions > &coords, const ViewSpec_t &viewspec) const
unit_at
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.
IndexType capacity() const
The maximum number of elements arranged in this pattern.
constexpr std::enable_if< std::is_integral< IndexType >::value, IndexType >::type index(IndexType idx)
IndexType size() const
The number of elements arranged in this pattern.
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...
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...
pattern_mapping_properties< pattern_mapping_tag::balanced, pattern_mapping_tag::unbalanced, pattern_mapping_tag::diagonal > mapping_properties
Satisfiable properties in pattern property category Mapping:
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...
Specifies cartesian extents in a specific number of dimensions.
Specifies view parameters for implementing submat, rows and cols.
SizeType blocksize(dim_t dimension) const
Maximum number of elements in a single block in the given dimension.
bool operator!=(const self_t &other) const
Inquality comparison operator.
int dim_t
Scalar type for a dimension value, with 0 indicating the first dimension.
std::array< IndexType, NumDimensions > global(team_unit_t unit, const std::array< IndexType, NumDimensions > &local_coords) const
global
IndexType lend() const
Resolves the global index past the last local element in the pattern.
bool operator==(const self_t &other) const
Equality comparison operator.
ViewSpec_t local_block(team_unit_t unit, index_type local_block_index) const
View spec (offset and extents) of block at local linear block index in global cartesian element space...
bool has_local_elements(dim_t dim, IndexType dim_offset, team_unit_t unit, const ViewSpec_t &viewspec) const
is_local
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...
SizeSpec_t sizespec() const
Size specification of the index space mapped by this pattern.
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(IndexType global_pos) const
Convert given global linear index to its assigned unit id.
The number of blocks assigned to units may differ.
local_coords_t local(const std::array< IndexType, NumDimensions > &global_coords) const
Converts global coordinates to their associated unit and its respective local coordinates.
SeqTilePattern(const SizeSpec_t &sizespec, const DistributionSpec_t &dist=DistributionSpec_t(), Team &team=dash::Team::All())
Constructor, initializes a pattern from explicit instances of SizeSpec, DistributionSpec and a Team...
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...
IndexType global(IndexType local_index) const
Resolve an element's linear global index from the calling unit's local index of that element...
dash::Team & team() const
The Team containing the units to which this pattern's elements are mapped.
Minimal number of blocks in every dimension, typically at most one block per unit.
Block extents are constant for every dimension.
The number of assigned blocks is identical for every unit.
Units are mapped to blocks in diagonal chains in all hyperplanes.
size_t size() const
The number of units in this team.
IndexType num_units() const
The number of units to which this pattern's elements are mapped.
SeqTilePattern(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.
pattern_layout_properties< pattern_layout_tag::blocked, pattern_layout_tag::linear > layout_properties
Satisfiable properties in pattern property category Layout:
const std::array< SizeType, NumDimensions > & extents() const
Size specification of the index space mapped by this pattern.
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.
IndexType at(const std::array< IndexType, NumDimensions > &global_coords, const ViewSpec_t &viewspec) const
at
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.
constexpr const extents_type & extents() const noexcept
Extents of the cartesian space, by dimension.
const BlockSpec_t & blockspec() const
Cartesian arrangement of pattern blocks.
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.
SeqTilePattern(const self_t &other)
Copy constructor.
IndexType local_at(const std::array< IndexType, NumDimensions > &local_coords) const
Convert given local coordinates to linear local offset (index).
Defines a cartesian, totally-ordered index space by mapping linear indices to cartesian coordinates d...
Defines how a list of global indices is mapped to single units within a Team.
BlockSpec_t local_blockspec(team_unit_t unit) const
Cartesian arrangement of pattern blocks.
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.
const TeamSpec_t & teamspec() const
Cartesian arrangement of the Team containing the units to which this pattern's elements are mapped...
static constexpr MemArrange memory_order()
Memory order followed by the pattern.
SeqTilePattern(self_t &other)
Copy constructor using non-const lvalue reference parameter.
IndexType at(Values ... values) const
Global coordinates to local index.
std::array< SizeType, NumDimensions > local_extents(team_unit_t unit=UNDEFINED_TEAM_UNIT_ID) const
The actual number of elements in this pattern that are local to the given unit, by dimension...
local_index_t local(IndexType g_index) const
Converts global index to its associated unit and respective local index.
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.
SizeType max_blocksize() const
Maximum number of elements in a single block in all dimensions.
pattern_partitioning_properties< pattern_partitioning_tag::minimal, pattern_partitioning_tag::rectangular, pattern_partitioning_tag::balanced > partitioning_properties
Satisfiable properties in pattern property category Partitioning:
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 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.
SeqTilePattern(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.
bool is_local(IndexType index, team_unit_t unit) const
Whether the given global index is local to the specified unit.
team_unit_t unit_at(IndexType global_pos, const ViewSpec_t &viewspec) const
Convert given global linear index to its assigned unit id.
const BlockSpec_t & local_blockspec() const
Cartesian arrangement of pattern blocks.
#define DART_UNDEFINED_UNIT_ID
Undefined unit ID.
SizeType extent(dim_t dim) const
extent
constexpr SizeType size() const noexcept
The number of discrete elements within the space spanned by the coordinate.
IndexType at(std::array< IndexType, NumDimensions > global_coords) const
Global coordinates to local index.
const DistributionSpec_t & distspec() const
Distribution specification of this pattern.
static constexpr dim_t ndim()
Number of dimensions of the cartesian space partitioned by the pattern.
static Team & All()
The invariant Team instance containing all available units.
see https://en.cppreference.com/w/cpp/feature_test for recommended feature tests
team_unit_t unit_at(const std::array< IndexType, NumDimensions > &coords) const
Convert given coordinate in pattern to its assigned unit id.
IndexType local_at(const std::array< IndexType, NumDimensions > &local_coords, const ViewSpec_t &viewspec) const
local
bool is_local(IndexType index) const
Whether the given global index is local to the unit that created this pattern instance.
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 block-wise iteration order...
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...
SizeType local_capacity() const
Maximum number of elements assigned to a single unit in total, equivalent to the local capacity of ev...
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...
index_type block_at(const std::array< index_type, NumDimensions > &g_coords) const
block
std::array< IndexType, NumDimensions > global(const std::array< IndexType, NumDimensions > &local_coords) const
Converts local coordinates of a active unit to global coordinates.
IndexType global_at(const std::array< IndexType, NumDimensions > &global_coords) const
Global coordinates to global position in the pattern's block-wise iteration order.
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.
SeqTilePattern & operator=(const SeqTilePattern &other)
Assignment operator.