| 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 <ShyLU_DDFROSch_config.h> |
| 11 |
|
| 12 |
#include <mpi.h> |
| 13 |
|
| 14 |
#include <Teuchos_GlobalMPISession.hpp> |
| 15 |
#include <Teuchos_CommandLineProcessor.hpp> |
| 16 |
#include <Teuchos_XMLParameterListCoreHelpers.hpp> |
| 17 |
#include <Teuchos_StackedTimer.hpp> |
| 18 |
|
| 19 |
#include <Epetra_MpiComm.h> |
| 20 |
#if defined(HAVE_SHYLU_DDFROSCH_EPETRAEXT) && defined(HAVE_SHYLU_DDFROSCH_HDF5) |
| 21 |
#include "EpetraExt_HDF5.h" |
| 22 |
#endif |
| 23 |
|
| 24 |
// Galeri::Xpetra |
| 25 |
#include "Galeri_XpetraProblemFactory.hpp" |
| 26 |
#include "Galeri_XpetraMatrixTypes.hpp" |
| 27 |
#include "Galeri_XpetraParameters.hpp" |
| 28 |
#include "Galeri_XpetraUtils.hpp" |
| 29 |
#include "Galeri_XpetraMaps.hpp" |
| 30 |
|
| 31 |
// Thyra includes |
| 32 |
#include <Thyra_LinearOpWithSolveBase.hpp> |
| 33 |
#include <Thyra_VectorBase.hpp> |
| 34 |
#include <Thyra_SolveSupportTypes.hpp> |
| 35 |
#include <Thyra_LinearOpWithSolveBase.hpp> |
| 36 |
#include <Thyra_LinearOpWithSolveFactoryHelpers.hpp> |
| 37 |
#include <Thyra_TpetraLinearOp.hpp> |
| 38 |
#include <Thyra_TpetraMultiVector.hpp> |
| 39 |
#include <Thyra_TpetraVector.hpp> |
| 40 |
#include <Thyra_TpetraThyraWrappers.hpp> |
| 41 |
#include <Thyra_VectorBase.hpp> |
| 42 |
#include <Thyra_VectorStdOps.hpp> |
| 43 |
#ifdef HAVE_SHYLU_DDFROSCH_EPETRA |
| 44 |
#include <Thyra_EpetraLinearOp.hpp> |
| 45 |
#endif |
| 46 |
#include <Thyra_VectorSpaceBase_def.hpp> |
| 47 |
#include <Thyra_VectorSpaceBase_decl.hpp> |
| 48 |
|
| 49 |
// Stratimikos includes |
| 50 |
//#include <Stratimikos_DefaultLinearSolverBuilder.hpp> |
| 51 |
#include <Stratimikos_FROSch_def.hpp> |
| 52 |
|
| 53 |
#include <Tpetra_Core.hpp> |
| 54 |
|
| 55 |
// Xpetra include |
| 56 |
#include <Xpetra_CrsMatrixWrap.hpp> |
| 57 |
#include <Xpetra_DefaultPlatform.hpp> |
| 58 |
#ifdef HAVE_XPETRA_EPETRA |
| 59 |
#include <Xpetra_EpetraCrsMatrix.hpp> |
| 60 |
#endif |
| 61 |
#include <Xpetra_Parameters.hpp> |
| 62 |
|
| 63 |
// FROSCH thyra includes |
| 64 |
#include "Thyra_FROSchLinearOp_def.hpp" |
| 65 |
#include "Thyra_FROSchFactory_def.hpp" |
| 66 |
#include <FROSch_Tools_def.hpp> |
| 67 |
|
| 68 |
|
| 69 |
using UN = unsigned; |
| 70 |
using SC = double; |
| 71 |
using LO = int; |
| 72 |
using GO = FROSch::DefaultGlobalOrdinal; |
| 73 |
using NO = Tpetra::KokkosClassic::DefaultNode::DefaultNodeType; |
| 74 |
|
| 75 |
using namespace std; |
| 76 |
using namespace EpetraExt; |
| 77 |
using namespace FROSch; |
| 78 |
using namespace Teuchos; |
| 79 |
using namespace Xpetra; |
| 80 |
using namespace Thyra; |
| 81 |
|
| 82 |
int main(int argc, char *argv[]) |
| 83 |
{ |
| 84 |
oblackholestream blackhole; |
| 85 |
GlobalMPISession mpiSession(&argc,&argv,&blackhole); |
| 86 |
|
| 87 |
RCP<const Comm<int> > CommWorld = DefaultPlatform::getDefaultPlatform().getComm(); |
| 88 |
|
| 89 |
CommandLineProcessor My_CLP; |
| 90 |
|
| 91 |
RCP<FancyOStream> out = VerboseObjectBase::getDefaultOStream(); |
| 92 |
|
| 93 |
// Overlap |
| 94 |
int Overlap = 0; |
| 95 |
My_CLP.setOption("O",&Overlap,"Overlap."); |
| 96 |
|
| 97 |
// XML-file specifying the solver configuration |
| 98 |
string xmlFile = "ParameterList_TwoLevelBlockPreconditioner_GDSW.xml"; |
| 99 |
My_CLP.setOption("PLIST",&xmlFile,"File name of the parameter list."); |
| 100 |
|
| 101 |
// Use Epetra as linear algebra stack |
| 102 |
bool useepetra = false; |
| 103 |
My_CLP.setOption("USEEPETRA","USETPETRA",&useepetra,"Use Epetra infrastructure for the linear algebra."); |
| 104 |
|
| 105 |
// File name of HDF5 file to be read |
| 106 |
string hdf5File = "stokes.h5"; |
| 107 |
My_CLP.setOption("HDF5FILE", &hdf5File, "File name of HDF5 file to be read."); |
| 108 |
|
| 109 |
My_CLP.recogniseAllOptions(true); |
| 110 |
My_CLP.throwExceptions(false); |
| 111 |
CommandLineProcessor::EParseCommandLineReturn parseReturn = My_CLP.parse(argc,argv); |
| 112 |
if (parseReturn == CommandLineProcessor::PARSE_HELP_PRINTED) { |
| 113 |
return(EXIT_SUCCESS); |
| 114 |
} |
| 115 |
|
| 116 |
CommWorld->barrier(); |
| 117 |
RCP<StackedTimer> stackedTimer = rcp(new StackedTimer("Thyra Stokes Test")); |
| 118 |
TimeMonitor::setStackedTimer(stackedTimer); |
| 119 |
|
| 120 |
int color=1; |
| 121 |
if (CommWorld->getRank()<4) { |
| 122 |
color=0; |
| 123 |
} |
| 124 |
|
| 125 |
UnderlyingLib xpetraLib = UseTpetra; |
| 126 |
if (useepetra) { |
| 127 |
xpetraLib = UseEpetra; |
| 128 |
} else { |
| 129 |
xpetraLib = UseTpetra; |
| 130 |
} |
| 131 |
|
| 132 |
RCP<const Comm<int> > Comm = CommWorld->split(color,CommWorld->getRank()); |
| 133 |
|
| 134 |
MPI_Comm COMM; |
| 135 |
MPI_Comm_split(MPI_COMM_WORLD,color,CommWorld->getRank(),&COMM); |
| 136 |
RCP<Epetra_MpiComm> EpetraComm(new Epetra_MpiComm(COMM)); |
| 137 |
|
| 138 |
#ifdef HAVE_EPETRAEXT_HDF5 |
| 139 |
if (color==0) { |
| 140 |
|
| 141 |
RCP<ParameterList> parameterList = getParametersFromXmlFile(xmlFile); |
| 142 |
|
| 143 |
Comm->barrier(); if (Comm->getRank()==0) cout << "##############################\n# Import Monolithic System #\n##############################\n" << endl; |
| 144 |
|
| 145 |
unsigned Dimension = 2; |
| 146 |
RCP<HDF5> hDF5IO(new HDF5(*EpetraComm)); |
| 147 |
hDF5IO->Open(hdf5File); |
| 148 |
|
| 149 |
/////////////////// |
| 150 |
// Repeated Maps // |
| 151 |
/////////////////// |
| 152 |
string groupNameRepeatedMapVelo = "RepeatedMapVelocity"; |
| 153 |
Epetra_Map *repeatedMapEpetraVelo; |
| 154 |
hDF5IO->Read(groupNameRepeatedMapVelo,repeatedMapEpetraVelo); |
| 155 |
|
| 156 |
RCP<Map<LO,GO,NO> > repeatedMapVelo = ConvertToXpetra<SC,LO,GO,NO>::ConvertMap(xpetraLib,*repeatedMapEpetraVelo,Comm); |
| 157 |
|
| 158 |
string groupNameRepeatedMapPress = "RepeatedMapPressure"; |
| 159 |
Epetra_Map *repeatedMapEpetraPress; |
| 160 |
hDF5IO->Read(groupNameRepeatedMapPress,repeatedMapEpetraPress); |
| 161 |
RCP<Map<LO,GO,NO> > repeatedMapPress = ConvertToXpetra<SC,LO,GO,NO>::ConvertMap(xpetraLib,*repeatedMapEpetraPress,Comm); |
| 162 |
|
| 163 |
// GO offsetVelocityMap = repeatedMapVelo->getMaxAllGlobalIndex()+1; |
| 164 |
// Array<GO> elementList(repeatedMapEpetraPress->NumMyElements()); |
| 165 |
// for (unsigned i=0; i<elementList.size(); i++) { |
| 166 |
// elementList[i] = repeatedMapEpetraPress->GID(i) + offsetVelocityMap; |
| 167 |
// } |
| 168 |
// RCP<Map<LO,GO,NO> > repeatedMapPress = MapFactory<LO,GO,NO>::Build(xpetraLib,-1,elementList,0,Comm); |
| 169 |
|
| 170 |
ArrayRCP<RCP<const Map<LO,GO,NO> > > repeatedMapsVectorConst(2); |
| 171 |
ArrayRCP<RCP<Map<LO,GO,NO> > > repeatedMapsVector(2); |
| 172 |
|
| 173 |
repeatedMapsVectorConst[0] = repeatedMapVelo.getConst(); |
| 174 |
repeatedMapsVectorConst[1] = repeatedMapPress.getConst(); |
| 175 |
|
| 176 |
RCP<Map<LO,GO,NO> > repeatedMap = MergeMapsNonConst(repeatedMapsVectorConst); |
| 177 |
|
| 178 |
repeatedMapsVector[0] = repeatedMapVelo; |
| 179 |
repeatedMapsVector[1] = repeatedMapPress; |
| 180 |
|
| 181 |
|
| 182 |
//////////////// |
| 183 |
// Unique Map // |
| 184 |
//////////////// |
| 185 |
RCP<Map<LO,GO,NO> > uniqueMap = rcp_const_cast<Map<LO,GO,NO> >(BuildUniqueMap<LO,GO,NO>(repeatedMap)); |
| 186 |
|
| 187 |
|
| 188 |
///////// |
| 189 |
// RHS // |
| 190 |
///////// |
| 191 |
string groupNameRHS = "RHS"; |
| 192 |
Epetra_MultiVector *rhsEpetra; |
| 193 |
hDF5IO->Read(groupNameRHS,rhsEpetra); |
| 194 |
|
| 195 |
RCP<MultiVector<SC,LO,GO,NO> > rhsTmp = ConvertToXpetra<SC,LO,GO,NO>::ConvertMultiVector(xpetraLib,*rhsEpetra,Comm); |
| 196 |
RCP<MultiVector<SC,LO,GO,NO> > rhs = MultiVectorFactory<SC,LO,GO,NO>::Build(uniqueMap,1); |
| 197 |
RCP<Import<LO,GO,NO> > scatter = ImportFactory<LO,GO,NO>::Build(rhsTmp->getMap(),uniqueMap); |
| 198 |
rhs->doImport(*rhsTmp,*scatter,ADD); |
| 199 |
|
| 200 |
|
| 201 |
//////////// |
| 202 |
// Matrix // |
| 203 |
//////////// |
| 204 |
string groupNameMatrix = "Matrix"; |
| 205 |
Epetra_CrsMatrix *matrixEpetra; |
| 206 |
hDF5IO->Read(groupNameMatrix,matrixEpetra); |
| 207 |
RCP<Matrix<SC,LO,GO,NO> > matrixTmp = ConvertToXpetra<SC,LO,GO,NO>::ConvertMatrix(xpetraLib,*matrixEpetra,Comm); |
| 208 |
RCP<Matrix<SC,LO,GO,NO> > matrix = MatrixFactory<SC,LO,GO,NO>::Build(uniqueMap,matrixTmp->getGlobalMaxNumRowEntries()); |
| 209 |
|
| 210 |
matrix->doImport(*matrixTmp,*scatter,ADD); |
| 211 |
matrix->fillComplete(); |
| 212 |
|
| 213 |
|
| 214 |
////////////////////// |
| 215 |
// Convert to Thyra // |
| 216 |
////////////////////// |
| 217 |
RCP<MultiVector<SC,LO,GO,NO> > xSolution = MultiVectorFactory<SC,LO,GO,NO>::Build(uniqueMap,1); |
| 218 |
RCP<MultiVector<SC,LO,GO,NO> > xRightHandSide = MultiVectorFactory<SC,LO,GO,NO>::Build(uniqueMap,1); |
| 219 |
|
| 220 |
xSolution->putScalar(ScalarTraits<SC>::zero()); |
| 221 |
xRightHandSide->putScalar(ScalarTraits<SC>::one()); |
| 222 |
|
| 223 |
RCP<CrsMatrixWrap<SC,LO,GO,NO> > tmpCrsWrap = rcp_dynamic_cast<CrsMatrixWrap<SC,LO,GO,NO> >(matrix); |
| 224 |
|
| 225 |
RCP<const Thyra::LinearOpBase<SC> > K_thyra = ThyraUtils<SC,LO,GO,NO>::toThyra(tmpCrsWrap->getCrsMatrix()); |
| 226 |
|
| 227 |
RCP<Thyra::MultiVectorBase<SC> >thyraX = |
| 228 |
rcp_const_cast<Thyra::MultiVectorBase<SC> >(ThyraUtils<SC,LO,GO,NO>::toThyraMultiVector(xSolution)); |
| 229 |
RCP<const Thyra::MultiVectorBase<SC> >thyraB = ThyraUtils<SC,LO,GO,NO>::toThyraMultiVector(xRightHandSide); |
| 230 |
|
| 231 |
|
| 232 |
/////////////////// |
| 233 |
// ParameterList // |
| 234 |
/////////////////// |
| 235 |
RCP<ParameterList> plList = sublist(parameterList,"Preconditioner Types"); |
| 236 |
sublist(plList,"FROSch")->set("Overlap",Overlap); |
| 237 |
|
| 238 |
sublist(plList,"FROSch")->set("Repeated Map Vector",repeatedMapsVector); |
| 239 |
|
| 240 |
ArrayRCP<DofOrdering> dofOrderings(2); |
| 241 |
ArrayRCP<UN> dofsPerNodeVector(2); |
| 242 |
dofOrderings[0] = NodeWise; |
| 243 |
dofOrderings[1] = NodeWise; |
| 244 |
dofsPerNodeVector[0] = Dimension; |
| 245 |
dofsPerNodeVector[1] = 1; |
| 246 |
|
| 247 |
sublist(plList,"FROSch")->set("DofOrdering Vector",dofOrderings); |
| 248 |
sublist(plList,"FROSch")->set("DofsPerNode Vector",dofsPerNodeVector); |
| 249 |
|
| 250 |
Comm->barrier(); |
| 251 |
if (Comm->getRank()==0) { |
| 252 |
cout << "##################\n# Parameter List #\n##################" << endl; |
| 253 |
parameterList->print(cout); |
| 254 |
cout << endl; |
| 255 |
} |
| 256 |
|
| 257 |
Comm->barrier(); if (Comm->getRank()==0) cout << "###################################\n# Stratimikos LinearSolverBuilder #\n###################################\n" << endl; |
| 258 |
Stratimikos::LinearSolverBuilder<SC> linearSolverBuilder; |
| 259 |
Stratimikos::enableFROSch<SC,LO,GO,NO>(linearSolverBuilder); |
| 260 |
linearSolverBuilder.setParameterList(parameterList); |
| 261 |
|
| 262 |
Comm->barrier(); if (Comm->getRank()==0) cout << "######################\n# Thyra PrepForSolve #\n######################\n" << endl; |
| 263 |
|
| 264 |
RCP<LinearOpWithSolveFactoryBase<SC> > lowsFactory = |
| 265 |
linearSolverBuilder.createLinearSolveStrategy(""); |
| 266 |
|
| 267 |
lowsFactory->setOStream(out); |
| 268 |
lowsFactory->setVerbLevel(VERB_HIGH); |
| 269 |
|
| 270 |
Comm->barrier(); if (Comm->getRank()==0) cout << "###########################\n# Thyra LinearOpWithSolve #\n###########################" << endl; |
| 271 |
|
| 272 |
RCP<LinearOpWithSolveBase<SC> > lows = |
| 273 |
linearOpWithSolve(*lowsFactory, K_thyra); |
| 274 |
|
| 275 |
Comm->barrier(); if (Comm->getRank()==0) cout << "\n#########\n# Solve #\n#########" << endl; |
| 276 |
SolveStatus<SC> status = |
| 277 |
solve<SC>(*lows, Thyra::NOTRANS, *thyraB, thyraX.ptr()); |
| 278 |
|
| 279 |
Comm->barrier(); if (Comm->getRank()==0) cout << "\n#############\n# Finished! #\n#############" << endl; |
| 280 |
} |
| 281 |
#endif |
| 282 |
|
| 283 |
CommWorld->barrier(); |
| 284 |
stackedTimer->stop("Thyra Stokes Test"); |
| 285 |
StackedTimer::OutputOptions options; |
| 286 |
options.output_fraction = options.output_histogram = options.output_minmax = true; |
| 287 |
stackedTimer->report(*out,CommWorld,options); |
| 288 |
|
| 289 |
return(EXIT_SUCCESS); |
| 290 |
|
| 291 |
} |
| 292 |
|
| 293 |
|
| 294 |
|