ShyLU  Version of the Day
shylu_partition_interface_def.hpp
Go to the documentation of this file.
1 //@HEADER
2 // ************************************************************************
3 //
4 // ShyLU: Hybrid preconditioner package
5 // Copyright 2012 Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
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 
49 #ifndef SHYLU_PARTITION_INTERFACE_DEF_HPP
50 #define SHYLU_PARTITION_INTERFACE_DEF_HPP
51 
52 #include "ShyLUCore_config.h"
54 
55 //#include "Zoltan2_config.h"
56 #include <Teuchos_XMLParameterListHelpers.hpp>
57 
58 
59 #ifdef HAVE_SHYLUCORE_ZOLTAN2
60 #include <Zoltan2_XpetraCrsMatrixAdapter.hpp>
61 #include <Zoltan2_XpetraMultiVectorAdapter.hpp>
62 #include <Zoltan2_PartitioningProblem.hpp>
63 #endif
64 
65 #ifdef HAVE_SHYLUCORE_TPETRA
66 #include <Tpetra_CrsMatrix.hpp>
67 #include <Tpetra_MultiVector.hpp>
68 #include <Tpetra_Vector.hpp>
69 #endif
70 
71 #include <Epetra_CrsMatrix.h>
72 #include <Epetra_MultiVector.h>
73 
74 
75 namespace ShyLU {
76 
77 
78 template <class Matrix, class Vector>
79 PartitionInterface<Matrix, Vector>::PartitionInterface(Matrix* inA, Teuchos::ParameterList *inpList)
80 {
81  A = inA;
82  pList = inpList;
83  ipart = NULL;
84  ird = NULL;
85 #ifdef HAVE_SHLY_ZOLTAN2
86  zadapter = NULL;
87  zproblem = NULL;
88 #endif
89 
90 }
91 template <class Matrix, class Vector>
93 {
94 
95  if(ipart!=NULL) delete ipart;
96  if(ird!=NULL) delete ird;
97  //if(zadapter!=NULL) delete zadapter;
98  //if(zproblem!=NULL) delete zproblem;
99 }
100 template <class Matrix, class Vector>
102 {
103  cout << " Not Supported \n";
104  return 1;
105 }
106 
107 template <>
109 {
110  Teuchos::ParameterList subList = pList->sublist("Isorropia Input");
111  ipart = new Isorropia::Epetra::Partitioner(A,subList,false);
112  ipart->partition();
113  ird = new Isorropia::Epetra::Redistributor(ipart);
114  return 0;
115 }
116 
117 
118 #ifdef HAVE_SHYLUCORE_ZOLTAN2
119 template <class Matrix, class Vector>
121 {
122 
123  ParameterList subList = pList->sublist("Zoltan2 Input");
124  Teuchos::RCP<Matrix> rA(A, false);
125  zadapter = new Zoltan2::XpetraCrsMatrixAdapter<Matrix, Vector>(rA);
126  zproblem = new Zoltan2::PartitioningProblem<Zoltan2::XpetraCrsMatrixAdapter <Matrix, Vector> >(zadapter, &subList);
127  zproblem->solve();
128  return 0;
129 }
130 #endif
131 
132 
133 template <class Matrix, class Vector>
135 {
136 #ifdef HAVE_SHYLUCORE_ZOLTAN2
137  return partitionZoltan2();
138 #else
139  return 1;
140 #endif
141 }
142 template <>
144 {
145  string partitioningPackage = Teuchos::getParameter<string>(*pList, "Partitioning Package");
146  if(partitioningPackage.compare("Isorropia") == 0)
147  {
148  return partitionIsorropia();
149  }
150 #ifdef HAVE_SHYLUCORE_ZOLTAN2
151  else if (partitioningPackage.compare("Zoltan2") == 0)
152  {
153  return partitionZoltan2();
154  }
155 #endif
156  else
157  {
158  cout << "**Error**: Paritioning package selected is not supported\n";
159  }
160  return 1;
161 }
162 
163 template <class Matrix, class Vector>
165 {
166  Matrix *B;
167  string partitioningPackage = Teuchos::getParameter<string>(*pList, "Partitioning Package");
168 
169 #if defined(HAVE_ZOLTAN2_PARMETIS) || defined(HAVE_ZOLTAN2_SCOTCH)
170  if(partitioningPackage.compare("Zoltan2") == 0)
171  {
172  zadapter->applyPartitioningSolution(*A, B, zproblem->getSolution());
173  }
174 #else
175 B = NULL;
176 
177 #endif
178  return B;
179 }
180 template < >
182 {
183  Epetra_CrsMatrix *B = NULL;
184  string partitioningPackage = Teuchos::getParameter<string>(*pList, "Partitioning Package");
185  if(partitioningPackage.compare("Isorropia") == 0)
186  {
187  ird->redistribute(*A, B);
188  }
189 #if defined(HAVE_ZOLTAN2_PARMETIS) || defined(HAVE_ZOLTAN2_SCOTCH)
190  else if (partitioningPackage.compare("Zoltan2") == 0)
191  {
192  zadapter->applyPartitioningSolution(*A, B, zproblem->getSolution());
193  }
194 #endif
195  return B;
196 
197 }
198 template <class Matrix, class Vector>
200 {
201  Vector *b = NULL;
202  string partitioningPackage = Teuchos::getParameter<string>(*pList, "Partitioning Package");
203 #if defined(HAVE_ZOLTAN2_PARMETIS) || defined(HAVE_ZOLTAN2_SCOTCH)
204  Teuchos::RCP<Vector> rx(x, false);
205  Zoltan2::XpetraMultiVectorAdapter<Vector> tempVecAdapter(rx);
206  tempVecAdapter.applyPartitioningSolution(*x, b, zproblem->getSolution());
207 #endif
208  return b;
209 }
210 template < >
211 Epetra_MultiVector* PartitionInterface<Epetra_CrsMatrix, Epetra_MultiVector>::reorderVector(Epetra_MultiVector* x )
212 {
213  Epetra_MultiVector *b = NULL;
214  string partitioningPackage = Teuchos::getParameter<string>(*pList, "Partitioning Package");
215  if(partitioningPackage.compare("Isorropia") == 0)
216  {
217  ird->redistribute(*x, b);
218  }
219 #if defined(HAVE_ZOLTAN2_PARMETIS) || defined(HAVE_ZOLTAN2_SCOTCH)
220  else if (partitioningPackage.compare("Zoltan2") == 0)
221  {
222  Teuchos::RCP<Epetra_MultiVector> rx(x);
223  Zoltan2::XpetraMultiVectorAdapter<Epetra_MultiVector> tempVecAdapter(rx);
224  tempVecAdapter.applyPartitioningSolution(*x, b, zproblem->getSolution());
225  }
226 #endif
227  return b;
228 }
229 
230 }
231 #endif
PartitionInterface class templated on Epetra/Tpetra Matrix and Vector.
Epetra/Tpetra templated interface for calls to Zoltan(Isorropia)/Zoltans.
PartitionInterface(Matrix *inA, Teuchos::ParameterList *pList)
Main constructor of class.