OP
0.1
OP is a optimization solver plugin package
|
Utility methods to facilitate common operations. More...
Namespaces | |
parallel | |
Parallel methods. | |
reductions | |
Reduction functions for recieved data provided for convenience. | |
Classes | |
struct | RankCommunication |
Holds communication information to and from rank. More... | |
struct | CommPattern |
Complete Op communication pattern information. More... | |
Typedefs | |
template<typename T > | |
using | inverseMapType = std::unordered_map< typename T::value_type, T > |
Functions | |
template<typename T > | |
CommPattern (op::utility::RankCommunication< T >, T, T) -> CommPattern< T > | |
template<typename T > | |
std::vector< T > | buildInclusiveOffsets (std::vector< T > &values_per_rank) |
Takes in sizes per index and and performs a rank-local inclusive offset. More... | |
template<typename T , typename M > | |
void | accessPermuteStore (T &vector, M &map, T &results) |
Retrieves from T and stores in permuted mapping M, result[M[i]] = T[i]. More... | |
template<typename T , typename M > | |
T | accessPermuteStore (T &vector, M &map, typename T::value_type pad_value, std::optional< typename T::size_type > arg_size=std::nullopt) |
Retrieves from T in order and stores in permuted mapping M, result[M[i]] = T[i]. More... | |
template<typename T , typename M > | |
T | permuteAccessStore (T &vector, M &map) |
Retrieves from T using a permuted mapping M and stores in order, result[i] = T[M[i]]. More... | |
template<typename T , typename M , typename I > | |
T | permuteMapAccessStore (T &vector, M &map, I &global_ids_of_local_vector) |
Retrieves from T using a permuted mapping M and index mapping I stores in order, result[i] = T[I[M[i]]]. More... | |
template<typename T > | |
auto | inverseMap (T &vector_map) |
Inverts a vector that providse a map into an unordered_map. More... | |
template<typename K , typename V > | |
auto | mapToVector (std::unordered_map< K, V > &map) |
Converts an inverseMap back to the vector representation. More... | |
template<typename T , typename V > | |
std::unordered_map< typename T::value_type, V > | remapRecvData (std::unordered_map< int, T > &recv, std::unordered_map< int, V > &recv_data) |
rearrange data so that map[rank]->local_ids and map[rank] -> V becomes map[local_ids]->values More... | |
template<typename T , typename V > | |
auto | remapRecvDataIncludeLocal (std::unordered_map< int, T > &recv, std::unordered_map< int, V > &recv_data, std::unordered_map< typename T::value_type, T > &global_to_local_map, V &local_variables) |
rearrange data so that map[rank]->local_ids and map[rank] -> V becomes map[local_ids]->values More... | |
template<typename M > | |
M::mapped_type | reduceRecvData (M &remapped_data, std::function< typename M::mapped_type::value_type(const typename M::mapped_type &)> reduce_op) |
apply reduction operation to recieved data More... | |
template<typename T > | |
auto | filterOut (const T &global_local_ids, std::unordered_map< int, std::vector< typename T::size_type >> &filter) |
remove values in filter that correspond to global_local_ids More... | |
Utility methods to facilitate common operations.
void op::utility::accessPermuteStore | ( | T & | vector, |
M & | map, | ||
T & | results | ||
) |
Retrieves from T and stores in permuted mapping M, result[M[i]] = T[i].
T is not guarnateed to work in-place. Requirements: range(M) <= size(T) <= size(R)
T = w x y z a b M = 3 1 2 0 5 R = z x y w * b
Re-applying the mapping T[M[i]] = R[i] T2 = w x y z * *
[in] | vector | values to permute |
[in] | map | indices of vector for a given element result[i] |
[in,out] | results | a vector for the results |
Definition at line 303 of file op_utility.hpp.
T op::utility::accessPermuteStore | ( | T & | vector, |
M & | map, | ||
typename T::value_type | pad_value, | ||
std::optional< typename T::size_type > | arg_size = std::nullopt |
||
) |
Retrieves from T in order and stores in permuted mapping M, result[M[i]] = T[i].
T is not guarnateed to work in-place. This method returns results in a newly padded vector Requirements: range(M) <= size(T) <= size(R)
T = w x y z a b
M = 3 1 2 0 5
R = z x y w * b
Re-applying the mapping T[M[i]] = R[i]
T2 = w x y z * *
[in] | vector | values to permute |
[in] | map | indices of vector for a given element result[i] |
[in] | pad_value | default padding value in result [in] arg_size A manually-specified size(R), otherwise size(T) |
Definition at line 337 of file op_utility.hpp.
std::vector<T> op::utility::buildInclusiveOffsets | ( | std::vector< T > & | values_per_rank | ) |
Takes in sizes per index and and performs a rank-local inclusive offset.
[in] | values_per_rank | |
[in] | return | inclusive offset |
Definition at line 43 of file op_utility.hpp.
auto op::utility::filterOut | ( | const T & | global_local_ids, |
std::unordered_map< int, std::vector< typename T::size_type >> & | filter | ||
) |
remove values in filter that correspond to global_local_ids
[in] | global_local_ids | The "global ids" corresponding to the local vector data |
[in] | filter | A map of {ranks : local indicies} to filter out |
Definition at line 561 of file op_utility.hpp.
auto op::utility::inverseMap | ( | T & | vector_map | ) |
Inverts a vector that providse a map into an unordered_map.
Inverts the mapping to map[global_index] = {local_indices...}
multiple local_indices may point to the same global index
vector_map = [1 4 3 2]
inverse_map = {{ 1, 0}, {4, 1}, {3, 2}, {2,4}}
[in] | vector_map | A vector who's indices map to numbers. |
Definition at line 417 of file op_utility.hpp.
auto op::utility::mapToVector | ( | std::unordered_map< K, V > & | map | ) |
Converts an inverseMap back to the vector representation.
[in] | map | Map to convert a dense vector |
Definition at line 446 of file op_utility.hpp.
T op::utility::permuteAccessStore | ( | T & | vector, |
M & | map | ||
) |
Retrieves from T using a permuted mapping M and stores in order, result[i] = T[M[i]].
Requirements: size(R) = size(M), range(M) <= size(T)
T = w x y z a b
M = 3 1 2 0 5
result = z x y w b
M = 3 1 2 0 4
T1 = w x y z b
[in] | vector | values to permute |
[in] | map | indices of vector for a given element result[i] |
Definition at line 368 of file op_utility.hpp.
T op::utility::permuteMapAccessStore | ( | T & | vector, |
M & | map, | ||
I & | global_ids_of_local_vector | ||
) |
Retrieves from T using a permuted mapping M and index mapping I stores in order, result[i] = T[I[M[i]]].
TODO
[in] | vector | values to permute |
[in] | map | indices of vector for a given element result[i] |
Definition at line 390 of file op_utility.hpp.
M::mapped_type op::utility::reduceRecvData | ( | M & | remapped_data, |
std::function< typename M::mapped_type::value_type(const typename M::mapped_type &)> | reduce_op | ||
) |
apply reduction operation to recieved data
[in] | remapped_data | Data that has been remapped using the remapRecvData* methods |
[in] | reduce_op | A user-defined method to reduce the recieved data |
Definition at line 519 of file op_utility.hpp.
std::unordered_map<typename T::value_type, V> op::utility::remapRecvData | ( | std::unordered_map< int, T > & | recv, |
std::unordered_map< int, V > & | recv_data | ||
) |
rearrange data so that map[rank]->local_ids and map[rank] -> V becomes map[local_ids]->values
[in] | recv | The recv mapping from RankCommunication that pertains to this data |
[in] | recv_data | The data recvied. |
Definition at line 465 of file op_utility.hpp.
auto op::utility::remapRecvDataIncludeLocal | ( | std::unordered_map< int, T > & | recv, |
std::unordered_map< int, V > & | recv_data, | ||
std::unordered_map< typename T::value_type, T > & | global_to_local_map, | ||
V & | local_variables | ||
) |
rearrange data so that map[rank]->local_ids and map[rank] -> V becomes map[local_ids]->values
[in] | recv | The recv mapping from RankCommunication that pertains to this data |
[in] | recv_data | The data recvied. |
[in] | global_to_local_map | The "global" indices corresponding to the local vector |
[in] | local_variables | The rank-local view of variables |
Definition at line 497 of file op_utility.hpp.