| 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 |
#ifdef HAVE_XPETRA_TPETRA |
| 28 |
#include "Xpetra_TpetraCrsMatrix.hpp" |
| 29 |
#endif |
| 30 |
#ifdef HAVE_XPETRA_EPETRA |
| 31 |
#include "Xpetra_EpetraCrsMatrix.hpp" |
| 32 |
#endif |
| 33 |
|
| 34 |
// Epetra |
| 35 |
#ifdef HAVE_MPI |
| 36 |
#include "Epetra_MpiComm.h" |
| 37 |
#include "mpi.h" |
| 38 |
#else |
| 39 |
#include "Epetra_SerialComm.h" |
| 40 |
#endif |
| 41 |
#include "Epetra_Map.h" |
| 42 |
#include "Epetra_Vector.h" |
| 43 |
#include "Epetra_CrsMatrix.h" |
| 44 |
#include "Epetra_LinearProblem.h" |
| 45 |
|
| 46 |
// MueLu |
| 47 |
#include <MueLu.hpp> |
| 48 |
#include <MueLu_TpetraOperator.hpp> |
| 49 |
#include <MueLu_CreateTpetraPreconditioner.hpp> |
| 50 |
#include <MueLu_Utilities.hpp> |
| 51 |
|
| 52 |
// =========== // |
| 53 |
// main driver // |
| 54 |
// =========== // |
| 55 |
|
| 56 |
int main(int argc, char* argv[]) { |
| 57 |
typedef double scalar_type; |
| 58 |
typedef int local_ordinal_type; |
| 59 |
typedef int global_ordinal_type; |
| 60 |
typedef scalar_type Scalar; |
| 61 |
typedef local_ordinal_type LocalOrdinal; |
| 62 |
typedef global_ordinal_type GlobalOrdinal; |
| 63 |
typedef Tpetra::KokkosClassic::DefaultNode::DefaultNodeType Node; |
| 64 |
|
| 65 |
typedef Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> Matrix; |
| 66 |
typedef Xpetra::MatrixSplitting<Scalar, LocalOrdinal, GlobalOrdinal, Node> MatrixSplitting; |
| 67 |
typedef Xpetra::CrsMatrixWrap<Scalar, LocalOrdinal, GlobalOrdinal, Xpetra::EpetraNode> EpCrsMatrix; |
| 68 |
|
| 69 |
TEUCHOS_TEST_FOR_EXCEPT_MSG(argc < 2, "\nInvalid name for input matrix\n"); |
| 70 |
|
| 71 |
int numGlobalElements = 1; |
| 72 |
|
| 73 |
Teuchos::RCP<const Teuchos::Comm<int> > comm = Teuchos::DefaultComm<int>::getComm(); |
| 74 |
|
| 75 |
// Create Xpetra map |
| 76 |
Teuchos::RCP<const Xpetra::Map<int, GlobalOrdinal, Xpetra::EpetraNode> > xpetraMap; |
| 77 |
xpetraMap = Xpetra::MapFactory<int, GlobalOrdinal, Xpetra::EpetraNode>::Build(Xpetra::UseEpetra, numGlobalElements, 0, comm); |
| 78 |
|
| 79 |
// Import matrix from an .mtx file into an Xpetra wrapper for an Epetra matrix |
| 80 |
Teuchos::RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > xpetraMatrix = Xpetra::IO<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Read(argv[1], Xpetra::UseEpetra, comm); |
| 81 |
// Export matrix from an Xpetra wrapper into an .mtx file |
| 82 |
Xpetra::IO<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Write("A_write.mtx", *xpetraMatrix); |
| 83 |
|
| 84 |
Teuchos::RCP<MatrixSplitting> xpetraMatrixSplitting; |
| 85 |
|
| 86 |
Teuchos::ParameterList xmlParams; |
| 87 |
Teuchos::RCP<MueLu::Hierarchy<Scalar, LocalOrdinal, GlobalOrdinal, Node> > Hierarchy = MueLu::CreateXpetraPreconditioner((Teuchos::RCP<Matrix>)xpetraMatrixSplitting, xmlParams); |
| 88 |
|
| 89 |
#ifdef HAVE_MPI |
| 90 |
MPI_Finalize(); |
| 91 |
#endif |
| 92 |
|
| 93 |
return (EXIT_SUCCESS); |
| 94 |
} |