20 #ifndef GALOIS_TRAITS_H
21 #define GALOIS_TRAITS_H
24 #include <type_traits>
26 #include "galois/config.h"
47 template <
typename T, T V>
58 template <
template <
typename...>
class TT,
typename... Args>
60 return TT<Args...>(args...);
68 template <
typename Base,
typename Derived>
70 std::is_base_of<Base, Derived>::value || std::is_same<Base, Derived>::value;
77 template <
typename T,
typename Tuple,
size_t Int,
size_t... Ints>
78 constexpr
size_t find_trait(std::index_sequence<Int, Ints...> ) {
80 T,
typename std::tuple_element<Int, Tuple>::type>) {
83 return find_trait<T, Tuple>(std::index_sequence<Ints...>{});
87 template <
typename T,
typename Tuple>
89 constexpr std::make_index_sequence<std::tuple_size<Tuple>::value> seq{};
90 return find_trait<T, Tuple>(seq);
96 template <
typename T,
typename... Ts>
98 return (... || at_least_base_of<T, Ts>);
101 template <
typename T,
typename Tuple>
103 return has_trait<T>(
static_cast<Tuple*
>(
nullptr));
111 template <
typename T,
typename Tuple>
113 constexpr
size_t match(find_trait<T, Tuple>());
114 return std::get<match>(tpl);
120 template <
typename T,
typename Tuple>
122 using type =
typename std::tuple_element<find_trait<T, Tuple>(), Tuple>::
type;
128 template <
typename S,
typename T,
typename D>
131 typename std::enable_if<has_trait<T, S>()>::type* =
nullptr) {
132 return std::make_tuple();
135 template <
typename S,
typename T,
typename D>
137 S GALOIS_UNUSED(source), T GALOIS_UNUSED(tags), D defaults,
138 typename std::enable_if<!has_trait<T, S>()>::type* =
nullptr) {
139 return std::make_tuple(defaults);
146 template <
typename S,
typename T,
typename D>
149 S GALOIS_UNUSED(source), T GALOIS_UNUSED(tags),
150 D GALOIS_UNUSED(defaults)) {
151 return std::make_tuple();
154 template <
size_t... Ints,
typename S,
typename T,
typename D>
157 S source, T tags, D defaults) {
159 std::get<Ints>(defaults))...);
162 template <
typename S,
typename T,
typename D>
164 constexpr std::make_index_sequence<std::tuple_size<T>::value> seq{};
168 template <
typename T>
170 -> decltype(std::declval<typename T::function_traits>(),
bool()) {
179 template <
typename T,
typename Enable =
void>
184 template <
typename T>
186 T, typename std::enable_if<has_function_traits<T>(0)>
::type> {
187 typedef typename T::function_traits
type;
212 template <
typename T,
typename... Args>
215 s_wl(Args&&... a) :
args(std::forward<Args>(a)...) {}
218 template <
typename T,
typename... Args>
220 return s_wl<T, Args...>(std::forward<Args>(args)...);
284 template <
typename T>
302 template <
typename T>
304 static_assert(std::is_same<
typename std::result_of<T()>::
type,
bool>::
value,
305 "signature must be bool()");
318 template <
typename T>
330 template <
typename T>
354 template <
unsigned SZ = 32>
357 constexpr
static unsigned clamp(
unsigned int v) {
363 constexpr
static unsigned value = clamp(SZ);
372 template <
typename Tup>
374 constexpr
static const bool value =
375 !has_trait<no_stats_tag, Tup>() && has_trait<loopname_tag, Tup>();
378 template <
typename Tup>
379 std::enable_if_t<has_trait<loopname_tag, Tup>(),
const char*>
380 getLoopName(
const Tup& t) {
381 return get_trait_value<loopname_tag>(t).value;
384 template <
typename Tup>
385 std::enable_if_t<!has_trait<loopname_tag, Tup>(),
const char*>
386 getLoopName(
const Tup&) {
T::function_traits type
Definition: Traits.h:187
neighborhood_visitor(T &&t)
Definition: Traits.h:288
Indicate whetherlink do_all()} loops should perform work-stealing.
Definition: Traits.h:205
det_id(const T &t=T())
Definition: Traits.h:320
loopname(const char *p="ANON_LOOP")
Definition: Traits.h:198
Indicates the operator may request the access to a per-iteration allocator.
Definition: Traits.h:240
T type
Definition: Traits.h:35
det_id(T &&t)
Definition: Traits.h:321
worklists::PerSocketChunkFIFO< chunk_size<>::value > defaultWL
Definition: Traits.h:368
constexpr size_t find_trait(std::index_sequence< Int, Ints...>)
Returns index of first matching trait in Tuple.
Definition: Traits.h:78
Indicates the operator has a function that optimizes the generation of unique ids for active elements...
Definition: Traits.h:317
Returns the type associated with the given trait in a tuple.
Definition: Traits.h:121
Specify chunk size for do_all_coupled & do_all_choice at compile time or at runtime.
Definition: Traits.h:355
For distributed Galois.
Definition: Traits.h:335
Indicates that the operator uses the intent to read flag.
Definition: Traits.h:276
trait_has_value(type &&v)
Definition: Traits.h:43
Indicates worklist to use.
Definition: Traits.h:211
T getValue() const
Definition: Traits.h:44
Indicate name to appear in statistics.
Definition: Traits.h:196
typename std::tuple_element< find_trait< T, Tuple >(), Tuple >::type type
Definition: Traits.h:122
Indicates that the neighborhood set does not change through out i.e.
Definition: Traits.h:269
T getValue() const
Definition: Traits.h:51
type value
Definition: Traits.h:41
Indicates the operator has a function that visits the neighborhood of the operator without modifying ...
Definition: Traits.h:283
s_wl< T, Args...> wl(Args &&...args)
Definition: Traits.h:219
const Ty max(std::atomic< Ty > &a, const Ty &b)
Definition: AtomicHelpers.h:40
static constexpr unsigned value
Definition: Traits.h:363
constexpr bool at_least_base_of
True if Derived is derived from Base or is Base itself.
Definition: Traits.h:69
chunk_size(unsigned cs=SZ)
Definition: Traits.h:365
std::tuple type
Definition: Traits.h:181
det_parallel_break(const T &t=T())
Definition: Traits.h:306
const Ty min(std::atomic< Ty > &a, const Ty &b)
Definition: AtomicHelpers.h:70
auto make_trait_with_args(Args...args) -> TT< Args...>
Utility function to simplify creating traits that take unnamed functions (i.e., lambdas).
Definition: Traits.h:59
neighborhood_visitor(const T &t=T{})
Definition: Traits.h:287
trait_has_value(const type &v)
Definition: Traits.h:42
s_wl(Args &&...a)
Definition: Traits.h:215
static const type value
Definition: Traits.h:50
Indicates the operator does not generate new work and push it on the worklist.
Definition: Traits.h:234
Indicates the operator doesn't need abort support.
Definition: Traits.h:259
det_parallel_break(T &&t)
Definition: Traits.h:307
Indicates the operator doesn't need its execution stats recorded.
Definition: Traits.h:246
std::tuple< Args...> args
Definition: Traits.h:214
T type
Definition: Traits.h:40
constexpr auto get_trait_value(Tuple tpl)
Returns the value associated with the given trait T in a tuple.
Definition: Traits.h:112
Indicates the operator has a function that allows a galois::for_each loop to be exited deterministica...
Definition: Traits.h:301
constexpr bool has_trait(std::tuple< Ts...> *)
Returns true if the tuple type contains the given trait T.
Definition: Traits.h:97
constexpr auto has_function_traits(int) -> decltype(std::declval< typename T::function_traits >(), bool())
Definition: Traits.h:169
constexpr auto get_default_trait_values(std::index_sequence<> GALOIS_UNUSED(seq), S GALOIS_UNUSED(source), T GALOIS_UNUSED(tags), D GALOIS_UNUSED(defaults))
Returns a tuple that has an element from defaults[i] for every type from tags[i] missing in source...
Definition: Traits.h:148
internal::ChunkMaster< T, ConExtLinkedQueue, true, false, ChunkSize, Concurrent > PerSocketChunkFIFO
Distributed chunked FIFO.
Definition: Chunk.h:296
constexpr auto get_default_trait_value(S, T, D, typename std::enable_if< has_trait< T, S >()>::type *=nullptr)
Definition: Traits.h:129
T type
Definition: Traits.h:49
Indicates the operator has a type that encapsulates state that is passed between the suspension and r...
Definition: Traits.h:329
Indicates the operator may request the parallel loop to be suspended and a given function run in seri...
Definition: Traits.h:228
Indicates the operator needs detailed stats Must provide loopname to enable this flag.
Definition: Traits.h:253