| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// ShyLU: Scalable Hybrid LU Preconditioner and Solver |
| 4 |
// |
| 5 |
// Copyright 2011 NTESS and the ShyLU contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
|
| 10 |
#include <assert.h> |
| 11 |
#include <iostream> |
| 12 |
#include <sstream> |
| 13 |
|
| 14 |
#include "shylu.h" |
| 15 |
#include "shylu_partition_interface.hpp" |
| 16 |
#include "ShyLU_DDCore_config.h" |
| 17 |
|
| 18 |
//Tperta |
| 19 |
#ifdef HAVE_SHYLU_DDCORE_TPETRA |
| 20 |
#include <Tpetra_Core.hpp> |
| 21 |
#include <Tpetra_Version.hpp> |
| 22 |
#include <Tpetra_Vector.hpp> |
| 23 |
#include <Tpetra_MultiVector.hpp> |
| 24 |
#include <Tpetra_CrsMatrix.hpp> |
| 25 |
#include <Tpetra_Map.hpp> |
| 26 |
#include <MatrixMarket_Tpetra.hpp> |
| 27 |
#endif |
| 28 |
|
| 29 |
|
| 30 |
#ifdef HAVE_MPI |
| 31 |
# include "Epetra_MpiComm.h" |
| 32 |
#endif // HAVE_MPI |
| 33 |
#include "Epetra_SerialComm.h" |
| 34 |
#include "Epetra_CrsMatrix.h" |
| 35 |
#include "Epetra_Map.h" |
| 36 |
#include "Epetra_MultiVector.h" |
| 37 |
#include "Epetra_Vector.h" |
| 38 |
#include "Epetra_LinearProblem.h" |
| 39 |
|
| 40 |
// Teuchos includes |
| 41 |
#ifdef HAVE_SHYLU_DDCORE_TPETRA |
| 42 |
#include "Teuchos_XMLParameterListHelpers.hpp" |
| 43 |
#include "Teuchos_RCP.hpp" |
| 44 |
#endif |
| 45 |
|
| 46 |
// EpetraExt includes |
| 47 |
#include "EpetraExt_RowMatrixOut.h" |
| 48 |
#include "EpetraExt_MultiVectorOut.h" |
| 49 |
#include "EpetraExt_CrsMatrixIn.h" |
| 50 |
#include "EpetraExt_MultiVectorIn.h" |
| 51 |
|
| 52 |
// Amesos includes |
| 53 |
#include "Amesos.h" |
| 54 |
#include "Amesos_BaseSolver.h" |
| 55 |
|
| 56 |
// AztecOO includes |
| 57 |
#include "AztecOO.h" |
| 58 |
|
| 59 |
// ML includes |
| 60 |
#include "ml_MultiLevelPreconditioner.h" |
| 61 |
#include "ml_epetra_utils.h" |
| 62 |
|
| 63 |
#include "Ifpack_ConfigDefs.h" |
| 64 |
#include "shylu.h" |
| 65 |
#include "shylu_util.h" |
| 66 |
#include "Ifpack_ShyLU.h" |
| 67 |
#include "Ifpack_ILUT.h" |
| 68 |
#include "Ifpack_ILU.h" |
| 69 |
|
| 70 |
#include "BelosConfigDefs.hpp" |
| 71 |
#include "BelosLinearProblem.hpp" |
| 72 |
#include "BelosEpetraAdapter.hpp" |
| 73 |
#include "BelosBlockGmresSolMgr.hpp" |
| 74 |
|
| 75 |
#include "EpetraExt_readEpetraLinearSystem.h" |
| 76 |
#include "EpetraExt_CrsMatrixIn.h" |
| 77 |
|
| 78 |
//Our test interfaces |
| 79 |
#include "shylu.h" |
| 80 |
#include "shylu_partition_interface.hpp" |
| 81 |
#include "shylu_directsolver_interface.hpp" |
| 82 |
|
| 83 |
using namespace std; |
| 84 |
|
| 85 |
int main(int argc, char** argv) |
| 86 |
{ |
| 87 |
|
| 88 |
Tpetra::ScopeGuard mpiSession(&argc, &argv); |
| 89 |
Teuchos::RCP <const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm(); |
| 90 |
int myPID = comm->getRank(); |
| 91 |
|
| 92 |
bool success = true; |
| 93 |
string pass = "End Result: TEST PASSED"; |
| 94 |
string fail = "End Result: TEST FAILED"; |
| 95 |
|
| 96 |
#if !defined(HAVE_TPETRA_INST_INT_INT) |
| 97 |
if(myPID == 0) |
| 98 |
{ |
| 99 |
cout << "Tpetra was not instantiated with INT_INT" << endl; |
| 100 |
} |
| 101 |
#else |
| 102 |
typedef double scalar_type; |
| 103 |
typedef int local_o_type; |
| 104 |
typedef int global_o_type; |
| 105 |
//typedef Tpetra::KokkosClassic::DefaultNode::DefaultNodeType node_type; |
| 106 |
|
| 107 |
typedef Tpetra::Details::DefaultTypes::node_type node_type; |
| 108 |
|
| 109 |
typedef Tpetra::CrsMatrix<scalar_type, local_o_type, global_o_type, node_type> Matrix_t; |
| 110 |
typedef Tpetra::MultiVector<scalar_type, local_o_type, global_o_type, node_type> Vector_t; |
| 111 |
|
| 112 |
if(myPID == 0) |
| 113 |
{ |
| 114 |
cout << "Starting Tpetra interface test" << endl; |
| 115 |
} |
| 116 |
|
| 117 |
Teuchos::ParameterList defaultParameters; |
| 118 |
|
| 119 |
/*----------------Load a test matrix---------------*/ |
| 120 |
string matrixFileName = "wathenSmall.mtx"; |
| 121 |
|
| 122 |
//Get Matrix |
| 123 |
Teuchos::RCP<Matrix_t> A = Tpetra::MatrixMarket::Reader<Matrix_t>::readSparseFile(matrixFileName, comm); |
| 124 |
|
| 125 |
|
| 126 |
//Note:: Tpetra::MatrixMarket::Reader is providing A->getColMap() wrong and equal A->row |
| 127 |
Teuchos::RCP<Vector_t> x = Teuchos::rcp(new Vector_t(A->getRowMap(), 1)); |
| 128 |
Teuchos::RCP<Vector_t> b = Teuchos::rcp(new Vector_t(A->getRowMap(), 1)); |
| 129 |
b->randomize(); |
| 130 |
x->randomize(); |
| 131 |
|
| 132 |
if(myPID == 0) |
| 133 |
{ |
| 134 |
cout << "num_vector : " << b->getNumVectors() << " " |
| 135 |
<< x->getNumVectors() << endl; |
| 136 |
cout << "length : " << b->getGlobalLength() << " " |
| 137 |
<< x->getGlobalLength() << endl; |
| 138 |
|
| 139 |
cout << "A length : " << A->getGlobalNumRows() << " " << A->getGlobalNumCols() << endl; |
| 140 |
cout << "A local length : " << A->getLocalNumRows() << " " << A->getLocalNumCols() << endl; |
| 141 |
} |
| 142 |
|
| 143 |
/*-----------------have_interface-----------------*/ |
| 144 |
/*---The have_interface checks is all the parameter list makes sense---*/ |
| 145 |
Teuchos::RCP <Teuchos::ParameterList> pLUList; |
| 146 |
string pListFileName = "ShyLU_epetra_interface.xml"; |
| 147 |
pLUList = Teuchos::getParametersFromXmlFile(pListFileName); |
| 148 |
|
| 149 |
|
| 150 |
/*----------------partitioning_interface--------------*/ |
| 151 |
/*-----------Will use check the epetra matrix on partition_interface------*/ |
| 152 |
|
| 153 |
pLUList->set("Partitioning Package","Zoltan2"); |
| 154 |
Teuchos::ParameterList ptemp = pLUList->sublist("Zoltan2 Input"); |
| 155 |
ptemp.set("algorithm", "parmetis"); |
| 156 |
ptemp.set("debug_level", "detailed_status"); |
| 157 |
pLUList->set("Zoltan2 Input", ptemp); |
| 158 |
|
| 159 |
|
| 160 |
if(myPID == 0) |
| 161 |
{ |
| 162 |
cout << " \n\n--------------------BIG BREAK --------------\n\n"; |
| 163 |
Teuchos::writeParameterListToXmlOStream(*pLUList, std::cout); |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
#if defined(HAVE_SHYLU_DDCORE_ZOLTAN2CORE) |
| 168 |
ShyLU::PartitionInterface<Matrix_t, Vector_t> partI3(A.get(), pLUList.get()); |
| 169 |
partI3.partition(); |
| 170 |
|
| 171 |
if(myPID == 0) |
| 172 |
{ |
| 173 |
cout << "Done with graph - parmetis" << endl; |
| 174 |
} |
| 175 |
#else |
| 176 |
|
| 177 |
success = false; |
| 178 |
|
| 179 |
#endif |
| 180 |
|
| 181 |
|
| 182 |
#ifdef HAVE_SHYLU_DDCORE_AMESOS2 |
| 183 |
|
| 184 |
pLUList->set("Direct Solver Package", "Amesos2"); |
| 185 |
ptemp = pLUList->sublist("Amesos2 Input"); |
| 186 |
//pptemp = ptemp.sublist("Amesos_Klu Input"); |
| 187 |
|
| 188 |
//pptemp.set("PrintTiming", true); |
| 189 |
//pptemp.set("PrintStatus", true); |
| 190 |
ptemp.set("Solver", "SuperLU"); |
| 191 |
//ptemp.set("Amesos_Klu Input", pptemp); |
| 192 |
pLUList->set("Amesos2 Input", ptemp); |
| 193 |
|
| 194 |
|
| 195 |
if(myPID == 0) |
| 196 |
{ |
| 197 |
cout << " \n\n--------------------BIG BREAK --------------\n\n"; |
| 198 |
Teuchos::writeParameterListToXmlOStream(*pLUList, std::cout); |
| 199 |
|
| 200 |
cout << "num_vector: " << b->getNumVectors() << " " |
| 201 |
<< x->getNumVectors() << endl; |
| 202 |
cout << "length: " << b->getGlobalLength() << " " |
| 203 |
<< x->getGlobalLength() << endl; |
| 204 |
|
| 205 |
cout << "A length" << A->getGlobalNumRows() << " " << A->getGlobalNumCols() << endl; |
| 206 |
cout << "A local length" << A->getLocalNumRows() << " " << A->getLocalNumCols() << endl; |
| 207 |
} |
| 208 |
|
| 209 |
|
| 210 |
ShyLU::DirectSolverInterface<Matrix_t, Vector_t> directsolver2(A.get(), pLUList.get()); |
| 211 |
directsolver2.factor(); |
| 212 |
directsolver2.solve(b.get(),x.get()); |
| 213 |
|
| 214 |
//Note: should multiple to set b and x for success |
| 215 |
|
| 216 |
if(myPID == 0) |
| 217 |
{ |
| 218 |
cout << "Done with Amesos2-SuperLU" << endl; |
| 219 |
} |
| 220 |
#else |
| 221 |
|
| 222 |
success = false; |
| 223 |
|
| 224 |
#endif |
| 225 |
#endif |
| 226 |
|
| 227 |
if(myPID == 0) |
| 228 |
{ |
| 229 |
if(success) |
| 230 |
cout << pass << endl; |
| 231 |
else |
| 232 |
cout << fail << endl; |
| 233 |
} |
| 234 |
|
| 235 |
return 0; |
| 236 |
} |
| 237 |
|