|
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 <cstddef> 00016 #include <stk_util/parallel/Parallel.hpp> 00017 00018 class UnitTestSTKParallelDistributedIndex ; 00019 00020 namespace stk_classic { 00021 namespace parallel { 00022 00040 class DistributedIndex { 00041 public: 00042 typedef uint64_t KeyType ; 00043 typedef int ProcType ; 00044 typedef std::pair<KeyType,KeyType> KeySpan ; 00045 typedef std::pair<KeyType,ProcType> KeyProc ; 00046 00047 /*----------------------------------------*/ 00048 00049 ~DistributedIndex(); 00050 00060 DistributedIndex( ParallelMachine comm , 00061 const std::vector<KeySpan> & partition_spans ); 00062 00063 /*----------------------------------------*/ 00065 void query( std::vector<KeyProc> & sharing_of_local_keys ) const ; 00066 00071 void query( const std::vector<KeyType> & keys , 00072 std::vector<KeyProc> & sharing_of_keys ) const ; 00073 00078 void query_to_usage( const std::vector<KeyType> & keys , 00079 std::vector<KeyProc> & sharing_of_keys ) const ; 00080 00081 /*------------------------------------------------------------------*/ 00086 void update_keys( const std::vector<KeyType> & add_new_keys , 00087 const std::vector<KeyType> & remove_existing_keys ); 00088 00107 void generate_new_keys( 00108 const std::vector<size_t> & requests , 00109 std::vector< std::vector<KeyType> > & requested_keys ); 00110 00111 private: 00112 00113 /*------------------------------------------------------------------*/ 00116 void generate_new_global_key_upper_bound( 00117 const std::vector<size_t> & requests , 00118 std::vector<DistributedIndex::KeyType> & global_key_upper_bound ) const; 00119 00120 00124 void generate_new_keys_local_planning( 00125 const std::vector<DistributedIndex::KeyType> & global_key_upper_bound , 00126 const std::vector<size_t> & requests_local , 00127 std::vector<long> & new_requests , 00128 std::vector<KeyType> & requested_keys , 00129 std::vector<KeyType> & contrib_keys ) const ; 00130 00134 void generate_new_keys_global_planning( 00135 const std::vector<long> & new_request , 00136 std::vector<long> & my_donations ) const ; 00137 00139 void query( const std::vector<KeyProc> & request , 00140 std::vector<KeyProc> & sharing_of_keys ) const ; 00141 00142 /*------------------------------------------------------------------*/ 00146 ProcType to_which_proc( const KeyType & key ) const ; 00147 00148 /*------------------------------------------------------------------*/ 00149 /* Disable default construction and copies. */ 00150 00151 DistributedIndex(); 00152 DistributedIndex( const DistributedIndex & ); 00153 DistributedIndex & operator = ( const DistributedIndex & ); 00154 00155 /*------------------------------------------------------------------*/ 00156 00157 ParallelMachine m_comm ; 00158 ProcType m_comm_rank ; 00159 ProcType m_comm_size ; 00160 size_t m_span_count ; 00161 std::vector<KeySpan> m_key_span ; 00162 std::vector<KeyProc> m_key_usage ; 00163 00164 /* Unit testing of internal methods requires the unit test to have 00165 * access to those internal methods. 00166 */ 00167 friend class ::UnitTestSTKParallelDistributedIndex ; 00168 }; 00169 00170 //---------------------------------------------------------------------- 00171 00172 } // namespace parallel 00173 } // namespace stk_classic 00174 00175 //---------------------------------------------------------------------- 00176 00177 #endif 00178