Sierra Toolkit  Version of the Day
DistributedIndex.hpp
1 /*------------------------------------------------------------------------*/
2 /* Copyright 2010 Sandia Corporation. */
3 /* Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive */
4 /* license for use of this work by or on behalf of the U.S. Government. */
5 /* Export of this program may require a license from the */
6 /* United States Government. */
7 /*------------------------------------------------------------------------*/
8 
9 #ifndef stk_util_parallel_DistributedIndex_hpp
10 #define stk_util_parallel_DistributedIndex_hpp
11 
12 #include <stdint.h>
13 #include <utility>
14 #include <vector>
15 #include <cstddef>
16 #include <stk_util/parallel/Parallel.hpp>
17 
18 class UnitTestSTKParallelDistributedIndex ;
19 
20 namespace stk_classic {
21 namespace parallel {
22 
41 public:
42  typedef uint64_t KeyType ;
43  typedef int ProcType ;
44  typedef std::pair<KeyType,KeyType> KeySpan ;
45  typedef std::pair<KeyType,ProcType> KeyProc ;
46 
47  /*----------------------------------------*/
48 
50 
61  const std::vector<KeySpan> & partition_spans );
62 
63  /*----------------------------------------*/
65  void query( std::vector<KeyProc> & sharing_of_local_keys ) const ;
66 
71  void query( const std::vector<KeyType> & keys ,
72  std::vector<KeyProc> & sharing_of_keys ) const ;
73 
78  void query_to_usage( const std::vector<KeyType> & keys ,
79  std::vector<KeyProc> & sharing_of_keys ) const ;
80 
81  /*------------------------------------------------------------------*/
86  void update_keys( const std::vector<KeyType> & add_new_keys ,
87  const std::vector<KeyType> & remove_existing_keys );
88 
107  void generate_new_keys(
108  const std::vector<size_t> & requests ,
109  std::vector< std::vector<KeyType> > & requested_keys );
110 
111 private:
112 
113  /*------------------------------------------------------------------*/
116  void generate_new_global_key_upper_bound(
117  const std::vector<size_t> & requests ,
118  std::vector<DistributedIndex::KeyType> & global_key_upper_bound ) const;
119 
120 
124  void generate_new_keys_local_planning(
125  const std::vector<DistributedIndex::KeyType> & global_key_upper_bound ,
126  const std::vector<size_t> & requests_local ,
127  std::vector<long> & new_requests ,
128  std::vector<KeyType> & requested_keys ,
129  std::vector<KeyType> & contrib_keys ) const ;
130 
134  void generate_new_keys_global_planning(
135  const std::vector<long> & new_request ,
136  std::vector<long> & my_donations ) const ;
137 
139  void query( const std::vector<KeyProc> & request ,
140  std::vector<KeyProc> & sharing_of_keys ) const ;
141 
142  /*------------------------------------------------------------------*/
146  ProcType to_which_proc( const KeyType & key ) const ;
147 
148  /*------------------------------------------------------------------*/
149  /* Disable default construction and copies. */
150 
153  DistributedIndex & operator = ( const DistributedIndex & );
154 
155  /*------------------------------------------------------------------*/
156 
157  ParallelMachine m_comm ;
158  ProcType m_comm_rank ;
159  ProcType m_comm_size ;
160  size_t m_span_count ;
161  std::vector<KeySpan> m_key_span ;
162  std::vector<KeyProc> m_key_usage ;
163 
164  /* Unit testing of internal methods requires the unit test to have
165  * access to those internal methods.
166  */
167  friend class ::UnitTestSTKParallelDistributedIndex ;
168 };
169 
170 //----------------------------------------------------------------------
171 
172 } // namespace parallel
173 } // namespace stk_classic
174 
175 //----------------------------------------------------------------------
176 
177 #endif
178 
void query_to_usage(const std::vector< KeyType > &keys, std::vector< KeyProc > &sharing_of_keys) const
Query which processors added the given keys. The results of the query are pushed to the processes on ...
void query(std::vector< KeyProc > &sharing_of_local_keys) const
Query with which process the local added keys are shared.
void generate_new_keys(const std::vector< size_t > &requests, std::vector< std::vector< KeyType > > &requested_keys)
Request a collection of unused keys.
Sierra Toolkit.
MPI_Comm ParallelMachine
Definition: Parallel.hpp:32
void update_keys(const std::vector< KeyType > &add_new_keys, const std::vector< KeyType > &remove_existing_keys)
Update a parallel index with new and changed keys. FIRST: Remove this process&#39; participation in the e...
Parallel cross-reference index for a collection of keys.