|
Sierra Toolkit Version of the Day
|
00001 /*------------------------------------------------------------------------*/ 00002 /* Copyright 2010 Sandia Corporation. */ 00003 /* Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive */ 00004 /* license for use of this work by or on behalf of the U.S. Government. */ 00005 /* Export of this program may require a license from the */ 00006 /* United States Government. */ 00007 /*------------------------------------------------------------------------*/ 00008 00009 #ifndef stk_util_parallel_DistributedIndex_hpp 00010 #define stk_util_parallel_DistributedIndex_hpp 00011 00012 #include <stdint.h> 00013 #include <utility> 00014 #include <vector> 00015 #include <stk_util/parallel/Parallel.hpp> 00016 00017 class UnitTestSTKParallelDistributedIndex ; 00018 00019 namespace stk { 00020 namespace parallel { 00021 00039 class DistributedIndex { 00040 public: 00041 typedef uint64_t KeyType ; 00042 typedef int ProcType ; 00043 typedef std::pair<KeyType,KeyType> KeySpan ; 00044 typedef std::pair<KeyType,ProcType> KeyProc ; 00045 00046 /*----------------------------------------*/ 00047 00048 ~DistributedIndex(); 00049 00059 DistributedIndex( ParallelMachine comm , 00060 const std::vector<KeySpan> & partition_spans ); 00061 00062 /*----------------------------------------*/ 00064 void query( std::vector<KeyProc> & sharing_of_local_keys ) const ; 00065 00070 void query( const std::vector<KeyType> & keys , 00071 std::vector<KeyProc> & sharing_of_keys ) const ; 00072 00077 void query_to_usage( const std::vector<KeyType> & keys , 00078 std::vector<KeyProc> & sharing_of_keys ) const ; 00079 00080 /*------------------------------------------------------------------*/ 00085 void update_keys( const std::vector<KeyType> & add_new_keys , 00086 const std::vector<KeyType> & remove_existing_keys ); 00087 00106 void generate_new_keys( 00107 const std::vector<size_t> & requests , 00108 std::vector< std::vector<KeyType> > & requested_keys ); 00109 00110 private: 00111 00112 /*------------------------------------------------------------------*/ 00115 void generate_new_global_key_upper_bound( 00116 const std::vector<size_t> & requests , 00117 std::vector<DistributedIndex::KeyType> & global_key_upper_bound ) const; 00118 00119 00123 void generate_new_keys_local_planning( 00124 const std::vector<DistributedIndex::KeyType> & global_key_upper_bound , 00125 const std::vector<size_t> & requests_local , 00126 std::vector<long> & new_requests , 00127 std::vector<KeyType> & requested_keys , 00128 std::vector<KeyType> & contrib_keys ) const ; 00129 00133 void generate_new_keys_global_planning( 00134 const std::vector<long> & new_request , 00135 std::vector<long> & my_donations ) const ; 00136 00138 void query( const std::vector<KeyProc> & request , 00139 std::vector<KeyProc> & sharing_of_keys ) const ; 00140 00141 /*------------------------------------------------------------------*/ 00145 ProcType to_which_proc( const KeyType & key ) const ; 00146 00147 /*------------------------------------------------------------------*/ 00148 /* Disable default construction and copies. */ 00149 00150 DistributedIndex(); 00151 DistributedIndex( const DistributedIndex & ); 00152 DistributedIndex & operator = ( const DistributedIndex & ); 00153 00154 /*------------------------------------------------------------------*/ 00155 00156 ParallelMachine m_comm ; 00157 ProcType m_comm_rank ; 00158 ProcType m_comm_size ; 00159 size_t m_span_count ; 00160 std::vector<KeySpan> m_key_span ; 00161 std::vector<KeyProc> m_key_usage ; 00162 00163 /* Unit testing of internal methods requires the unit test to have 00164 * access to those internal methods. 00165 */ 00166 friend class ::UnitTestSTKParallelDistributedIndex ; 00167 }; 00168 00169 //---------------------------------------------------------------------- 00170 00171 } // namespace parallel 00172 } // namespace stk 00173 00174 //---------------------------------------------------------------------- 00175 00176 #endif 00177