13 #define COUT(expr) { \ 14 std::ostringstream os; \ 16 std::cout << os.str(); \ 22 template<
typename Key>
29 typedef Key argument_type;
52 result_type operator()(
53 const argument_type & key)
const 56 return result_type{0};
58 return result_type((key ^ 0xAA) % _nunits);
63 size_type _nunits = 0;
69 typedef double mapped_t;
73 typedef typename map_t::value_type value_t;
74 typedef typename map_t::size_type size_type;
77 template<
typename InputIt>
78 void print_map(InputIt first, InputIt last)
81 for (
auto mit = first; mit != last; ++mit) {
83 auto lpos = mit.lpos();
84 COUT(std::setw(3) << idx <<
": " 85 <<
"unit:" << std::setw(2) << lpos.unit <<
", " 86 <<
"lidx:" << std::setw(3) << lpos.index <<
" " 91 << std::setprecision(3) << std::fixed
92 << static_cast<mapped_t>(elem.second)
98 int main(
int argc,
char* argv[])
106 size_type init_global_size = 0;
112 size_type bucket_size = (myid % 2 == 0) ? 5 : 7;
114 size_type min_elem_per_unit = 5;
115 size_type max_elem_per_unit = 12;
117 min_elem_per_unit =
static_cast<size_type
>(atoi(argv[1]));
118 max_elem_per_unit =
static_cast<size_type
>(atoi(argv[2]));
126 <<
"ex.02.unordered_map <min inserts> <max inserts>" << endl
127 <<
" min. number of elements inserted per unit: " 128 << min_elem_per_unit << endl
129 <<
" max. number of elements inserted per unit: " 130 << max_elem_per_unit << endl
132 <<
"Initial map size: " << map.
size()
138 COUT(
"Initial local map size (unit " << myid <<
"): " << map.
lsize());
143 std::srand(std::time(0) + myid);
144 size_type num_add_elem = min_elem_per_unit + (
146 (max_elem_per_unit - min_elem_per_unit));
148 for (
auto i = 0; i < num_add_elem; i++) {
149 key_t key = 100 * (myid+1) + i;
150 mapped_t mapped = 1.000 * (myid+1) + ((i+1) * 0.001);
151 value_t value = std::make_pair(key, mapped);
154 auto insertion = map.
insert(value);
155 bool key_existed = !insertion.second;
156 auto inserted_it = insertion.first;
157 assert(!key_existed);
158 assert(map.
count(key) == 1);
160 mapped_t new_mapped_val = mapped + 400;
162 map[key] = new_mapped_val;
165 auto read_it = map.
find(key);
166 value_t read_value = *read_it;
167 assert(read_it != map.
end());
169 assert(read_value.second == new_mapped_val);
174 COUT(
"Local map size after inserts (unit " << myid <<
"): " << map.
lsize());
180 <<
"Map size before commit: " << map.
size() << endl
181 <<
"Elements accessible to unit 0 before commit: " << endl);
190 <<
"Size of map after commit: " << map.
size() << endl
191 <<
"Elements accessible to unit 0 after commit: ");
MyHash(dash::Team &team)
Constructor.
global_unit_t myid()
Shortcut to query the global unit ID of the calling unit.
internal::default_unsigned_index default_size_t
Unsigned integer type used as default for size values.
size_type size() const noexcept
The size of the map.
size_t size()
Return the number of units in the global team.
Hash functor for mapping element keys to units.
int32_t dart_unit_t
Data type for storing a unit ID.
size_type lsize() const noexcept
The number of elements in the local part of the map.
MyHash()
Default constructor.
size_t size() const
The number of units in this team.
A Team instance specifies a subset of all available units.
iterator & begin() noexcept
Global iterator to the beginning of the map.
struct dash::unit_id< dash::local_unit, dart_team_unit_t > team_unit_t
Unit ID to use for team-local IDs.
iterator & end() noexcept
Global iterator to the end of the map.
#define DART_UNDEFINED_UNIT_ID
Undefined unit ID.
void barrier()
A global barrier involving all units.
void barrier()
Synchronize changes on local and global memory space of the map since initialization or the last call...
static Team & All()
The invariant Team instance containing all available units.
void init(int *argc, char ***argv)
Initialize the DASH library and the underlying runtime system.
iterator find(const key_type &key)
Get iterator to element with specified key.
std::pair< iterator, bool > insert(const value_type &value)
Insert a new element as key-value pair, increasing the container size by 1.
size_type count(const key_type &key) const
Count elements with a specific key.