IFPACK  Development
Ifpack_OverlappingPartitioner.h
1 /*@HEADER
2 // ***********************************************************************
3 //
4 // Ifpack: Object-Oriented Algebraic Preconditioner Package
5 // Copyright (2002) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 //@HEADER
41 */
42 
43 #ifndef IFPACK_OVERLAPPINGPARTITIONER_H
44 #define IFPACK_OVERLAPPINGPARTITIONER_H
45 
46 #include "Ifpack_ConfigDefs.h"
47 #include "Ifpack_Partitioner.h"
48 #include "Teuchos_ParameterList.hpp"
49 class Epetra_Comm;
50 class Ifpack_Graph;
51 class Epetra_Map;
52 class Epetra_BlockMap;
53 class Epetra_Import;
54 
55 /* \brief Ifpack_OverlappingPartitioner: A class to create overlapping
56  partitions of a local graph.
57 
58 Class Ifpack_OverlappingPartitioner enables the extension of
59 non-overlapping partitions to an arbitrary value of overlap.
60 Note that overlap refers to the overlap among \e local parts,
61 and not the overlap among the processes.
62 
63 Supported parameters are:
64 - \c "partitioner: local parts": the required number of parts;
65 - \c "partitioner: overlap": the required amount of overlap is set in
66  parameter. Default = 0 (integer).
67 - \c "partitioner: verbose": if \c true, information are reported on
68  cout. Nothing is reported otherwise.
69 
70 This class is a semi-virtual class, that contains the basic utilities
71 for derived classes Ifpack_LinearPartitioner, Ifpack_GreedyPartitioner,
72 Ifpack_METISPartitioner, and Ifpack_EquationPartitioner. Graphs in
73 input to one of these classes are supposed to contain no singletons.
74 Usually, this means that the graph is derived from an Epetra_RowMatrix,
75 that has been filtered using Ifpack_SingletonFilter.
76 
77 \author Marzio Sala, SNL 9214.
78 
79 \date Last update: Oct-04.
80 */
82 
83 public:
84 
87 
90 
92  int NumLocalParts() const
93  {
94  return(NumLocalParts_);
95  }
96 
98  int OverlappingLevel() const
99  {
100  return(OverlappingLevel_);
101  }
102 
104 
111  int operator() (int MyRow) const
112  {
113  if ((MyRow < 0) || (MyRow > NumMyRows()))
114  IFPACK_CHK_ERR(-1); // input value not valid
115 
116  return(Partition_[MyRow]);
117  }
118 
120  int operator() (int i, int j) const
121  {
122  if ((i < 0) || (i >= NumLocalParts()))
123  IFPACK_CHK_ERR(-1);
124 
125  if ((j < 0) || (j > (int)Parts_[i].size()))
126  IFPACK_CHK_ERR(-2);
127 
128  return(Parts_[i][j]);
129  }
130 
132  inline int NumRowsInPart(const int Part) const
133  {
134  return(Parts_[Part].size());
135  }
136 
137  int RowsInPart(const int Part, int* List) const
138  {
139  for (int i = 0 ; i < NumRowsInPart(Part) ; ++i)
140  List[i] = Parts_[Part][i];
141 
142  return(0);
143  }
144 
145  const int* NonOverlappingPartition() const
146  {
147  return(&Partition_[0]);
148  }
149 
151 
156  virtual int SetParameters(Teuchos::ParameterList& List);
157 
159 
163  virtual int SetPartitionParameters(Teuchos::ParameterList& List) = 0;
164 
166  virtual int Compute();
167 
169  virtual int ComputePartitions() = 0;
170 
172  virtual int ComputeOverlappingPartitions();
173 
175  bool IsComputed()
176  {
177  return(IsComputed_);
178  }
179 
181  virtual std::ostream& Print(std::ostream& os) const;
182 
183 protected:
184 
186  int NumMyRows() const;
188  int NumMyNonzeros() const;
189 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
190  int NumGlobalRows() const;
192 #endif
193  long long NumGlobalRows64() const;
195  int MaxNumEntries() const;
197  const Epetra_Comm& Comm() const;
201  std::vector<int> Partition_;
203  // partition i
204  std::vector<std::vector<int> > Parts_;
212  bool verbose_;
213 
214 }; // class Ifpack_Partitioner
215 
216 #endif // IFPACK_OVERLAPPINGPARTITIONER_H
Ifpack_OverlappingPartitioner::NumGlobalRows
int NumGlobalRows() const
Returns the number of global rows.
Definition: Ifpack_OverlappingPartitioner.cpp:266
Ifpack_OverlappingPartitioner::Ifpack_OverlappingPartitioner
Ifpack_OverlappingPartitioner(const Ifpack_Graph *Graph)
Constructor.
Definition: Ifpack_OverlappingPartitioner.cpp:57
Ifpack_OverlappingPartitioner
Definition: Ifpack_OverlappingPartitioner.h:81
Ifpack_OverlappingPartitioner::MaxNumEntries
int MaxNumEntries() const
Returns the max number of local entries in a row.
Definition: Ifpack_OverlappingPartitioner.cpp:277
Ifpack_OverlappingPartitioner::NumMyRows
int NumMyRows() const
Returns the number of local rows.
Definition: Ifpack_OverlappingPartitioner.cpp:253
Ifpack_OverlappingPartitioner::NumLocalParts
int NumLocalParts() const
Returns the number of computed local partitions.
Definition: Ifpack_OverlappingPartitioner.h:92
Ifpack_OverlappingPartitioner::NumLocalParts_
int NumLocalParts_
Number of local subgraphs.
Definition: Ifpack_OverlappingPartitioner.h:199
Ifpack_OverlappingPartitioner::operator()
int operator()(int MyRow) const
Returns the local non-overlapping partition ID of the specified row.
Definition: Ifpack_OverlappingPartitioner.h:111
Ifpack_OverlappingPartitioner::Comm
const Epetra_Comm & Comm() const
Returns the communicator object of Graph.
Definition: Ifpack_OverlappingPartitioner.cpp:283
Epetra_Comm
Ifpack_OverlappingPartitioner::Partition_
std::vector< int > Partition_
Partition_[i] contains the ID of non-overlapping part it belongs to.
Definition: Ifpack_OverlappingPartitioner.h:201
Ifpack_OverlappingPartitioner::Parts_
std::vector< std::vector< int > > Parts_
Parts_[i][j] is the ID of the j-th row contained in the (overlapping)
Definition: Ifpack_OverlappingPartitioner.h:204
Ifpack_OverlappingPartitioner::~Ifpack_OverlappingPartitioner
virtual ~Ifpack_OverlappingPartitioner()
Destructor.
Definition: Ifpack_OverlappingPartitioner.cpp:67
Ifpack_OverlappingPartitioner::Graph_
const Ifpack_Graph * Graph_
Reference to the graph to be partitioned.
Definition: Ifpack_OverlappingPartitioner.h:206
Ifpack_OverlappingPartitioner::SetParameters
virtual int SetParameters(Teuchos::ParameterList &List)
Sets all the parameters for the partitioner.
Definition: Ifpack_OverlappingPartitioner.cpp:72
Ifpack_OverlappingPartitioner::verbose_
bool verbose_
If true, information are reported on cout.
Definition: Ifpack_OverlappingPartitioner.h:212
Ifpack_OverlappingPartitioner::SetPartitionParameters
virtual int SetPartitionParameters(Teuchos::ParameterList &List)=0
Sets all the parameters for the partitioner.
Epetra_BlockMap
Ifpack_Partitioner
Ifpack_Partitioner: A class to decompose local Ifpack_Graph's.
Definition: Ifpack_Partitioner.h:162
Ifpack_OverlappingPartitioner::ComputePartitions
virtual int ComputePartitions()=0
Computes the partitions. Returns 0 if successful.
Ifpack_OverlappingPartitioner::NumRowsInPart
int NumRowsInPart(const int Part) const
Returns the number of rows contained in specified partition.
Definition: Ifpack_OverlappingPartitioner.h:132
Ifpack_OverlappingPartitioner::OverlappingLevel
int OverlappingLevel() const
Returns the overlapping level.
Definition: Ifpack_OverlappingPartitioner.h:98
Ifpack_OverlappingPartitioner::RowsInPart
int RowsInPart(const int Part, int *List) const
Copies into List the rows in the (overlapping) partition Part.
Definition: Ifpack_OverlappingPartitioner.h:137
Ifpack_OverlappingPartitioner::Print
virtual std::ostream & Print(std::ostream &os) const
Prints basic information on iostream. This function is used by operator<<.
Definition: Ifpack_OverlappingPartitioner.cpp:289
Ifpack_OverlappingPartitioner::Compute
virtual int Compute()
Computes the partitions. Returns 0 if successful.
Definition: Ifpack_OverlappingPartitioner.cpp:97
Ifpack_OverlappingPartitioner::OverlappingLevel_
int OverlappingLevel_
Overlapping level.
Definition: Ifpack_OverlappingPartitioner.h:208
Ifpack_OverlappingPartitioner::NonOverlappingPartition
const int * NonOverlappingPartition() const
Returns a pointer to the integer vector containing the non-overlapping partition ID of each local row...
Definition: Ifpack_OverlappingPartitioner.h:145
Epetra_Map
Ifpack_Graph
Ifpack_Graph: a pure virtual class that defines graphs for IFPACK.
Definition: Ifpack_Graph.h:61
Ifpack_OverlappingPartitioner::IsComputed_
bool IsComputed_
If true, the graph has been successfully partitioned.
Definition: Ifpack_OverlappingPartitioner.h:210
Ifpack_OverlappingPartitioner::ComputeOverlappingPartitions
virtual int ComputeOverlappingPartitions()
Computes the partitions. Returns 0 if successful.
Definition: Ifpack_OverlappingPartitioner.cpp:149
Epetra_Import
Ifpack_OverlappingPartitioner::NumMyNonzeros
int NumMyNonzeros() const
Returns the number of local nonzero elements.
Definition: Ifpack_OverlappingPartitioner.cpp:259
Ifpack_OverlappingPartitioner::IsComputed
bool IsComputed()
Returns true if partitions have been computed successfully.
Definition: Ifpack_OverlappingPartitioner.h:175