| 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 |
// Galeri::Xpetra |
| 20 |
#include "Galeri_XpetraProblemFactory.hpp" |
| 21 |
#include "Galeri_XpetraMatrixTypes.hpp" |
| 22 |
#include "Galeri_XpetraParameters.hpp" |
| 23 |
#include "Galeri_XpetraUtils.hpp" |
| 24 |
#include "Galeri_XpetraMaps.hpp" |
| 25 |
|
| 26 |
// Xpetra include |
| 27 |
#include <Xpetra_CrsMatrixWrap.hpp> |
| 28 |
#include <Xpetra_DefaultPlatform.hpp> |
| 29 |
#ifdef HAVE_SHYLU_DDFROSCH_EPETRA |
| 30 |
#include <Xpetra_EpetraCrsMatrix.hpp> |
| 31 |
#endif |
| 32 |
#include <Xpetra_Parameters.hpp> |
| 33 |
|
| 34 |
// FROSch thyra includes |
| 35 |
#include <FROSch_SolverFactory_def.hpp> |
| 36 |
|
| 37 |
|
| 38 |
using UN = unsigned; |
| 39 |
using SC = double; |
| 40 |
using LO = int; |
| 41 |
using GO = FROSch::DefaultGlobalOrdinal; |
| 42 |
using NO = Tpetra::KokkosClassic::DefaultNode::DefaultNodeType; |
| 43 |
|
| 44 |
using namespace std; |
| 45 |
using namespace Teuchos; |
| 46 |
using namespace Xpetra; |
| 47 |
using namespace FROSch; |
| 48 |
using namespace Thyra; |
| 49 |
|
| 50 |
int main(int argc, char *argv[]) |
| 51 |
{ |
| 52 |
oblackholestream blackhole; |
| 53 |
GlobalMPISession mpiSession(&argc,&argv,&blackhole); |
| 54 |
|
| 55 |
RCP<const Comm<int> > CommWorld = DefaultPlatform::getDefaultPlatform().getComm(); |
| 56 |
|
| 57 |
CommandLineProcessor My_CLP; |
| 58 |
|
| 59 |
RCP<FancyOStream> out = VerboseObjectBase::getDefaultOStream(); |
| 60 |
|
| 61 |
int M = 3; |
| 62 |
My_CLP.setOption("M",&M,"H / h."); |
| 63 |
int Dimension = 2; |
| 64 |
My_CLP.setOption("DIM",&Dimension,"Dimension."); |
| 65 |
int Overlap = 0; |
| 66 |
My_CLP.setOption("O",&Overlap,"Overlap."); |
| 67 |
string xmlFile = "ParameterList.xml"; |
| 68 |
My_CLP.setOption("PLIST",&xmlFile,"File name of the parameter list."); |
| 69 |
bool useepetra = false; |
| 70 |
My_CLP.setOption("USEEPETRA","USETPETRA",&useepetra,"Use Epetra infrastructure for the linear algebra."); |
| 71 |
|
| 72 |
My_CLP.recogniseAllOptions(true); |
| 73 |
My_CLP.throwExceptions(false); |
| 74 |
CommandLineProcessor::EParseCommandLineReturn parseReturn = My_CLP.parse(argc,argv); |
| 75 |
if (parseReturn == CommandLineProcessor::PARSE_HELP_PRINTED) { |
| 76 |
return(EXIT_SUCCESS); |
| 77 |
} |
| 78 |
|
| 79 |
CommWorld->barrier(); |
| 80 |
RCP<StackedTimer> stackedTimer = rcp(new StackedTimer("FROSch Solver Factory Test")); |
| 81 |
TimeMonitor::setStackedTimer(stackedTimer); |
| 82 |
|
| 83 |
int N = 0; |
| 84 |
int color=1; |
| 85 |
if (Dimension == 2) { |
| 86 |
N = (int) (pow(CommWorld->getSize(),1/2.) + 100*numeric_limits<double>::epsilon()); // 1/H |
| 87 |
if (CommWorld->getRank()<N*N) { |
| 88 |
color=0; |
| 89 |
} |
| 90 |
} else if (Dimension == 3) { |
| 91 |
N = (int) (pow(CommWorld->getSize(),1/3.) + 100*numeric_limits<double>::epsilon()); // 1/H |
| 92 |
if (CommWorld->getRank()<N*N*N) { |
| 93 |
color=0; |
| 94 |
} |
| 95 |
} else { |
| 96 |
assert(false); |
| 97 |
} |
| 98 |
|
| 99 |
UnderlyingLib xpetraLib = UseTpetra; |
| 100 |
if (useepetra) { |
| 101 |
xpetraLib = UseEpetra; |
| 102 |
} else { |
| 103 |
xpetraLib = UseTpetra; |
| 104 |
} |
| 105 |
|
| 106 |
RCP<const Comm<int> > Comm = CommWorld->split(color,CommWorld->getRank()); |
| 107 |
|
| 108 |
if (color==0) { |
| 109 |
|
| 110 |
RCP<ParameterList> parameterList = getParametersFromXmlFile(xmlFile); |
| 111 |
|
| 112 |
Comm->barrier(); if (Comm->getRank()==0) cout << "######################\n# Assembly Laplacian #\n######################\n" << endl; |
| 113 |
|
| 114 |
ParameterList GaleriList; |
| 115 |
GaleriList.set("nx", GO(N*M)); |
| 116 |
GaleriList.set("ny", GO(N*M)); |
| 117 |
GaleriList.set("nz", GO(N*M)); |
| 118 |
GaleriList.set("mx", GO(N)); |
| 119 |
GaleriList.set("my", GO(N)); |
| 120 |
GaleriList.set("mz", GO(N)); |
| 121 |
|
| 122 |
RCP<const Map<LO,GO,NO> > UniqueMap; |
| 123 |
RCP<MultiVector<SC,LO,GO,NO> > Coordinates; |
| 124 |
RCP<Matrix<SC,LO,GO,NO> > K; |
| 125 |
if (Dimension==2) { |
| 126 |
UniqueMap = Galeri::Xpetra::CreateMap<LO,GO,NO>(xpetraLib,"Cartesian2D",Comm,GaleriList); // RCP<FancyOStream> fancy = fancyOStream(rcpFromRef(cout)); nodeMap->describe(*fancy,VERB_EXTREME); |
| 127 |
Coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC,LO,GO,Map<LO,GO,NO>,MultiVector<SC,LO,GO,NO> >("2D",UniqueMap,GaleriList); |
| 128 |
RCP<Galeri::Xpetra::Problem<Map<LO,GO,NO>,CrsMatrixWrap<SC,LO,GO,NO>,MultiVector<SC,LO,GO,NO> > > Problem = Galeri::Xpetra::BuildProblem<SC,LO,GO,Map<LO,GO,NO>,CrsMatrixWrap<SC,LO,GO,NO>,MultiVector<SC,LO,GO,NO> >("Laplace2D",UniqueMap,GaleriList); |
| 129 |
K = Problem->BuildMatrix(); |
| 130 |
} else if (Dimension==3) { |
| 131 |
UniqueMap = Galeri::Xpetra::CreateMap<LO,GO,NO>(xpetraLib,"Cartesian3D",Comm,GaleriList); // RCP<FancyOStream> fancy = fancyOStream(rcpFromRef(cout)); nodeMap->describe(*fancy,VERB_EXTREME); |
| 132 |
Coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC,LO,GO,Map<LO,GO,NO>,MultiVector<SC,LO,GO,NO> >("3D",UniqueMap,GaleriList); |
| 133 |
RCP<Galeri::Xpetra::Problem<Map<LO,GO,NO>,CrsMatrixWrap<SC,LO,GO,NO>,MultiVector<SC,LO,GO,NO> > > Problem = Galeri::Xpetra::BuildProblem<SC,LO,GO,Map<LO,GO,NO>,CrsMatrixWrap<SC,LO,GO,NO>,MultiVector<SC,LO,GO,NO> >("Laplace3D",UniqueMap,GaleriList); |
| 134 |
K = Problem->BuildMatrix(); |
| 135 |
} |
| 136 |
RCP<const Map<LO,GO,NO> > RepeatedMap = BuildRepeatedMap<LO,GO,NO>(K->getCrsGraph()); |
| 137 |
|
| 138 |
RCP<MultiVector<SC,LO,GO,NO> > xSolution = MultiVectorFactory<SC,LO,GO,NO>::Build(UniqueMap,1); |
| 139 |
RCP<MultiVector<SC,LO,GO,NO> > xRightHandSide = MultiVectorFactory<SC,LO,GO,NO>::Build(UniqueMap,1); |
| 140 |
|
| 141 |
xSolution->putScalar(ScalarTraits<SC>::zero()); |
| 142 |
xRightHandSide->putScalar(ScalarTraits<SC>::one()); |
| 143 |
|
| 144 |
RCP<ParameterList> twoLevelBlockPreconditionerList = sublist(sublist(parameterList,"FROSchPreconditioner"),"TwoLevelBlockPreconditioner"); |
| 145 |
twoLevelBlockPreconditionerList->set("Dimension",Dimension); |
| 146 |
twoLevelBlockPreconditionerList->set("Overlap",Overlap); |
| 147 |
ArrayRCP<DofOrdering> dofOrderings(1); |
| 148 |
dofOrderings[0] = NodeWise; |
| 149 |
twoLevelBlockPreconditionerList->set("DofOrdering Vector",dofOrderings); |
| 150 |
ArrayRCP<UN> dofsPerNodeVector(1); |
| 151 |
dofsPerNodeVector[0] = 1; |
| 152 |
twoLevelBlockPreconditionerList->set("DofsPerNode Vector",dofsPerNodeVector); |
| 153 |
ArrayRCP<RCP<const Map<LO,GO,NO> > > RepeatedMaps(1); |
| 154 |
RepeatedMaps[0] = RepeatedMap; |
| 155 |
twoLevelBlockPreconditionerList->set("Repeated Map Vector",RepeatedMaps); |
| 156 |
|
| 157 |
RCP<ParameterList> twoLevelPreconditionerList = sublist(sublist(parameterList,"FROSchPreconditioner"),"TwoLevelPreconditioner"); |
| 158 |
twoLevelPreconditionerList->set("Dimension",Dimension); |
| 159 |
twoLevelPreconditionerList->set("Overlap",Overlap); |
| 160 |
twoLevelPreconditionerList->set("DofOrdering Vector",dofOrderings); |
| 161 |
twoLevelPreconditionerList->set("DofsPerNode Vector",dofsPerNodeVector); |
| 162 |
twoLevelPreconditionerList->set("Repeated Map Vector",RepeatedMaps); |
| 163 |
|
| 164 |
Comm->barrier(); |
| 165 |
if (Comm->getRank()==0) { |
| 166 |
cout << "##################\n# Parameter List #\n##################" << endl; |
| 167 |
parameterList->print(cout); |
| 168 |
cout << endl; |
| 169 |
} |
| 170 |
|
| 171 |
Comm->barrier(); if (Comm->getRank()==0) cout << "####################\n# Construct Solver #\n####################" << endl; |
| 172 |
RCP<Solver<SC,LO,GO,NO> > FROSchSolverInterface = SolverFactory<SC,LO,GO,NO>::Build(K,parameterList,"Solver Tester"); |
| 173 |
|
| 174 |
FROSchSolverInterface->initialize(); |
| 175 |
|
| 176 |
FROSchSolverInterface->compute(); |
| 177 |
|
| 178 |
Comm->barrier(); if (Comm->getRank()==0) cout << "\n#########\n# Solve #\n#########" << endl; |
| 179 |
|
| 180 |
FROSchSolverInterface->apply(*xRightHandSide,*xSolution); |
| 181 |
|
| 182 |
Comm->barrier(); if (Comm->getRank()==0) cout << "\n#############\n# Finished! #\n#############" << endl; |
| 183 |
} |
| 184 |
|
| 185 |
CommWorld->barrier(); |
| 186 |
stackedTimer->stop("FROSch Solver Factory Test"); |
| 187 |
StackedTimer::OutputOptions options; |
| 188 |
options.output_fraction = options.output_histogram = options.output_minmax = true; |
| 189 |
stackedTimer->report(*out,CommWorld,options); |
| 190 |
|
| 191 |
return(EXIT_SUCCESS); |
| 192 |
|
| 193 |
} |