| 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 |
// Thyra includes |
| 27 |
#include <Thyra_LinearOpWithSolveBase.hpp> |
| 28 |
#include <Thyra_VectorBase.hpp> |
| 29 |
#include <Thyra_SolveSupportTypes.hpp> |
| 30 |
#include <Thyra_LinearOpWithSolveBase.hpp> |
| 31 |
#include <Thyra_LinearOpWithSolveFactoryHelpers.hpp> |
| 32 |
#include <Thyra_TpetraLinearOp.hpp> |
| 33 |
#include <Thyra_TpetraMultiVector.hpp> |
| 34 |
#include <Thyra_TpetraVector.hpp> |
| 35 |
#include <Thyra_TpetraThyraWrappers.hpp> |
| 36 |
#include <Thyra_VectorBase.hpp> |
| 37 |
#include <Thyra_VectorStdOps.hpp> |
| 38 |
#ifdef HAVE_SHYLU_DDFROSCH_EPETRA |
| 39 |
#include <Thyra_EpetraLinearOp.hpp> |
| 40 |
#endif |
| 41 |
#include <Thyra_VectorSpaceBase_def.hpp> |
| 42 |
#include <Thyra_VectorSpaceBase_decl.hpp> |
| 43 |
|
| 44 |
// Stratimikos includes |
| 45 |
#include <Stratimikos_FROSch_def.hpp> |
| 46 |
|
| 47 |
#include <Tpetra_Core.hpp> |
| 48 |
|
| 49 |
// Xpetra include |
| 50 |
#include <Xpetra_CrsMatrixWrap.hpp> |
| 51 |
#include <Xpetra_DefaultPlatform.hpp> |
| 52 |
#ifdef HAVE_SHYLU_DDFROSCH_EPETRA |
| 53 |
#include <Xpetra_EpetraCrsMatrix.hpp> |
| 54 |
#endif |
| 55 |
#include <Xpetra_Parameters.hpp> |
| 56 |
|
| 57 |
// FROSCH thyra includes |
| 58 |
#include "Thyra_FROSchLinearOp_def.hpp" |
| 59 |
#include "Thyra_FROSchFactory_def.hpp" |
| 60 |
#include <FROSch_Tools_def.hpp> |
| 61 |
|
| 62 |
|
| 63 |
using UN = unsigned; |
| 64 |
using SC = double; |
| 65 |
using LO = int; |
| 66 |
using GO = FROSch::DefaultGlobalOrdinal; |
| 67 |
using NO = Tpetra::KokkosClassic::DefaultNode::DefaultNodeType; |
| 68 |
|
| 69 |
using namespace std; |
| 70 |
using namespace Teuchos; |
| 71 |
using namespace Xpetra; |
| 72 |
using namespace FROSch; |
| 73 |
using namespace Thyra; |
| 74 |
|
| 75 |
int main(int argc, char *argv[]) |
| 76 |
{ |
| 77 |
oblackholestream blackhole; |
| 78 |
GlobalMPISession mpiSession(&argc,&argv,&blackhole); |
| 79 |
|
| 80 |
RCP<const Comm<int> > CommWorld = DefaultPlatform::getDefaultPlatform().getComm(); |
| 81 |
|
| 82 |
CommandLineProcessor My_CLP; |
| 83 |
|
| 84 |
RCP<FancyOStream> out = VerboseObjectBase::getDefaultOStream(); |
| 85 |
|
| 86 |
int M = 4; |
| 87 |
My_CLP.setOption("M",&M,"H / h."); |
| 88 |
int Dimension = 2; |
| 89 |
My_CLP.setOption("DIM",&Dimension,"Dimension."); |
| 90 |
int Iterations = 2; |
| 91 |
My_CLP.setOption("ITS",&Iterations,"Iterations."); |
| 92 |
string xmlFile = "ParameterList.xml"; |
| 93 |
My_CLP.setOption("PLIST",&xmlFile,"File name of the parameter list."); |
| 94 |
bool useepetra = false; |
| 95 |
My_CLP.setOption("USEEPETRA","USETPETRA",&useepetra,"Use Epetra infrastructure for the linear algebra."); |
| 96 |
|
| 97 |
My_CLP.recogniseAllOptions(true); |
| 98 |
My_CLP.throwExceptions(false); |
| 99 |
CommandLineProcessor::EParseCommandLineReturn parseReturn = My_CLP.parse(argc,argv); |
| 100 |
if (parseReturn == CommandLineProcessor::PARSE_HELP_PRINTED) { |
| 101 |
return(EXIT_SUCCESS); |
| 102 |
} |
| 103 |
|
| 104 |
CommWorld->barrier(); |
| 105 |
RCP<StackedTimer> stackedTimer = rcp(new StackedTimer("Gathering Test")); |
| 106 |
TimeMonitor::setStackedTimer(stackedTimer); |
| 107 |
|
| 108 |
int N = 0; |
| 109 |
int color=1; |
| 110 |
if (Dimension == 2) { |
| 111 |
N = (int) (pow(CommWorld->getSize(),1/2.) + 100*numeric_limits<double>::epsilon()); // 1/H |
| 112 |
if (CommWorld->getRank()<N*N) { |
| 113 |
color=0; |
| 114 |
} |
| 115 |
} else if (Dimension == 3) { |
| 116 |
N = (int) (pow(CommWorld->getSize(),1/3.) + 100*numeric_limits<double>::epsilon()); // 1/H |
| 117 |
if (CommWorld->getRank()<N*N*N) { |
| 118 |
color=0; |
| 119 |
} |
| 120 |
} else { |
| 121 |
assert(false); |
| 122 |
} |
| 123 |
|
| 124 |
UnderlyingLib xpetraLib = UseTpetra; |
| 125 |
if (useepetra) { |
| 126 |
xpetraLib = UseEpetra; |
| 127 |
} else { |
| 128 |
xpetraLib = UseTpetra; |
| 129 |
} |
| 130 |
|
| 131 |
RCP<const Comm<int> > Comm = CommWorld->split(color,CommWorld->getRank()); |
| 132 |
|
| 133 |
if (color==0) { |
| 134 |
|
| 135 |
RCP<ParameterList> parameterList = getParametersFromXmlFile(xmlFile); |
| 136 |
|
| 137 |
Comm->barrier(); |
| 138 |
if (Comm->getRank()==0) { |
| 139 |
cout << "##################\n# Parameter List #\n##################" << endl; |
| 140 |
parameterList->print(cout); |
| 141 |
cout << endl; |
| 142 |
} |
| 143 |
|
| 144 |
Comm->barrier(); if (Comm->getRank()==0) cout << "##############################\n# Assembly Laplacian #\n##############################\n" << endl; |
| 145 |
|
| 146 |
ParameterList GaleriList; |
| 147 |
GaleriList.set("nx", GO(N*M)); |
| 148 |
GaleriList.set("ny", GO(N*M)); |
| 149 |
GaleriList.set("nz", GO(N*M)); |
| 150 |
GaleriList.set("mx", GO(N)); |
| 151 |
GaleriList.set("my", GO(N)); |
| 152 |
GaleriList.set("mz", GO(N)); |
| 153 |
|
| 154 |
RCP<const Map<LO,GO,NO> > UniqueMap; |
| 155 |
RCP<MultiVector<SC,LO,GO,NO> > Coordinates; |
| 156 |
RCP<Matrix<SC,LO,GO,NO> > K; |
| 157 |
if (Dimension==2) { |
| 158 |
UniqueMap = Galeri::Xpetra::CreateMap<LO,GO,NO>(xpetraLib,"Cartesian2D",Comm,GaleriList); // RCP<FancyOStream> fancy = fancyOStream(rcpFromRef(cout)); nodeMap->describe(*fancy,VERB_EXTREME); |
| 159 |
Coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC,LO,GO,Map<LO,GO,NO>,MultiVector<SC,LO,GO,NO> >("2D",UniqueMap,GaleriList); |
| 160 |
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); |
| 161 |
K = Problem->BuildMatrix(); |
| 162 |
} else if (Dimension==3) { |
| 163 |
UniqueMap = Galeri::Xpetra::CreateMap<LO,GO,NO>(xpetraLib,"Cartesian3D",Comm,GaleriList); // RCP<FancyOStream> fancy = fancyOStream(rcpFromRef(cout)); nodeMap->describe(*fancy,VERB_EXTREME); |
| 164 |
Coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC,LO,GO,Map<LO,GO,NO>,MultiVector<SC,LO,GO,NO> >("3D",UniqueMap,GaleriList); |
| 165 |
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); |
| 166 |
K = Problem->BuildMatrix(); |
| 167 |
} |
| 168 |
RCP<const Map<LO,GO,NO> > RepeatedMap = BuildRepeatedMapNonConst<LO,GO,NO>(K->getCrsGraph()); |
| 169 |
|
| 170 |
Comm->barrier(); if (Comm->getRank()==0) cout << "##############################\n# Set Up Coarse Operator #\n##############################\n" << endl; |
| 171 |
|
| 172 |
RCP<GDSWCoarseOperator<SC,LO,GO,NO> > CoarseOperator(new GDSWCoarseOperator<SC,LO,GO,NO>(K,parameterList)); |
| 173 |
CoarseOperator->initialize(Dimension,RepeatedMap); |
| 174 |
CoarseOperator->compute(); |
| 175 |
|
| 176 |
RCP<MultiVector<SC,LO,GO,NO> > x = MultiVectorFactory<SC,LO,GO,NO>::Build(K->getMap(),1); |
| 177 |
RCP<MultiVector<SC,LO,GO,NO> > y = MultiVectorFactory<SC,LO,GO,NO>::Build(K->getMap(),1); |
| 178 |
x->putScalar(ScalarTraits<SC>::one()); |
| 179 |
y->putScalar(ScalarTraits<SC>::zero()); |
| 180 |
|
| 181 |
Comm->barrier(); if (Comm->getRank()==0) cout << "##############################\n# Apply Coarse Operator #\n##############################\n" << endl; |
| 182 |
for (int i=0; i<Iterations; i++) { |
| 183 |
CoarseOperator->apply(*x,*y,true); |
| 184 |
*x = *y; |
| 185 |
} |
| 186 |
|
| 187 |
Comm->barrier(); |
| 188 |
SC norm = y->getVector(0)->norm2(); |
| 189 |
if (Comm->getRank()==0) cout << "Norm2: " << norm << endl; |
| 190 |
} |
| 191 |
|
| 192 |
CommWorld->barrier(); |
| 193 |
stackedTimer->stop("Gathering Test"); |
| 194 |
StackedTimer::OutputOptions options; |
| 195 |
options.output_fraction = options.output_histogram = options.output_minmax = true; |
| 196 |
stackedTimer->report(*out,CommWorld,options); |
| 197 |
|
| 198 |
return(EXIT_SUCCESS); |
| 199 |
|
| 200 |
} |