OP  0.1
OP is a optimization solver plugin package
 All Classes Namespaces Functions Variables Typedefs Enumerations Friends
Namespaces | Classes | Typedefs | Functions
op::utility Namespace Reference

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 >
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 >
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 >
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...
 

Detailed Description

Utility methods to facilitate common operations.

Function Documentation

template<typename T , typename M >
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 * *

Parameters
[in]vectorvalues to permute
[in]mapindices of vector for a given element result[i]
[in,out]resultsa vector for the results

Definition at line 303 of file op_utility.hpp.

template<typename T , typename M >
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 * *

Parameters
[in]vectorvalues to permute
[in]mapindices of vector for a given element result[i]
[in]pad_valuedefault padding value in result [in] arg_size A manually-specified size(R), otherwise size(T)

Definition at line 337 of file op_utility.hpp.

template<typename T >
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.

Parameters
[in]values_per_rank
[in]returninclusive offset

Definition at line 43 of file op_utility.hpp.

template<typename T >
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

Parameters
[in]global_local_idsThe "global ids" corresponding to the local vector data
[in]filterA map of {ranks : local indicies} to filter out

Definition at line 561 of file op_utility.hpp.

template<typename T >
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}}

Parameters
[in]vector_mapA vector who's indices map to numbers.

Definition at line 417 of file op_utility.hpp.

template<typename K , typename V >
auto op::utility::mapToVector ( std::unordered_map< K, V > &  map)

Converts an inverseMap back to the vector representation.

Note
The vector mapping has the same number of elements as the number of keys in map
Parameters
[in]mapMap to convert a dense vector

Definition at line 446 of file op_utility.hpp.

template<typename T , typename M >
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

Parameters
[in]vectorvalues to permute
[in]mapindices of vector for a given element result[i]

Definition at line 368 of file op_utility.hpp.

template<typename T , typename M , typename I >
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

Parameters
[in]vectorvalues to permute
[in]mapindices of vector for a given element result[i]

Definition at line 390 of file op_utility.hpp.

template<typename M >
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

Parameters
[in]remapped_dataData that has been remapped using the remapRecvData* methods
[in]reduce_opA user-defined method to reduce the recieved data

Definition at line 519 of file op_utility.hpp.

template<typename T , typename V >
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

Note
doesn't includes local_variable data in the remapped map
Parameters
[in]recvThe recv mapping from RankCommunication that pertains to this data
[in]recv_dataThe data recvied.

Definition at line 465 of file op_utility.hpp.

template<typename T , typename V >
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

Note
includes local_variable data in the remapped map
Parameters
[in]recvThe recv mapping from RankCommunication that pertains to this data
[in]recv_dataThe data recvied.
[in]global_to_local_mapThe "global" indices corresponding to the local vector
[in]local_variablesThe rank-local view of variables
Returns
mapping of owned of variable data

Definition at line 497 of file op_utility.hpp.