1 #ifndef DASH__TILE_PATTERN_H_ 2 #define DASH__TILE_PATTERN_H_ 12 #include <dash/Types.h> 13 #include <dash/Distribution.h> 14 #include <dash/Exception.h> 15 #include <dash/Dimensional.h> 16 #include <dash/Cartesian.h> 17 #include <dash/Team.h> 19 #include <dash/pattern/PatternProperties.h> 20 #include <dash/pattern/internal/PatternArguments.h> 22 #include <dash/internal/Math.h> 23 #include <dash/internal/Logging.h> 45 MemArrange Arrangement = ROW_MAJOR,
50 static constexpr
char const * PatternName =
"TilePattern";
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;
126 TeamSpec_t _teamspec;
129 MemoryLayout_t _memory_layout;
133 BlockSizeSpec_t _blocksize_spec;
135 BlockSpec_t _blockspec;
137 BlockSpec_t _local_blockspec;
141 LocalMemoryLayout_t _local_memory_layout;
143 SizeType _local_capacity;
184 template<
typename ... Args>
196 DASH_LOG_TRACE(
"TilePattern()",
"Constructor with Argument list");
197 initialize_local_range();
238 DistributionSpec_t dist,
243 : _distspec(
std::move(dist))
245 , _myid(_team->
myid())
246 , _teamspec(teamspec, _distspec, *_team)
247 , _memory_layout(sizespec.
extents())
248 , _nunits(_teamspec.
size())
250 initialize_blocksizespec(sizespec, _distspec, _teamspec))
251 , _blockspec(initialize_blockspec(sizespec, _blocksize_spec, _teamspec))
253 initialize_local_blockspec(_blockspec, _blocksize_spec, _teamspec))
254 , _local_memory_layout(initialize_local_extents(_myid))
255 , _local_capacity(initialize_local_capacity(_local_memory_layout))
257 DASH_LOG_TRACE(
"TilePattern()",
"(sizespec, dist, teamspec, team)");
258 initialize_local_range();
296 const SizeSpec_t &sizespec,
300 DistributionSpec_t dist = DistributionSpec_t(),
303 : _distspec(
std::move(dist))
305 , _myid(_team->
myid())
306 , _teamspec(_distspec, *_team)
307 , _memory_layout(sizespec.
extents())
308 , _nunits(_teamspec.
size())
310 initialize_blocksizespec(sizespec, _distspec, _teamspec))
311 , _blockspec(initialize_blockspec(sizespec, _blocksize_spec, _teamspec))
313 initialize_local_blockspec(_blockspec, _blocksize_spec, _teamspec))
314 , _local_memory_layout(initialize_local_extents(_myid))
315 , _local_capacity(initialize_local_capacity(_local_memory_layout))
317 DASH_LOG_TRACE(
"TilePattern()",
"(sizespec, dist, team)");
318 initialize_local_range();
346 if (
this == &other) {
352 _distspec == other._distspec &&
353 _teamspec == other._teamspec &&
354 _memory_layout == other._memory_layout &&
355 _blockspec == other._blockspec &&
356 _blocksize_spec == other._blocksize_spec &&
357 _nunits == other._nunits
366 const self_t & other)
const 368 return !(*
this == other);
385 constexpr IndexType
lend()
const {
400 const std::array<IndexType, NumDimensions> &
coords,
402 const ViewSpec_t & viewspec)
const 404 DASH_LOG_TRACE(
"TilePattern.unit_at()",
406 "viewspec:", viewspec);
407 std::array<IndexType, NumDimensions> unit_ts_coords{};
408 std::array<IndexType, NumDimensions> block_coords{};
411 for (
auto d = 0; d < NumDimensions; ++d) {
412 auto vs_coord = coords[d] + viewspec.offset(d);
414 block_coords[d] = vs_coord / _blocksize_spec.
extent(d);
415 unit_ts_coords[d] = block_coords[d] % _teamspec.
extent(d);
418 DASH_LOG_TRACE_VAR(
"TilePattern.unit_at", block_coords);
419 DASH_LOG_TRACE_VAR(
"TilePattern.unit_at", unit_ts_coords);
420 DASH_LOG_TRACE_VAR(
"TilePattern.unit_at >", unit_id);
430 const std::array<IndexType, NumDimensions> &
coords)
const 432 DASH_LOG_TRACE(
"TilePattern.unit_at()",
434 std::array<IndexType, NumDimensions> unit_ts_coords{};
435 std::array<IndexType, NumDimensions> block_coords{};
438 for (
auto d = 0; d < NumDimensions; ++d) {
440 block_coords[d] = coords[d] / _blocksize_spec.
extent(d);
441 unit_ts_coords[d] = block_coords[d] % _teamspec.
extent(d);
444 DASH_LOG_TRACE_VAR(
"TilePattern.unit_at", block_coords);
445 DASH_LOG_TRACE_VAR(
"TilePattern.unit_at", unit_ts_coords);
446 DASH_LOG_TRACE_VAR(
"TilePattern.unit_at >", unit_id);
457 IndexType global_pos,
459 const ViewSpec_t & viewspec)
const 461 auto global_coords = _memory_layout.
coords(global_pos);
462 return unit_at(global_coords, viewspec);
472 IndexType global_pos)
const 474 auto global_coords = _memory_layout.
coords(global_pos);
492 if (dim >= NumDimensions || dim < 0) {
495 "Wrong dimension for TilePattern::local_extent. " 496 <<
"Expected dimension between 0 and " << NumDimensions-1 <<
", " 499 return _memory_layout.
extent(dim);
515 if (dim >= NumDimensions || dim < 0) {
518 "Wrong dimension for TilePattern::local_extent. " 519 <<
"Expected dimension between 0 and " << NumDimensions-1 <<
", " 522 return _local_memory_layout.
extent(dim);
541 ? _local_memory_layout.
extents()
542 : initialize_local_extents(unit) );
557 const std::array<IndexType, NumDimensions> &
local_coords,
559 const ViewSpec_t & viewspec)
const 561 DASH_LOG_TRACE(
"TilePattern.local_at()",
562 "local_coords:", local_coords,
564 "local blocks:", _local_blockspec.
extents());
566 std::array<IndexType, NumDimensions> phase_coords{};
568 std::array<IndexType, NumDimensions> block_coords_l{};
569 for (
auto d = 0; d < NumDimensions; ++d) {
570 auto vs_offset_d = viewspec.offset(d);
571 auto vs_coord_d = local_coords[d] + vs_offset_d;
572 auto block_size_d = _blocksize_spec.
extent(d);
573 phase_coords[d] = vs_coord_d % block_size_d;
574 block_coords_l[d] = vs_coord_d / block_size_d;
576 DASH_LOG_TRACE(
"TilePattern.local_at",
577 "local_coords:", local_coords);
578 DASH_LOG_TRACE(
"TilePattern.local_at",
580 DASH_LOG_TRACE(
"TilePattern.local_at",
581 "local blocks:", _local_blockspec.
extents());
582 DASH_LOG_TRACE(
"TilePattern.local_at",
583 "local block coords:", block_coords_l);
584 DASH_LOG_TRACE(
"TilePattern.local_at",
585 "phase coords:", phase_coords);
587 auto block_offset_l = _local_blockspec.
at(block_coords_l);
588 DASH_LOG_TRACE(
"TilePattern.local_at",
589 "local block offset:", block_offset_l);
591 block_offset_l * _blocksize_spec.
size() +
592 _blocksize_spec.
at(phase_coords);
593 DASH_LOG_TRACE_VAR(
"TilePattern.local_at >",
local_index);
604 const std::array<IndexType, NumDimensions> &
local_coords)
const 606 DASH_LOG_TRACE(
"TilePattern.local_at()",
607 "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 gcoord_d = local_coords[d];
615 auto block_size_d = _blocksize_spec.
extent(d);
616 phase_coords[d] = gcoord_d % block_size_d;
617 block_coords_l[d] = gcoord_d / block_size_d;
619 DASH_LOG_TRACE(
"TilePattern.local_at",
620 "local_coords:", local_coords,
621 "local blocks:", _local_blockspec.
extents(),
622 "local block coords:", block_coords_l,
623 "block size:", _blocksize_spec.
extents(),
624 "phase coords:", phase_coords);
626 auto block_offset_l = _local_blockspec.
at(block_coords_l);
628 block_offset_l * _blocksize_spec.
size() +
629 _blocksize_spec.
at(phase_coords);
630 DASH_LOG_TRACE_VAR(
"TilePattern.local_at >",
local_index);
641 const std::array<IndexType, NumDimensions> & global_coords)
const 645 std::array<IndexType, NumDimensions> unit_ts_coords{};
646 for (
dim_t d = 0; d < NumDimensions; ++d) {
647 auto nunits_d = _teamspec.
extent(d);
648 auto blocksize_d = _blocksize_spec.
extent(d);
649 auto block_coord_d = global_coords[d] / blocksize_d;
650 auto phase_d = global_coords[d] % blocksize_d;
651 auto l_block_coord_d = block_coord_d / nunits_d;
652 unit_ts_coords[d] = block_coord_d % nunits_d;
653 local_coords[d] = (l_block_coord_d * blocksize_d) + phase_d;
655 l_coords.unit = _teamspec.
at(unit_ts_coords);
669 IndexType g_index)
const 683 const std::array<IndexType, NumDimensions> & global_coords)
const 686 for (
dim_t d = 0; d < NumDimensions; ++d) {
687 auto nunits_d = _teamspec.
extent(d);
688 auto blocksize_d = _blocksize_spec.
extent(d);
689 auto block_coord_d = global_coords[d] / blocksize_d;
690 auto phase_d = global_coords[d] % blocksize_d;
691 auto l_block_coord_d = block_coord_d / nunits_d;
692 local_coords[d] = (l_block_coord_d * blocksize_d) + phase_d;
703 const std::array<IndexType, NumDimensions> & global_coords)
const 705 DASH_LOG_TRACE_VAR(
"TilePattern.local_index()", global_coords);
707 auto l_pos_coords =
local(global_coords);
708 auto l_coords = l_pos_coords.coords;
709 auto unit = l_pos_coords.unit;
710 index_type l_index = -1;
711 DASH_LOG_TRACE_VAR(
"TilePattern.local_index", l_coords);
712 DASH_LOG_TRACE_VAR(
"TilePattern.local_index", unit);
720 auto remote_l_blockspec = initialize_local_blockspec(
721 _blockspec, _blocksize_spec, _teamspec,
725 std::array<IndexType, NumDimensions> phase_coords{};
727 std::array<IndexType, NumDimensions> block_coords_l{};
728 for (
auto d = 0; d < NumDimensions; ++d) {
729 auto gcoord_d = l_coords[d];
730 auto block_size_d = _blocksize_spec.
extent(d);
731 phase_coords[d] = gcoord_d % block_size_d;
732 block_coords_l[d] = gcoord_d / block_size_d;
734 DASH_LOG_TRACE(
"TilePattern.local_index",
735 "local_coords:", l_coords,
736 "local blocks:", remote_l_blockspec.extents(),
737 "local block coords:", block_coords_l,
738 "block size:", _blocksize_spec.
extents(),
739 "phase coords:", phase_coords);
741 auto block_offset_l = remote_l_blockspec.at(block_coords_l);
742 l_index = block_offset_l * _blocksize_spec.
size() +
743 _blocksize_spec.
at(phase_coords);
745 DASH_LOG_TRACE_VAR(
"TilePattern.local_index >", l_index);
759 std::array<IndexType, NumDimensions>
global(
761 const std::array<IndexType, NumDimensions> &
local_coords)
const 763 DASH_LOG_DEBUG(
"TilePattern.global()",
765 "lcoords:", local_coords);
767 std::array<IndexType, NumDimensions> global_coords{};
768 std::array<IndexType, NumDimensions> unit_ts_coords = _teamspec.
coords(
770 for (
dim_t d = 0; d < NumDimensions; ++d) {
771 auto blocksize_d = _blocksize_spec.
extent(d);
772 auto nunits_d = _teamspec.
extent(d);
773 auto phase = local_coords[d] % blocksize_d;
774 auto l_block_coord_d = local_coords[d] / blocksize_d;
775 auto g_block_coord_d = (l_block_coord_d * nunits_d) +
777 global_coords[d] = (g_block_coord_d * blocksize_d) + phase;
779 DASH_LOG_DEBUG_VAR(
"TilePattern.global >", global_coords);
780 return global_coords;
788 constexpr std::array<IndexType, NumDimensions>
global(
789 const std::array<IndexType, NumDimensions> &
local_coords)
const {
790 return global(_myid, local_coords);
804 DASH_LOG_TRACE(
"TilePattern.global()",
805 "local_index:", local_index,
807 auto block_size = _blocksize_spec.
size();
808 auto phase = local_index % block_size;
809 auto l_block_index = local_index / block_size;
811 auto l_block_coord = _local_blockspec.
coords(l_block_index);
813 auto phase_coord = _blocksize_spec.
coords(phase);
814 DASH_LOG_TRACE(
"TilePattern.global",
815 "local block index:", l_block_index,
816 "local block coords:", l_block_coord,
817 "phase coords:", phase_coord);
819 std::array<IndexType, NumDimensions> l_coords{};
820 for (
auto d = 0; d < NumDimensions; ++d) {
821 l_coords[d] = l_block_coord[d] * _blocksize_spec.
extent(d) +
824 std::array<IndexType, NumDimensions> g_coords =
827 DASH_LOG_TRACE_VAR(
"TilePattern.global >", offset);
842 const std::array<IndexType, NumDimensions> &
local_coords)
const 844 DASH_LOG_TRACE(
"TilePattern.global_index()",
846 "local_coords:", local_coords);
847 std::array<IndexType, NumDimensions> global_coords =
848 global(unit, local_coords);
849 auto g_index = _memory_layout.
at(global_coords);
850 DASH_LOG_TRACE_VAR(
"TilePattern.global_index >", g_index);
868 const std::array<IndexType, NumDimensions> & global_coords,
869 const ViewSpec_t & viewspec)
const 871 DASH_LOG_TRACE(
"TilePattern.global_at()",
872 "gcoords:", global_coords,
873 "viewspec:", viewspec);
875 std::array<IndexType, NumDimensions> phase_coords{};
877 std::array<IndexType, NumDimensions> block_coords{};
878 for (
auto d = 0; d < NumDimensions; ++d) {
879 auto vs_coord = global_coords[d] + viewspec.offset(d);
880 phase_coords[d] = vs_coord % _blocksize_spec.
extent(d);
881 block_coords[d] = vs_coord / _blocksize_spec.
extent(d);
883 DASH_LOG_TRACE(
"TilePattern.global_at",
884 "block coords:", block_coords,
885 "phase coords:", phase_coords);
888 auto block_index = _blockspec.
at(block_coords);
889 DASH_LOG_TRACE(
"TilePattern.global_at",
890 "block index:", block_index);
891 auto offset = block_index * _blocksize_spec.
size() +
892 _blocksize_spec.
at(phase_coords);
893 DASH_LOG_TRACE_VAR(
"TilePattern.global_at >", offset);
911 const std::array<IndexType, NumDimensions> & global_coords)
const 913 DASH_LOG_TRACE(
"TilePattern.global_at()",
914 "gcoords:", global_coords);
916 std::array<IndexType, NumDimensions> phase_coords;
918 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(
"TilePattern.global_at",
926 "block coords:", block_coords,
927 "phase coords:", phase_coords);
930 auto block_index = _blockspec.
at(block_coords);
931 DASH_LOG_TRACE(
"TilePattern.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(
"TilePattern.global_at >", offset);
951 const std::array<IndexType, NumDimensions> & global_coords,
952 const ViewSpec_t & viewspec)
const 954 DASH_LOG_TRACE(
"TilePattern.at()",
955 "gcoords:", global_coords,
956 "viewspec:", viewspec);
958 std::array<IndexType, NumDimensions> phase_coords;
960 std::array<IndexType, NumDimensions> block_coords;
962 std::array<IndexType, NumDimensions> l_block_coords;
963 for (
auto d = 0; d < NumDimensions; ++d) {
964 auto nunits_d = _teamspec.
extent(d);
965 auto vs_coord = global_coords[d] + viewspec.offset(d);
966 phase_coords[d] = vs_coord % _blocksize_spec.
extent(d);
967 block_coords[d] = vs_coord / _blocksize_spec.
extent(d);
968 l_block_coords[d] = block_coords[d] / nunits_d;
970 index_type l_block_index = _local_blockspec.
at(l_block_coords);
971 DASH_LOG_TRACE(
"TilePattern.at",
972 "block_coords:", block_coords,
973 "l_block_coords:", l_block_coords,
974 "l_block_index:", l_block_index,
975 "phase_coords:", phase_coords);
976 auto offset = l_block_index * _blocksize_spec.
size() +
977 _blocksize_spec.
at(phase_coords);
978 DASH_LOG_TRACE_VAR(
"TilePattern.at >", offset);
991 std::array<IndexType, NumDimensions> global_coords)
const 993 DASH_LOG_TRACE(
"TilePattern.at()",
"gcoords:", global_coords);
995 std::array<IndexType, NumDimensions> phase_coords{};
997 std::array<IndexType, NumDimensions> block_coords{};
999 std::array<IndexType, NumDimensions> l_block_coords{};
1000 for (
auto d = 0; d < NumDimensions; ++d) {
1001 auto nunits_d = _teamspec.
extent(d);
1002 auto gcoord_d = global_coords[d];
1003 phase_coords[d] = gcoord_d % _blocksize_spec.
extent(d);
1004 block_coords[d] = gcoord_d / _blocksize_spec.
extent(d);
1005 l_block_coords[d] = block_coords[d] / nunits_d;
1007 index_type l_block_index = _local_blockspec.
at(l_block_coords);
1008 DASH_LOG_TRACE(
"TilePattern.at",
1009 "block_coords:", block_coords,
1010 "l_block_coords:", l_block_coords,
1011 "l_block_index:", l_block_index,
1012 "phase_coords:", phase_coords);
1013 auto offset = l_block_index * _blocksize_spec.
size() +
1014 _blocksize_spec.
at(phase_coords);
1015 DASH_LOG_TRACE_VAR(
"TilePattern.at >", offset);
1026 template<
typename ... Values>
1027 IndexType
at(Values ... values)
const 1030 sizeof...(values) == NumDimensions,
1031 "Wrong parameter number");
1032 std::array<IndexType, NumDimensions> inputindex = {
1033 (IndexType)values...
1035 return at(inputindex);
1052 IndexType dim_offset,
1056 const ViewSpec_t & viewspec)
const 1058 DASH_LOG_TRACE_VAR(
"TilePattern.has_local_elements()", dim);
1059 DASH_LOG_TRACE_VAR(
"TilePattern.has_local_elements()", dim_offset);
1060 DASH_LOG_TRACE_VAR(
"TilePattern.has_local_elements()", unit);
1061 DASH_LOG_TRACE_VAR(
"TilePattern.has_local_elements()", viewspec);
1063 dim_offset += viewspec.offset(dim);
1065 IndexType block_coord_d = dim_offset / _blocksize_spec.
extent(dim);
1066 DASH_LOG_TRACE_VAR(
"TilePattern.has_local_elements", block_coord_d);
1068 IndexType teamspec_coord_d = block_coord_d % _teamspec.
extent(dim);
1069 DASH_LOG_TRACE_VAR(
"TilePattern.has_local_elements",
1087 auto glob_coords =
coords(index);
1088 auto coords_unit =
unit_at(glob_coords);
1089 DASH_LOG_TRACE_VAR(
"TilePattern.is_local >", (coords_unit == unit));
1090 return coords_unit == unit;
1100 IndexType
index)
const 1116 const std::array<index_type, NumDimensions> & g_coords)
const 1118 std::array<index_type, NumDimensions> block_coords{};
1120 for (
auto d = 0; d < NumDimensions; ++d) {
1121 block_coords[d] = g_coords[d] / _blocksize_spec.
extent(d);
1124 auto block_idx = _blockspec.
at(block_coords);
1125 DASH_LOG_TRACE(
"TilePattern.block_at",
1127 "> block index", block_idx);
1138 const std::array<index_type, NumDimensions> & g_coords)
const 1142 std::array<IndexType, NumDimensions> l_block_coords{};
1143 std::array<IndexType, NumDimensions> unit_ts_coords{};
1144 for (
dim_t d = 0; d < NumDimensions; ++d) {
1145 auto nunits_d = _teamspec.
extent(d);
1146 auto blocksize_d = _blocksize_spec.
extent(d);
1147 auto block_coord_d = g_coords[d] / blocksize_d;
1148 l_block_coords[d] = block_coord_d / nunits_d;
1149 unit_ts_coords[d] = block_coord_d % nunits_d;
1151 l_pos.unit = _teamspec.
at(unit_ts_coords);
1152 l_pos.index = _local_blockspec.
at(l_block_coords);
1154 DASH_LOG_TRACE(
"TilePattern.local_block_at >",
1156 "unit:", l_pos.unit,
1157 "local block index:", l_pos.index);
1168 index_type global_block_index)
const 1170 DASH_LOG_TRACE_VAR(
"TilePattern.block()", global_block_index);
1172 auto block_coords = _blockspec.
coords(global_block_index);
1173 DASH_LOG_TRACE_VAR(
"TilePattern.block", block_coords);
1174 DASH_LOG_TRACE_VAR(
"TilePattern.block", _blocksize_spec.
extents());
1175 std::array<index_type, NumDimensions> offsets{};
1176 std::array<size_type, NumDimensions>
extents{};
1177 for (
auto d = 0; d < NumDimensions; ++d) {
1178 auto blocksize_d = _blocksize_spec.
extent(d);
1180 offsets[d] = block_coords[d] * blocksize_d;
1182 DASH_LOG_TRACE(
"TilePattern.block",
1183 "offsets:", offsets,
1185 auto block_vs = ViewSpec_t(offsets,
extents);
1186 DASH_LOG_TRACE_VAR(
"TilePattern.block >", block_vs);
1197 const std::array<index_type, NumDimensions> & block_coords)
const 1199 DASH_LOG_TRACE_VAR(
"TilePattern.block()", block_coords);
1201 DASH_LOG_TRACE_VAR(
"TilePattern.block", _blocksize_spec.
extents());
1202 std::array<index_type, NumDimensions> offsets;
1203 std::array<size_type, NumDimensions>
extents;
1204 for (
auto d = 0; d < NumDimensions; ++d) {
1205 auto blocksize_d = _blocksize_spec.
extent(d);
1206 extents[d] = blocksize_d;
1207 offsets[d] = block_coords[d] * blocksize_d;
1209 DASH_LOG_TRACE(
"TilePattern.block",
1210 "offsets:", offsets,
1211 "extents:", extents);
1212 auto block_vs = ViewSpec_t(offsets, extents);
1213 DASH_LOG_TRACE_VAR(
"TilePattern.block >", block_vs);
1224 index_type local_block_index)
const 1237 index_type local_block_index)
const 1239 DASH_LOG_TRACE(
"TilePattern.local_block()",
1241 "lblock_idx:", local_block_index,
1242 "lblockspec:", _local_blockspec.
extents());
1245 auto l_block_coords = _local_blockspec.
coords(local_block_index);
1246 auto unit_ts_coords = _teamspec.
coords(unit);
1247 DASH_LOG_TRACE_VAR(
"TilePattern.local_block", l_block_coords);
1248 std::array<index_type, NumDimensions> offsets{};
1249 std::array<size_type, NumDimensions>
extents{};
1250 for (
auto d = 0; d < NumDimensions; ++d) {
1251 auto blocksize_d = _blocksize_spec.
extent(d);
1254 auto nunits_d = _teamspec.
extent(d);
1255 offsets[d] = ((l_block_coords[d] * nunits_d) + unit_ts_coords[d]) *
1258 auto num_blocks_d =_local_blockspec.
extent(d);
1259 if(l_block_coords[d] == (num_blocks_d - 1)){
1263 blocksize_d = remaining;
1268 ViewSpec_t block_vs(offsets,
extents);
1269 DASH_LOG_TRACE_VAR(
"TilePattern.local_block >", block_vs);
1280 index_type local_block_index)
const 1282 DASH_LOG_TRACE_VAR(
"TilePattern.local_block_local()",
1285 std::array<index_type, NumDimensions> offsets{};
1286 std::array<size_type, NumDimensions>
extents =
1289 auto l_block_coords = _local_blockspec.
coords(local_block_index);
1291 for (
auto d = 0; d < NumDimensions; ++d) {
1292 auto blocksize_d = extents[d];
1293 offsets[d] = l_block_coords[d] * blocksize_d;
1295 ViewSpec_t block_vs(offsets, extents);
1296 DASH_LOG_TRACE_VAR(
"TilePattern.local_block_local >", block_vs);
1313 return _local_blockspec;
1325 dim_t dimension)
const 1327 return _blocksize_spec.
extent(dimension);
1339 return _blocksize_spec.
size();
1364 return _local_memory_layout.
size();
1368 return LocalMemoryLayout_t(initialize_local_extents(unit)).size();
1377 return _teamspec.
size();
1386 return _memory_layout.
size();
1395 return _memory_layout.
size();
1409 constexpr
const DistributionSpec_t &
distspec()
const {
1419 return SizeSpec_t(_memory_layout.
extents());
1427 constexpr
const std::array<SizeType, NumDimensions> &
extents()
const {
1428 return _memory_layout.
extents();
1447 constexpr std::array<IndexType, NumDimensions>
coords(
1449 IndexType
index)
const {
1451 ::std::array<IndexType, NumDimensions> pos{};
1452 auto block_coords = _blockspec.
coords(index / _blocksize_spec.
size());
1453 auto phase_coords = _blocksize_spec.
coords(index % _blocksize_spec.
size());
1454 for (
auto d = 0; d < NumDimensions; ++d) {
1455 pos[d] = block_coords[d]*_blocksize_spec.
extent(d) + phase_coords[d];
1466 constexpr std::array<IndexType, NumDimensions>
coords(
1470 const ViewSpec_t & viewspec)
const {
1472 ::std::array<IndexType, NumDimensions> pos;
1473 auto block_coords = _blockspec.
coords(index / _blocksize_spec.
size(),
1475 auto phase_coords = _blocksize_spec.
coords(index % _blocksize_spec.
size(),
1477 for (
auto d = 0; d < NumDimensions; ++d) {
1478 pos[d] = block_coords[d]*_blocksize_spec.
extent(d) + phase_coords[d];
1495 return NumDimensions;
1506 auto ovf_blocksize = _memory_layout.
extent(dimension) %
1509 if (ovf_blocksize == 0) {
1513 DASH_LOG_DEBUG_VAR(
"TilePattern.underfilled_blocksize", ovf_blocksize);
1514 auto reg_blocksize =
blocksize(dimension);
1515 return reg_blocksize - ovf_blocksize;
1521 : _distspec(arguments.distspec()),
1522 _team(&arguments.team()),
1523 _myid(_team->myid()),
1524 _teamspec(arguments.teamspec()),
1525 _memory_layout(arguments.sizespec().extents()),
1526 _nunits(_teamspec.
size()),
1527 _blocksize_spec(initialize_blocksizespec(
1528 arguments.sizespec(),
1531 _blockspec(initialize_blockspec(
1532 arguments.sizespec(),
1535 _local_blockspec(initialize_local_blockspec(
1539 _local_memory_layout(
1540 initialize_local_extents(_myid)),
1542 initialize_local_capacity(_local_memory_layout))
1549 BlockSizeSpec_t initialize_blocksizespec(
1550 const SizeSpec_t & sizespec,
1551 const DistributionSpec_t &
distspec,
1552 const TeamSpec_t & teamspec)
const {
1553 DASH_LOG_TRACE(
"TilePattern.init_blocksizespec()",
1554 "sizespec:", sizespec.
extents(),
1555 "distspec:", distspec.
values(),
1556 "teamspec:", teamspec.
extents());
1558 std::array<SizeType, NumDimensions> s_blocks{};
1559 if (sizespec.
size() == 0 || teamspec.
size() == 0) {
1560 DASH_LOG_TRACE(
"TilePattern.init_blocksizespec >",
1561 "sizespec or teamspec uninitialized",
1562 "(default construction?), cancel");
1563 return BlockSizeSpec_t(s_blocks);
1565 for (
auto d = 0; d < NumDimensions; ++d) {
1567 auto extent_d = sizespec.
extent(d);
1568 auto units_d = teamspec.
extent(d);
1569 DASH_ASSERT_GT(extent_d, 0,
1570 "Extent of size spec in dimension" << d <<
"is 0");
1571 DASH_ASSERT_GT(units_d, 0,
1572 "Extent of team spec in dimension" << d <<
"is 0");
1578 s_blocks[d] = blocksize_d;
1580 DASH_LOG_TRACE_VAR(
"TilePattern.init_blocksizespec >", s_blocks);
1581 return BlockSizeSpec_t(s_blocks);
1588 BlockSpec_t initialize_blockspec(
1589 const SizeSpec_t & sizespec,
1590 const BlockSizeSpec_t & blocksizespec,
1591 const TeamSpec_t & teamspec)
const 1593 DASH_LOG_TRACE(
"TilePattern.init_blockspec()",
1594 "pattern size:", sizespec.
extents(),
1595 "block size:", blocksizespec.
extents(),
1596 "team size:", teamspec.
extents());
1598 if (teamspec.
size() == 0 || sizespec.
size() == 0) {
1599 BlockSpec_t empty_blockspec;
1600 DASH_LOG_TRACE_VAR(
"TilePattern.init_blockspec >",
1602 return empty_blockspec;
1604 std::array<SizeType, NumDimensions> n_blocks{};
1605 for (
auto d = 0; d < NumDimensions; ++d) {
1606 SizeType max_blocksize_d = blocksizespec.
extent(d);
1607 SizeType max_blocks_d = dash::math::div_ceil(
1610 n_blocks[d] = max_blocks_d;
1613 DASH_LOG_TRACE_VAR(
"TilePattern.init_blockspec >", n_blocks);
1621 BlockSpec_t initialize_local_blockspec(
1623 const BlockSizeSpec_t & blocksizespec,
1624 const TeamSpec_t & teamspec,
1627 DASH_LOG_TRACE_VAR(
"TilePattern.init_local_blockspec()",
1632 if (blockspec.
size() == 0 || teamspec.
size() == 0 ||
1633 blocksizespec.
size() == 0) {
1634 BlockSpec_t empty_blockspec;
1635 DASH_LOG_TRACE_VAR(
"TilePattern.init_local_blockspec >",
1637 return empty_blockspec;
1640 auto l_blocks = blockspec.
extents();
1642 auto unit_ts_coords = _teamspec.
coords(unit_id);
1643 DASH_LOG_TRACE_VAR(
"TilePattern.init_local_blockspec", unit_ts_coords);
1644 for (
auto d = 0; d < NumDimensions; ++d) {
1646 auto num_units_d = _teamspec.
extent(d);
1648 auto num_blocks_d = _blockspec.
extent(d);
1650 auto num_l_blocks_d = num_blocks_d / num_units_d;
1651 auto num_odd_blocks_d = num_blocks_d % num_units_d;
1652 if (num_odd_blocks_d > unit_ts_coords[d]) {
1655 l_blocks[d] = num_l_blocks_d;
1657 DASH_LOG_TRACE_VAR(
"TilePattern.init_local_blockspec >", l_blocks);
1658 DASH_LOG_DEBUG_VAR(
"TilePattern.init_local_extents >", initialize_local_extents(unit_id));
1659 return BlockSpec_t(l_blocks);
1669 SizeType initialize_local_capacity(
1672 DASH_LOG_TRACE_VAR(
"TilePattern.init_local_capacity()",
1674 auto l_capacity = local_extents.
size();
1675 DASH_LOG_TRACE_VAR(
"TilePattern.init_local_capacity >", l_capacity);
1683 void initialize_local_range()
1686 DASH_LOG_DEBUG_VAR(
"TilePattern.init_local_range()",
local_size);
1696 DASH_LOG_DEBUG_VAR(
"TilePattern.init_local_range >", _lbegin);
1697 DASH_LOG_DEBUG_VAR(
"TilePattern.init_local_range >", _lend);
1703 std::array<SizeType, NumDimensions> initialize_local_extents(
1707 DASH_LOG_DEBUG_VAR(
"TilePattern.init_local_extents()", unit);
1708 if (_teamspec.
size() == 0) {
1709 ::std::array<SizeType, NumDimensions> empty_extents = {{ }};
1710 DASH_LOG_DEBUG_VAR(
"TilePattern.init_local_extents >", empty_extents);
1711 return empty_extents;
1713 auto unit_ts_coords = _teamspec.
coords(unit);
1714 DASH_LOG_TRACE_VAR(
"TilePattern.init_local_extents", unit_ts_coords);
1715 ::std::array<SizeType, NumDimensions> l_extents{};
1716 for (
auto d = 0; d < NumDimensions; ++d) {
1718 auto num_units_d = _teamspec.
extent(d);
1720 auto num_blocks_d = _blockspec.
extent(d);
1722 auto blocksize_d = _blocksize_spec.
extent(d);
1724 auto num_l_blocks_d = num_blocks_d / num_units_d;
1725 auto num_odd_blocks_d = num_blocks_d % num_units_d;
1726 if (num_odd_blocks_d > unit_ts_coords[d]) {
1731 auto unit_ts_coord = unit_ts_coords[d];
1734 l_extents[d] = num_l_blocks_d * blocksize_d;
1736 team_unit_t last_block_unit_d((num_blocks_d % num_units_d == 0)
1738 : (num_blocks_d % num_units_d) - 1);
1740 if(unit_ts_coord == last_block_unit_d) {
1744 DASH_LOG_TRACE_VAR(
"TilePattern.init_local_extents",
1745 undfill_blocksize_d);
1746 l_extents[d] -= undfill_blocksize_d;
1749 DASH_LOG_DEBUG_VAR(
"TilePattern.init_local_extents >", l_extents);
1758 std::ostream & operator<<(
1762 typedef Index index_t;
1766 std::string storage_order = pattern.
memory_order() == ROW_MAJOR
1774 std::ostringstream ss;
1779 << storage_order <<
"," 1780 <<
typeid(index_t).name()
1786 <<
"BlockSize:" << blocksize
1789 return operator<<(os, ss.str());
1794 #include <dash/pattern/TilePattern1D.h> 1796 #endif // DASH__TILE_PATTERN_H_ team_unit_t unit_at(IndexType global_pos, const ViewSpec_t &viewspec) const
Convert given global linear index to its assigned unit id.
constexpr team_unit_t UNDEFINED_TEAM_UNIT_ID
Invalid local unit ID.
constexpr const DistributionSpec_t & distspec() const
Distribution specification of this pattern.
All blocks have identical size.
constexpr local_index_t local(IndexType g_index) const
Converts global index to its associated unit and respective local index.
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...
SizeType extent(dim_t dim) const
extent
constexpr const std::array< ElementType, NumDimensions > & values() const
Return value with all dimensions as array of NumDimensions elements.
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...
global_unit_t myid()
Shortcut to query the global unit ID of the calling unit.
constexpr 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...
team_unit_t unit_at(const std::array< IndexType, NumDimensions > &coords, const ViewSpec_t &viewspec) const
unit_at
constexpr std::enable_if< std::is_integral< IndexType >::value, IndexType >::type index(IndexType idx)
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...
bool has_local_elements(dim_t dim, IndexType dim_offset, team_unit_t unit, const ViewSpec_t &viewspec) const
is_local
IndexType global(IndexType local_index) const
Resolve an element's linear global index from the calling unit's local index of that element...
Specifies cartesian extents in a specific number of dimensions.
IndexType local_at(const std::array< IndexType, NumDimensions > &local_coords, const ViewSpec_t &viewspec) const
local
local_coords_t local(const std::array< IndexType, NumDimensions > &global_coords) const
Converts global coordinates to their associated unit and its respective local coordinates.
Specifies view parameters for implementing submat, rows and cols.
local_index_t local_block_at(const std::array< index_type, NumDimensions > &g_coords) const
Unit and local block index at given global coordinates.
IndexType at(const std::array< IndexType, NumDimensions > &global_coords, const ViewSpec_t &viewspec) const
at
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...
TilePattern(SizeType arg, Args &&... args)
Constructor, initializes a pattern from an argument list consisting of the pattern size (extent...
int dim_t
Scalar type for a dimension value, with 0 indicating the first dimension.
constexpr const BlockSpec_t & blockspec() const
Cartesian arrangement of pattern blocks.
team_unit_t unit_at(const std::array< IndexType, NumDimensions > &coords) const
Convert given coordinate in pattern to its assigned unit id.
SizeType underfilled_blocksize(dim_t dimension) const
Number of elements missing in the overflow block of given dimension compared to the regular blocksize...
IndexType at(Values ... values) const
Global coordinates to local index.
constexpr IndexType size() const
The number of elements arranged in this pattern.
constexpr SizeType local_capacity() const
Maximum number of elements assigned to a single unit in total, equivalent to the local capacity of ev...
The number of blocks assigned to units may differ.
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 SizeType blocksize(dim_t dimension) const
Maximum number of elements in a single block in the given dimension.
constexpr bool is_local(IndexType index) const
Whether the given global index is local to the unit that created this pattern instance.
constexpr 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...
Defines how a list of global indices is mapped to single units within a Team.
Block extents are constant for every dimension.
The number of assigned blocks is identical for every unit.
bool is_local(IndexType index, team_unit_t unit) const
Whether the given global index is local to the specified unit.
size_t size() const
The number of units in this team.
static constexpr MemArrange memory_order()
Memory order followed by the pattern.
internal::default_signed_index default_index_t
Signed integer type used as default for index values.
IndexType local_at(const std::array< IndexType, NumDimensions > &local_coords) const
Convert given local coordinates to linear local offset (index).
A Team instance specifies a subset of all available units.
constexpr const BlockSpec_t & local_blockspec() const
Cartesian arrangement of local pattern blocks.
constexpr std::array< IndexType, NumDimensions > global(const std::array< IndexType, NumDimensions > &local_coords) const
Converts local coordinates of a active unit to global coordinates.
constexpr IndexType num_units() const
The number of units to which this pattern's elements are mapped.
constexpr const extents_type & extents() const noexcept
Extents of the cartesian space, by dimension.
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.
constexpr IndexType capacity() const
The maximum number of elements arranged in this pattern.
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.
IndexType at(std::array< IndexType, NumDimensions > global_coords) const
Global coordinates to local index.
SizeType extent(dim_t dim) const
The extent of the cartesian space in the given dimension.
index_type block_at(const std::array< index_type, NumDimensions > &g_coords) const
block
constexpr std::array< IndexType, NumDimensions > coords(IndexType index) const
Convert given global linear offset (index) to global cartesian coordinates.
Defines a cartesian, totally-ordered index space by mapping linear indices to cartesian coordinates d...
ViewSpec_t block(const std::array< index_type, NumDimensions > &block_coords) const
View spec (offset and extents) of block at global block coordinates.
constexpr IndexType at(IndexType arg, Args... args) const
Convert the given coordinates to their respective linear index.
pattern_mapping_properties< pattern_mapping_tag::balanced, pattern_mapping_tag::unbalanced > mapping_properties
Satisfiable properties in pattern property category Mapping:
Specifies how a Pattern distributes elements to units in a specific dimension.
std::array< IndexType, NumDimensions > global(team_unit_t unit, const std::array< IndexType, NumDimensions > &local_coords) const
global
constexpr SizeSpec_t sizespec() const
Size specification of the index space mapped by this pattern.
team_unit_t unit_at(IndexType global_pos) const
Convert given global linear index to its assigned unit id.
bool operator==(const self_t &other) const
Equality comparison operator.
TilePattern(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...
constexpr const TeamSpec_t & teamspec() const
Cartesian arrangement of the Team containing the units to which this pattern's elements are mapped...
constexpr const std::array< SizeType, NumDimensions > & extents() const
Size specification (shape) 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.
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.
TilePattern(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.
static constexpr dim_t ndim()
Number of dimensions of the cartesian space partitioned by the pattern.
pattern_layout_properties< pattern_layout_tag::blocked, pattern_layout_tag::linear > layout_properties
Satisfiable properties in pattern property category Layout:
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.
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...
constexpr IndexType lbegin() const
Resolves the global index of the first local element in the pattern.
constexpr IndexType lend() const
Resolves the global index past the last local element in the pattern.
SizeType extent(dim_t dim) const
The extent of the cartesian space in the given dimension.
pattern_partitioning_properties< pattern_partitioning_tag::rectangular, pattern_partitioning_tag::balanced > partitioning_properties
Satisfiable properties in pattern property category Partitioning:
constexpr SizeType max_blocksize() const
Maximum number of elements in a single block in all dimensions.
constexpr std::array< IndexType, NumDimensions > coords(IndexType index, const ViewSpec_t &viewspec) const
Convert given global linear offset (index) to global cartesian coordinates.
IndexType global_at(const std::array< IndexType, NumDimensions > &global_coords) const
Global coordinates to global position in the pattern's iteration order.
#define DART_UNDEFINED_UNIT_ID
Undefined unit ID.
constexpr SizeType size() const noexcept
The number of discrete elements within the space spanned by the coordinate.
constexpr bool operator!=(const self_t &other) const
Inquality comparison operator.
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...
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.
constexpr SizeType size() const noexcept
The number of discrete elements within the space spanned by the coordinate.
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...
constexpr dash::Team & team() const
The Team containing the units to which this pattern's elements are mapped.
constexpr const extents_type & extents() const noexcept
Extents of the cartesian space, by dimension.
DistributionSpec describes distribution patterns of all dimensions,.
TilePattern(self_t &other)
Copy constructor using non-const lvalue reference parameter.
TilePattern & operator=(const self_t &other)=default
Assignment operator.
Generic type of mapping properties of a model satisfying the Pattern concept.