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>
63 
64 #define Z2_THROW_NOT_IMPLEMENTED_IN_ALGORITHM \
65  { \
66  std::ostringstream emsg; \
67  emsg << __FILE__ << "," << __LINE__ \
68  << " error: " << __func__zoltan2__ \
69  << " is not implement in selected algorithm " \
70  << std::endl; \
71  throw std::runtime_error(emsg.str()); \
72  }
73 
74 
75 namespace Zoltan2 {
76 
78 //
79 // Algorithms do not have to implement all methods in the Algorithm base
80 // class. They should implement only those methods that are relevant.
81 // For example AlgScotch might implement partition() and order(), while
82 // AlgMJ might implement partition() and boxAssign().
83 // Default implementations throw a "not implemented" error
84 
85 template <typename Adapter>
86 class Algorithm {
87 
88 public:
89 
90  typedef typename Adapter::lno_t lno_t;
91  typedef typename Adapter::gno_t gno_t;
92  typedef typename Adapter::scalar_t scalar_t;
93  typedef typename Adapter::part_t part_t;
94 
95  // Virtual destructor needed to avoid undefined behavior and compiler warnings
96  virtual ~Algorithm() {}
97 
99  virtual int order(const RCP<OrderingSolution<lno_t, gno_t> > &solution)
100  {
102  }
103 
105  virtual void color(const RCP<ColoringSolution<Adapter> > &solution)
106  {
108  }
109 
112 
114  virtual void partition(const RCP<PartitioningSolution<Adapter> > &solution)
115  {
117  }
118 
120  // computed parts
121  // Not all partitioning algorithms will support
122  // this method.
123  //
124  virtual std::vector<coordinateModelPartBox<scalar_t, part_t> > &
126  {
128  }
129 
131  // when a point lies on a part boundary, the lowest part
132  // number on that boundary is returned.
133  // Not all partitioning algorithms will support
134  // this method.
135  //
136  // \param dim : the number of dimensions specified for the point in space
137  // \param point : the coordinates of the point in space; array of size dim
138  // \return the part number of a part overlapping the given point
139  virtual part_t pointAssign(int dim, scalar_t *point) const
140  {
142  }
143 
145  // Return an array of all parts overlapping a given box in space.
146  // This method allocates memory for the return argument, but does not
147  // control that memory. The user is responsible for freeing the
148  // memory.
149  //
150  // \param dim : (in) the number of dimensions specified for the box
151  // \param ptLower : (in) the coordinates of the lower corner of the box;
152  // array of size dim
153  // \param ptUpper : (in) the coordinates of the upper corner of the box;
154  // array of size dim
155  // \param nParts : (out) the number of parts overlapping the box
156  // \param parts : (out) array of parts overlapping the box
157  virtual void boxAssign(int dim, scalar_t *lower, scalar_t *upper,
158  size_t &nParts, part_t **partsFound) const
159  {
161  }
162 
164  // Returned graph is identical on all processors, and represents the
165  // global communication pattern in the partition.
166  //
167  // \param comXAdj: (out) the offset array: offsets into comAdj
168  // Format is standard CSR format:
169  // # nbor parts of part i = comXAdj[i+1]-comXAdj[i]
170  // That is, comXAdj[i] = Sum of # nbor parts of parts
171  // 0 through i-1
172  // \param comAdj (out) the neighboring parts
173  virtual void getCommunicationGraph(
174  const PartitioningSolution<Adapter> *solution,
175  ArrayRCP<part_t> &comXAdj,
176  ArrayRCP<part_t> &comAdj)
177  // TODO: Should the return args be ArrayViews?
178  {
180  }
181 
182 private:
183 };
184 
185 } //namespace Zoltan2
186 
187 #endif
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
virtual void getCommunicationGraph(const PartitioningSolution< Adapter > *solution, ArrayRCP< part_t > &comXAdj, ArrayRCP< part_t > &comAdj)
returns serial communication graph of a computed partition
Defines the OrderingSolution class.
virtual std::vector< coordinateModelPartBox< scalar_t, part_t > > & getPartBoxesView() const
for partitioning methods, return bounding boxes of the
Defines the PartitioningSolution class.
Adapter::scalar_t scalar_t
A PartitioningSolution is a solution to a partitioning problem.
virtual void match()
Matching method.
Adapter::part_t part_t
Algorithm defines the base class for all algorithms.
virtual int order(const RCP< OrderingSolution< lno_t, gno_t > > &solution)
Ordering method.
virtual void partition(const RCP< PartitioningSolution< Adapter > > &solution)
Partitioning method.
virtual part_t pointAssign(int dim, scalar_t *point) const
pointAssign method: Available only for some partitioning algorithms
virtual void color(const RCP< ColoringSolution< Adapter > > &solution)
Coloring method.
Gathering definitions used in software development.
Defines the ColoringSolution class.
#define nParts
The class containing ordering solutions.
#define Z2_THROW_NOT_IMPLEMENTED_IN_ALGORITHM
The class containing coloring solution.