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 #include "Epetra_ConfigDefs.h"
48 #include "Epetra_DistObject.h"
49 #include "Epetra_BlockMap.h"
50 #include "Epetra_Distributor.h"
51 
52 template<typename value_type> class Epetra_HashTable;
53 class Epetra_Map;
54 
56 
105 class EPETRA_LIB_DLL_EXPORT Epetra_MapColoring: public Epetra_DistObject {
106 
107  public:
108 
110 
111 
123  Epetra_MapColoring(const Epetra_BlockMap& Map, const int DefaultColor = 0);
124 
126 
144  Epetra_MapColoring(const Epetra_BlockMap& Map, int * ElementColors, const int DefaultColor = 0);
145 
147 
148  Epetra_MapColoring(const Epetra_MapColoring& Source);
149 
151 
152  virtual ~Epetra_MapColoring();
154 
156 
157 
159 
162  int& operator [] (int LID) {ListsAreValid_ = false; return ElementColors_[LID];};
163 
165 
170  int& operator () (long long GID) {ListsAreValid_ = false; return ElementColors_[Map().LID(GID)];};
172 
174 
175 
179  const int& operator [] (int LID) const { return ElementColors_[LID];};
180 
182 
187  const int& operator () (long long GID) const {return ElementColors_[Map().LID(GID)];};
189 
191 
192  int NumColors() const {if (!ListsAreValid_) GenerateLists(); return(NumColors_);};
194 
196  int MaxNumColors() const;
197 
199 
203  int * ListOfColors() const {if (!ListsAreValid_) GenerateLists(); return(ListOfColors_);};
204 
206  int DefaultColor() const {return(DefaultColor_);};
207 
209  int NumElementsWithColor(int Color) const;
210 
212 
216  int * ColorLIDList(int Color) const;
217 
219 
222  int * ElementColors() const{if (!ListsAreValid_) GenerateLists(); return(ElementColors_);};
223 
225 
227 
234  Epetra_Map * GenerateMap(int Color) const;
235 
237 
244  Epetra_BlockMap * GenerateBlockMap(int Color) const;
246 
248 
249 
251  virtual void Print(std::ostream & os) const;
253 
254  private:
255  int Allocate(int * ElementColors, int Increment);
256  int GenerateLists() const;
257  int DeleteLists() const;
258  bool InItemList(int ColorValue) const;
259 
260  // Routines to implement Epetra_DistObject virtual methods
261 
262  int CheckSizes(const Epetra_SrcDistObject& A);
263  int CopyAndPermute(const Epetra_SrcDistObject & Source,
264  int NumSameIDs,
265  int NumPermuteIDs,
266  int * PermuteToLIDs,
267  int * PermuteFromLIDs,
268  const Epetra_OffsetIndex * Indexor,
269  Epetra_CombineMode CombineMode = Zero);
270 
271  int PackAndPrepare(const Epetra_SrcDistObject & Source,
272  int NumExportIDs,
273  int * ExportLIDs,
274  int & LenExports,
275  char * & Exports,
276  int & SizeOfPacket,
277  int * Sizes,
278  bool & VarSizes,
279  Epetra_Distributor & Distor);
280 
281  int UnpackAndCombine(const Epetra_SrcDistObject & Source,
282  int NumImportIDs,
283  int * ImportLIDs,
284  int LenImports,
285  char * Imports,
286  int & SizeOfPacket,
287  Epetra_Distributor & Distor,
288  Epetra_CombineMode CombineMode,
289  const Epetra_OffsetIndex * Indexor );
290 
291 
292  struct ListItem {
295 
296  ListItem( const int itemValue = 0, ListItem * nextItem = 0)
297  : ItemValue(itemValue), NextItem(nextItem){}
298 
299  // Constructors commented out due to Intel v.7.1 compiler error (4/2005).
300  //ListItem(const Epetra_MapColoring::ListItem & Item); // Make these inaccessible
301  //ListItem & operator=(const Epetra_MapColoring::ListItem & Item);
302  };
303 
307  mutable int NumColors_;
308  mutable int * ListOfColors_;
309  mutable int * ColorCount_;
310  mutable int * ElementColors_;
311  mutable int ** ColorLists_;
313  mutable bool ListsAreGenerated_;
314  mutable bool ListsAreValid_;
315 
316  Epetra_MapColoring & operator=(const Epetra_MapColoring & Coloring); // Make these inaccessible
317 
318  template<typename int_type>
319  Epetra_Map * TGenerateMap(int Color) const;
320 
321  template<typename int_type>
322  Epetra_BlockMap * TGenerateBlockMap(int Color) const;
323  };
324 
325 #endif /* EPETRA_MAPCOLORING_H */
Epetra_Map: A class for partitioning vectors and matrices.
Definition: Epetra_Map.h:119
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.