| 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 "Zoltan2_config.h" |
| 15 |
|
| 16 |
#ifdef HAVE_MPI |
| 17 |
# include "Epetra_MpiComm.h" |
| 18 |
#endif // HAVE_MPI |
| 19 |
#include "Epetra_SerialComm.h" |
| 20 |
#include "Epetra_CrsMatrix.h" |
| 21 |
#include "Epetra_Map.h" |
| 22 |
#include "Epetra_MultiVector.h" |
| 23 |
#include "Epetra_Vector.h" |
| 24 |
#include "Epetra_LinearProblem.h" |
| 25 |
|
| 26 |
// Teuchos includes |
| 27 |
#include "Teuchos_GlobalMPISession.hpp" |
| 28 |
#include "Teuchos_XMLParameterListHelpers.hpp" |
| 29 |
#include "Teuchos_RCP.hpp" |
| 30 |
|
| 31 |
// EpetraExt includes |
| 32 |
#include "EpetraExt_RowMatrixOut.h" |
| 33 |
#include "EpetraExt_MultiVectorOut.h" |
| 34 |
#include "EpetraExt_CrsMatrixIn.h" |
| 35 |
#include "EpetraExt_MultiVectorIn.h" |
| 36 |
|
| 37 |
// Amesos includes |
| 38 |
#include "Amesos.h" |
| 39 |
#include "Amesos_BaseSolver.h" |
| 40 |
|
| 41 |
// AztecOO includes |
| 42 |
#include "AztecOO.h" |
| 43 |
|
| 44 |
// ML includes |
| 45 |
#include "ml_MultiLevelPreconditioner.h" |
| 46 |
#include "ml_epetra_utils.h" |
| 47 |
|
| 48 |
#include "Ifpack_ConfigDefs.h" |
| 49 |
#include "shylu.h" |
| 50 |
#include "shylu_util.h" |
| 51 |
#include "Ifpack_ShyLU.h" |
| 52 |
#include "Ifpack_ILUT.h" |
| 53 |
#include "Ifpack_ILU.h" |
| 54 |
|
| 55 |
#include "BelosConfigDefs.hpp" |
| 56 |
#include "BelosLinearProblem.hpp" |
| 57 |
#include "BelosEpetraAdapter.hpp" |
| 58 |
#include "BelosBlockGmresSolMgr.hpp" |
| 59 |
|
| 60 |
#include "EpetraExt_readEpetraLinearSystem.h" |
| 61 |
#include "EpetraExt_CrsMatrixIn.h" |
| 62 |
|
| 63 |
//Our test interfaces |
| 64 |
#include "shylu.h" |
| 65 |
#include "shylu_partition_interface.hpp" |
| 66 |
#include "shylu_directsolver_interface.hpp" |
| 67 |
|
| 68 |
using namespace std; |
| 69 |
|
| 70 |
|
| 71 |
int main(int argc, char** argv) |
| 72 |
{ |
| 73 |
|
| 74 |
#ifdef HAVE_MPI |
| 75 |
Teuchos::GlobalMPISession mpiSession(&argc, &argv, 0); |
| 76 |
Epetra_MpiComm Comm(MPI_COMM_WORLD); |
| 77 |
#else |
| 78 |
Epetra_SerialComm Comm; |
| 79 |
#endif |
| 80 |
|
| 81 |
|
| 82 |
bool success = true; |
| 83 |
string pass = "End Result: TEST PASSED"; |
| 84 |
string fail = "End Result: TEST FAILED"; |
| 85 |
|
| 86 |
int myPID = Comm.MyPID(); |
| 87 |
if(myPID == 0) |
| 88 |
{ |
| 89 |
cout << "Starting Epetra interface test" << endl; |
| 90 |
} |
| 91 |
|
| 92 |
/*----------------Load a test matrix---------------*/ |
| 93 |
string matrixFileName = "wathenSmall.mtx"; |
| 94 |
Epetra_CrsMatrix *A; |
| 95 |
Epetra_CrsMatrix *AHat; |
| 96 |
Epetra_MultiVector *b; |
| 97 |
Epetra_MultiVector *bHat; |
| 98 |
Epetra_MultiVector *x; |
| 99 |
int n = 0; |
| 100 |
|
| 101 |
//Get Matrix |
| 102 |
int err = EpetraExt::MatrixMarketFileToCrsMatrix(matrixFileName.c_str(), Comm, A); |
| 103 |
if(err!=0 && myPID ==0) |
| 104 |
{ |
| 105 |
cout << "Error reading matrix file, info = " << err << endl; |
| 106 |
cout << fail << endl; |
| 107 |
exit(1); |
| 108 |
} |
| 109 |
n = A->NumGlobalRows(); |
| 110 |
|
| 111 |
//Make b vecotor |
| 112 |
|
| 113 |
Epetra_Map vecMap(n,0,Comm); |
| 114 |
b = new Epetra_MultiVector(vecMap,1,false); |
| 115 |
b->Random(); |
| 116 |
x = new Epetra_MultiVector(vecMap,1,false); |
| 117 |
x->Random(); |
| 118 |
|
| 119 |
cout << "Epetra matrices loaded" << endl; |
| 120 |
|
| 121 |
|
| 122 |
/*-----------------have_interface-----------------*/ |
| 123 |
/*---The have_interface checks is all the parameter list makes sense---*/ |
| 124 |
Teuchos::RCP <Teuchos::ParameterList> pLUList; |
| 125 |
string pListFileName = "ShyLU_epetra_interface.xml"; |
| 126 |
pLUList = Teuchos::getParametersFromXmlFile(pListFileName); |
| 127 |
|
| 128 |
|
| 129 |
/*----------------partitioning_interface--------------*/ |
| 130 |
/*-----------Will use check the epetra matrix on partition_interface------*/ |
| 131 |
|
| 132 |
|
| 133 |
//Isorropia Test - graph/Parmetis |
| 134 |
pLUList->set("Partitioning Package","Isorropia"); |
| 135 |
Teuchos::ParameterList ptemp; |
| 136 |
ptemp = pLUList->sublist("Isorropia Input"); |
| 137 |
|
| 138 |
Teuchos::ParameterList pptemp; |
| 139 |
pptemp = ptemp.sublist("Zoltan"); |
| 140 |
pptemp.set("GRAPH_PACKAGE", "Parmetis"); |
| 141 |
pptemp.set("DEBUG_LEVEL", "1"); |
| 142 |
|
| 143 |
ptemp.set("partitioning method", "graph"); |
| 144 |
ptemp.set("Zoltan", pptemp); |
| 145 |
pLUList->set("Isorropia Input", ptemp); |
| 146 |
|
| 147 |
cout << " \n\n--------------------BIG BREAK --------------\n\n"; |
| 148 |
Teuchos::writeParameterListToXmlOStream(*pLUList, std::cout); |
| 149 |
|
| 150 |
|
| 151 |
ShyLU::PartitionInterface<Epetra_CrsMatrix, Epetra_MultiVector> partI(A, pLUList.get()); |
| 152 |
partI.partition(); |
| 153 |
AHat = partI.reorderMatrix(); |
| 154 |
bHat = partI.reorderVector(b); |
| 155 |
|
| 156 |
EpetraExt::RowMatrixToMatlabFile("Epetra_Isorropia_Parmetis.mat", *AHat); |
| 157 |
|
| 158 |
|
| 159 |
cout << "Done with graph - parmetis (Zoltan)" << endl; |
| 160 |
|
| 161 |
/* |
| 162 |
|
| 163 |
//Isorropia Test - Graph/PT-Scotch |
| 164 |
pLUList->set("Partitioning Package","Isorropia"); |
| 165 |
ptemp = pLUList->sublist("Isorropia Input"); |
| 166 |
|
| 167 |
//Teuchos::ParameterList pptemp; |
| 168 |
pptemp = ptemp.sublist("Zoltan"); |
| 169 |
pptemp.set("GRAPH_PACKAGE", "scotch"); |
| 170 |
pptemp.set("DEBUG_LEVEL", "1"); |
| 171 |
|
| 172 |
|
| 173 |
ptemp.set("partitioning method", "graph"); |
| 174 |
ptemp.set("Zoltan", pptemp); |
| 175 |
pLUList->set("Isorropia Input", ptemp); |
| 176 |
|
| 177 |
cout << " \n\n--------------------BIG BREAK --------------\n\n"; |
| 178 |
Teuchos::writeParameterListToXmlOStream(*pLUList, std::cout); |
| 179 |
|
| 180 |
PartitionInterface<Epetra_CrsMatrix, Epetra_MultiVector> partI2(A, pLUList.get()); |
| 181 |
partI2.partition(); |
| 182 |
AHat = partI2.reorderMatrix(); |
| 183 |
bHat = partI2.reorderVector(b); |
| 184 |
cout << "Done with graph - pt-scotch" << endl; |
| 185 |
|
| 186 |
*/ |
| 187 |
|
| 188 |
//Zoltan2 Test |
| 189 |
|
| 190 |
#if defined(HAVE_SHYLU_DDCORE_ZOLTAN2CORE) && (!defined(HAVE_SHYLU_DDCORE_TPETRA) || defined(HAVE_TPETRA_INST_INT_INT)) |
| 191 |
|
| 192 |
//Isorropia Test - Graph/ParMetis |
| 193 |
pLUList->set("Partitioning Package","Zoltan2"); |
| 194 |
ptemp = pLUList->sublist("Zoltan2 Input"); |
| 195 |
ptemp.set("algorithm", "parmetis"); |
| 196 |
ptemp.set("debug_level", "detailed_status"); |
| 197 |
pLUList->set("Zoltan2 Input", ptemp); |
| 198 |
|
| 199 |
|
| 200 |
cout << " \n\n--------------------BIG BREAK --------------\n\n"; |
| 201 |
Teuchos::writeParameterListToXmlOStream(*pLUList, std::cout); |
| 202 |
|
| 203 |
ShyLU::PartitionInterface<Epetra_CrsMatrix, Epetra_MultiVector> partI3(A, pLUList.get()); |
| 204 |
partI3.partition(); |
| 205 |
AHat = partI3.reorderMatrix(); |
| 206 |
bHat = partI3.reorderVector(b); |
| 207 |
cout << "Done with graph - parmetis (Zoltan2)" << endl; |
| 208 |
|
| 209 |
EpetraExt::RowMatrixToMatlabFile("Epetra_Zoltan2_Parmetis.mat", *AHat); |
| 210 |
|
| 211 |
#endif |
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
/*----------------------Direct Solver Interfaces----------------*/ |
| 216 |
//#ifdef HAVE_SHYLU_AMESOS |
| 217 |
|
| 218 |
//Amesos - klu |
| 219 |
pLUList->set("Direct Solver Package", "Amesos"); |
| 220 |
ptemp = pLUList->sublist("Amesos Input"); |
| 221 |
pptemp = ptemp.sublist("Amesos_Klu Input"); |
| 222 |
|
| 223 |
|
| 224 |
pptemp.set("PrintTiming", true); |
| 225 |
pptemp.set("PrintStatus", true); |
| 226 |
ptemp.set("Solver", "Amesos_Klu"); |
| 227 |
ptemp.set("Amesos_Klu Input", pptemp); |
| 228 |
pLUList->set("Amesos Input", ptemp); |
| 229 |
|
| 230 |
|
| 231 |
cout << " \n\n--------------------BIG BREAK --------------\n\n"; |
| 232 |
Teuchos::writeParameterListToXmlOStream(*pLUList, std::cout); |
| 233 |
|
| 234 |
ShyLU::DirectSolverInterface<Epetra_CrsMatrix, Epetra_MultiVector> directsolver(A, pLUList.get()); |
| 235 |
|
| 236 |
directsolver.factor(); |
| 237 |
directsolver.solve(b,x); |
| 238 |
|
| 239 |
cout << "Done with Amesos-KLU" << endl; |
| 240 |
|
| 241 |
//#endif |
| 242 |
|
| 243 |
//Amesos2 -klu2 |
| 244 |
#ifdef HAVE_SHYLU_AMESOS2 |
| 245 |
|
| 246 |
pLUList->set("Direct Solver Package", "Amesos2"); |
| 247 |
ptemp = pLUList->sublist("Amesos2 Input"); |
| 248 |
//pptemp = ptemp.sublist("Amesos_Klu Input"); |
| 249 |
|
| 250 |
|
| 251 |
pptemp.set("PrintTiming", true); |
| 252 |
pptemp.set("PrintStatus", true); |
| 253 |
ptemp.set("Solver", "KLU2"); |
| 254 |
//ptemp.set("Amesos_Klu Input", pptemp); |
| 255 |
pLUList->set("Amesos2 Input", ptemp); |
| 256 |
|
| 257 |
|
| 258 |
cout << " \n\n--------------------BIG BREAK --------------\n\n"; |
| 259 |
Teuchos::writeParameterListToXmlOStream(*pLUList, std::cout); |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
ShyLU::DirectSolverInterface<Epetra_CrsMatrix, Epetra_MultiVector> directsolver2(A, pLUList.get()); |
| 265 |
|
| 266 |
directsolver2.factor(); |
| 267 |
directsolver2.solve(b,x); |
| 268 |
|
| 269 |
cout << "Done with Amesos-KLU2" << endl; |
| 270 |
|
| 271 |
#endif |
| 272 |
|
| 273 |
if(success) |
| 274 |
{ |
| 275 |
cout << pass << endl; |
| 276 |
} |
| 277 |
|
| 278 |
(void)bHat; |
| 279 |
return 0; |
| 280 |
} |
| 281 |
|