|
Zoltan2
|
00001 // @HEADER 00002 // 00003 // *********************************************************************** 00004 // 00005 // Zoltan2: A package of combinatorial algorithms for scientific computing 00006 // Copyright 2012 Sandia Corporation 00007 // 00008 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 00009 // the U.S. Government retains certain rights in this software. 00010 // 00011 // Redistribution and use in source and binary forms, with or without 00012 // modification, are permitted provided that the following conditions are 00013 // met: 00014 // 00015 // 1. Redistributions of source code must retain the above copyright 00016 // notice, this list of conditions and the following disclaimer. 00017 // 00018 // 2. Redistributions in binary form must reproduce the above copyright 00019 // notice, this list of conditions and the following disclaimer in the 00020 // documentation and/or other materials provided with the distribution. 00021 // 00022 // 3. Neither the name of the Corporation nor the names of the 00023 // contributors may be used to endorse or promote products derived from 00024 // this software without specific prior written permission. 00025 // 00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00037 // 00038 // Questions? Contact Karen Devine (kddevin@sandia.gov) 00039 // Erik Boman (egboman@sandia.gov) 00040 // Siva Rajamanickam (srajama@sandia.gov) 00041 // 00042 // *********************************************************************** 00043 // 00044 // @HEADER 00045 00050 #ifndef _ZOLTAN2_ALGAMD_HPP_ 00051 #define _ZOLTAN2_ALGAMD_HPP_ 00052 00053 #include <Zoltan2_Algorithm.hpp> 00054 #include <Zoltan2_GraphModel.hpp> 00055 #include <Zoltan2_OrderingSolution.hpp> 00056 00057 00058 #ifdef HAVE_ZOLTAN2_AMD 00059 #include "amd.h" 00060 #endif 00061 00062 namespace Zoltan2{ 00063 00064 #ifdef HAVE_ZOLTAN2_AMD 00065 template <typename Ordinal> 00066 class AMDTraits 00067 { 00068 public: 00069 Ordinal order(Ordinal n, const Ordinal *Ap, const Ordinal *Ai, 00070 Ordinal *perm, double *control, double *info); 00071 }; 00072 00073 template <> 00074 class AMDTraits<int> 00075 { 00076 public: 00077 int order(int n, const int *Ap, const int *Ai, int *perm, 00078 double *control, double *info) 00079 { 00080 return (amd_order(n, Ap, Ai, perm, control, info)); 00081 } 00082 }; 00083 00084 template <> 00085 class AMDTraits<long> 00086 { 00087 public: 00088 long order(long n, const long *Ap, const long *Ai, long *perm, 00089 double *control, double *info) 00090 { 00091 return (amd_l_order(n, Ap, Ai, perm, control, info)); 00092 } 00093 }; 00094 #endif 00095 00096 } 00097 00098 00099 namespace Zoltan2{ 00100 00101 template <typename Adapter> 00102 class AlgAMD : public Algorithm<Adapter> 00103 { 00104 private: 00105 00106 const RCP<GraphModel<Adapter> > model; 00107 const RCP<Teuchos::ParameterList> &pl; 00108 const RCP<Teuchos::Comm<int> > &comm; 00109 00110 public: 00111 00112 AlgAMD( 00113 const RCP<GraphModel<Adapter> > &model__, 00114 const RCP<Teuchos::ParameterList> &pl__, 00115 const RCP<Teuchos::Comm<int> > &comm__ 00116 ) : model(model__), pl(pl__), comm(comm__) 00117 { } 00118 00119 int order(const RCP<OrderingSolution<typename Adapter::zgid_t, 00120 typename Adapter::lno_t> > &solution) 00121 { 00122 #ifndef HAVE_ZOLTAN2_AMD 00123 throw std::runtime_error( 00124 "BUILD ERROR: AMD requested but not compiled into Zoltan2.\n" 00125 "Please set CMake flag Zoltan2_ENABLE_AMD:BOOL=ON."); 00126 #else 00127 typedef typename Adapter::lno_t lno_t; 00128 typedef typename Adapter::gno_t gno_t; 00129 typedef typename Adapter::zgid_t zgid_t; 00130 typedef typename Adapter::scalar_t scalar_t; 00131 00132 int ierr= 0; 00133 00134 if (comm->getSize() != 1) 00135 { 00136 throw std::runtime_error( 00137 "ERROR: AMD requested with distributed matrix.\n" 00138 "This feature is not supported yet. Please use a local matrix."); 00139 } 00140 00141 const size_t nVtx = model->getLocalNumVertices(); 00142 00143 //cout << "Local num vertices" << nVtx << endl; 00144 ArrayView<const gno_t> edgeIds; 00145 ArrayView<const int> procIds; 00146 ArrayView<const lno_t> offsets; 00147 ArrayView<StridedData<lno_t, scalar_t> > wgts; 00148 00149 //const size_t nEdgs = model->getEdgeList( edgeIds, 00150 // procIds, offsets, wgts); 00151 // TODO: Should use the local graph 00152 model->getEdgeList( edgeIds, procIds, offsets, wgts); 00153 00154 AMDTraits<lno_t> AMDobj; 00155 double Control[AMD_CONTROL]; 00156 double Info[AMD_INFO]; 00157 00158 amd_defaults(Control); 00159 amd_control(Control); 00160 00161 lno_t *perm; 00162 perm = (lno_t *) (solution->getPermutationRCP().getRawPtr()); 00163 00164 lno_t result = AMDobj.order(nVtx, offsets.getRawPtr(), 00165 edgeIds.getRawPtr(), perm, Control, Info); 00166 00167 if (result != AMD_OK && result != AMD_OK_BUT_JUMBLED) 00168 ierr = -1; // TODO: Change return value to lno_t 00169 00170 solution->setHavePerm(true); 00171 return ierr; 00172 #endif 00173 } 00174 }; 00175 00176 } 00177 00178 00179 00180 #endif
1.7.6.1