Epetra Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Epetra_MapColoring.h
Go to the documentation of this file.
1 /*
2 //@HEADER
3 // ************************************************************************
4 //
5 // Epetra: Linear Algebra Services Package
6 // Copyright 2011 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
39 //
40 // ************************************************************************
41 //@HEADER
42 */
43 
44 #ifndef EPETRA_MAPCOLORING_H
45 #define EPETRA_MAPCOLORING_H
46 
47 #if defined(Epetra_SHOW_DEPRECATED_WARNINGS)
48 #ifdef __GNUC__
49 #warning "The Epetra package is deprecated"
50 #endif
51 #endif
52 
53 
54 
55 #include "Epetra_ConfigDefs.h"
56 #include "Epetra_DistObject.h"
57 #include "Epetra_BlockMap.h"
58 #include "Epetra_Distributor.h"
59 
60 template<typename value_type> class Epetra_HashTable;
61 class Epetra_Map;
62 
64 
113 class EPETRA_LIB_DLL_EXPORT Epetra_MapColoring: public Epetra_DistObject {
114 
115  public:
116 
118 
119 
131  Epetra_MapColoring(const Epetra_BlockMap& Map, const int DefaultColor = 0);
132 
134 
152  Epetra_MapColoring(const Epetra_BlockMap& Map, int * ElementColors, const int DefaultColor = 0);
153 
155 
156  Epetra_MapColoring(const Epetra_MapColoring& Source);
157 
159 
160  virtual ~Epetra_MapColoring();
162 
164 
165 
167 
170  int& operator [] (int LID) {ListsAreValid_ = false; return ElementColors_[LID];};
171 
173 
178  int& operator () (long long GID) {ListsAreValid_ = false; return ElementColors_[Map().LID(GID)];};
180 
182 
183 
187  const int& operator [] (int LID) const { return ElementColors_[LID];};
188 
190 
195  const int& operator () (long long GID) const {return ElementColors_[Map().LID(GID)];};
197 
199 
200  int NumColors() const {if (!ListsAreValid_) GenerateLists(); return(NumColors_);};
202 
204  int MaxNumColors() const;
205 
207 
211  int * ListOfColors() const {if (!ListsAreValid_) GenerateLists(); return(ListOfColors_);};
212 
214  int DefaultColor() const {return(DefaultColor_);};
215 
217  int NumElementsWithColor(int Color) const;
218 
220 
224  int * ColorLIDList(int Color) const;
225 
227 
230  int * ElementColors() const{if (!ListsAreValid_) GenerateLists(); return(ElementColors_);};
231 
233 
235 
242  Epetra_Map * GenerateMap(int Color) const;
243 
245 
252  Epetra_BlockMap * GenerateBlockMap(int Color) const;
254 
256 
257 
259  virtual void Print(std::ostream & os) const;
261 
262  private:
263  int Allocate(int * ElementColors, int Increment);
264  int GenerateLists() const;
265  int DeleteLists() const;
266  bool InItemList(int ColorValue) const;
267 
268  // Routines to implement Epetra_DistObject virtual methods
269 
270  int CheckSizes(const Epetra_SrcDistObject& A);
271  int CopyAndPermute(const Epetra_SrcDistObject & Source,
272  int NumSameIDs,
273  int NumPermuteIDs,
274  int * PermuteToLIDs,
275  int * PermuteFromLIDs,
276  const Epetra_OffsetIndex * Indexor,
277  Epetra_CombineMode CombineMode = Zero);
278 
279  int PackAndPrepare(const Epetra_SrcDistObject & Source,
280  int NumExportIDs,
281  int * ExportLIDs,
282  int & LenExports,
283  char * & Exports,
284  int & SizeOfPacket,
285  int * Sizes,
286  bool & VarSizes,
287  Epetra_Distributor & Distor);
288 
289  int UnpackAndCombine(const Epetra_SrcDistObject & Source,
290  int NumImportIDs,
291  int * ImportLIDs,
292  int LenImports,
293  char * Imports,
294  int & SizeOfPacket,
295  Epetra_Distributor & Distor,
296  Epetra_CombineMode CombineMode,
297  const Epetra_OffsetIndex * Indexor );
298 
299 
300  struct ListItem {
303 
304  ListItem( const int itemValue = 0, ListItem * nextItem = 0)
305  : ItemValue(itemValue), NextItem(nextItem){}
306 
307  // Constructors commented out due to Intel v.7.1 compiler error (4/2005).
308  //ListItem(const Epetra_MapColoring::ListItem & Item); // Make these inaccessible
309  //ListItem & operator=(const Epetra_MapColoring::ListItem & Item);
310  };
311 
315  mutable int NumColors_;
316  mutable int * ListOfColors_;
317  mutable int * ColorCount_;
318  mutable int * ElementColors_;
319  mutable int ** ColorLists_;
321  mutable bool ListsAreGenerated_;
322  mutable bool ListsAreValid_;
323 
324  Epetra_MapColoring & operator=(const Epetra_MapColoring & Coloring); // Make these inaccessible
325 
326  template<typename int_type>
327  Epetra_Map * TGenerateMap(int Color) const;
328 
329  template<typename int_type>
330  Epetra_BlockMap * TGenerateBlockMap(int Color) const;
331  };
332 
333 #endif /* EPETRA_MAPCOLORING_H */
Epetra_Map: A class for partitioning vectors and matrices.
Definition: Epetra_Map.h:127
Epetra_MapColoring: A class for coloring Epetra_Map and Epetra_BlockMap objects.
Epetra_HashTable< int > * ColorIDs_
Epetra_Distributor: The Epetra Gather/Scatter Setup Base Class.
virtual int CopyAndPermute(const Epetra_SrcDistObject &Source, int NumSameIDs, int NumPermuteIDs, int *PermuteToLIDs, int *PermuteFromLIDs, const Epetra_OffsetIndex *Indexor, Epetra_CombineMode CombineMode=Zero)=0
Perform ID copies and permutations that are on processor.
Epetra_OffsetIndex: This class builds index for efficient mapping of data from one Epetra_CrsGraph ba...
virtual void Print(std::ostream &os) const
Print method.
virtual int CheckSizes(const Epetra_SrcDistObject &Source)=0
Allows the source and target (this) objects to be compared for compatibility, return nonzero if not...
int DefaultColor() const
Returns default color.
int * ListOfColors() const
Array of length NumColors() containing List of color values used in this coloring.
int * ElementColors() const
Returns pointer to array of the colors associated with the LIDs on the calling processor.
virtual int UnpackAndCombine(const Epetra_SrcDistObject &Source, int NumImportIDs, int *ImportLIDs, int LenImports, char *Imports, int &SizeOfPacket, Epetra_Distributor &Distor, Epetra_CombineMode CombineMode, const Epetra_OffsetIndex *Indexor)=0
Perform any unpacking and combining after call to DoTransfer().
Epetra_BlockMap: A class for partitioning block element vectors and matrices.
int LID(int GID) const
Returns local ID of global ID, return -1 if not found on this processor.
Epetra_DistObject & operator=(const Epetra_DistObject &src)
Epetra_CombineMode
ListItem(const int itemValue=0, ListItem *nextItem=0)
Epetra_SrcDistObject: A class for supporting flexible source distributed objects for import/export op...
Epetra_DistObject: A class for constructing and using dense multi-vectors, vectors and matrices in pa...
virtual int PackAndPrepare(const Epetra_SrcDistObject &Source, int NumExportIDs, int *ExportLIDs, int &LenExports, char *&Exports, int &SizeOfPacket, int *Sizes, bool &VarSizes, Epetra_Distributor &Distor)=0
Perform any packing or preparation required for call to DoTransfer().
const Epetra_BlockMap & Map() const
Returns the address of the Epetra_BlockMap for this multi-vector.