Zoltan2
Zoltan2_Algorithm.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Zoltan2: A package of combinatorial algorithms for scientific computing
6 // Copyright 2012 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 Karen Devine (kddevin@sandia.gov)
39 // Erik Boman (egboman@sandia.gov)
40 // Siva Rajamanickam (srajama@sandia.gov)
41 //
42 // ***********************************************************************
43 //
44 // @HEADER
45 
50 #ifndef _ZOLTAN2_ALGORITHM_HPP_
51 #define _ZOLTAN2_ALGORITHM_HPP_
52 
53 namespace Zoltan2 {
54 template <typename Adapter>
55 class Algorithm;
56 }
57 
58 #include <Zoltan2_Standards.hpp>
64 
65 
66 namespace Zoltan2 {
67 
69 //
70 // Algorithms do not have to implement all methods in the Algorithm base
71 // class. They should implement only those methods that are relevant.
72 // For example AlgScotch might implement partition() and order(), while
73 // AlgMJ might implement partition() and boxAssign().
74 // Default implementations throw a "not implemented" error
75 
76 template <typename Adapter>
77 class Algorithm {
78 
79 public:
80 
81  typedef typename Adapter::lno_t lno_t;
82  typedef typename Adapter::gno_t gno_t;
83  typedef typename Adapter::scalar_t scalar_t;
84  typedef typename Adapter::part_t part_t;
85 
86  // Virtual destructor needed to avoid undefined behavior and compiler warnings
87  virtual ~Algorithm() {}
88 
90  virtual int localOrder(const RCP<LocalOrderingSolution<lno_t> > &solution)
91  {
93  }
94 
96  virtual int globalOrder(const RCP<GlobalOrderingSolution<gno_t> > &solution)
97  {
99  }
100 
102  virtual void color(const RCP<ColoringSolution<Adapter> > &solution)
103  {
105  }
106 
108  virtual void match() {
110  }
111 
113  virtual void partition(const RCP<PartitioningSolution<Adapter> > &solution)
114  {
116  }
117 
119  virtual void map(const RCP<MappingSolution<Adapter> > &solution)
120  {
122  }
123 
125  virtual bool isPartitioningTreeBinary() const
126  {
128  }
129 
131  virtual void getPartitionTree(part_t numParts,
132  part_t & numTreeVerts,
133  std::vector<part_t> & permPartNums,
134  std::vector<part_t> & splitRangeBeg,
135  std::vector<part_t> & splitRangeEnd,
136  std::vector<part_t> & treeVertParents) const
137  {
139  }
140 
142  // computed parts
143  // Not all partitioning algorithms will support
144  // this method.
145  //
146  virtual std::vector<coordinateModelPartBox<scalar_t, part_t> > &
148  {
150  }
151 
153  // when a point lies on a part boundary, the lowest part
154  // number on that boundary is returned.
155  // Not all partitioning algorithms will support
156  // this method.
157  //
158  // \param dim : the number of dimensions specified for the point in space
159  // \param point : the coordinates of the point in space; array of size dim
160  // \return the part number of a part overlapping the given point
161  virtual part_t pointAssign(int dim, scalar_t *point) const
162  {
164  }
165 
167  // Return an array of all parts overlapping a given box in space.
168  // This method allocates memory for the return argument, but does not
169  // control that memory. The user is responsible for freeing the
170  // memory.
171  //
172  // \param dim : (in) the number of dimensions specified for the box
173  // \param ptLower : (in) the coordinates of the lower corner of the box;
174  // array of size dim
175  // \param ptUpper : (in) the coordinates of the upper corner of the box;
176  // array of size dim
177  // \param nParts : (out) the number of parts overlapping the box
178  // \param parts : (out) array of parts overlapping the box
179  virtual void boxAssign(int dim, scalar_t *lower, scalar_t *upper,
180  size_t &nParts, part_t **partsFound) const
181  {
183  }
184 
186  // Returned graph is identical on all processors, and represents the
187  // global communication pattern in the partition.
188  //
189  // \param comXAdj: (out) the offset array: offsets into comAdj
190  // Format is standard CSR format:
191  // # nbor parts of part i = comXAdj[i+1]-comXAdj[i]
192  // That is, comXAdj[i] = Sum of # nbor parts of parts
193  // 0 through i-1
194  // \param comAdj (out) the neighboring parts
195  virtual void getCommunicationGraph(
196  const PartitioningSolution<Adapter> *solution,
197  ArrayRCP<part_t> &comXAdj,
198  ArrayRCP<part_t> &comAdj)
199  // TODO: Should the return args be ArrayViews?
200  {
202  }
203 
205  // \param p: (in) the part for which the rank is sought
206  // This method need not be implemented by every algorithm or, indeed,
207  // for every mapping algorithm. Mapping algorithms may provide this
208  // function to prevent additional memory use in MappingSolution.
209  // For example, AlgContiguousMapping can compute this function implicitly,
210  // with no additional storage. However, Mapping algorithms can skip this
211  // function and, instead, register their results in MappingSolution.
212  virtual int getRankForPart(part_t p)
213  {
215  }
216 
218  // \param numParts: (out) the number of parts assigned to the current rank
219  // \param parts: (out) a view of the assigned parts
220  //
221  // This method need not be implemented by every algorithm or, indeed,
222  // for every mapping algorithm. Mapping algorithms may provide this
223  // function to prevent additional memory use in MappingSolution.
224  // For example, AlgContiguousMapping can compute this function implicitly,
225  // with no additional storage. However, Mapping algorithms can skip this
226  // function and, instead, register their results in MappingSolution.
227  virtual void getMyPartsView(part_t &numParts, part_t *&parts)
228  {
230  }
231 
232 
233 private:
234 };
235 
236 } //namespace Zoltan2
237 
238 #endif
virtual void getPartitionTree(part_t numParts, part_t &numTreeVerts, std::vector< part_t > &permPartNums, std::vector< part_t > &splitRangeBeg, std::vector< part_t > &splitRangeEnd, std::vector< part_t > &treeVertParents) const
for partitioning methods, fill arrays with partition tree info
virtual int localOrder(const RCP< LocalOrderingSolution< lno_t > > &solution)
Ordering method.
virtual void map(const RCP< MappingSolution< Adapter > > &solution)
Mapping method.
virtual std::vector< coordinateModelPartBox< scalar_t, part_t > > & getPartBoxesView() const
for partitioning methods, return bounding boxes of the
virtual void getCommunicationGraph(const PartitioningSolution< Adapter > *solution, ArrayRCP< part_t > &comXAdj, ArrayRCP< part_t > &comAdj)
returns serial communication graph of a computed partition
PartitionMapping maps a solution or an input distribution to ranks.
virtual part_t pointAssign(int dim, scalar_t *point) const
pointAssign method: Available only for some partitioning algorithms
Defines the OrderingSolution class.
#define Z2_THROW_NOT_IMPLEMENTED
virtual int globalOrder(const RCP< GlobalOrderingSolution< gno_t > > &solution)
Ordering method.
Defines the PartitioningSolution class.
virtual void getMyPartsView(part_t &numParts, part_t *&parts)
In mapping, returns a view of parts assigned to the current rank.
SparseMatrixAdapter_t::part_t part_t
Adapter::scalar_t scalar_t
A PartitioningSolution is a solution to a partitioning problem.
virtual void match()
Matching method.
Adapter::part_t part_t
virtual int getRankForPart(part_t p)
In mapping, returns the rank to which a part is assigned.
Algorithm defines the base class for all algorithms.
virtual void partition(const RCP< PartitioningSolution< Adapter > > &solution)
Partitioning method.
Defines the MappingSolution class.
virtual void color(const RCP< ColoringSolution< Adapter > > &solution)
Coloring method.
virtual void boxAssign(int dim, scalar_t *lower, scalar_t *upper, size_t &nParts, part_t **partsFound) const
boxAssign method: Available only for some partitioning algorithms
Gathering definitions used in software development.
Defines the ColoringSolution class.
virtual bool isPartitioningTreeBinary() const
return if algorithm determins tree to be binary
#define nParts
The class containing coloring solution.