1 #ifndef DASH__DYNAMIC_PATTERN_H__INCLUDED 2 #define DASH__DYNAMIC_PATTERN_H__INCLUDED 8 #include <dash/Types.h> 9 #include <dash/Distribution.h> 10 #include <dash/Exception.h> 11 #include <dash/Dimensional.h> 12 #include <dash/Cartesian.h> 13 #include <dash/Team.h> 14 #include <dash/PatternProperties.h> 16 #include <dash/internal/Math.h> 17 #include <dash/internal/Logging.h> 18 #include <dash/internal/PatternArguments.h> 31 MemArrange Arrangement = dash::ROW_MAJOR,
44 MemArrange Arrangement,
46 class DynamicPattern<1, Arrangement, IndexType>
49 static const dim_t NumDimensions = 1;
52 static constexpr
char const * PatternName =
"DynamicPattern1D";
85 typedef DynamicPattern<NumDimensions, Arrangement, IndexType>
88 typedef typename std::make_unsigned<IndexType>::type
104 typedef internal::PatternArguments<NumDimensions, IndexType>
108 typedef IndexType index_type;
109 typedef SizeType size_type;
117 std::array<index_type, NumDimensions> coords;
127 template<
typename ... Args>
137 : DynamicPattern(PatternArguments_t(arg, args...))
140 DASH_LOG_TRACE(
"DynamicPattern()",
"Constructor with argument list");
142 _local_sizes.size(), _nunits,
143 "Number of given local sizes " << _local_sizes.size() <<
" " <<
144 "does not match number of units" << _nunits);
145 initialize_local_range();
146 DASH_LOG_TRACE(
"DynamicPattern()",
"DynamicPattern initialized");
156 const SizeSpec_t & sizespec,
158 const DistributionSpec_t & distspec,
160 const TeamSpec_t & teamspec,
163 : _size(sizespec.
size()),
164 _local_sizes(initialize_local_sizes(
168 _block_offsets(initialize_block_offsets(
170 _memory_layout(
std::array<SizeType, 1> { _size }),
171 _blockspec(initialize_blockspec(
174 _distspec(DistributionSpec_t()),
176 _myid(_team->myid()),
181 _nunits(_team->size()),
182 _blocksize(initialize_blocksize(
188 initialize_local_extent(_team->myid())),
189 _local_memory_layout(std::array<SizeType, 1> { _local_size }),
190 _local_capacity(initialize_local_capacity())
192 DASH_LOG_TRACE(
"DynamicPattern()",
"(sizespec, dist, team)");
194 _local_sizes.size(), _nunits,
195 "Number of given local sizes " << _local_sizes.size() <<
" " <<
196 "does not match number of units" << _nunits);
197 initialize_local_range();
198 DASH_LOG_TRACE(
"DynamicPattern()",
"DynamicPattern initialized");
208 const SizeSpec_t & sizespec,
210 const DistributionSpec_t & distspec,
213 : _size(sizespec.
size()),
214 _local_sizes(initialize_local_sizes(
218 _block_offsets(initialize_block_offsets(
220 _memory_layout(
std::array<SizeType, 1> { _size }),
221 _blockspec(initialize_blockspec(
224 _distspec(DistributionSpec_t()),
226 _myid(_team->myid()),
227 _teamspec(_distspec, *_team),
228 _nunits(_team->size()),
229 _blocksize(initialize_blocksize(
235 initialize_local_extent(_team->myid())),
236 _local_memory_layout(std::array<SizeType, 1> { _local_size }),
237 _local_capacity(initialize_local_capacity())
239 DASH_LOG_TRACE(
"DynamicPattern()",
"(sizespec, dist, team)");
241 _local_sizes.size(), _nunits,
242 "Number of given local sizes " << _local_sizes.size() <<
" " <<
243 "does not match number of units" << _nunits);
244 initialize_local_range();
245 DASH_LOG_TRACE(
"DynamicPattern()",
"DynamicPattern initialized");
254 template<
typename ... Args>
257 const std::vector<size_type> & local_sizes,
266 : DynamicPattern(local_sizes, PatternArguments_t(arg, args...))
268 DASH_LOG_TRACE(
"DynamicPattern()",
"Constructor with argument list");
270 _local_sizes.size(), _nunits,
271 "Number of given local sizes " << _local_sizes.size() <<
" " <<
272 "does not match number of units" << _nunits);
273 initialize_local_range();
274 DASH_LOG_TRACE(
"DynamicPattern()",
"DynamicPattern initialized");
284 const std::vector<size_type> & local_sizes,
286 const TeamSpec_t & teamspec,
289 : _size(initialize_size(
291 _local_sizes(local_sizes),
292 _block_offsets(initialize_block_offsets(
294 _memory_layout(
std::array<SizeType, 1> { _size }),
295 _blockspec(initialize_blockspec(
298 _distspec(DistributionSpec_t()),
300 _myid(_team->myid()),
305 _nunits(_team->size()),
306 _blocksize(initialize_blocksize(
312 initialize_local_extent(_team->myid())),
313 _local_memory_layout(std::array<SizeType, 1> { _local_size }),
314 _local_capacity(initialize_local_capacity())
316 DASH_LOG_TRACE(
"DynamicPattern()",
"(sizespec, dist, teamspec, team)");
318 _local_sizes.size(), _nunits,
319 "Number of given local sizes " << _local_sizes.size() <<
" " <<
320 "does not match number of units" << _nunits);
321 initialize_local_range();
322 DASH_LOG_TRACE(
"DynamicPattern()",
"DynamicPattern initialized");
332 const std::vector<size_type> & local_sizes,
335 : _size(initialize_size(
337 _local_sizes(local_sizes),
338 _block_offsets(initialize_block_offsets(
340 _memory_layout(
std::array<SizeType, 1> { _size }),
341 _blockspec(initialize_blockspec(
344 _distspec(DistributionSpec_t()),
346 _myid(_team->myid()),
347 _teamspec(_distspec, *_team),
348 _nunits(_team->size()),
349 _blocksize(initialize_blocksize(
355 initialize_local_extent(_team->myid())),
356 _local_memory_layout(std::array<SizeType, 1> { _local_size }),
357 _local_capacity(initialize_local_capacity())
359 DASH_LOG_TRACE(
"DynamicPattern()",
"(sizespec, dist, team)");
361 _local_sizes.size(), _nunits,
362 "Number of given local sizes " << _local_sizes.size() <<
" " <<
363 "does not match number of units" << _nunits);
364 initialize_local_range();
365 DASH_LOG_TRACE(
"DynamicPattern()",
"DynamicPattern initialized");
372 : _size(other._size),
373 _local_sizes(other._local_sizes),
374 _block_offsets(other._block_offsets),
375 _memory_layout(other._memory_layout),
376 _blockspec(other._blockspec),
377 _distspec(other._distspec),
380 _teamspec(other._teamspec),
381 _nunits(other._nunits),
382 _blocksize(other._blocksize),
383 _nblocks(other._nblocks),
384 _local_size(other._local_size),
385 _local_memory_layout(other._local_memory_layout),
386 _local_capacity(other._local_capacity),
387 _lbegin(other._lbegin),
392 DASH_LOG_TRACE(
"DynamicPattern(other)",
"DynamicPattern copied");
402 : DynamicPattern(static_cast<const self_t &>(other))
410 const self_t & other)
const 412 if (
this == &other) {
418 _size == other._size &&
419 _local_sizes == other._local_sizes &&
420 _distspec == other._distspec &&
421 _teamspec == other._teamspec &&
422 _nblocks == other._nblocks &&
423 _blocksize == other._blocksize &&
424 _nunits == other._nunits
433 const self_t & other)
const 435 return !(*
this == other);
441 self_t & operator=(
const self_t & other) =
default;
472 _local_sizes[unit] = local_size;
480 _local_sizes[_myid] = local_size;
502 const std::array<IndexType, NumDimensions> & coords,
504 const ViewSpec_t & viewspec)
const 506 DASH_LOG_TRACE_VAR(
"DynamicPattern.unit_at()", coords);
508 team_unit_t unit_id(((coords[0] + viewspec.offset(0)) / _blocksize)
510 DASH_LOG_TRACE_VAR(
"DynamicPattern.unit_at >", unit_id);
520 const std::array<IndexType, NumDimensions> & g_coords)
const 522 DASH_LOG_TRACE_VAR(
"DynamicPattern.unit_at()", g_coords);
523 auto g_coord = g_coords[0];
524 for (
team_unit_t unit_idx{0}; unit_idx < _nunits - 1; ++unit_idx) {
525 if (_block_offsets[unit_idx+1] >= g_coord) {
526 DASH_LOG_TRACE_VAR(
"DynamicPattern.unit_at >", unit_idx);
530 DASH_LOG_TRACE_VAR(
"DynamicPattern.unit_at >", _nunits-1);
541 IndexType global_pos,
543 const ViewSpec_t & viewspec)
const 545 DASH_LOG_TRACE_VAR(
"DynamicPattern.unit_at()", global_pos);
546 DASH_LOG_TRACE_VAR(
"DynamicPattern.unit_at()", viewspec);
548 auto g_coord = global_pos + viewspec.offset(0);
549 for (
team_unit_t unit_idx{0}; unit_idx < _nunits - 1; ++unit_idx) {
550 if (_block_offsets[unit_idx+1] >= static_cast<size_type>(g_coord)) {
551 DASH_LOG_TRACE_VAR(
"DynamicPattern.unit_at >", unit_idx);
555 DASH_LOG_TRACE_VAR(
"DynamicPattern.unit_at >", _nunits-1);
566 IndexType g_index)
const 568 DASH_LOG_TRACE_VAR(
"DynamicPattern.unit_at()", g_index);
569 for (
team_unit_t unit_idx{0}; unit_idx < _nunits - 1; ++unit_idx) {
570 if (_block_offsets[unit_idx+1] > static_cast<size_type>(g_index)) {
571 DASH_LOG_TRACE_VAR(
"DynamicPattern.unit_at >", unit_idx);
575 DASH_LOG_TRACE_VAR(
"DynamicPattern.unit_at >", _nunits-1);
596 "Wrong dimension for Pattern::local_extent. " <<
597 "Expected dimension = 0, got " << dim);
616 "Wrong dimension for Pattern::local_extent. " <<
617 "Expected dimension = 0, got " << dim);
635 DASH_LOG_DEBUG_VAR(
"DynamicPattern.local_extents()", unit);
636 DASH_LOG_DEBUG_VAR(
"DynamicPattern.local_extents >", _local_size);
637 return std::array<SizeType, 1> { _local_size };
652 const std::array<IndexType, NumDimensions> & local_coords,
654 const ViewSpec_t & viewspec)
const 656 return local_coords[0] + viewspec.offset(0);
666 const std::array<IndexType, NumDimensions> & local_coords)
const 668 return local_coords[0];
680 const std::array<IndexType, NumDimensions> & g_coords)
const 682 DASH_LOG_TRACE_VAR(
"DynamicPattern.local()", g_coords);
683 IndexType g_index = g_coords[0];
684 local_index_t l_index;
685 for (
auto unit_idx = _nunits-1; unit_idx >= 0; --unit_idx) {
686 index_type block_offset = _block_offsets[unit_idx];
687 if (block_offset <= g_index) {
688 l_index.unit = unit_idx;
689 l_index.index = g_index - block_offset;
690 DASH_LOG_TRACE_VAR(
"DynamicPattern.local >", l_index.unit);
691 DASH_LOG_TRACE_VAR(
"DynamicPattern.local >", l_index.index);
697 "DynamicPattern.local: global coord " << g_index <<
" is out of bounds");
708 IndexType g_index)
const 710 DASH_LOG_TRACE_VAR(
"DynamicPattern.local()", g_index);
711 DASH_LOG_TRACE_VAR(
"DynamicPattern.local", _block_offsets.size());
712 DASH_ASSERT_GT(_nunits, 0,
714 DASH_ASSERT_GE(_block_offsets.size(), _nunits,
715 "missing block offsets");
716 local_index_t l_index;
717 index_type unit_idx =
static_cast<index_type
>(_nunits-1);
718 for (; unit_idx >= 0; --unit_idx) {
719 DASH_LOG_TRACE_VAR(
"DynamicPattern.local", unit_idx);
720 index_type block_offset = _block_offsets[unit_idx];
721 DASH_LOG_TRACE_VAR(
"DynamicPattern.local", block_offset);
722 if (block_offset <= g_index) {
723 l_index.unit = unit_idx;
724 l_index.index = g_index - block_offset;
725 DASH_LOG_TRACE_VAR(
"DynamicPattern.local >", l_index.unit);
726 DASH_LOG_TRACE_VAR(
"DynamicPattern.local >", l_index.index);
732 "DynamicPattern.local: global index " << g_index <<
" is out of bounds");
742 const std::array<IndexType, NumDimensions> & g_coords)
const 744 DASH_LOG_TRACE_VAR(
"DynamicPattern.local_coords()", g_coords);
745 IndexType g_index = g_coords[0];
746 index_type unit_idx =
static_cast<index_type
>(_nunits-1);
747 for (; unit_idx >= 0; --unit_idx) {
748 index_type block_offset = _block_offsets[unit_idx];
749 if (block_offset <= g_index) {
750 auto l_coord = g_index - block_offset;
751 DASH_LOG_TRACE_VAR(
"DynamicPattern.local_coords >", l_coord);
752 return std::array<IndexType, 1> { l_coord };
757 "DynamicPattern.local_coords: global index " << g_index <<
758 " is out of bounds");
768 const std::array<IndexType, NumDimensions> & g_coords)
const 770 IndexType g_index = g_coords[0];
771 DASH_LOG_TRACE_VAR(
"DynamicPattern.local_index()", g_coords);
772 local_index_t l_index;
773 index_type unit_idx =
static_cast<index_type
>(_nunits-1);
774 for (; unit_idx >= 0; --unit_idx) {
775 index_type block_offset = _block_offsets[unit_idx];
776 if (block_offset <= g_index) {
777 l_index.unit = unit_idx;
778 l_index.index = g_index - block_offset;
779 DASH_LOG_TRACE_VAR(
"DynamicPattern.local >", l_index.unit);
780 DASH_LOG_TRACE_VAR(
"DynamicPattern.local >", l_index.index);
786 "DynamicPattern.local: global index " << g_index <<
" is out of bounds");
798 std::array<IndexType, NumDimensions>
global(
800 const std::array<IndexType, NumDimensions> & local_coords)
const 802 DASH_LOG_DEBUG_VAR(
"DynamicPattern.global()", unit);
803 DASH_LOG_DEBUG_VAR(
"DynamicPattern.global()", local_coords);
804 DASH_LOG_TRACE_VAR(
"DynamicPattern.global", _nunits);
809 index_type glob_index = _block_offsets[unit] + local_coords[0];
810 DASH_LOG_TRACE_VAR(
"DynamicPattern.global >", glob_index);
811 return std::array<IndexType, 1> { glob_index };
819 std::array<IndexType, NumDimensions>
global(
820 const std::array<IndexType, NumDimensions> & l_coords)
const 822 return global(_team->myid(), l_coords);
835 IndexType l_index)
const 837 return global(unit, std::array<IndexType, 1> { l_index })[0];
849 IndexType l_index)
const 851 return global(_team->myid(), std::array<IndexType, 1> { l_index })[0];
864 const std::array<IndexType, NumDimensions> & l_coords)
const 866 auto g_index =
global(unit, l_coords[0]);
883 const std::array<IndexType, NumDimensions> & g_coords)
const 885 return local_coords(g_coords)[0];
896 const std::array<IndexType, NumDimensions> & g_coords,
897 const ViewSpec_t & viewspec)
const 899 auto vs_coords = g_coords;
900 vs_coords[0] += viewspec.offset(0);
901 return local_coords(vs_coords)[0];
911 template<
typename ... Values>
912 IndexType
at(IndexType value, Values ... values)
const 915 sizeof...(values) == NumDimensions-1,
916 "Wrong parameter number");
917 std::array<IndexType, NumDimensions> inputindex = {
918 value, (IndexType)values...
920 return at(inputindex);
937 IndexType dim_offset,
941 const ViewSpec_t & viewspec)
const 945 "Wrong dimension for Pattern::has_local_elements. " <<
946 "Expected dimension = 0, got " << dim);
947 DASH_LOG_TRACE_VAR(
"DynamicPattern.has_local_elements()", dim_offset);
948 DASH_LOG_TRACE_VAR(
"DynamicPattern.has_local_elements()", unit);
949 DASH_LOG_TRACE_VAR(
"DynamicPattern.has_local_elements()", viewspec);
952 "DynamicPattern.has_local_elements is not implemented");
964 DASH_LOG_TRACE_VAR(
"DynamicPattern.is_local()", index);
965 DASH_LOG_TRACE_VAR(
"DynamicPattern.is_local()", unit);
966 bool is_loc = index >= _block_offsets[unit] &&
967 (unit == _nunits-1 ||
968 index < _block_offsets[unit+1]);
969 DASH_LOG_TRACE_VAR(
"DynamicPattern.is_local >", is_loc);
980 IndexType
index)
const 982 auto unit = team().myid();
983 DASH_LOG_TRACE_VAR(
"DynamicPattern.is_local()", index);
984 DASH_LOG_TRACE_VAR(
"DynamicPattern.is_local", unit);
985 bool is_loc = index >= _block_offsets[unit] &&
986 (unit == _nunits-1 ||
987 index < _block_offsets[unit+1]);
988 DASH_LOG_TRACE_VAR(
"DynamicPattern.is_local >", is_loc);
1011 const std::array<index_type, NumDimensions> & g_coords)
const 1013 DASH_LOG_TRACE_VAR(
"DynamicPattern.block_at()", g_coords);
1014 auto g_coord = g_coords[0];
1015 for (index_type block_idx = 0; block_idx < _nunits - 1; ++block_idx) {
1016 if (_block_offsets[block_idx+1] >= g_coord) {
1017 DASH_LOG_TRACE_VAR(
"DynamicPattern.block_at >", block_idx);
1021 DASH_LOG_TRACE_VAR(
"DynamicPattern.block_at >", _nunits-1);
1030 index_type g_block_index)
const 1032 DASH_LOG_DEBUG_VAR(
"DynamicPattern<1>.block >", g_block_index);
1033 index_type offset = _block_offsets[g_block_index];
1034 auto block_size = _local_sizes[g_block_index];
1035 std::array<index_type, NumDimensions> offsets = { offset };
1036 std::array<size_type, NumDimensions> extents = { block_size };
1037 ViewSpec_t block_vs(offsets, extents);
1038 DASH_LOG_DEBUG_VAR(
"DynamicPattern<1>.block >", block_vs);
1047 index_type l_block_index)
const 1049 DASH_LOG_DEBUG_VAR(
"DynamicPattern<1>.local_block()", l_block_index);
1052 "DynamicPattern always assigns exactly 1 block to a single unit");
1053 index_type block_offset = _block_offsets[_team->myid()];
1054 size_type block_size = _local_sizes[_team->myid()];
1055 std::array<index_type, NumDimensions> offsets = { block_offset };
1056 std::array<size_type, NumDimensions> extents = { block_size };
1057 ViewSpec_t block_vs(offsets, extents);
1058 DASH_LOG_DEBUG_VAR(
"DynamicPattern<1>.local_block >", block_vs);
1067 index_type l_block_index)
const 1069 DASH_LOG_DEBUG_VAR(
"DynamicPattern<1>.local_block_local >", l_block_index);
1070 size_type block_size = _local_sizes[_team->myid()];
1071 std::array<index_type, NumDimensions> offsets = { 0 };
1072 std::array<size_type, NumDimensions> extents = { block_size };
1073 ViewSpec_t block_vs(offsets, extents);
1074 DASH_LOG_DEBUG_VAR(
"DynamicPattern<1>.local_block_local >", block_vs);
1087 dim_t dimension)
const 1114 return _local_capacity;
1187 return SizeSpec_t(std::array<SizeType, 1> { _size });
1195 const std::array<SizeType, NumDimensions> &
extents()
const 1197 return std::array<SizeType, 1> { _size };
1218 IndexType
index)
const 1220 return std::array<IndexType, 1> { index };
1231 const ViewSpec_t & viewspec)
const 1233 return std::array<IndexType, 1> { index + viewspec.offset(0) };
1256 DynamicPattern(
const PatternArguments_t & arguments)
1258 initialize_local_sizes(
1259 arguments.sizespec().size(),
1260 arguments.distspec(),
1266 const std::vector<size_type> & local_sizes,
1267 const PatternArguments_t & arguments)
1268 : _size(arguments.sizespec().size()),
1269 _local_sizes(local_sizes),
1270 _block_offsets(initialize_block_offsets(
1272 _memory_layout(std::array<SizeType, 1> { _size }),
1273 _blockspec(initialize_blockspec(
1276 _distspec(arguments.distspec()),
1277 _team(&arguments.team()),
1278 _myid(_team->myid()),
1279 _teamspec(arguments.teamspec()),
1280 _nunits(_team->size()),
1281 _blocksize(initialize_blocksize(
1287 initialize_local_extent(_team->myid())),
1288 _local_memory_layout(std::array<SizeType, 1> { _local_size }),
1289 _local_capacity(initialize_local_capacity())
1295 SizeType initialize_size(
1296 const std::vector<size_type> & local_sizes)
const 1298 DASH_LOG_TRACE_VAR(
"DynamicPattern.init_size()", local_sizes);
1300 for (size_type unit_idx = 0; unit_idx < local_sizes.size(); ++unit_idx) {
1301 size += local_sizes[unit_idx];
1303 DASH_LOG_TRACE_VAR(
"DynamicPattern.init_size >", size);
1311 std::vector<size_type> initialize_local_sizes(
1312 size_type total_size,
1313 const DistributionSpec_t & distspec,
1316 DASH_LOG_TRACE_VAR(
"DynamicPattern.init_local_sizes()", total_size);
1317 std::vector<size_type> l_sizes;
1318 auto nunits = team.
size();
1319 DASH_LOG_TRACE_VAR(
"DynamicPattern.init_local_sizes()", nunits);
1323 auto dist_type = distspec[0].type;
1324 DASH_LOG_TRACE_VAR(
"DynamicPattern.init_local_sizes()", dist_type);
1326 if (dist_type == dash::internal::DIST_BLOCKED ||
1327 dist_type == dash::internal::DIST_TILE) {
1328 auto blocksize = dash::math::div_ceil(total_size, nunits);
1329 for (size_type u = 0; u < nunits; ++u) {
1330 l_sizes.push_back(blocksize);
1334 }
else if (dist_type == dash::internal::DIST_UNDEFINED) {
1335 for (size_type u = 0; u < nunits; ++u) {
1336 l_sizes.push_back(0);
1339 }
else if (dist_type == dash::internal::DIST_NONE) {
1340 l_sizes.push_back(total_size);
1341 for (size_type u = 0; u < nunits-1; ++u) {
1342 l_sizes.push_back(0);
1348 "DynamicPattern expects TILE (" << dash::internal::DIST_TILE <<
") " <<
1349 "or BLOCKED (" << dash::internal::DIST_BLOCKED <<
") " <<
1350 "distribution, got " << dist_type);
1352 DASH_LOG_TRACE_VAR(
"DynamicPattern.init_local_sizes >", l_sizes);
1356 BlockSpec_t initialize_blockspec(
1358 const std::vector<size_type> & local_sizes)
const 1360 DASH_LOG_TRACE_VAR(
"DynamicPattern.init_blockspec", local_sizes);
1361 BlockSpec_t blockspec({
1362 static_cast<size_type
>(local_sizes.size())
1364 DASH_LOG_TRACE_VAR(
"DynamicPattern.init_blockspec >", blockspec);
1372 std::vector<size_type> initialize_block_offsets(
1373 const std::vector<size_type> & local_sizes)
const 1375 DASH_LOG_TRACE_VAR(
"DynamicPattern.init_block_offsets", local_sizes);
1376 std::vector<size_type> block_offsets;
1377 if (local_sizes.size() > 0) {
1379 block_offsets.push_back(0);
1380 for (size_type unit_idx = 0;
1381 unit_idx < local_sizes.size()-1;
1384 auto block_offset = block_offsets[unit_idx] +
1385 local_sizes[unit_idx];
1386 block_offsets.push_back(block_offset);
1389 DASH_LOG_TRACE_VAR(
"DynamicPattern.init_block_offsets >", block_offsets);
1390 return block_offsets;
1397 SizeType initialize_blocksize(
1399 const DistributionSpec_t & distspec,
1400 SizeType nunits)
const 1402 DASH_LOG_TRACE_VAR(
"DynamicPattern.init_blocksize", nunits);
1413 SizeType initialize_num_local_blocks(
1414 SizeType num_blocks,
1416 const DistributionSpec_t & distspec,
1418 SizeType local_size)
const 1420 auto num_l_blocks = local_size;
1421 if (blocksize > 0) {
1422 num_l_blocks = dash::math::div_ceil(
1428 DASH_LOG_TRACE_VAR(
"DynamicPattern.init_num_local_blocks", num_l_blocks);
1429 return num_l_blocks;
1435 SizeType initialize_local_capacity()
const 1437 SizeType l_capacity = 0;
1441 DASH_LOG_TRACE_VAR(
"DynamicPattern.init_lcapacity", _nunits);
1445 _local_sizes.end()));
1446 DASH_LOG_DEBUG_VAR(
"DynamicPattern.init_lcapacity >", l_capacity);
1454 void initialize_local_range()
1456 auto l_size = _local_size;
1457 DASH_LOG_DEBUG_VAR(
"DynamicPattern.init_local_range()", l_size);
1467 _lend =
global(l_size - 1) + 1;
1469 DASH_LOG_DEBUG_VAR(
"DynamicPattern.init_local_range >", _lbegin);
1470 DASH_LOG_DEBUG_VAR(
"DynamicPattern.init_local_range >", _lend);
1476 SizeType initialize_local_extent(
1479 DASH_LOG_DEBUG_VAR(
"DynamicPattern.init_local_extent()", unit);
1480 DASH_LOG_DEBUG_VAR(
"DynamicPattern.init_local_extent()", _nunits);
1485 SizeType l_extent = _local_sizes[
static_cast<int>(unit)];
1486 DASH_LOG_DEBUG_VAR(
"DynamicPattern.init_local_extent >", l_extent);
1494 std::vector<size_type> _local_sizes;
1496 std::vector<size_type> _block_offsets;
1498 MemoryLayout_t _memory_layout;
1500 BlockSpec_t _blockspec;
1503 DistributionSpec_t _distspec;
1509 TeamSpec_t _teamspec;
1511 SizeType _nunits = 0;
1513 SizeType _blocksize = 0;
1515 SizeType _nblocks = 0;
1517 SizeType _local_size;
1519 LocalMemoryLayout_t _local_memory_layout;
1521 SizeType _local_capacity;
1531 #endif // DASH__DYNAMIC_PATTERN_H__INCLUDED constexpr team_unit_t UNDEFINED_TEAM_UNIT_ID
Invalid local unit ID.
const BlockSpec_t & blockspec() const
block
All blocks have identical size.
constexpr std::enable_if< std::is_integral< IndexType >::value, IndexType >::type index(IndexType idx)
size_t size()
Return the number of units in the global team.
IndexType global_index(team_unit_t unit, const std::array< IndexType, NumDimensions > &l_coords) const
Resolve an element's linear global index from a given unit's local coordinates of that element...
DynamicPattern(const SizeSpec_t &sizespec, const DistributionSpec_t &distspec, Team &team=dash::Team::All())
Constructor, initializes a pattern from explicit instances of SizeSpec, DistributionSpec and Team...
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...
std::array< IndexType, NumDimensions > global(const std::array< IndexType, NumDimensions > &l_coords) const
Converts local coordinates of active unit to global coordinates.
Specifies cartesian extents in a specific number of dimensions.
IndexType at(const std::array< IndexType, NumDimensions > &g_coords, const ViewSpec_t &viewspec) const
Global coordinates and viewspec to local index.
const std::array< SizeType, NumDimensions > & extents() const
Size specification of the index space mapped by this pattern.
Specifies view parameters for implementing submat, rows and cols.
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...
DynamicPattern(const std::vector< size_type > &local_sizes, const TeamSpec_t &teamspec, dash::Team &team=dash::Team::All())
Constructor, initializes a pattern from explicit instances of SizeSpec, DistributionSpec, TeamSpec and a Team.
int dim_t
Scalar type for a dimension value, with 0 indicating the first dimension.
IndexType local_extent(dim_t dim) const
The actual number of elements in this pattern that are local to the calling unit in the given dimensi...
SizeSpec_t sizespec() const
Size specification of the index space mapped by this pattern.
pattern_partitioning_properties< pattern_partitioning_tag::minimal, pattern_partitioning_tag::rectangular, pattern_partitioning_tag::balanced, pattern_partitioning_tag::unbalanced, pattern_partitioning_tag::dynamic > partitioning_properties
Satisfiable properties in pattern property category Partitioning:
team_unit_t unit_at(const std::array< IndexType, NumDimensions > &coords, const ViewSpec_t &viewspec) const
unit_at
IndexType extent(dim_t dim) const
extent
const DistributionSpec_t & distspec() const
Distribution specification of this pattern.
IndexType lbegin() const
Resolves the global index of the first local element in the pattern.
pattern_mapping_properties< pattern_mapping_tag::unbalanced > mapping_properties
Satisfiable properties in pattern property category Mapping:
ViewSpec_t block(index_type g_block_index) const
View spec (offset and extents) of block at global linear block index in cartesian element space...
The number of blocks assigned to units may differ.
local_index_t local(IndexType g_index) const
Converts global index to its associated unit and respective local index.
void balance()
Balance the number of local elements across all units in the pattern's associated team...
static constexpr dim_t ndim()
Number of dimensions of the cartesian space partitioned by the pattern.
SizeType local_capacity(team_unit_t unit=UNDEFINED_TEAM_UNIT_ID) const
Maximum number of elements assigned to a single unit in total, equivalent to the local capacity of ev...
bool operator==(const self_t &other) const
Equality comparison operator.
Minimal number of blocks in every dimension, typically at most one block per unit.
Block extents are constant for every dimension.
constexpr std::enable_if< dash::view_traits< ViewType >::is_view::value &&dash::view_traits< ViewType >::is_local::value, const typename ViewType::global_type & >::type global(const ViewType &v)
size_t size() const
The number of units in this team.
index_type block_at(const std::array< index_type, NumDimensions > &g_coords) const
Index of block at given global coordinates.
Cartesian space defined by extents in n dimensions.
IndexType at(const std::array< IndexType, NumDimensions > &g_coords) const
at
internal::default_signed_index default_index_t
Signed integer type used as default for index values.
dash::Team & team() const
The Team containing the units to which this pattern's elements are mapped.
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.
std::array< IndexType, NumDimensions > coords(IndexType index, const ViewSpec_t &viewspec) const
Convert given global linear offset (index) to global cartesian coordinates using viewspec.
Elements are contiguous in local memory within a single block and thus indexed blockwise.
DynamicPattern(const self_t &other)
Copy constructor.
DynamicPattern(const SizeSpec_t &sizespec, const DistributionSpec_t &distspec, const TeamSpec_t &teamspec, Team &team=dash::Team::All())
Constructor, initializes a pattern from explicit instances of SizeSpec, DistributionSpec, TeamSpec and Team.
Defines a cartesian, totally-ordered index space by mapping linear indices to cartesian coordinates d...
Data range is partitioned dynamically.
IndexType global(team_unit_t unit, IndexType l_index) const
Resolve an element's linear global index from the given unit's local index of that element...
bool operator!=(const self_t &other) const
Inquality comparison operator.
SizeType blocksize(dim_t dimension) const
Maximum number of elements in a single block in the given dimension.
DynamicPattern(const std::vector< size_type > &local_sizes, Team &team=dash::Team::All())
Constructor, initializes a pattern from explicit instances of SizeSpec, DistributionSpec, TeamSpec and a Team.
Size of blocks may differ.
IndexType local_at(const std::array< IndexType, NumDimensions > &local_coords, const ViewSpec_t &viewspec) const
local
IndexType at(IndexType value, Values ... values) const
Global coordinates to local index.
DynamicPattern(SizeType arg, Args &&... args)
Constructor, initializes a pattern from an argument list consisting of the pattern size (extent...
pattern_layout_properties< pattern_layout_tag::blocked, pattern_layout_tag::linear > layout_properties
Satisfiable properties in pattern property category Layout:
struct dash::unit_id< dash::local_unit, dart_team_unit_t > team_unit_t
Unit ID to use for team-local IDs.
local_coords_t local(const std::array< IndexType, NumDimensions > &g_coords) const
Converts global coordinates to their associated unit and its respective local coordinates.
std::array< SizeType, NumDimensions > local_extents(team_unit_t unit) const
The actual number of elements in this pattern that are local to the given unit, by dimension...
ViewSpec_t local_block(index_type l_block_index) const
View spec (offset and extents) of block at local linear block index in global cartesian element space...
IndexType local_at(const std::array< IndexType, NumDimensions > &local_coords) const
Convert given local coordinates to linear local offset (index).
bool has_local_elements(dim_t dim, IndexType dim_offset, team_unit_t unit, const ViewSpec_t &viewspec) const
is_local
bool is_local(IndexType index, team_unit_t unit) const
Whether the given global index is local to the specified unit.
GlobIter max_element(const GlobIter &first, const GlobIter &last, Compare compare=Compare())
Finds an iterator pointing to the element with the greatest value in the range [first,last).
void local_resize(team_unit_t unit, size_type local_size)
resize / balance
static constexpr MemArrange memory_order()
Memory order followed by the pattern.
SizeType max_blocksize() const
Maximum number of elements in a single block in all dimensions.
std::array< IndexType, NumDimensions > local_coords(const std::array< IndexType, NumDimensions > &g_coords) const
Converts global coordinates to their associated unit's respective local coordinates.
DynamicPattern(const std::vector< size_type > &local_sizes, 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.
ViewSpec_t local_block_local(index_type l_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(const std::array< IndexType, NumDimensions > &g_coords) const
Convert given coordinate in pattern to its assigned unit id.
team_unit_t unit_at(IndexType global_pos, const ViewSpec_t &viewspec) const
Convert given global linear index to its assigned unit id.
IndexType global(IndexType l_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 g_index) const
Convert given global linear index to its assigned unit id.
static Team & All()
The invariant Team instance containing all available units.
see https://en.cppreference.com/w/cpp/feature_test for recommended feature tests
IndexType lend() const
Resolves the global index past the last local element in the pattern.
IndexType capacity() const
The maximum number of elements arranged in this pattern.
DynamicPattern(self_t &other)
Copy constructor using non-const lvalue reference parameter.
IndexType size() const
The number of elements arranged in this pattern.
local_index_t local_index(const std::array< IndexType, NumDimensions > &g_coords) const
Converts global coordinates to their associated unit and their respective local index.
IndexType num_units() const
The number of units to which this pattern's elements are mapped.
const TeamSpec_t & teamspec() const
Cartesian arrangement of the Team containing the units to which this pattern's elements are mapped...
DistributionSpec describes distribution patterns of all dimensions,.
void local_resize(size_type local_size)
Update the number of local elements of the active unit.
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.