| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// MueLu: A package for multigrid based preconditioning |
| 4 |
// |
| 5 |
// Copyright 2012 NTESS and the MueLu contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
|
| 10 |
// |
| 11 |
// To compile and run this example, Trilinos must be configured with |
| 12 |
// Tpetra, Amesos2, MueLu, Ifpack2, and Belos. |
| 13 |
// |
| 14 |
// This example will only work with Tpetra, not Epetra. |
| 15 |
// |
| 16 |
// Commonly used options are |
| 17 |
// --matrixType |
| 18 |
// --nx |
| 19 |
// --ny |
| 20 |
// --xmlFile |
| 21 |
// |
| 22 |
// "./MueLu_Repartition_ADR.exe --help" shows all supported command line options. |
| 23 |
// |
| 24 |
#include <iostream> |
| 25 |
#include <cmath> |
| 26 |
|
| 27 |
extern clock_t Timers_Max[4]; |
| 28 |
|
| 29 |
// Belos provides Krylov solvers |
| 30 |
#include <BelosConfigDefs.hpp> |
| 31 |
#include <BelosLinearProblem.hpp> |
| 32 |
#include <BelosBlockCGSolMgr.hpp> |
| 33 |
#include <BelosPseudoBlockCGSolMgr.hpp> |
| 34 |
#include <BelosBlockGmresSolMgr.hpp> |
| 35 |
#include <BelosBiCGStabSolMgr.hpp> |
| 36 |
#include <BelosTpetraAdapter.hpp> |
| 37 |
|
| 38 |
// Galeri |
| 39 |
#include <Galeri_XpetraParameters.hpp> |
| 40 |
#include <Galeri_XpetraProblemFactory.hpp> |
| 41 |
#include <Galeri_XpetraUtils.hpp> |
| 42 |
#include <Galeri_XpetraMaps.hpp> |
| 43 |
|
| 44 |
// ADR subdirectory |
| 45 |
#include "CreateADRMatrix.hpp" |
| 46 |
#include <CreateADRMatrix.hpp> |
| 47 |
#include <ADRProblemFactory.hpp> |
| 48 |
#include <ADR_XpetraParameters.hpp> |
| 49 |
|
| 50 |
#include "Smooth_Prolongation.cpp" |
| 51 |
//#include "neighbours.hpp" |
| 52 |
#include "BAP.hpp" |
| 53 |
#include "CreateBrickMap.hpp" |
| 54 |
|
| 55 |
int main(int argc, char* argv[]) { |
| 56 |
// Define default types |
| 57 |
typedef double scalar_type; |
| 58 |
typedef int local_ordinal_type; |
| 59 |
typedef int global_ordinal_type; |
| 60 |
typedef Tpetra::KokkosClassic::DefaultNode::DefaultNodeType node_type; |
| 61 |
|
| 62 |
// Convenient typedef's |
| 63 |
typedef Tpetra::Operator<scalar_type, local_ordinal_type, global_ordinal_type, node_type> operator_type; |
| 64 |
typedef Tpetra::CrsMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> crs_matrix_type; |
| 65 |
typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> row_matrix_type; |
| 66 |
typedef Tpetra::Vector<scalar_type, local_ordinal_type, global_ordinal_type, node_type> vector_type; |
| 67 |
typedef Tpetra::MultiVector<scalar_type, local_ordinal_type, global_ordinal_type, node_type> multivector_type; |
| 68 |
typedef Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> driver_map_type; |
| 69 |
|
| 70 |
typedef MueLu::TpetraOperator<scalar_type, local_ordinal_type, global_ordinal_type, node_type> muelu_tpetra_operator_type; |
| 71 |
typedef MueLu::Utilities<scalar_type, local_ordinal_type, global_ordinal_type, node_type> MueLuUtilities; |
| 72 |
|
| 73 |
typedef Belos::LinearProblem<scalar_type, multivector_type, operator_type> linear_problem_type; |
| 74 |
typedef Belos::SolverManager<scalar_type, multivector_type, operator_type> belos_solver_manager_type; |
| 75 |
typedef Belos::PseudoBlockCGSolMgr<scalar_type, multivector_type, operator_type> belos_pseudocg_manager_type; |
| 76 |
typedef Belos::BlockGmresSolMgr<scalar_type, multivector_type, operator_type> belos_gmres_manager_type; |
| 77 |
typedef Belos::BiCGStabSolMgr<scalar_type, multivector_type, operator_type> belos_bicgstab_manager_type; |
| 78 |
|
| 79 |
typedef Ifpack2::Preconditioner<scalar_type, local_ordinal_type, global_ordinal_type, node_type> precond_type; |
| 80 |
|
| 81 |
// MueLu_UseShortNames.hpp wants these typedefs. |
| 82 |
typedef scalar_type Scalar; |
| 83 |
typedef local_ordinal_type LocalOrdinal; |
| 84 |
typedef global_ordinal_type GlobalOrdinal; |
| 85 |
typedef node_type Node; |
| 86 |
#include <MueLu_UseShortNames.hpp> |
| 87 |
|
| 88 |
typedef Galeri::Xpetra::Problem<Map, CrsMatrixWrap, MultiVector> GaleriXpetraProblem; |
| 89 |
typedef ADR::Xpetra::Problem<Map, CrsMatrixWrap, MultiVector> ADRXpetraProblem; |
| 90 |
|
| 91 |
using Teuchos::RCP; // reference count pointers |
| 92 |
using Teuchos::rcp; // reference count pointers |
| 93 |
|
| 94 |
// |
| 95 |
// MPI initialization using Teuchos |
| 96 |
// |
| 97 |
|
| 98 |
Teuchos::GlobalMPISession mpiSession(&argc, &argv, NULL); |
| 99 |
RCP<const Teuchos::Comm<int>> comm = Teuchos::DefaultComm<int>::getComm(); |
| 100 |
int mypid = comm->getRank(); |
| 101 |
/* |
| 102 |
int subCommRank[3]={0,1,2}; |
| 103 |
Teuchos::ArrayView<int> arraySubCommRank(subCommRank, 3); |
| 104 |
auto subComm = comm->createSubcommunicator(arraySubCommRank); |
| 105 |
*/ |
| 106 |
Teuchos::CommandLineProcessor clp(false); |
| 107 |
|
| 108 |
global_ordinal_type maxIts = 10000; |
| 109 |
scalar_type tol = 1e-10; |
| 110 |
std::string solverOptionsFile = "final_parser.xml"; |
| 111 |
std::string krylovSolverType = "bicgstab"; |
| 112 |
|
| 113 |
clp.setOption("xmlFile", &solverOptionsFile, "XML file containing MueLu solver parameters"); |
| 114 |
clp.setOption("maxits", &maxIts, "maximum number of Krylov iterations"); |
| 115 |
clp.setOption("tol", &tol, "tolerance for Krylov solver"); |
| 116 |
clp.setOption("krylovType", &krylovSolverType, "cg or gmres solver"); |
| 117 |
|
| 118 |
switch (clp.parse(argc, argv)) { |
| 119 |
case Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED: return EXIT_SUCCESS; |
| 120 |
case Teuchos::CommandLineProcessor::PARSE_ERROR: |
| 121 |
case Teuchos::CommandLineProcessor::PARSE_UNRECOGNIZED_OPTION: return EXIT_FAILURE; |
| 122 |
case Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL: break; |
| 123 |
} |
| 124 |
|
| 125 |
Teuchos::ParameterList xmlParams; |
| 126 |
Teuchos::ParameterList mueluParams; |
| 127 |
Teuchos::ParameterList problemParams; |
| 128 |
Teuchos::updateParametersFromXmlFile(solverOptionsFile, Teuchos::inoutArg(xmlParams)); |
| 129 |
mueluParams = xmlParams.sublist(static_cast<const std::string>("MueLu")); |
| 130 |
problemParams = xmlParams.sublist(static_cast<const std::string>("Problem")); |
| 131 |
|
| 132 |
// Problem definition |
| 133 |
std::string problem_type = problemParams.get<std::string>(static_cast<const std::string>("problem type")); |
| 134 |
|
| 135 |
// Parameters |
| 136 |
|
| 137 |
Scalar Lx = problemParams.get<scalar_type>(static_cast<const std::string>("domain size in x-direction")); |
| 138 |
Scalar Ly = problemParams.get<scalar_type>(static_cast<const std::string>("domain size in y-direction")); |
| 139 |
Scalar Lz = problemParams.get<scalar_type>(static_cast<const std::string>("domain size in z-direction")); |
| 140 |
|
| 141 |
global_ordinal_type nx = problemParams.get<int>(static_cast<const std::string>("nodes in x-direction")); |
| 142 |
global_ordinal_type ny = problemParams.get<int>(static_cast<const std::string>("nodes in y-direction")); |
| 143 |
global_ordinal_type nz = problemParams.get<int>(static_cast<const std::string>("nodes in z-direction")); |
| 144 |
|
| 145 |
MueLu::DomainPartitioning domain; |
| 146 |
|
| 147 |
int keep_boundary = 0; |
| 148 |
Scalar stretchx = (Scalar)Lx / nx; |
| 149 |
Scalar stretchy = (Scalar)Ly / ny; |
| 150 |
Scalar stretchz = (Scalar)Lz / nz; |
| 151 |
|
| 152 |
ADR::Xpetra::Parameters<GO> matrixParameters(clp, nx, ny, nz, problem_type, keep_boundary, stretchx, stretchy, stretchz); // manage parameters of the test case |
| 153 |
Xpetra::Parameters xpetraParameters(clp); // manage parameters of xpetra |
| 154 |
|
| 155 |
if (xpetraParameters.GetLib() == Xpetra::UseEpetra) { |
| 156 |
throw std::invalid_argument("This example only supports Tpetra."); |
| 157 |
} |
| 158 |
|
| 159 |
// |
| 160 |
// Construct the problem |
| 161 |
// |
| 162 |
|
| 163 |
global_ordinal_type indexBase = 0; |
| 164 |
RCP<const Map> xpetraMap; |
| 165 |
std::vector<global_ordinal_type> ind; |
| 166 |
|
| 167 |
// BRICK SIZE |
| 168 |
int brick_sizex = mueluParams.get<int>(static_cast<const std::string>("aggregation: brick x size")); |
| 169 |
int brick_sizey = mueluParams.get<int>(static_cast<const std::string>("aggregation: brick y size")); |
| 170 |
int brick_sizez = mueluParams.get<int>(static_cast<const std::string>("aggregation: brick z size")); |
| 171 |
|
| 172 |
// Creation of the map where processor 0 gets nothing at the fine level |
| 173 |
if (comm->getSize() > 1) { |
| 174 |
if (problem_type == "ADR1D") |
| 175 |
createBrickMap1D(matrixParameters.GetNumGlobalElements(), ind, comm); |
| 176 |
|
| 177 |
else if (problem_type == "ADR2D") |
| 178 |
createBrickMap2D(nx, brick_sizex, brick_sizey, ind, comm); |
| 179 |
|
| 180 |
else if (problem_type == "ADR3D") |
| 181 |
createBrickMap3D(nx, ny, brick_sizex, brick_sizey, brick_sizez, ind, comm); |
| 182 |
|
| 183 |
ind.shrink_to_fit(); |
| 184 |
|
| 185 |
Teuchos::ArrayView<const global_ordinal_type> elementList(ind); |
| 186 |
xpetraMap = MapFactory::Build(Xpetra::UseTpetra, matrixParameters.GetNumGlobalElements(), elementList, indexBase, comm); |
| 187 |
} else if (comm->getSize() == 1) { |
| 188 |
xpetraMap = MapFactory::Build(Xpetra::UseTpetra, matrixParameters.GetNumGlobalElements(), indexBase, comm); |
| 189 |
} |
| 190 |
|
| 191 |
RCP<MultiVector> coordinates; |
| 192 |
|
| 193 |
if (problem_type == "ADR1D") |
| 194 |
coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<scalar_type, local_ordinal_type, global_ordinal_type, Map, MultiVector>("1D", xpetraMap, matrixParameters.GetParameterList()); |
| 195 |
else if (problem_type == "ADR2D") |
| 196 |
coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<scalar_type, local_ordinal_type, global_ordinal_type, Map, MultiVector>("2D", xpetraMap, matrixParameters.GetParameterList()); |
| 197 |
else if (problem_type == "ADR3D") |
| 198 |
coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<scalar_type, local_ordinal_type, global_ordinal_type, Map, MultiVector>("3D", xpetraMap, matrixParameters.GetParameterList()); |
| 199 |
|
| 200 |
RCP<ADRXpetraProblem> Pr = ADR::Xpetra::BuildProblem<scalar_type, local_ordinal_type, global_ordinal_type, Map, CrsMatrixWrap, MultiVector>(matrixParameters.GetMatrixType(), xpetraMap, matrixParameters.GetParameterList()); |
| 201 |
RCP<Matrix> xpetraA = Pr->BuildMatrix(); |
| 202 |
|
| 203 |
RCP<crs_matrix_type> A = toTpetra(xpetraA); |
| 204 |
RCP<const driver_map_type> map = toTpetra(xpetraMap); |
| 205 |
|
| 206 |
// =================================================== |
| 207 |
// Domain Decomposition Preconditioner |
| 208 |
// =================================== |
| 209 |
|
| 210 |
// Creation of the MueLu list for the DD preconditioner |
| 211 |
RCP<Teuchos::ParameterList> dd_list = rcp(new Teuchos::ParameterList()); |
| 212 |
dd_list->setName("MueLu"); |
| 213 |
dd_list->set("verbosity", "low"); |
| 214 |
dd_list->set("number of equations", 1); |
| 215 |
dd_list->set("max levels", 1); |
| 216 |
dd_list->set("coarse: type", "SCHWARZ"); // FOR A ONE LEVEL PRECONDITIONER THE COARSE LEVEL IS INTERPRETED AS SMOOTHING LEVEL |
| 217 |
|
| 218 |
Teuchos::ParameterList& dd_smooth_sublist = dd_list->sublist("coarse: params"); |
| 219 |
dd_smooth_sublist.set("schwarz: overlap level", 0); |
| 220 |
dd_smooth_sublist.set("schwarz: combine mode", "Zero"); |
| 221 |
dd_smooth_sublist.set("subdomain solver name", "RILUK"); |
| 222 |
|
| 223 |
Teuchos::ParameterList& coarse_subdomain_solver = dd_smooth_sublist.sublist("subdomain solver parameters"); |
| 224 |
coarse_subdomain_solver.set("fact: iluk level-of-fill", 3); |
| 225 |
coarse_subdomain_solver.set("fact: absolute thresh/old", 0.); |
| 226 |
coarse_subdomain_solver.set("fact: relative threshold", 1.); |
| 227 |
coarse_subdomain_solver.set("fact: relax value", 0.); |
| 228 |
|
| 229 |
RCP<muelu_tpetra_operator_type> B_DD = MueLu::CreateTpetraPreconditioner((RCP<operator_type>)A, *dd_list); |
| 230 |
|
| 231 |
// Construct a multigrid preconditioner |
| 232 |
RCP<muelu_tpetra_operator_type> M; |
| 233 |
|
| 234 |
// Manual set up of the prolongation and restriction |
| 235 |
MueLu::ParameterListInterpreter<scalar_type> mueLuFactory(mueluParams); |
| 236 |
RCP<MueLu::Hierarchy<scalar_type>> H = mueLuFactory.CreateHierarchy(); |
| 237 |
H->setVerbLevel(Teuchos::VERB_HIGH); |
| 238 |
|
| 239 |
H->GetLevel(0)->Set("A", xpetraA); |
| 240 |
H->GetLevel(0)->Set("Coordinates", coordinates); |
| 241 |
|
| 242 |
// Multigrid setup phase |
| 243 |
mueLuFactory.SetupHierarchy(*H); |
| 244 |
|
| 245 |
RCP<Level> L = H->GetLevel(1); |
| 246 |
|
| 247 |
RCP<Xpetra::Matrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type>> prolong, restr; |
| 248 |
|
| 249 |
if (L->IsAvailable("P")) |
| 250 |
prolong = L->template Get<RCP<Xpetra::Matrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type>>>("P"); |
| 251 |
|
| 252 |
if (L->IsAvailable("R")) |
| 253 |
restr = L->template Get<RCP<Xpetra::Matrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type>>>("R"); |
| 254 |
|
| 255 |
RCP<crs_matrix_type> tpetra_prolong = toTpetra(prolong); |
| 256 |
RCP<crs_matrix_type> tpetra_restr = toTpetra(restr); |
| 257 |
|
| 258 |
#include <Teuchos_TimeMonitor.hpp> |
| 259 |
RCP<Teuchos::Time> PbarSetUp = Teuchos::TimeMonitor::getNewCounter("Pbar: SetUp"); |
| 260 |
PbarSetUp->start(); |
| 261 |
RCP<Matrix> mueluPbar; |
| 262 |
|
| 263 |
// We have to transform P into a condensed multivector |
| 264 |
RCP<multivector_type> identity_shrunk = rcp(new multivector_type(tpetra_prolong->getDomainMap(), std::pow(3, coordinates->getNumVectors()))); |
| 265 |
Teuchos::ArrayView<const global_ordinal_type> myIdentityGlobalElements = tpetra_prolong->getDomainMap()->getLocalElementList(); |
| 266 |
typedef typename Teuchos::ArrayView<const global_ordinal_type>::const_iterator iter_type; |
| 267 |
|
| 268 |
int number_runs = 1; |
| 269 |
|
| 270 |
for (int trial = 1; trial <= number_runs; ++trial) { |
| 271 |
if (1 == coordinates->getNumVectors()) { |
| 272 |
for (int j = 0; j < 3; ++j) { |
| 273 |
int color = j; |
| 274 |
|
| 275 |
Teuchos::ArrayRCP<scalar_type> localMV = identity_shrunk->getDataNonConst(color); |
| 276 |
|
| 277 |
for (iter_type it = myIdentityGlobalElements.begin(); it != myIdentityGlobalElements.end(); ++it) { |
| 278 |
const local_ordinal_type i_local = *it; |
| 279 |
const local_ordinal_type aux = identity_shrunk->getMap()->getLocalElement(i_local); |
| 280 |
int local_color = (i_local) % 3; |
| 281 |
|
| 282 |
if (local_color == color) |
| 283 |
localMV[aux] = 1.0; |
| 284 |
} |
| 285 |
} |
| 286 |
} else if (2 == coordinates->getNumVectors()) { |
| 287 |
for (int j = 0; j < 9; ++j) { |
| 288 |
int color = j; |
| 289 |
|
| 290 |
Teuchos::ArrayRCP<scalar_type> localMV = identity_shrunk->getDataNonConst(color); |
| 291 |
|
| 292 |
for (iter_type it = myIdentityGlobalElements.begin(); it != myIdentityGlobalElements.end(); ++it) { |
| 293 |
const local_ordinal_type i_local = *it; |
| 294 |
const local_ordinal_type aux = identity_shrunk->getMap()->getLocalElement(i_local); |
| 295 |
const local_ordinal_type local_color = coloring2D(i_local + 1, std::sqrt(tpetra_prolong->getGlobalNumCols())); |
| 296 |
|
| 297 |
if (local_color == color) { |
| 298 |
localMV[aux] = 1.0; |
| 299 |
// std::cout<<"ID: "<<i_local+1<<" -- color: "<<color+1<<std::endl; |
| 300 |
} |
| 301 |
} |
| 302 |
} |
| 303 |
} else if (3 == coordinates->getNumVectors()) { |
| 304 |
// const local_ordinal_type local_color = coloring3D( mypid, std::cbrt( tpetra_prolong->getGlobalNumCols() ), std::cbrt( tpetra_prolong->getGlobalNumCols() ) ); |
| 305 |
|
| 306 |
for (int j = 0; j < 27; ++j) { |
| 307 |
int color = j; |
| 308 |
|
| 309 |
Teuchos::ArrayRCP<scalar_type> localMV = identity_shrunk->getDataNonConst(color); |
| 310 |
|
| 311 |
for (iter_type it = myIdentityGlobalElements.begin(); it != myIdentityGlobalElements.end(); ++it) { |
| 312 |
const local_ordinal_type i_local = *it; |
| 313 |
const local_ordinal_type aux = identity_shrunk->getMap()->getLocalElement(i_local); |
| 314 |
const local_ordinal_type local_color = coloring3D(i_local + 1, std::cbrt(tpetra_prolong->getGlobalNumCols()), std::cbrt(tpetra_prolong->getGlobalNumCols())); |
| 315 |
|
| 316 |
if (local_color == color) { |
| 317 |
// std::cout<<"i_local: "<<i_local+1<<" has color: "<<color<<std::endl; |
| 318 |
// sleep(1); |
| 319 |
localMV[aux] = 1.0; |
| 320 |
} |
| 321 |
} |
| 322 |
} |
| 323 |
} |
| 324 |
|
| 325 |
RCP<multivector_type> P_shrunk = rcp(new multivector_type(tpetra_prolong->getRangeMap(), std::pow(3, coordinates->getNumVectors()))); |
| 326 |
tpetra_prolong->apply(*identity_shrunk, *P_shrunk); |
| 327 |
RCP<multivector_type> AP_shrunk = rcp(new multivector_type(A->getRangeMap(), std::pow(3, coordinates->getNumVectors()))); |
| 328 |
A->apply(*P_shrunk, *AP_shrunk); |
| 329 |
|
| 330 |
//======================================================================================================== |
| 331 |
|
| 332 |
// CREATION OF BAP |
| 333 |
|
| 334 |
RCP<multivector_type> BAP_shrunk = rcp(new multivector_type(B_DD->getRangeMap(), AP_shrunk->getNumVectors())); |
| 335 |
B_DD->apply(*AP_shrunk, *BAP_shrunk, Teuchos::NO_TRANS, Teuchos::ScalarTraits<scalar_type>::one(), Teuchos::ScalarTraits<scalar_type>::zero()); |
| 336 |
|
| 337 |
// Columns Map for BAP |
| 338 |
std::vector<int> indBAPcolMap; |
| 339 |
if (1 == coordinates->getNumVectors()) |
| 340 |
neighbours1D(tpetra_prolong, indBAPcolMap, comm); |
| 341 |
else if (2 == coordinates->getNumVectors()) |
| 342 |
neighbours2D(tpetra_prolong, indBAPcolMap, comm, std::sqrt(tpetra_prolong->getGlobalNumCols())); |
| 343 |
else if (3 == coordinates->getNumVectors()) |
| 344 |
neighbours3D(tpetra_prolong, indBAPcolMap, comm, std::cbrt(tpetra_prolong->getGlobalNumCols()), std::cbrt(tpetra_prolong->getGlobalNumCols())); |
| 345 |
|
| 346 |
Teuchos::ArrayView<const global_ordinal_type> elementListBAP(indBAPcolMap); |
| 347 |
Teuchos::RCP<Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type>> BAPcolMap = rcp(new Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type>(static_cast<size_t>(tpetra_prolong->getGlobalNumCols()), elementListBAP, indexBase, comm)); |
| 348 |
|
| 349 |
RCP<crs_matrix_type> BAP = rcp(new crs_matrix_type(tpetra_prolong->getRowMap(), BAPcolMap, tpetra_prolong->getGlobalNumCols())); |
| 350 |
Teuchos::ArrayView<const global_ordinal_type> myLocalElements = BAP->getRowMap()->getLocalElementList(); |
| 351 |
|
| 352 |
if (1 == coordinates->getNumVectors()) |
| 353 |
BAP1D(BAP, tpetra_prolong, BAP_shrunk, comm); |
| 354 |
else if (2 == coordinates->getNumVectors()) |
| 355 |
BAP2D(BAP, tpetra_prolong, BAP_shrunk, comm, std::sqrt(tpetra_prolong->getGlobalNumCols())); |
| 356 |
else if (3 == coordinates->getNumVectors()) |
| 357 |
BAP3D(BAP, tpetra_prolong, BAP_shrunk, comm, std::cbrt(tpetra_prolong->getGlobalNumCols()), std::cbrt(tpetra_prolong->getGlobalNumCols())); |
| 358 |
|
| 359 |
BAP->fillComplete(tpetra_prolong->getDomainMap(), tpetra_prolong->getRangeMap()); |
| 360 |
|
| 361 |
// Tpetra::MatrixMarket::Writer<crs_matrix_type>::writeSparseFile("BAP.mtx", BAP); |
| 362 |
//============================================================================================================= |
| 363 |
RCP<crs_matrix_type> Pbar = Tpetra::MatrixMatrix::add(1.0, false, *tpetra_prolong, -1.0, false, *BAP); |
| 364 |
mueluPbar = MueLu::TpetraCrs_To_XpetraMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type>(Pbar); |
| 365 |
} |
| 366 |
PbarSetUp->stop(); |
| 367 |
|
| 368 |
H->GetLevel(1)->Set("Pbar", mueluPbar); |
| 369 |
|
| 370 |
H->IsPreconditioner(true); |
| 371 |
|
| 372 |
M = rcp(new muelu_tpetra_operator_type(H)); |
| 373 |
|
| 374 |
RCP<multivector_type> X = rcp(new multivector_type(map, 1)); |
| 375 |
RCP<multivector_type> B = rcp(new multivector_type(map, 1)); |
| 376 |
|
| 377 |
for (int trial = 1; trial <= number_runs; ++trial) { |
| 378 |
X->putScalar((scalar_type)0.0); |
| 379 |
B->randomize(); |
| 380 |
|
| 381 |
// |
| 382 |
// Set up Krylov solver and iterate. |
| 383 |
// |
| 384 |
|
| 385 |
RCP<multivector_type> X_muelu = rcp(new multivector_type(map, 1)); |
| 386 |
RCP<linear_problem_type> Problem_muelu = rcp(new linear_problem_type(A, X_muelu, B)); |
| 387 |
Problem_muelu->setRightPrec(M); |
| 388 |
Problem_muelu->setProblem(); |
| 389 |
|
| 390 |
RCP<Teuchos::ParameterList> belosList = rcp(new Teuchos::ParameterList()); |
| 391 |
belosList->set("Maximum Iterations", maxIts); // Maximum number of iterations allowed |
| 392 |
belosList->set("Convergence Tolerance", tol); // Relative convergence tolerance requested |
| 393 |
// belosList->set("Verbosity", Belos::Errors + Belos::Warnings + Belos::StatusTestDetails); |
| 394 |
belosList->set("Verbosity", Belos::Errors); |
| 395 |
belosList->set("Output Frequency", 1); |
| 396 |
belosList->set("Output Style", Belos::Brief); |
| 397 |
belosList->set("Implicit Residual Scaling", "None"); |
| 398 |
RCP<belos_solver_manager_type> solver; |
| 399 |
if (krylovSolverType == "cg") |
| 400 |
solver = rcp(new belos_pseudocg_manager_type(Problem_muelu, belosList)); |
| 401 |
else if (krylovSolverType == "gmres") |
| 402 |
solver = rcp(new belos_gmres_manager_type(Problem_muelu, belosList)); |
| 403 |
else if (krylovSolverType == "bicgstab") |
| 404 |
solver = rcp(new belos_bicgstab_manager_type(Problem_muelu, belosList)); |
| 405 |
else |
| 406 |
throw std::invalid_argument("bad Krylov solver type"); |
| 407 |
|
| 408 |
solver->solve(); |
| 409 |
int numIterations_muelu = solver->getNumIters(); |
| 410 |
|
| 411 |
Teuchos::Array<typename Teuchos::ScalarTraits<scalar_type>::magnitudeType> normVec_muelu(1); |
| 412 |
multivector_type residual_muelu(B->getMap(), 1); |
| 413 |
A->apply(*X_muelu, residual_muelu); |
| 414 |
residual_muelu.update(1.0, *B, -1.0); |
| 415 |
residual_muelu.norm2(normVec_muelu); |
| 416 |
if (mypid == 0) { |
| 417 |
std::cout << "number of iterations with MueLu preconditioner= " << numIterations_muelu << std::endl; |
| 418 |
std::cout << "||Residual|| = " << normVec_muelu[0] << std::endl; |
| 419 |
} |
| 420 |
} |
| 421 |
|
| 422 |
// Teuchos::TimeMonitor::summarize (); |
| 423 |
|
| 424 |
// Columns Map for BAP |
| 425 |
std::vector<int> indTimerMap; |
| 426 |
if (0 != mypid) |
| 427 |
indTimerMap.emplace_back(mypid - 1); |
| 428 |
|
| 429 |
Teuchos::ArrayView<const global_ordinal_type> elementListTimer(indTimerMap); |
| 430 |
Teuchos::RCP<Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type>> TimerMap = rcp(new Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type>(static_cast<size_t>(comm->getSize()), elementListTimer, indexBase, comm)); |
| 431 |
|
| 432 |
RCP<multivector_type> TimerRestr = rcp(new multivector_type(TimerMap, 1)); |
| 433 |
RCP<multivector_type> TimerProlong = rcp(new multivector_type(TimerMap, 1)); |
| 434 |
RCP<multivector_type> TimerFine = rcp(new multivector_type(TimerMap, 1)); |
| 435 |
RCP<multivector_type> TimerCoarse = rcp(new multivector_type(TimerMap, 1)); |
| 436 |
|
| 437 |
return EXIT_SUCCESS; |
| 438 |
} |