DASH  0.3.0
PatternProperties.h
1 #ifndef DASH__PATTERN_PROPERTIES_H__
2 #define DASH__PATTERN_PROPERTIES_H__
3 
4 #include <dash/Types.h>
5 #include <sstream>
6 #include <iostream>
7 
8 namespace dash {
9 
56 // Pattern Layout Properties
59 
80 {
81  typedef enum {
83  any,
84 
87 
90 
94 
98 
103 
104  } type;
105 };
106 
110 template<pattern_layout_tag::type ... Tags>
112 {
114 
116 
118  static const bool row_major = true;
119 
121  static const bool col_major = false;
122 
124  static const bool blocked = false;
125 
127  static const bool canonical = true;
128 
132  static const bool linear = false;
133 };
134 
135 #ifndef DOXYGEN
136 
144 template<pattern_layout_tag::type ... Tags>
146  pattern_layout_tag::type::blocked, Tags ...>
147 : public pattern_layout_properties<Tags ...>
148 {
150  static const bool blocked;
151  static const bool canonical;
152 };
153 
154 template<pattern_layout_tag::type ... Tags>
155 const bool
157  pattern_layout_tag::type::blocked, Tags ...
158 >::blocked = true;
159 
160 template<pattern_layout_tag::type ... Tags>
161 const bool
163  pattern_layout_tag::type::blocked, Tags ...
164 >::canonical = false;
165 
173 template<pattern_layout_tag::type ... Tags>
175  pattern_layout_tag::type::canonical, Tags ...>
176 : public pattern_layout_properties<Tags ...>
177 {
179  static const bool canonical;
180  static const bool blocked;
181 };
182 
183 template<pattern_layout_tag::type ... Tags>
184 const bool
186  pattern_layout_tag::type::canonical, Tags ...
187 >::blocked = false;
188 
189 template<pattern_layout_tag::type ... Tags>
190 const bool
192  pattern_layout_tag::type::canonical, Tags ...
193 >::canonical = true;
194 
202 template<pattern_layout_tag::type ... Tags>
204  pattern_layout_tag::type::linear, Tags ...>
205 : public pattern_layout_properties<Tags ...>
206 {
210  static const bool linear;
211 };
212 
213 template<pattern_layout_tag::type ... Tags>
214 const bool
216  pattern_layout_tag::type::linear, Tags ...
217 >::linear = true;
218 
219 #endif // DOXYGEN
220 
222 // Pattern Mapping Properties
224 
249 {
250  typedef enum {
253 
256 
259 
262 
266 
269 
273 
276  cyclic
277 
278  } type;
279 };
280 
306 template<pattern_mapping_tag::type ... Tags>
308 {
310 
312 
314  static const bool balanced = false;
315 
317  static const bool unbalanced = false;
318 
320  static const bool neighbor = false;
321 
324  static const bool shifted = false;
325 
327  static const bool diagonal = false;
328 
331  static const bool multiple = false;
332 
335  static const bool cyclic = false;
336 };
337 
338 #ifndef DOXYGEN
339 
347 template<pattern_mapping_tag::type ... Tags>
349  pattern_mapping_tag::type::balanced, Tags ...>
350 : public pattern_mapping_properties<Tags ...>
351 {
353  static const bool balanced;
354 };
355 
356 template<pattern_mapping_tag::type ... Tags>
357 const bool
359  pattern_mapping_tag::type::balanced, Tags ...
360 >::balanced = true;
361 
369 template<pattern_mapping_tag::type ... Tags>
371  pattern_mapping_tag::type::unbalanced, Tags ...>
372 : public pattern_mapping_properties<Tags ...>
373 {
375  static const bool unbalanced;
376 };
377 
378 template<pattern_mapping_tag::type ... Tags>
379 const bool
381  pattern_mapping_tag::type::unbalanced, Tags ...
382 >::unbalanced = true;
383 
391 template<pattern_mapping_tag::type ... Tags>
393  pattern_mapping_tag::type::neighbor, Tags ...>
394 : public pattern_mapping_properties<Tags ...>
395 {
397  static const bool neighbor;
398 };
399 
400 template<pattern_mapping_tag::type ... Tags>
401 const bool
403  pattern_mapping_tag::type::neighbor, Tags ...
404 >::neighbor = true;
405 
413 template<pattern_mapping_tag::type ... Tags>
415  pattern_mapping_tag::type::shifted, Tags ...>
416 : public pattern_mapping_properties<Tags ...>
417 {
420  static const bool shifted;
421 };
422 
423 template<pattern_mapping_tag::type ... Tags>
424 const bool
426  pattern_mapping_tag::type::shifted, Tags ...
427 >::shifted = true;
428 
436 template<pattern_mapping_tag::type ... Tags>
438  pattern_mapping_tag::type::diagonal, Tags ...>
439 : public pattern_mapping_properties<Tags ...>
440 {
442  static const bool diagonal;
443 };
444 
445 template<pattern_mapping_tag::type ... Tags>
446 const bool
448  pattern_mapping_tag::type::diagonal, Tags ...
449 >::diagonal = true;
450 
458 template<pattern_mapping_tag::type ... Tags>
460  pattern_mapping_tag::type::multiple, Tags ...>
461 : public pattern_mapping_properties<Tags ...>
462 {
465  static const bool multiple;
466 };
467 
468 template<pattern_mapping_tag::type ... Tags>
469 const bool
471  pattern_mapping_tag::type::multiple, Tags ...
472 >::multiple = true;
473 
481 template<pattern_mapping_tag::type ... Tags>
483  pattern_mapping_tag::type::cyclic, Tags ...>
484 : public pattern_mapping_properties<Tags ...>
485 {
488  static const bool cyclic;
489 };
490 
491 template<pattern_mapping_tag::type ... Tags>
492 const bool
494  pattern_mapping_tag::type::cyclic, Tags ...
495 >::cyclic = true;
496 
497 #endif // DOXYGEN
498 
500 // Pattern partitioning properties
502 
523 {
524  typedef enum {
525  any,
526 
529 
533 
536 
539 
542 
545 
547  dynamic
548  } type;
549 };
550 
554 template<pattern_partitioning_tag::type ... Tags>
556 {
558 
560 
562  static const bool rectangular = false;
563 
566  static const bool minimal = false;
567 
569  static const bool regular = false;
570 
572  static const bool balanced = false;
573 
575  static const bool unbalanced = false;
576 
578  static const bool ndimensional = false;
579 
581  static const bool dynamic = false;
582 };
583 
584 #ifndef DOXYGEN
585 
594 template<pattern_partitioning_tag::type ... Tags>
596  pattern_partitioning_tag::type::rectangular, Tags ...>
597 : public pattern_partitioning_properties<Tags ...>
598 {
601  static const bool rectangular;
602 };
603 
604 template<pattern_partitioning_tag::type ... Tags>
605 const bool
607  pattern_partitioning_tag::type::rectangular, Tags ...
608 >::rectangular = true;
609 
618 template<pattern_partitioning_tag::type ... Tags>
620  pattern_partitioning_tag::type::minimal, Tags ...>
621 : public pattern_partitioning_properties<Tags ...>
622 {
625  static const bool minimal;
626 };
627 
628 template<pattern_partitioning_tag::type ... Tags>
629 const bool
631  pattern_partitioning_tag::type::minimal, Tags ...
632 >::minimal = true;
633 
642 template<pattern_partitioning_tag::type ... Tags>
644  pattern_partitioning_tag::type::regular, Tags ...>
645 : public pattern_partitioning_properties<Tags ...>
646 {
648  static const bool regular;
649 };
650 
651 template<pattern_partitioning_tag::type ... Tags>
652 const bool
654  pattern_partitioning_tag::type::regular, Tags ...
655 >::regular = true;
656 
665 template<pattern_partitioning_tag::type ... Tags>
667  pattern_partitioning_tag::type::balanced, Tags ...>
668 : public pattern_partitioning_properties<Tags ...>
669 {
671  static const bool balanced;
672 };
673 
674 template<pattern_partitioning_tag::type ... Tags>
675 const bool
677  pattern_partitioning_tag::type::balanced, Tags ...
678 >::balanced = true;
679 
688 template<pattern_partitioning_tag::type ... Tags>
690  pattern_partitioning_tag::type::unbalanced, Tags ...>
691 : public pattern_partitioning_properties<Tags ...>
692 {
694  static const bool unbalanced;
695 };
696 
697 template<pattern_partitioning_tag::type ... Tags>
698 const bool
700  pattern_partitioning_tag::type::unbalanced, Tags ...
701 >::unbalanced = true;
702 
711 template<pattern_partitioning_tag::type ... Tags>
713  pattern_partitioning_tag::type::ndimensional, Tags ...>
714 : public pattern_partitioning_properties<Tags ...>
715 {
717  static const bool ndimensional;
718 };
719 
720 template<pattern_partitioning_tag::type ... Tags>
721 const bool
723  pattern_partitioning_tag::type::ndimensional, Tags ...
724 >::ndimensional = true;
725 
734 template<pattern_partitioning_tag::type ... Tags>
736  pattern_partitioning_tag::type::dynamic, Tags ...>
737 : public pattern_partitioning_properties<Tags ...>
738 {
740  static const bool dynamic;
741 };
742 
743 template<pattern_partitioning_tag::type ... Tags>
744 const bool
746  pattern_partitioning_tag::type::dynamic, Tags ...
747 >::dynamic = true;
748 
749 #endif // DOXYGEN
750 
752 // Pattern Traits Default Definitions
754 
755 template<typename PatternType>
757 {
758  typedef typename PatternType::partitioning_properties
759  type;
760 };
761 
762 template<typename PatternType>
764 {
765  typedef typename PatternType::mapping_properties
766  type;
767 };
768 
769 template<typename PatternType>
771 {
772  typedef typename PatternType::layout_properties
773  type;
774 };
775 
776 template<typename PatternType>
778 {
779  typedef typename PatternType::index_type
780  index_type;
781  typedef typename PatternType::size_type
782  size_type;
783 
784  typedef typename dash::pattern_partitioning_traits<PatternType>::type
785  partitioning;
786  typedef typename dash::pattern_mapping_traits<PatternType>::type
787  mapping;
788  typedef typename dash::pattern_layout_traits<PatternType>::type
789  layout;
790 
791  typedef typename std::decay<
792  decltype(std::declval<PatternType>().blockspec())
793  >::type
794  blockspec_type;
795  typedef typename std::decay<
796  decltype(std::declval<PatternType>().local_blockspec())
797  >::type
798  local_blockspec_type;
799 };
800 
802 // Verifying Pattern Properties
804 
812 template<
813  typename PartitioningConstraints,
814  typename MappingConstraints,
815  typename LayoutConstraints,
816  typename PatternType
817 >
819  const PatternType & pattern)
820 {
821  // Pattern property traits of category Partitioning
822  typedef typename dash::pattern_traits< PatternType >::partitioning
823  partitioning_traits;
824  // Pattern property traits of category Mapping
825  typedef typename dash::pattern_traits< PatternType >::mapping
826  mapping_traits;
827  // Pattern property traits of category Layout
828  typedef typename dash::pattern_traits< PatternType >::layout
829  layout_traits;
830  // Check compile-time invariants:
831 
832  // Partitioning properties:
833  //
834  static_assert(!PartitioningConstraints::rectangular ||
835  partitioning_traits::rectangular,
836  "Pattern does not implement rectangular partitioning");
837  static_assert(!PartitioningConstraints::minimal ||
838  partitioning_traits::minimal,
839  "Pattern does not implement minimal partitioning");
840  static_assert(!PartitioningConstraints::regular ||
841  partitioning_traits::regular,
842  "Pattern does not implement regular partitioning");
843  static_assert(!PartitioningConstraints::balanced ||
844  partitioning_traits::balanced,
845  "Pattern does not implement balanced partitioning");
846  static_assert(!PartitioningConstraints::unbalanced ||
847  partitioning_traits::unbalanced,
848  "Pattern does not implement unbalanced partitioning");
849  // Mapping properties:
850  //
851  static_assert(!MappingConstraints::balanced ||
852  mapping_traits::balanced,
853  "Pattern does not implement balanced mapping");
854  static_assert(!MappingConstraints::unbalanced ||
855  mapping_traits::unbalanced,
856  "Pattern does not implement unbalanced mapping");
857  static_assert(!MappingConstraints::neighbor ||
858  mapping_traits::neighbor,
859  "Pattern does not implement neighbor mapping");
860  static_assert(!MappingConstraints::shifted ||
861  mapping_traits::shifted,
862  "Pattern does not implement shifted mapping");
863  static_assert(!MappingConstraints::diagonal ||
864  mapping_traits::diagonal,
865  "Pattern does not implement diagonal mapping");
866  static_assert(!MappingConstraints::cyclic ||
867  mapping_traits::cyclic,
868  "Pattern does not implement cyclic mapping");
869  // Layout properties:
870  //
871  static_assert(!LayoutConstraints::blocked ||
872  layout_traits::blocked,
873  "Pattern does not implement blocked layout");
874  static_assert(!LayoutConstraints::canonical ||
875  layout_traits::canonical,
876  "Pattern does not implement canonical layout");
877  static_assert(!LayoutConstraints::linear ||
878  layout_traits::linear,
879  "Pattern does not implement linear layout");
880  return true;
881 }
882 
891 template<
892  typename PartitioningConstraints,
893  typename MappingConstraints,
894  typename LayoutConstraints,
895  typename PatternType
896 >
898 {
899  // Pattern property traits of category Partitioning
900  typedef typename dash::pattern_traits< PatternType >::partitioning
901  partitioning_traits;
902  // Pattern property traits of category Mapping
903  typedef typename dash::pattern_traits< PatternType >::mapping
904  mapping_traits;
905  // Pattern property traits of category Layout
906  typedef typename dash::pattern_traits< PatternType >::layout
907  layout_traits;
908 
909  typedef std::integral_constant<
910  bool,
911  //
912  // Partitioning properties:
913  //
914  ( !PartitioningConstraints::rectangular ||
915  partitioning_traits::rectangular )
916  &&
917  ( !PartitioningConstraints::minimal ||
918  partitioning_traits::minimal )
919  &&
920  ( !PartitioningConstraints::regular ||
921  partitioning_traits::regular )
922  &&
923  ( !PartitioningConstraints::balanced ||
924  partitioning_traits::balanced )
925  &&
926  ( !PartitioningConstraints::unbalanced ||
927  partitioning_traits::unbalanced )
928  &&
929  //
930  // Mapping properties:
931  //
932  ( !MappingConstraints::balanced ||
933  mapping_traits::balanced )
934  &&
935  ( !MappingConstraints::unbalanced ||
936  mapping_traits::unbalanced )
937  &&
938  ( !MappingConstraints::neighbor ||
939  mapping_traits::neighbor )
940  &&
941  ( !MappingConstraints::shifted ||
942  mapping_traits::shifted )
943  &&
944  ( !MappingConstraints::diagonal ||
945  mapping_traits::diagonal )
946  &&
947  ( !MappingConstraints::cyclic ||
948  mapping_traits::cyclic )
949  &&
950  //
951  // Layout properties:
952  //
953  ( !LayoutConstraints::blocked ||
954  layout_traits::blocked )
955  &&
956  ( !LayoutConstraints::canonical ||
957  layout_traits::canonical )
958  &&
959  ( !LayoutConstraints::linear ||
960  layout_traits::linear )
961  > satisfied;
962 };
963 
965 // Default Pattern Traits Definitions
967 
972 
976 
982 
983 
984 #ifndef DOXYGEN
985 
986 template<pattern_layout_tag::type ... Tags>
987 std::ostream & operator<<(
988  std::ostream & os,
990 {
991  std::ostringstream ss;
992  ss << "dash::pattern_layout_properties< ";
993  if (traits.row_major) {
994  ss << "row_major ";
995  }
996  if (traits.col_major) {
997  ss << "col_major ";
998  }
999  if (traits.blocked) {
1000  ss << "blocked ";
1001  }
1002  if (traits.canonical) {
1003  ss << "canonical ";
1004  }
1005  if (traits.linear) {
1006  ss << "linear ";
1007  }
1008  ss << ">";
1009  return operator<<(os, ss.str());
1010 }
1011 
1012 template<pattern_mapping_tag::type ... Tags>
1013 std::ostream & operator<<(
1014  std::ostream & os,
1016 {
1017  std::ostringstream ss;
1018  ss << "dash::pattern_mapping_properties< ";
1019  if (traits.balanced) {
1020  ss << "balanced ";
1021  }
1022  if (traits.unbalanced) {
1023  ss << "unbalanced ";
1024  }
1025  if (traits.neighbor) {
1026  ss << "neighbor ";
1027  }
1028  if (traits.shifted) {
1029  ss << "shifted ";
1030  }
1031  if (traits.diagonal) {
1032  ss << "diagonal ";
1033  }
1034  if (traits.cyclic) {
1035  ss << "cyclic ";
1036  }
1037  ss << ">";
1038  return operator<<(os, ss.str());
1039 }
1040 
1041 template<pattern_partitioning_tag::type ... Tags>
1042 std::ostream & operator<<(
1043  std::ostream & os,
1045 {
1046  std::ostringstream ss;
1047  ss << "dash::pattern_partitioning_properties< ";
1048  if (traits.rectangular) {
1049  ss << "rectangular ";
1050  }
1051  if (traits.minimal) {
1052  ss << "minimal ";
1053  }
1054  if (traits.regular) {
1055  ss << "regular ";
1056  }
1057  if (traits.balanced) {
1058  ss << "balanced ";
1059  }
1060  if (traits.unbalanced) {
1061  ss << "unbalanced ";
1062  }
1063  ss << ">";
1064  return operator<<(os, ss.str());
1065 }
1066 
1067 #endif
1068 
1069 } // namespace dash
1070 
1071 #endif // DASH__PATTERN_PROPERTIES_H__
static const bool neighbor
Adjacent blocks in any dimension are located at a remote unit.
static const bool balanced
Mapping properties defaults:
All blocks have identical size.
This class is a simple memory pool which holds allocates elements of size ValueType.
Definition: AllOf.h:8
static const bool cyclic
Blocks are assigned to processes like dealt from a deck of cards in every hyperplane, starting from first unit.
Local element order corresponds to a logical linearization within single blocks (if blocked) or withi...
Units are mapped to blocks in diagonal chains in at least one hyperplane.
Traits for compile-time pattern constraints checking, suitable as a helper for template definitions e...
static const bool linear
Local element order corresponds to a logical linearization within single blocks (blocked) or within e...
Adjacent blocks in any dimension are located at a remote unit.
All local indices are mapped to a single logical index domain and thus not indexed blockwise...
static const bool canonical
All local indices are mapped to a single logical index domain.
static const bool rectangular
Partitioning properties defaults:
static const bool balanced
All blocks have identical size.
Row major storage order, used by default.
The number of blocks assigned to units may differ.
static const bool row_major
Layout properties defaults:
Column major storage order.
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.
static const bool diagonal
Units are mapped to blocks in diagonal chains in all hyperplanes.
All blocks have identical extents.
Elements are contiguous in local memory within a single block and thus indexed blockwise.
Container type for mapping properties of models satisfying the Pattern concept.
static const bool col_major
Column major storage order.
static const bool unbalanced
Size of blocks may differ.
bool check_pattern_constraints(const PatternType &pattern)
Traits for compile- and run-time pattern constraints checking, suitable for property checks where det...
Units are mapped to more than one block.
static const bool blocked
Elements are contiguous in local memory within a single block.
static const bool regular
All blocks have identical extents.
Unspecified mapping property.
Unspecified layout property.
static const bool unbalanced
The number of blocks assigned to units may differ.
static const bool minimal
Minimal number of blocks in every dimension, typically at most one block per unit.
Data range is partitioned in at least two dimensions.
static const bool shifted
Units are mapped to blocks in diagonal chains in at least one hyperplane.
Generic type of mapping properties of a model satisfying the Pattern concept.