| 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_DefaultSerialComm.hpp> |
| 19 |
#include "Teuchos_CommandLineProcessor.hpp" |
| 20 |
#include <Teuchos_XMLParameterListCoreHelpers.hpp> |
| 21 |
#include <Teuchos_StackedTimer.hpp> |
| 22 |
|
| 23 |
#include <Tpetra_KokkosCompat_DefaultNode.hpp> |
| 24 |
|
| 25 |
#include "Xpetra_CrsMatrixWrap.hpp" |
| 26 |
#include "Xpetra_CrsMatrix.hpp" |
| 27 |
#include <Xpetra_DefaultPlatform.hpp> |
| 28 |
|
| 29 |
#include <FROSch_GDSWInterfacePartitionOfUnity_def.hpp> |
| 30 |
|
| 31 |
#include <FROSch_Tools_decl.hpp> |
| 32 |
|
| 33 |
|
| 34 |
using UN = unsigned; |
| 35 |
using SC = double; |
| 36 |
using LO = int; |
| 37 |
using GO = FROSch::DefaultGlobalOrdinal; |
| 38 |
using NO = Tpetra::KokkosClassic::DefaultNode::DefaultNodeType; |
| 39 |
|
| 40 |
int main(int argc, char *argv[]) |
| 41 |
{ |
| 42 |
using namespace std; |
| 43 |
using namespace Teuchos; |
| 44 |
using namespace Xpetra; |
| 45 |
using namespace FROSch; |
| 46 |
|
| 47 |
oblackholestream blackhole; |
| 48 |
GlobalMPISession mpiSession(&argc,&argv,&blackhole); |
| 49 |
|
| 50 |
RCP<const Comm<int> > CommWorld = DefaultPlatform::getDefaultPlatform().getComm(); |
| 51 |
|
| 52 |
CommandLineProcessor My_CLP; |
| 53 |
|
| 54 |
RCP<FancyOStream> out = VerboseObjectBase::getDefaultOStream(); |
| 55 |
|
| 56 |
int M = 4; |
| 57 |
My_CLP.setOption("M",&M,"H / h."); |
| 58 |
int Dimension = 3; |
| 59 |
My_CLP.setOption("DIM",&Dimension,"Dimension."); |
| 60 |
bool useepetra = true; |
| 61 |
My_CLP.setOption("USEEPETRA","USETPETRA",&useepetra,"Use Epetra infrastructure for the linear algebra."); |
| 62 |
|
| 63 |
My_CLP.recogniseAllOptions(true); |
| 64 |
My_CLP.throwExceptions(false); |
| 65 |
CommandLineProcessor::EParseCommandLineReturn parseReturn = My_CLP.parse(argc,argv); |
| 66 |
if (parseReturn == CommandLineProcessor::PARSE_HELP_PRINTED) { |
| 67 |
return(EXIT_SUCCESS); |
| 68 |
} |
| 69 |
|
| 70 |
CommWorld->barrier(); |
| 71 |
RCP<StackedTimer> stackedTimer = rcp(new StackedTimer("Interface Partition of Unity Test")); |
| 72 |
TimeMonitor::setStackedTimer(stackedTimer); |
| 73 |
|
| 74 |
int N=4; |
| 75 |
int color=1; |
| 76 |
if (Dimension == 2) { |
| 77 |
N = (int) (pow(CommWorld->getSize(),1/2.) + 100*numeric_limits<double>::epsilon()); // 1/H |
| 78 |
if (CommWorld->getRank()<N*N) { |
| 79 |
color=0; |
| 80 |
} |
| 81 |
} else if (Dimension == 3) { |
| 82 |
N = (int) (pow(CommWorld->getSize(),1/3.) + 100*numeric_limits<double>::epsilon()); // 1/H |
| 83 |
if (CommWorld->getRank()<N*N*N) { |
| 84 |
color=0; |
| 85 |
} |
| 86 |
} else { |
| 87 |
assert(false); |
| 88 |
} |
| 89 |
|
| 90 |
UnderlyingLib xpetraLib = UseTpetra; |
| 91 |
if (useepetra) { |
| 92 |
xpetraLib = UseEpetra; |
| 93 |
} else { |
| 94 |
xpetraLib = UseTpetra; |
| 95 |
} |
| 96 |
|
| 97 |
RCP<const Comm<int> > comm = CommWorld->split(color,CommWorld->getRank()); |
| 98 |
|
| 99 |
if (color==0) { |
| 100 |
|
| 101 |
comm->barrier(); if (comm->getRank()==0) cout << "#############\n# Assembly #\n#############\n" << endl; |
| 102 |
|
| 103 |
ParameterList GaleriList; |
| 104 |
GaleriList.set("nx", GO(N*M)); |
| 105 |
GaleriList.set("ny", GO(N*M)); |
| 106 |
GaleriList.set("nz", GO(N*M)); |
| 107 |
GaleriList.set("mx", GO(N)); |
| 108 |
GaleriList.set("my", GO(N)); |
| 109 |
GaleriList.set("mz", GO(N)); |
| 110 |
|
| 111 |
RCP<const Map<LO,GO,NO> > UniqueMap; |
| 112 |
RCP<MultiVector<SC,LO,GO,NO> > Coordinates; |
| 113 |
RCP<Matrix<SC,LO,GO,NO> > K; |
| 114 |
if (Dimension==2) { |
| 115 |
UniqueMap = Galeri::Xpetra::CreateMap<LO,GO,NO>(xpetraLib,"Cartesian2D",comm,GaleriList); // RCP<FancyOStream> fancy = fancyOStream(rcpFromRef(cout)); nodeMap->describe(*fancy,VERB_EXTREME); |
| 116 |
Coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC,LO,GO,Map<LO,GO,NO>,MultiVector<SC,LO,GO,NO> >("2D",UniqueMap,GaleriList); |
| 117 |
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); |
| 118 |
K = Problem->BuildMatrix(); |
| 119 |
} else if (Dimension==3) { |
| 120 |
UniqueMap = Galeri::Xpetra::CreateMap<LO,GO,NO>(xpetraLib,"Cartesian3D",comm,GaleriList); // RCP<FancyOStream> fancy = fancyOStream(rcpFromRef(cout)); nodeMap->describe(*fancy,VERB_EXTREME); |
| 121 |
Coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC,LO,GO,Map<LO,GO,NO>,MultiVector<SC,LO,GO,NO> >("3D",UniqueMap,GaleriList); |
| 122 |
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); |
| 123 |
K = Problem->BuildMatrix(); |
| 124 |
} |
| 125 |
|
| 126 |
comm->barrier(); if (comm->getRank()==0) cout << "#############\n# Constructing Repeated Map #\n#############\n" << endl; |
| 127 |
RCP<const Map<LO,GO,NO> > RepeatedMap = BuildRepeatedMap<LO,GO,NO>(K->getCrsGraph()); |
| 128 |
|
| 129 |
RCP<const Map<LO,GO,NO> > RepeatedNodesMap; |
| 130 |
ArrayRCP<RCP<const Map<LO,GO,NO> > > RepeatedDofMaps; |
| 131 |
BuildDofMaps(RepeatedMap,1,NodeWise,RepeatedNodesMap,RepeatedDofMaps); |
| 132 |
|
| 133 |
comm->barrier(); if (comm->getRank()==0) cout << "#############\n# Constructing Interface Partition of Unity #\n#############\n" << endl; |
| 134 |
RCP<const Comm<int> > SerialComm = createSerialComm<int>(); |
| 135 |
|
| 136 |
RCP<ParameterList> parameterList = getParametersFromXmlFile("ParametersIPOU.xml"); |
| 137 |
RCP<InterfacePartitionOfUnity<SC,LO,GO,NO> > IPOU(new GDSWInterfacePartitionOfUnity<SC,LO,GO,NO>(RepeatedMap->getComm(),SerialComm,Dimension,1,RepeatedNodesMap,RepeatedDofMaps,sublist(parameterList,"GDSW"),All,UN(1))); |
| 138 |
IPOU->sortInterface(K); |
| 139 |
IPOU->computePartitionOfUnity(); |
| 140 |
|
| 141 |
comm->barrier(); if (comm->getRank()==0) cout << "\n#############\n# Finished! #\n#############" << endl; |
| 142 |
} |
| 143 |
|
| 144 |
CommWorld->barrier(); |
| 145 |
stackedTimer->stop("Interface Partition of Unity Test"); |
| 146 |
StackedTimer::OutputOptions options; |
| 147 |
options.output_fraction = options.output_histogram = options.output_minmax = true; |
| 148 |
stackedTimer->report(*out,CommWorld,options); |
| 149 |
|
| 150 |
return(EXIT_SUCCESS); |
| 151 |
} |