Zoltan2  Version of the Day
Zoltan2_AlgAMD.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_ALGAMD_HPP_
51 #define _ZOLTAN2_ALGAMD_HPP_
52 
53 #include <Zoltan2_GraphModel.hpp>
55 
56 #ifndef HAVE_ZOLTAN2_AMD
57 
58 namespace Zoltan2{
59 
60 template <typename Adapter>
61 int AlgAMD(
62  const RCP<GraphModel<Adapter> > &model,
63  const RCP<OrderingSolution<typename Adapter::gid_t,
64  typename Adapter::lno_t> > &solution,
65  const RCP<Teuchos::ParameterList> &pl,
66  const RCP<Teuchos::Comm<int> > &comm
67 )
68 {
69  // We don't need to check comm size here as we throw an exception always.
70  throw std::runtime_error(
71  "BUILD ERROR: AMD requested but not compiled into Zoltan2.\n"
72  "Please set CMake flag Zoltan2_ENABLE_AMD:BOOL=ON.");
73 }
74 
75 }
76 
77 #else
78 
79 #include "amd.h"
80 
81 namespace Zoltan2{
82 
83 template <typename Ordinal>
84 class AMDTraits
85 {
86  public:
87  Ordinal order(Ordinal n, const Ordinal *Ap, const Ordinal *Ai,
88  Ordinal *perm, double *control, double *info);
89 };
90 
91 template <>
92 class AMDTraits<int>
93 {
94  public:
95  int order(int n, const int *Ap, const int *Ai, int *perm,
96  double *control, double *info)
97  {
98  return (amd_order(n, Ap, Ai, perm, control, info));
99  }
100 };
101 
102 template <>
103 class AMDTraits<long>
104 {
105  public:
106  long order(long n, const long *Ap, const long *Ai, long *perm,
107  double *control, double *info)
108  {
109  return (amd_l_order(n, Ap, Ai, perm, control, info));
110  }
111 };
112 
113 template <typename Adapter>
114 int AlgAMD(
115  const RCP<GraphModel<Adapter> > &model,
116  const RCP<OrderingSolution<typename Adapter::gid_t,
117  typename Adapter::lno_t> > &solution,
118  const RCP<Teuchos::ParameterList> &pl,
119  const RCP<Teuchos::Comm<int> > &comm
120 )
121 {
122  typedef typename Adapter::lno_t lno_t;
123  typedef typename Adapter::gno_t gno_t;
124  typedef typename Adapter::gid_t gid_t;
125  typedef typename Adapter::scalar_t scalar_t;
126 
127  int ierr= 0;
128 
129  if (comm->getSize() != 1)
130  {
131  throw std::runtime_error(
132  "ERROR: AMD requested with distributed matrix.\n"
133  "This feature is not supported yet. Please use a local matrix.");
134  }
135 
136  const size_t nVtx = model->getLocalNumVertices();
137 
138  cout << "Local num vertices" << nVtx << endl;
139  ArrayView<const gno_t> edgeIds;
140  ArrayView<const int> procIds;
141  ArrayView<const lno_t> offsets;
142  ArrayView<StridedData<lno_t, scalar_t> > wgts;
143 
144  //const size_t nEdgs = model->getEdgeList( edgeIds,
145  // procIds, offsets, wgts);
146  // TODO: Should use the local graph
147  model->getEdgeList( edgeIds, procIds, offsets, wgts);
148 
149  AMDTraits<lno_t> AMDobj;
150  double Control[AMD_CONTROL];
151  double Info[AMD_INFO];
152 
153  amd_defaults(Control);
154  amd_control(Control);
155 
156  lno_t *perm;
157  perm = (lno_t *) (solution->getPermutationRCP().getRawPtr());
158 
159  lno_t result = AMDobj.order(nVtx, offsets.getRawPtr(),
160  edgeIds.getRawPtr(), perm, Control, Info);
161 
162  if (result != AMD_OK && result != AMD_OK_BUT_JUMBLED)
163  ierr = -1; // TODO: Change return value to lno_t
164 
165  return ierr;
166 }
167 
168 }
169 
170 #endif // ZOLTAN2_HAVE_AMD
171 
172 #endif
Defines the OrderingSolution class.
int AlgAMD(const RCP< GraphModel< Adapter > > &model, const RCP< OrderingSolution< typename Adapter::gid_t, typename Adapter::lno_t > > &solution, const RCP< Teuchos::ParameterList > &pl, const RCP< Teuchos::Comm< int > > &comm)
double scalar_t
GraphModel defines the interface required for graph models.
Defines the GraphModel interface.
The class containing ordering solutions and metrics.