| 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 |
#include <iostream> |
| 11 |
|
| 12 |
// Teuchos |
| 13 |
#include <Teuchos_RCP.hpp> |
| 14 |
#include <Teuchos_DefaultComm.hpp> |
| 15 |
#include "Teuchos_Assert.hpp" |
| 16 |
#include "Teuchos_LocalTestingHelpers.hpp" |
| 17 |
#include <Teuchos_StandardCatchMacros.hpp> |
| 18 |
#include "Teuchos_ParameterList.hpp" |
| 19 |
|
| 20 |
// Xpetra |
| 21 |
#include "Xpetra_Map.hpp" |
| 22 |
#include "Xpetra_MapFactory.hpp" |
| 23 |
#include "Xpetra_Matrix.hpp" |
| 24 |
#include "Xpetra_CrsMatrixWrap.hpp" |
| 25 |
#include "Xpetra_IO.hpp" |
| 26 |
#include "Xpetra_MatrixSplitting.hpp" |
| 27 |
#include "Xpetra_RegionAMG_def.hpp" |
| 28 |
#include "Xpetra_RegionHandler_def.hpp" |
| 29 |
#ifdef HAVE_XPETRA_TPETRA |
| 30 |
#include "Xpetra_TpetraCrsMatrix.hpp" |
| 31 |
#endif |
| 32 |
#ifdef HAVE_XPETRA_EPETRA |
| 33 |
#include "Xpetra_EpetraCrsMatrix.hpp" |
| 34 |
#endif |
| 35 |
|
| 36 |
// Epetra |
| 37 |
#ifdef HAVE_MPI |
| 38 |
#include "Epetra_MpiComm.h" |
| 39 |
#include "mpi.h" |
| 40 |
#else |
| 41 |
#include "Epetra_SerialComm.h" |
| 42 |
#endif |
| 43 |
#include "Epetra_Map.h" |
| 44 |
#include "Epetra_Vector.h" |
| 45 |
#include "Epetra_CrsMatrix.h" |
| 46 |
#include "Epetra_LinearProblem.h" |
| 47 |
|
| 48 |
// =========== // |
| 49 |
// main driver // |
| 50 |
// =========== // |
| 51 |
|
| 52 |
int main(int argc, char* argv[]) { |
| 53 |
typedef double scalar_type; |
| 54 |
typedef int local_ordinal_type; |
| 55 |
typedef int global_ordinal_type; |
| 56 |
typedef scalar_type Scalar; |
| 57 |
typedef local_ordinal_type LocalOrdinal; |
| 58 |
typedef global_ordinal_type GlobalOrdinal; |
| 59 |
typedef Tpetra::KokkosClassic::DefaultNode::DefaultNodeType Node; |
| 60 |
|
| 61 |
typedef Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> multivector_type; |
| 62 |
typedef Xpetra::MatrixSplitting<Scalar, LocalOrdinal, GlobalOrdinal, Node, Xpetra::UseTpetra, false> tpetra_splitting; |
| 63 |
|
| 64 |
#ifdef HAVE_MPI |
| 65 |
MPI_Init(&argc, &argv); |
| 66 |
Epetra_MpiComm CommEpetra(MPI_COMM_WORLD); |
| 67 |
#else |
| 68 |
Epetra_SerialComm CommEpetra; |
| 69 |
#endif |
| 70 |
|
| 71 |
// Here we create the linear problem |
| 72 |
// |
| 73 |
// Matrix * LHS = RHS |
| 74 |
// |
| 75 |
// with Matrix arising from a 5-point formula discretization. |
| 76 |
|
| 77 |
TEUCHOS_TEST_FOR_EXCEPT_MSG(argc < 4, "\nInvalid name for input matrix and output file\n"); |
| 78 |
|
| 79 |
Teuchos::RCP<Teuchos::FancyOStream> out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout)); |
| 80 |
|
| 81 |
// process command line arguments |
| 82 |
const char* xmlFileName = argv[1]; |
| 83 |
const char* matrixFileName = argv[2]; |
| 84 |
const char* mappingFileName = argv[3]; |
| 85 |
|
| 86 |
Teuchos::ParameterList xmlParams; |
| 87 |
Teuchos::ParameterList mueluParams; |
| 88 |
Teuchos::updateParametersFromXmlFile(argv[1], Teuchos::inoutArg(mueluParams)); |
| 89 |
|
| 90 |
Teuchos::RCP<const Teuchos::Comm<int> > comm = Teuchos::DefaultComm<int>::getComm(); |
| 91 |
if (CommEpetra.MyPID() == 0) |
| 92 |
std::cout << "Number of processors: " << CommEpetra.NumProc() << std::endl; |
| 93 |
|
| 94 |
// SplittingDriver |
| 95 |
/*Xpetra::SplittingDriver<Scalar, LocalOrdinal, GlobalOrdinal, Node> driver("node.txt", comm); |
| 96 |
Teuchos::Array<GlobalOrdinal> elementlist = driver.GetGlobalRowMap(); |
| 97 |
driver.printInactive(); |
| 98 |
Xpetra::MatrixSplitting<Scalar,LocalOrdinal,GlobalOrdinal,Node,Xpetra::UseTpetra> xpetraWrapper( argv[1], argv[2], comm ); |
| 99 |
std::string output_file="A_write.mtx"; |
| 100 |
xpetraWrapper.writeGlobalMatrix(); |
| 101 |
xpetraWrapper.writeRegionMatrices();*/ |
| 102 |
|
| 103 |
// Teuchos::RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > A; |
| 104 |
// A = Xpetra::IO<Scalar,LocalOrdinal,GlobalOrdinal,Node>::Read(argv[2], Xpetra::UseTpetra, comm); |
| 105 |
|
| 106 |
// Create the RegionHandler to deal with mappings of nodes to regions etc. |
| 107 |
Teuchos::RCP<Xpetra::RegionHandler<Scalar, LocalOrdinal, GlobalOrdinal, Node> > regionHandler = Teuchos::rcp(new Xpetra::RegionHandler<Scalar, LocalOrdinal, GlobalOrdinal, Node>(mappingFileName, comm)); |
| 108 |
Teuchos::Array<GlobalOrdinal> elementlist = regionHandler->GetGlobalRowMap(); |
| 109 |
std::size_t num_total_elements = regionHandler->GetNumGlobalElements(); |
| 110 |
std::size_t num_total_regions = regionHandler->GetNumTotalRegions(); |
| 111 |
|
| 112 |
// Read and split the matrix |
| 113 |
Teuchos::RCP<tpetra_splitting> matrixSplitting = Teuchos::rcp(new tpetra_splitting(matrixFileName, regionHandler, comm)); |
| 114 |
|
| 115 |
// Create region-wise AMG hierarchy |
| 116 |
int max_num_levels = 4; |
| 117 |
int coarsening_factor = 3; |
| 118 |
Xpetra::RegionAMG<Scalar, LocalOrdinal, GlobalOrdinal, Node> preconditioner(matrixSplitting, regionHandler, comm, mueluParams, max_num_levels, coarsening_factor); |
| 119 |
|
| 120 |
// // Setup vectors for test problem |
| 121 |
// Teuchos::RCP<multivector_type> X = Xpetra::MultiVectorFactory< Scalar, LocalOrdinal, GlobalOrdinal, Node >::Build(preconditioner.getDomainMap(), 1) ; |
| 122 |
// Teuchos::RCP<multivector_type> Y = Xpetra::MultiVectorFactory< Scalar, LocalOrdinal, GlobalOrdinal, Node >::Build(preconditioner.getRangeMap(), 1) ; |
| 123 |
// X->randomize(); |
| 124 |
// Y->putScalar((scalar_type) 0.0); |
| 125 |
// |
| 126 |
// // Apply the preconditioner |
| 127 |
// preconditioner.apply(*X,*Y); |
| 128 |
// |
| 129 |
// // Output result to screen |
| 130 |
// Y->describe(*out, Teuchos::VERB_EXTREME); |
| 131 |
|
| 132 |
#ifdef HAVE_MPI |
| 133 |
MPI_Finalize(); |
| 134 |
#endif |
| 135 |
|
| 136 |
return (EXIT_SUCCESS); |
| 137 |
} |