Interface Documentation
Version: invalid
common.hh
Go to the documentation of this file.
1 /*
2  @@@@@@@@ @@ @@@@@@ @@@@@@@@ @@
3  /@@///// /@@ @@////@@ @@////// /@@
4  /@@ /@@ @@@@@ @@ // /@@ /@@
5  /@@@@@@@ /@@ @@///@@/@@ /@@@@@@@@@/@@
6  /@@//// /@@/@@@@@@@/@@ ////////@@/@@
7  /@@ /@@/@@//// //@@ @@ /@@/@@
8  /@@ @@@//@@@@@@ //@@@@@@ @@@@@@@@ /@@
9  // /// ////// ////// //////// //
10 
11  Copyright (c) 2016, Triad National Security, LLC
12  All rights reserved.
13  */
14 #pragma once
15 
18 #include <cstdint>
19 #include <functional>
20 #include <limits>
21 #include <sstream>
22 #include <typeinfo>
23 
24 #include "flecsi/util/id.hh"
25 #include "flecsi/util/offset.hh"
26 
27 #ifndef FLECSI_ID_PBITS
28 #define FLECSI_ID_PBITS 20
29 #endif
30 
31 #ifndef FLECSI_ID_EBITS
32 #define FLECSI_ID_EBITS 40
33 #endif
34 
35 #ifndef FLECSI_ID_FBITS
36 #define FLECSI_ID_FBITS 4
37 #endif
38 
39 #ifndef FLECSI_ID_GBITS
40 #define FLECSI_ID_GBITS 60
41 #endif
42 
43 namespace flecsi {
44 namespace util {
45 
46 //----------------------------------------------------------------------------//
47 // Entity id type.
48 //----------------------------------------------------------------------------//
49 
50 using id_t =
51  id_<FLECSI_ID_PBITS, FLECSI_ID_EBITS, FLECSI_ID_FBITS, FLECSI_ID_GBITS>;
52 
53 using offset_t = offset<16>;
54 
55 //----------------------------------------------------------------------------//
56 // Index type
57 //----------------------------------------------------------------------------//
58 
59 #ifndef FLECSI_COUNTER_TYPE
60 #define FLECSI_COUNTER_TYPE int32_t
61 #endif
62 
63 using counter_t = FLECSI_COUNTER_TYPE;
64 
65 //----------------------------------------------------------------------------//
66 // Square
67 //----------------------------------------------------------------------------//
68 
70 template<typename T>
71 inline T
72 square(const T & a) {
73  return a * a;
74 }
75 
76 //----------------------------------------------------------------------------//
77 // Unique Identifier Utilities
78 //----------------------------------------------------------------------------//
79 
80 //----------------------------------------------------------------------------//
81 // This value is used by the Legion runtime backend to automatically
82 // assign task and field ids. The current maximum value that is allowed
83 // in legion_config.h is 1<<20.
84 //
85 // We are reserving 4096 places for internal use.
86 //----------------------------------------------------------------------------//
87 
88 #if !defined(FLECSI_GENERATED_ID_MAX)
89 // 1044480 = (1<<20) - 4096
90 #define FLECSI_GENERATED_ID_MAX 1044480
91 #endif
92 
101 template<typename UNIQUENESS_TYPE,
102  typename COUNTER_TYPE = size_t,
103  COUNTER_TYPE MAXIMUM = (std::numeric_limits<COUNTER_TYPE>::max)()>
104 struct unique_id {
105 
106  static_assert(std::is_integral<COUNTER_TYPE>::value,
107  "COUNTER_TYPE must be an integral type");
108 
109  static unique_id & instance() {
110  static unique_id u;
111  return u;
112  } // instance
113 
114  auto next() {
115  assert(id_ + 1 <= MAXIMUM && "id exceeds maximum value");
116  return ++id_;
117  } // next
118 
119 private:
120  unique_id() : id_(0) {}
121  unique_id(const unique_id &) {}
122  ~unique_id() {}
123 
124  COUNTER_TYPE id_;
125 }; // unique_id
126 
128 template<typename T>
129 std::string
130 unique_name(const T * const t) {
131  const void * const address = static_cast<const void *>(t);
132  const std::size_t id = unique_id<T>::instance().next();
133  std::stringstream ss;
134  ss << typeid(T).name() << "-" << address << "-" << id;
135  return ss.str();
136 } // unique_name
137 
138 } // namespace util
139 } // namespace flecsi
T square(const T &a)
P.O.D.
Definition: common.hh:72
Definition: id.hh:36
std::string unique_name(const T *const t)
Create a unique name from the type, address, and unique id.
Definition: common.hh:130
Definition: common.hh:104
Definition: control.hh:31