Skip to content

Commit

Permalink
Updated container constructors.
Browse files Browse the repository at this point in the history
  • Loading branch information
rogerpearce committed Aug 2, 2024
1 parent 2867752 commit d4894da
Show file tree
Hide file tree
Showing 8 changed files with 233 additions and 294 deletions.
21 changes: 18 additions & 3 deletions include/ygm/container/bag.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,39 @@ class bag : public detail::base_async_insert_value<bag<Item>, std::tuple<Item>>,

bag(ygm::comm &comm, std::initializer_list<Item> l)
: m_comm(comm), pthis(this), partitioner(comm) {
m_comm.cout0("initializer_list assumes all ranks are equal");
pthis.check(m_comm);
if (m_comm.rank0()) {
for (const Item &i : l) {
async_insert(i);
}
}
m_comm.barrier();
}

template <typename STLContainer>
bag(ygm::comm &comm, const STLContainer &cont)
requires detail::STLContainer<STLContainer> &&
std::convertible_to<typename STLContainer::value_type, Item>
: m_comm(comm), pthis(this), partitioner(comm) {
m_comm.cout0("STLContainer assumes all ranks are different");
pthis.check(m_comm);

for (const Item &i : cont) {
async_insert(i);
this->async_insert(i);
}
m_comm.barrier();
}

template <typename YGMContainer>
bag(ygm::comm &comm, const YGMContainer &yc)
requires detail::HasForAll<YGMContainer> &&
detail::SingleItemTuple<
typename YGMContainer::for_all_args>
: m_comm(comm), pthis(this), partitioner(comm) {
pthis.check(m_comm);

yc.for_all([this](const Item &value) { this->async_insert(value); });

m_comm.barrier();
}

~bag() { m_comm.barrier(); }
Expand Down
72 changes: 0 additions & 72 deletions include/ygm/container/bag_orig.hpp

This file was deleted.

44 changes: 41 additions & 3 deletions include/ygm/container/counting_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class counting_set
const size_type count_cache_size = 1024 * 1024;

counting_set(ygm::comm &comm)
: m_map(comm /*, mapped_type(0)*/),
: m_map(comm ),
m_comm(comm),
partitioner(m_map.partitioner),
pthis(this) {
Expand All @@ -43,9 +43,47 @@ class counting_set

counting_set() = delete;

void async_insert(const key_type &key) { cache_insert(key); }
counting_set(ygm::comm &comm, std::initializer_list<Key> l)
: m_map(comm ),
m_comm(comm),
partitioner(m_map.partitioner),
pthis(this) {
pthis.check(m_comm);
if (m_comm.rank0()) {
for (const Key &i : l) {
async_insert(i);
}
}
m_comm.barrier();
}

template <typename STLContainer>
counting_set(ygm::comm &comm, const STLContainer &cont)
requires detail::STLContainer<STLContainer> &&
std::convertible_to<typename STLContainer::value_type, Key>
: m_comm(comm), pthis(this), partitioner(comm) {
pthis.check(m_comm);

for (const Key &i : cont) {
this->async_insert(i);
}
m_comm.barrier();
}

template <typename YGMContainer>
counting_set(ygm::comm &comm, const YGMContainer &yc)
requires detail::HasForAll<YGMContainer> &&
detail::SingleItemTuple<
typename YGMContainer::for_all_args>
: m_comm(comm), pthis(this), partitioner(comm) {
pthis.check(m_comm);

// void async_erase(const key_type& key) { cache_erase(key); }
yc.for_all([this](const Key &value) { this->async_insert(value); });

m_comm.barrier();
}

void async_insert(const key_type &key) { cache_insert(key); }

template <typename Function>
void local_for_all(Function fn) {
Expand Down
72 changes: 72 additions & 0 deletions include/ygm/container/map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,42 @@ class map
pthis.check(m_comm);
}

map(ygm::comm& comm, std::initializer_list<std::pair<Key, Value>> l)
: m_comm(comm), pthis(this), partitioner(comm) {
pthis.check(m_comm);
if (m_comm.rank0()) {
for (const std::pair<Key, Value>& i : l) {
async_insert(i);
}
}
}

template <typename STLContainer>
map(ygm::comm &comm, const STLContainer &cont)
requires detail::STLContainer<STLContainer> &&
std::convertible_to<typename STLContainer::value_type, std::pair<Key, Value>>
: m_comm(comm), pthis(this), partitioner(comm) {
pthis.check(m_comm);

for (const std::pair<Key, Value> &i : cont) {
this->async_insert(i);
}
m_comm.barrier();
}

template <typename YGMContainer>
map(ygm::comm &comm, const YGMContainer &yc)
requires detail::HasForAll<YGMContainer> &&
detail::SingleItemTuple<
typename YGMContainer::for_all_args>
: m_comm(comm), pthis(this), partitioner(comm) {
pthis.check(m_comm);

yc.for_all([this](const std::pair<Key, Value> &value) { this->async_insert(value); });

m_comm.barrier();
}

~map() { m_comm.barrier(); }

using detail::base_async_erase_key<map<Key, Value>,
Expand Down Expand Up @@ -326,6 +362,42 @@ class multimap
pthis.check(m_comm);
}

multimap(ygm::comm& comm, std::initializer_list<std::pair<Key, Value>> l)
: m_comm(comm), pthis(this), partitioner(comm) {
pthis.check(m_comm);
if (m_comm.rank0()) {
for (const std::pair<Key, Value>& i : l) {
async_insert(i);
}
}
}

template <typename STLContainer>
multimap(ygm::comm &comm, const STLContainer &cont)
requires detail::STLContainer<STLContainer> &&
std::convertible_to<typename STLContainer::value_type, std::pair<Key, Value>>
: m_comm(comm), pthis(this), partitioner(comm) {
pthis.check(m_comm);

for (const std::pair<Key, Value> &i : cont) {
this->async_insert(i);
}
m_comm.barrier();
}

template <typename YGMContainer>
multimap(ygm::comm &comm, const YGMContainer &yc)
requires detail::HasForAll<YGMContainer> &&
detail::SingleItemTuple<
typename YGMContainer::for_all_args>
: m_comm(comm), pthis(this), partitioner(comm) {
pthis.check(m_comm);

yc.for_all([this](const std::pair<Key, Value> &value) { this->async_insert(value); });

m_comm.barrier();
}

~multimap() { m_comm.barrier(); }

void local_insert(const key_type& key) {
Expand Down
Loading

0 comments on commit d4894da

Please sign in to comment.