| 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 "mpi.h" |
| 11 |
|
| 12 |
#include "Galeri_XpetraProblemFactory.hpp" |
| 13 |
#include "Galeri_XpetraMatrixTypes.hpp" |
| 14 |
#include "Galeri_XpetraParameters.hpp" |
| 15 |
#include "Galeri_XpetraUtils.hpp" |
| 16 |
#include "Galeri_XpetraMaps.hpp" |
| 17 |
|
| 18 |
#include "Teuchos_CommandLineProcessor.hpp" |
| 19 |
#include <Teuchos_StackedTimer.hpp> |
| 20 |
|
| 21 |
#include <Tpetra_KokkosCompat_DefaultNode.hpp> |
| 22 |
|
| 23 |
#include "Xpetra_CrsMatrixWrap.hpp" |
| 24 |
#include "Xpetra_CrsMatrix.hpp" |
| 25 |
#include <Xpetra_DefaultPlatform.hpp> |
| 26 |
|
| 27 |
#include <FROSch_DDInterface_def.hpp> |
| 28 |
|
| 29 |
#include <FROSch_Tools_decl.hpp> |
| 30 |
|
| 31 |
|
| 32 |
using UN = unsigned; |
| 33 |
using SC = double; |
| 34 |
using LO = int; |
| 35 |
using GO = FROSch::DefaultGlobalOrdinal; |
| 36 |
using NO = Tpetra::KokkosClassic::DefaultNode::DefaultNodeType; |
| 37 |
|
| 38 |
using namespace std; |
| 39 |
using namespace Teuchos; |
| 40 |
using namespace Xpetra; |
| 41 |
using namespace FROSch; |
| 42 |
|
| 43 |
int main(int argc, char *argv[]) |
| 44 |
{ |
| 45 |
using namespace std; |
| 46 |
using namespace Teuchos; |
| 47 |
using namespace Xpetra; |
| 48 |
using namespace FROSch; |
| 49 |
|
| 50 |
oblackholestream blackhole; |
| 51 |
GlobalMPISession mpiSession(&argc,&argv,&blackhole); |
| 52 |
|
| 53 |
RCP<const Comm<int> > CommWorld = DefaultPlatform::getDefaultPlatform().getComm(); |
| 54 |
|
| 55 |
CommandLineProcessor My_CLP; |
| 56 |
|
| 57 |
RCP<FancyOStream> out = VerboseObjectBase::getDefaultOStream(); |
| 58 |
|
| 59 |
int M = 4; |
| 60 |
My_CLP.setOption("M",&M,"H / h."); |
| 61 |
int Dimension = 3; |
| 62 |
My_CLP.setOption("DIM",&Dimension,"Dimension."); |
| 63 |
bool useEpetra = true; |
| 64 |
My_CLP.setOption("USEEPETRA","USETPETRA",&useEpetra,"Use Epetra infrastructure for the linear algebra."); |
| 65 |
int communicationStrategy = 0; |
| 66 |
My_CLP.setOption("COMMSTRAT",&communicationStrategy,"Communication strategy for the domain decomposition interface."); |
| 67 |
|
| 68 |
My_CLP.recogniseAllOptions(true); |
| 69 |
My_CLP.throwExceptions(false); |
| 70 |
CommandLineProcessor::EParseCommandLineReturn parseReturn = My_CLP.parse(argc,argv); |
| 71 |
if (parseReturn == CommandLineProcessor::PARSE_HELP_PRINTED) { |
| 72 |
return(EXIT_SUCCESS); |
| 73 |
} |
| 74 |
|
| 75 |
CommWorld->barrier(); |
| 76 |
RCP<StackedTimer> stackedTimer = rcp(new StackedTimer("InterfaceSets Test")); |
| 77 |
TimeMonitor::setStackedTimer(stackedTimer); |
| 78 |
|
| 79 |
int N = 0; |
| 80 |
int color=1; |
| 81 |
if (Dimension == 2) { |
| 82 |
N = (int) (pow(CommWorld->getSize(),1/2.) + 100*numeric_limits<double>::epsilon()); // 1/H |
| 83 |
if (CommWorld->getRank()<N*N) { |
| 84 |
color=0; |
| 85 |
} |
| 86 |
} else if (Dimension == 3) { |
| 87 |
N = (int) (pow(CommWorld->getSize(),1/3.) + 100*numeric_limits<double>::epsilon()); // 1/H |
| 88 |
if (CommWorld->getRank()<N*N*N) { |
| 89 |
color=0; |
| 90 |
} |
| 91 |
} else { |
| 92 |
assert(false); |
| 93 |
} |
| 94 |
|
| 95 |
UnderlyingLib xpetraLib = UseTpetra; |
| 96 |
if (useEpetra) { |
| 97 |
xpetraLib = UseEpetra; |
| 98 |
} else { |
| 99 |
xpetraLib = UseTpetra; |
| 100 |
} |
| 101 |
|
| 102 |
RCP<const Comm<int> > Comm = CommWorld->split(color,CommWorld->getRank()); |
| 103 |
|
| 104 |
if (color==0) { |
| 105 |
|
| 106 |
Comm->barrier(); if (Comm->getRank()==0) cout << "#############\n# Assembly #\n#############\n" << endl; |
| 107 |
//stackedTimer->start("Assembly Time"); |
| 108 |
FROSCH_TIMER_START(assemblyTimer,"Assembly"); |
| 109 |
|
| 110 |
ParameterList GaleriList; |
| 111 |
GaleriList.set("nx", GO(N*M)); |
| 112 |
GaleriList.set("ny", GO(N*M)); |
| 113 |
GaleriList.set("nz", GO(N*M)); |
| 114 |
GaleriList.set("mx", GO(N)); |
| 115 |
GaleriList.set("my", GO(N)); |
| 116 |
GaleriList.set("mz", GO(N)); |
| 117 |
|
| 118 |
RCP<const Map<LO,GO,NO> > UniqueMap; |
| 119 |
RCP<MultiVector<SC,LO,GO,NO> > Coordinates; |
| 120 |
RCP<Matrix<SC,LO,GO,NO> > K; |
| 121 |
if (Dimension==2) { |
| 122 |
UniqueMap = Galeri::Xpetra::CreateMap<LO,GO,NO>(xpetraLib,"Cartesian2D",Comm,GaleriList); // RCP<FancyOStream> fancy = fancyOStream(rcpFromRef(cout)); nodeMap->describe(*fancy,VERB_EXTREME); |
| 123 |
Coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC,LO,GO,Map<LO,GO,NO>,MultiVector<SC,LO,GO,NO> >("2D",UniqueMap,GaleriList); |
| 124 |
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); |
| 125 |
K = Problem->BuildMatrix(); |
| 126 |
} else if (Dimension==3) { |
| 127 |
UniqueMap = Galeri::Xpetra::CreateMap<LO,GO,NO>(xpetraLib,"Cartesian3D",Comm,GaleriList); // RCP<FancyOStream> fancy = fancyOStream(rcpFromRef(cout)); nodeMap->describe(*fancy,VERB_EXTREME); |
| 128 |
Coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC,LO,GO,Map<LO,GO,NO>,MultiVector<SC,LO,GO,NO> >("3D",UniqueMap,GaleriList); |
| 129 |
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); |
| 130 |
K = Problem->BuildMatrix(); |
| 131 |
} |
| 132 |
|
| 133 |
FROSCH_TIMER_STOP(assemblyTimer); |
| 134 |
Comm->barrier(); if (Comm->getRank()==0) cout << "#############\n# Constructing Repeated Map #\n#############\n" << endl; |
| 135 |
FROSCH_TIMER_START(repMapTimer,"Construct RepeatedMap"); |
| 136 |
|
| 137 |
RCP<const Map<LO,GO,NO> > RepeatedMap = BuildRepeatedMap<LO,GO,NO>(K->getCrsGraph()); |
| 138 |
|
| 139 |
FROSCH_TIMER_STOP(repMapTimer); |
| 140 |
Comm->barrier(); if (Comm->getRank()==0) cout << "#############\n# Identification of Interface Sets #\n#############\n" << endl; |
| 141 |
FROSCH_TIMER_START(intSetsTimer,"Identification of Interface Sets"); |
| 142 |
RCP<EntitySet<SC,LO,GO,NO> > vertices,shortEdges,straightEdges,edges,faces,interface,interior; |
| 143 |
//RCP<Map<LO,GO,NO> > verticesMap,shortEdgesMap,straightEdgesMap,edgesMap,facesMap; |
| 144 |
|
| 145 |
DDInterface<SC,LO,GO,NO> dDInterface(Dimension,1,RepeatedMap,All,(CommunicationStrategy) communicationStrategy); |
| 146 |
dDInterface.divideUnconnectedEntities(K); |
| 147 |
dDInterface.sortVerticesEdgesFaces(); |
| 148 |
|
| 149 |
dDInterface.buildEntityHierarchy(); |
| 150 |
|
| 151 |
dDInterface.buildEntityMaps(true, |
| 152 |
true, |
| 153 |
true, |
| 154 |
true, |
| 155 |
true, |
| 156 |
true); |
| 157 |
|
| 158 |
FROSCH_TIMER_STOP(intSetsTimer); |
| 159 |
Comm->barrier(); if (Comm->getRank()==0) cout << "\n#############\n# Finished! #\n#############" << endl; |
| 160 |
} |
| 161 |
|
| 162 |
CommWorld->barrier(); |
| 163 |
stackedTimer->stop("InterfaceSets Test"); |
| 164 |
StackedTimer::OutputOptions options; |
| 165 |
options.output_fraction = options.output_histogram = options.output_minmax = true; |
| 166 |
stackedTimer->report(*out,CommWorld,options); |
| 167 |
|
| 168 |
return(EXIT_SUCCESS); |
| 169 |
} |