Epetra Package Browser (Single Doxygen Collection) Development
Epetra_MapColoring.h
Go to the documentation of this file.
00001 /*
00002 //@HEADER
00003 // ************************************************************************
00004 //
00005 //               Epetra: Linear Algebra Services Package
00006 //                 Copyright 2011 Sandia Corporation
00007 //
00008 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00009 // the U.S. Government retains certain rights in this software.
00010 //
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are
00013 // met:
00014 //
00015 // 1. Redistributions of source code must retain the above copyright
00016 // notice, this list of conditions and the following disclaimer.
00017 //
00018 // 2. Redistributions in binary form must reproduce the above copyright
00019 // notice, this list of conditions and the following disclaimer in the
00020 // documentation and/or other materials provided with the distribution.
00021 //
00022 // 3. Neither the name of the Corporation nor the names of the
00023 // contributors may be used to endorse or promote products derived from
00024 // this software without specific prior written permission.
00025 //
00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 //
00038 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00039 //
00040 // ************************************************************************
00041 //@HEADER
00042 */
00043 
00044 #ifndef EPETRA_MAPCOLORING_H
00045 #define EPETRA_MAPCOLORING_H
00046 
00047 #include "Epetra_ConfigDefs.h"
00048 #include "Epetra_DistObject.h"
00049 #include "Epetra_BlockMap.h"
00050 #include "Epetra_Distributor.h"
00051 
00052 template<typename value_type> class Epetra_HashTable;
00053 class Epetra_Map;
00054 
00056 
00105 class EPETRA_LIB_DLL_EXPORT Epetra_MapColoring: public Epetra_DistObject {
00106 
00107   public:
00108 
00110 
00111 
00112 
00123   Epetra_MapColoring(const Epetra_BlockMap& Map, const int DefaultColor = 0);
00124 
00126 
00144   Epetra_MapColoring(const Epetra_BlockMap& Map, int * ElementColors, const int DefaultColor = 0);
00145 
00147 
00148   Epetra_MapColoring(const Epetra_MapColoring& Source);
00149 
00151 
00152   virtual ~Epetra_MapColoring();
00154 
00156 
00157 
00159 
00162   int& operator [] (int LID) {ListsAreValid_ = false; return ElementColors_[LID];};
00163 
00165 
00170   int& operator () (long long GID) {ListsAreValid_ = false; return ElementColors_[Map().LID(GID)];};
00172 
00174 
00175 
00176 
00179   const int& operator [] (int LID) const { return ElementColors_[LID];};
00180 
00182 
00187   const int& operator () (long long GID) const {return ElementColors_[Map().LID(GID)];};
00189 
00191 
00192 
00193   int NumColors() const {if (!ListsAreValid_) GenerateLists(); return(NumColors_);};
00194 
00196   int MaxNumColors() const;
00197 
00199 
00203   int * ListOfColors() const {if (!ListsAreValid_) GenerateLists(); return(ListOfColors_);};
00204 
00206   int DefaultColor() const {return(DefaultColor_);};
00207 
00209   int NumElementsWithColor(int Color) const;
00210 
00212 
00216   int * ColorLIDList(int Color) const;
00217 
00219 
00222   int * ElementColors() const{if (!ListsAreValid_) GenerateLists(); return(ElementColors_);};
00223 
00225 
00226 
00227 
00228 
00234   Epetra_Map * GenerateMap(int Color) const;
00235 
00237 
00244   Epetra_BlockMap * GenerateBlockMap(int Color) const;
00246 
00248 
00249 
00251   virtual void Print(std::ostream & os) const;
00253 
00254  private:
00255   int Allocate(int * ElementColors, int Increment);
00256   int GenerateLists() const;
00257   int DeleteLists() const;
00258   bool InItemList(int ColorValue) const;
00259 
00260    // Routines to implement Epetra_DistObject virtual methods
00261 
00262   int CheckSizes(const Epetra_SrcDistObject& A);
00263   int CopyAndPermute(const Epetra_SrcDistObject & Source,
00264                      int NumSameIDs,
00265                      int NumPermuteIDs,
00266                      int * PermuteToLIDs,
00267                      int * PermuteFromLIDs,
00268                      const Epetra_OffsetIndex * Indexor);
00269 
00270   int PackAndPrepare(const Epetra_SrcDistObject & Source,
00271                      int NumExportIDs,
00272                      int * ExportLIDs,
00273                      int & LenExports,
00274                      char * & Exports,
00275                      int & SizeOfPacket,
00276                      int * Sizes,
00277                      bool & VarSizes,
00278                      Epetra_Distributor & Distor);
00279 
00280   int UnpackAndCombine(const Epetra_SrcDistObject & Source,
00281            int NumImportIDs,
00282                        int * ImportLIDs,
00283                        int LenImports,
00284            char * Imports,
00285                        int & SizeOfPacket,
00286            Epetra_Distributor & Distor,
00287                        Epetra_CombineMode CombineMode,
00288                        const Epetra_OffsetIndex * Indexor );
00289 
00290 
00291   struct ListItem {
00292     int ItemValue;
00293     ListItem * NextItem;
00294 
00295     ListItem( const int itemValue = 0, ListItem * nextItem = 0)
00296       : ItemValue(itemValue), NextItem(nextItem){}
00297 
00298     // Constructors commented out due to Intel v.7.1 compiler error (4/2005).
00299     //ListItem(const Epetra_MapColoring::ListItem & Item); // Make these inaccessible
00300     //ListItem & operator=(const Epetra_MapColoring::ListItem & Item);
00301   };
00302 
00303   int DefaultColor_;
00304   mutable Epetra_HashTable<int> * ColorIDs_;
00305   mutable ListItem * FirstColor_;
00306   mutable int NumColors_;
00307   mutable int * ListOfColors_;
00308   mutable int * ColorCount_;
00309   mutable int * ElementColors_;
00310   mutable int ** ColorLists_;
00311   bool Allocated_;
00312   mutable bool ListsAreGenerated_;
00313   mutable bool ListsAreValid_;
00314 
00315   Epetra_MapColoring & operator=(const Epetra_MapColoring & Coloring); // Make these inaccessible
00316 
00317   template<typename int_type>
00318   Epetra_Map * TGenerateMap(int Color) const;
00319 
00320   template<typename int_type>
00321   Epetra_BlockMap * TGenerateBlockMap(int Color) const;
00322  };
00323 
00324 #endif /* EPETRA_MAPCOLORING_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines