DistributedIndex.hpp

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 
00073   /*------------------------------------------------------------------*/
00078   void update_keys( const std::vector<KeyType> & add_new_keys ,
00079                     const std::vector<KeyType> & remove_existing_keys );
00080 
00099   void generate_new_keys(
00100     const std::vector<size_t>                 & requests ,
00101           std::vector< std::vector<KeyType> > & requested_keys );
00102 
00103 private:
00104 
00105   /*------------------------------------------------------------------*/
00108   void generate_new_keys_global_counts(
00109     const std::vector<size_t> & requests ,
00110           std::vector<size_t> & requests_global_sum ,
00111           std::vector<size_t> & existing_global_sum ) const ;
00112 
00116   void generate_new_keys_local_planning(
00117     const std::vector<size_t>  & existing_global_sum ,
00118     const std::vector<size_t>  & requests_global_sum ,
00119     const std::vector<size_t>  & requests_local ,
00120           std::vector<long>    & new_requests ,
00121           std::vector<KeyType> & requested_keys ,
00122           std::vector<KeyType> & contrib_keys ) const ;
00123 
00127   void generate_new_keys_global_planning(
00128     const std::vector<KeyType> & contrib_keys ,
00129     const std::vector<long>    & new_request ,
00130           std::vector<long>    & my_donations ) const ;
00131 
00133   void query( const std::vector<KeyProc> & request ,
00134                     std::vector<KeyProc> & sharing_of_keys ) const ;
00135 
00136   /*------------------------------------------------------------------*/
00140   inline ProcType to_which_proc( const KeyType & key ) const ;
00141 
00145   inline size_t chunk_offset( ProcType rank , size_t chunk ) 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<size_t>  m_chunk_first ; 
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
00174 
00175 //----------------------------------------------------------------------
00176 
00177 #endif
00178 

Generated on Tue Jul 13 09:27:32 2010 for Sierra Toolkit by  doxygen 1.4.7