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 2001 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 #include "Epetra_DistObject.h"
00047 #include "Epetra_BlockMap.h"
00048 #include "Epetra_Distributor.h"
00049 class Epetra_HashTable;
00050 class Epetra_Map;
00051 
00053 
00102 class EPETRA_LIB_DLL_EXPORT Epetra_MapColoring: public Epetra_DistObject {
00103     
00104   public:
00105 
00107 
00108 
00109 
00120   Epetra_MapColoring(const Epetra_BlockMap& Map, const int DefaultColor = 0);
00121 
00123 
00141   Epetra_MapColoring(const Epetra_BlockMap& Map, int * ElementColors, const int DefaultColor = 0);
00142 
00144   
00145   Epetra_MapColoring(const Epetra_MapColoring& Source);
00146   
00148   
00149   virtual ~Epetra_MapColoring();
00151   
00153 
00154   
00156 
00159   int& operator [] (int LID) {ListsAreValid_ = false; return ElementColors_[LID];};
00160   
00162 
00167   int& operator () (int GID) {ListsAreValid_ = false; return ElementColors_[Map().LID(GID)];};
00169   
00171 
00172 
00173 
00176   const int& operator [] (int LID) const { return ElementColors_[LID];};
00177   
00179 
00184   const int& operator () (int GID) const {return ElementColors_[Map().LID(GID)];};
00186   
00188 
00189 
00190   int NumColors() const {if (!ListsAreValid_) GenerateLists(); return(NumColors_);};
00191   
00193   int MaxNumColors() const;
00194   
00196 
00200   int * ListOfColors() const {if (!ListsAreValid_) GenerateLists(); return(ListOfColors_);};
00201   
00203   int DefaultColor() const {return(DefaultColor_);};
00204   
00206   int NumElementsWithColor(int Color) const;
00207   
00209 
00213   int * ColorLIDList(int Color) const;
00214   
00216 
00219   int * ElementColors() const{if (!ListsAreValid_) GenerateLists(); return(ElementColors_);};
00220   
00222 
00223 
00224 
00225 
00231   Epetra_Map * GenerateMap(int Color) const;
00232   
00234 
00241   Epetra_BlockMap * GenerateBlockMap(int Color) const;
00243   
00245 
00246   
00248   virtual void Print(ostream & os) const;
00250   
00251  private:
00252   int Allocate(int * ElementColors, int Increment);
00253   int GenerateLists() const;
00254   int DeleteLists() const;
00255   bool InItemList(int ColorValue) const;
00256   
00257    // Routines to implement Epetra_DistObject virtual methods
00258 
00259   int CheckSizes(const Epetra_SrcDistObject& A);
00260   int CopyAndPermute(const Epetra_SrcDistObject & Source, 
00261                      int NumSameIDs, 
00262                      int NumPermuteIDs,
00263                      int * PermuteToLIDs,
00264                      int * PermuteFromLIDs,
00265                      const Epetra_OffsetIndex * Indexor);
00266 
00267   int PackAndPrepare(const Epetra_SrcDistObject & Source,
00268                      int NumExportIDs,
00269                      int * ExportLIDs,
00270                      int & LenExports,
00271                      char * & Exports,
00272                      int & SizeOfPacket,
00273                      int * Sizes,
00274                      bool & VarSizes,
00275                      Epetra_Distributor & Distor);
00276   
00277   int UnpackAndCombine(const Epetra_SrcDistObject & Source,
00278            int NumImportIDs,
00279                        int * ImportLIDs, 
00280                        int LenImports,
00281            char * Imports,
00282                        int & SizeOfPacket, 
00283            Epetra_Distributor & Distor,
00284                        Epetra_CombineMode CombineMode,
00285                        const Epetra_OffsetIndex * Indexor );
00286 
00287 
00288   struct ListItem {
00289     int ItemValue;
00290     ListItem * NextItem;
00291     
00292     ListItem( const int itemValue = 0, ListItem * nextItem = 0)
00293       : ItemValue(itemValue), NextItem(nextItem){}
00294 
00295     // Constructors commented out due to Intel v.7.1 compiler error (4/2005).
00296     //ListItem(const Epetra_MapColoring::ListItem & Item); // Make these inaccessible
00297     //ListItem & operator=(const Epetra_MapColoring::ListItem & Item);
00298   };
00299   
00300   int DefaultColor_;
00301   mutable Epetra_HashTable * ColorIDs_;
00302   mutable ListItem * FirstColor_;
00303   mutable int NumColors_;
00304   mutable int * ListOfColors_;
00305   mutable int * ColorCount_;
00306   mutable int * ElementColors_;
00307   mutable int ** ColorLists_;
00308   bool Allocated_;
00309   mutable bool ListsAreGenerated_;
00310   mutable bool ListsAreValid_;
00311   
00312   Epetra_MapColoring & operator=(const Epetra_MapColoring & Coloring); // Make these inaccessible
00313 
00314   
00315   
00316 };
00317 
00318 #endif /* EPETRA_MAPCOLORING_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines