set
-
template<typename Value>
class set : public ygm::container::detail::base_async_insert_value<set<Value>, std::tuple<Value>>, public ygm::container::detail::base_async_erase_key<set<Value>, std::tuple<Value>>, public ygm::container::detail::base_batch_erase_key<set<Value>, std::tuple<Value>>, public ygm::container::detail::base_async_contains<set<Value>, std::tuple<Value>>, public ygm::container::detail::base_async_insert_contains<set<Value>, std::tuple<Value>>, public ygm::container::detail::base_contains<set<Value>, std::tuple<Value>>, public ygm::container::detail::base_count<set<Value>, std::tuple<Value>>, public ygm::container::detail::base_misc<set<Value>, std::tuple<Value>>, public ygm::container::detail::base_iterators<set<Value>>, public ygm::container::detail::base_iteration_value<set<Value>, std::tuple<Value>> Public Types
-
using size_type = size_t
-
using container_type = ygm::container::set_tag
-
using iterator = typename local_container_type::iterator
-
using const_iterator = typename local_container_type::const_iterator
Public Functions
-
inline set(ygm::comm &comm)
Set constructor.
- Parameters:
comm – Communicator to use for communication
-
inline set(ygm::comm &comm, std::initializer_list<Value> l)
Construct set from std::initializer_list of values.
Initializer list is assumed to be replicated on all ranks.
- Parameters:
comm – Communicator to use for communication
l – Initializer list of values to put in set
-
inline set(ygm::comm &comm, std::ranges::input_range auto &&range)
Construct set from std::ranges::input_range of values.
Input range is assumed to be unique on all ranks.
- Parameters:
comm – Communicator to use for communication
range – Input range of values to put in set
-
inline ~set()
-
set() = delete
-
inline bool operator==(const self_type &other) const
Check if two sets are equal.
- Parameters:
other – Set to compare with
- Returns:
true if sets are equal, false otherwise
-
inline iterator local_begin()
Access to begin iterator of locally-held items.
Does not call
barrier().- Returns:
Local iterator to beginning of items held by process.
-
inline const_iterator local_begin() const
Access to begin const_iterator of locally-held items for const set.
Does not call
barrier().- Returns:
Local const iterator to beginning of items held by process.
-
inline const_iterator local_cbegin() const
Access to begin const_iterator of locally-held items for const set.
Does not call
barrier().- Returns:
Local const iterator to beginning of items held by process.
-
inline iterator local_end()
Access to end iterator of locally-held items.
Does not call
barrier().- Returns:
Local iterator to ending of items held by process.
-
inline const_iterator local_end() const
Access to end const_iterator of locally-held items for const set.
Does not call
barrier().- Returns:
Local const iterator to ending of items held by process.
-
inline const_iterator local_cend() const
Access to end const_iterator of locally-held items for const set.
Does not call
barrier().- Returns:
Local const iterator to ending of items held by process.
-
inline void local_insert(const value_type &val)
Insert a value into local storage.
- Parameters:
val – Value to store
-
inline void local_erase(const value_type &val)
Erase value from local storage.
- Parameters:
val – Value to erase from local storage
-
inline void local_clear()
Clear local storage.
-
inline size_t local_count(const value_type &val) const
Count the number of times a value is found locally.
- Returns:
Number of local occurrences of
val
-
inline bool local_contains(const value_type &val) const
Check if a value exists locally.
- Parameters:
val – Value to check for
- Returns:
True if value exists locally, false otherwise
-
inline size_t local_size() const
Get the number of elements stored on the local process.
- Returns:
Local size of set
-
template<typename Function>
inline void local_for_all(Function &&fn) Execute a functor on every locally-held value.
- Template Parameters:
Function – functor type
- Parameters:
fn – Functor to execute on values
-
template<typename Function>
inline void local_for_all(Function &&fn) const local_for_allforconstcontainersconstreferences to values are provided tofn- Template Parameters:
Function – functor type
- Parameters:
fn – Functor to execute on values
-
template<typename ReturnSet = std::set<value_type>>
inline ReturnSet gather_values(std::ranges::input_range auto &&range) Collective operation to look up items that exist within set.
- Parameters:
values – Values local rank wants to look up in set
- Returns:
std::setof provided values that exist within the YGM set
-
inline void serialize(const std::string &fname)
Serialize a set to a collection of files to be read back in later.
- Parameters:
fname – Filename prefix to create filename used by every rank from
-
inline void deserialize(const std::string &fname)
Deserialize a set from files.
Currently requires the number of ranks deserializing a bag to be the same as was used for serialization.
- Parameters:
fname – Filename prefix to create filename used by every rank from
-
inline void local_swap(self_type &other)
Swap elements held locally between sets.
- Parameters:
other – Set to swap elements with
-
inline void async_insert(const typename std::tuple_element<0, std::tuple<Value>>::type &value)
Asynchronously inserts a value in a container.
ygm::container::bag<int> my_bag(world); my_bag.async_insert(world.rank());
- Parameters:
value – Value to insert into container
-
inline void async_erase(const typename std::tuple_element<0, std::tuple<Value>>::type &key)
Asynchronously erases a key from a container.
- Parameters:
key – Key to erase (key, value) pair of in containers with keys and values or value to erase in containers without keys
-
inline void erase(const Container &cont)
Erases keys contained in a
ygm::containerwith afor_all()method that are found in the calling container.This variation requires the container of keys to have
for_all_argsthat is a tuple containing a single item.- Template Parameters:
Container – YGM container type holding keys to erase
- Parameters:
cont – Container of keys
-
inline void erase(const Container &cont)
Erases keys contained in an STL container that are found in the calling container.
- Template Parameters:
Container – STL container type
- Parameters:
cont – STL container of keys to erase
-
inline void async_contains(const typename std::tuple_element<0, std::tuple<Value>>::type &value, Function &&fn, const FuncArgs&... args)
Asynchronously execute a function with knowledge of if the container contains the given value.
The user-provided function is provided with (1) an optional pointer to the container, (2) a boolean indicating whether the desired value was found, (3) the value searched for, and (4) any additional arguments passed to async_contains by the user
- Template Parameters:
Function – Type of user function
FuncArgs... – Variadic types of user-provided arguments to function
- Parameters:
value – Value to check for existence of in container
fn – User-provided function to execute
args... – Variadic arguments to user-provided function
-
inline void async_insert_contains(const typename std::tuple_element<0, std::tuple<Value>>::type &value, Function &&fn, const FuncArgs&... args)
Asynchronously insert into a container if value is not already present and execute a user-provided function that is told whether the value was already present.
Insertion only occurs if value is not already present. Containers with keys and values will not have values reset to the value’s default.
ygm::container::map<int, int> my_map(world); my_bag.async_insert_contains(10, [](bool contains, auto &value) { if (contains) { wcout() << "my_map already contained " << value << std::endl; } else { wcout() << "my_map did not already contain " << value << " but now it does" << std::endl; } });
- Parameters:
value – Value to attempt to insert
fn – Function to execute after attempted insertion
args... – Variadic arguments to pass to fn
-
inline bool contains(const typename std::tuple_element<0, std::tuple<Value>>::type &value) const
Checks for the presence of a value within a container.
- Parameters:
value – Value to search for within container (key in the case of containers with keys)
- Returns:
True if
valueexists in container; false otherwise.
-
inline auto count(const typename std::tuple_element<0, std::tuple<Value>>::type &value) const
Counts all occurrences of a value within a container.
- Parameters:
value – Value to search for within container (key in the case of containers with keys)
- Returns:
Count of times
valueis seen in container
-
inline size_t size() const
Gets number of elements in a YGM container.
- Returns:
Container size
-
inline void clear()
Clears the contents of a YGM container.
-
inline void swap(set<Value> &other)
Swaps the contents of a YGM container.
- Parameters:
other – Container to swap with
-
inline ygm::comm &comm() const
Access to underlying YGM communicator.
- Returns:
YGM communicator used for communication by container
-
inline ygm::ygm_ptr<set<Value>> get_ygm_ptr()
Access to the ygm_ptr used by the container.
- Returns:
ygm_ptrused by the container when identifying itself inasynccalls on theygm::comm
-
inline const ygm::ygm_ptr<set<Value>> get_ygm_ptr() const
Const access to the ygm ptr used by the container.
- Returns:
ygm_ptrto const version of container
-
inline auto begin()
Returns an iterator to the beginning of the local container’s data.
This function is primarly a convienience function for range based for loops
Warning
The iterator is a local iterator, not a global iterator
- Returns:
iterator to the beginning of the local container’s data.
-
inline auto begin() const
Returns a const_iterator to the beginning of the local container’s data.
This function is primarly a convienience function for range based for loops
Warning
The const_iterator is a local iterator, not a global iterator
- Returns:
auto const_iterator to the beginning of the local container’s data.
-
inline auto cbegin() const
Returns a const_iterator to the beginning of the local container’s data.
This function is primarly a convienience function for range based for loops
Warning
The const_iterator is a local iterator, not a global iterator
- Returns:
auto const_iterator to the beginning of the local container’s data.
-
inline auto end()
Returns an iterator to the end of the local container’s data.
This function is primarly a convienience function for range based for loops
Warning
The iterator is a local iterator, not a global iterator
- Returns:
iterator to the end of the local container’s data.
-
inline auto end() const
Returns a const_iterator to the end of the local container’s data.
This function is primarly a convienience function for range based for loops
Warning
The const_iterator is a local iterator, not a global iterator
- Returns:
auto const_iterator to the end of the local container’s data.
-
inline auto cend() const
Returns a const_iterator to the end of the local container’s data.
This function is primarly a convienience function for range based for loops
Warning
The const_iterator is a local iterator, not a global iterator
- Returns:
auto const_iterator to the end of the local container’s data.
-
inline void for_all(Function &&fn)
Iterates over all items in a container and executes a user-provided function object on each.
The user-provided function is expected to take a single argument that is an item within the container. If the user provides a lambda as their function object, the lambda is allowed to capture.
- Template Parameters:
Function – Type of user-provided function
- Parameters:
fn – User-provided function
-
inline void for_all(Function &&fn) const
Const version of for_all that iterates over all items and passes them to the user function as const *.
The user-provided function is expected to take a single argument that is an item within the container. If the user provides a lambda as their function object, the lambda is allowed to capture.
- Template Parameters:
Function – Type of user-provided function
- Parameters:
fn – User-provided function
-
inline void gather(STLContainer >o, int rank) const
Gather all values in an STL container.
- Template Parameters:
STLContainer – Type of STL container to gather to
- Parameters:
gto – Container to store results in
rank – Rank to tather results on. Use -1 to gather to all ranks
-
inline void gather(STLContainer >o) const
Gather all values in an STL container on all ranks.
Equivalent to
gather(gto, -1)- Template Parameters:
STLContainer – Type of STL container to gather to
- Parameters:
gto – Container to store results in
-
inline std::vector<value_type> gather_topk(size_t k, Compare comp = std::greater<value_type>()) const
Gather the k “largest” values according to provided comparison function.
- Template Parameters:
Compare – Type of comparison operator
- Parameters:
k – Number of values to gather
comp – Comparison function for identifying elements to gather
- Returns:
vector of largest values
-
inline value_type reduce(MergeFunction merge) const
Perform a reduction over all items in container.
reduceonly makes sense to use with commutative and associative functors defining merges. Otherwise, ranks will not receive the same result.- Template Parameters:
MergeFunction – Merge functor type
- Parameters:
merge – Functor to combine pairs of items
- Returns:
Value from all reductions
-
inline void collect(YGMContainer &c) const
Collects all items in a new YGM container.
- Template Parameters:
YGMContainer – Container type
- Parameters:
c – Container to collect into
-
inline void reduce_by_key(MapType &map, ReductionOp reducer) const
Reduces all values in key-value pairs with matching keys.
- Template Parameters:
MapType – Result YGM container type
ReductionOp – Functor type
- Parameters:
map – YGM container to hold result
reducer – Functor for combining values
-
transform_proxy_value<set<Value>, TransformFunction> transform(TransformFunction &&ffn)
Creates proxy that transforms items in container that are presented to user
for_allcalls.The underlying items within the container are not modified.
will complete successfully.ygm::container::bag<int> my_bag(world); my_bag.async_insert(2); my_bag.barrier(); my_bag.transform([](auto &val) { return 2*val; }).for_all([](const auto &transformed_val) { YGM_ASSERT_RELEASE(val == 4); }); my_bag.for_all([](const auto &val) { YGM_ASSERT_RELEASE(val == 2); });
- Template Parameters:
TransformFunction – functor type
- Parameters:
ffn – Function to transform items in container
-
inline flatten_proxy_value<set<Value>> flatten()
Flattens STL containers of values to allow a function to be called on inner items individually.
Underlying container is not modified.
will printygm::container::bag<std::vector<int>> my_bag(world, {{1, 2, 3}}); my_bag.flatten().for_all([](const int &nested_val) { std::cout << "Nested value: " << nested_val << std::cout; });
Nested value: 1 Nested value: 2 Nested value: 3
-
filter_proxy_value<set<Value>, FilterFunction> filter(FilterFunction &&ffn)
Filters items in a container so only allow
for_allto execute on those that satisfy a given predicate function.Filtered items are not removed from underlying container.
ygm::container::bag<int> my_bag(world, {1, 2, 3, 4}); my_bag.filter([](const auto &val) { return (val % 2) == 0; }).for_all([](const auto &filtered_val) { YGM_ASSERT_RELEASE((filtered_val % 2) == 0); });
- Template Parameters:
FilterFunction – Functor type
- Parameters:
ffn – Function used to filter items in container.
Public Members
-
detail::hash_partitioner<detail::hash<value_type>> partitioner
Friends
- friend struct detail::base_misc< set< Value >, std::tuple< Value > >
-
using size_type = size_t