| 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 |
// Teuchos |
| 11 |
#include <Teuchos_StandardCatchMacros.hpp> |
| 12 |
#include <Teuchos_XMLParameterListHelpers.hpp> |
| 13 |
|
| 14 |
#include <MueLu.hpp> |
| 15 |
#include <MueLu_ParameterListInterpreter.hpp> // TODO: move into MueLu.hpp |
| 16 |
#include <MueLu_VisualizationHelpers.hpp> |
| 17 |
|
| 18 |
#include <MueLu_CreateXpetraPreconditioner.hpp> |
| 19 |
|
| 20 |
#ifdef HAVE_MUELU_BELOS |
| 21 |
#include <BelosConfigDefs.hpp> |
| 22 |
#include <BelosLinearProblem.hpp> |
| 23 |
#include <BelosBlockCGSolMgr.hpp> |
| 24 |
#include <BelosPseudoBlockGmresSolMgr.hpp> |
| 25 |
#include <BelosXpetraAdapter.hpp> // => This header defines Belos::XpetraOp |
| 26 |
#include <BelosMueLuAdapter.hpp> // => This header defines Belos::MueLuOp |
| 27 |
#endif |
| 28 |
|
| 29 |
template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node> |
| 30 |
class ExportVTK : public MueLu::VisualizationHelpers<Scalar, LocalOrdinal, GlobalOrdinal, Node> { |
| 31 |
public: |
| 32 |
ExportVTK(){}; |
| 33 |
|
| 34 |
public: |
| 35 |
void writeFile(std::ofstream& fout, Teuchos::RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >& coordinates, Teuchos::RCP<Xpetra::Vector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >& sol) { |
| 36 |
using namespace std; |
| 37 |
typedef MueLu::VisualizationHelpers<Scalar, LocalOrdinal, GlobalOrdinal, Node> VH; |
| 38 |
Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node> > nodeMap = coordinates->getMap(); |
| 39 |
std::vector<LocalOrdinal> vertices; |
| 40 |
std::vector<LocalOrdinal> geomSize; |
| 41 |
LocalOrdinal numFineNodes = Teuchos::as<LocalOrdinal>(coordinates->getLocalLength()); |
| 42 |
|
| 43 |
vertices.reserve(numFineNodes); |
| 44 |
geomSize.reserve(numFineNodes); |
| 45 |
for (LocalOrdinal i = 0; i < numFineNodes; i++) { |
| 46 |
vertices.push_back(i); |
| 47 |
geomSize.push_back(1); |
| 48 |
} |
| 49 |
|
| 50 |
Teuchos::ArrayRCP<const double> xCoords = Teuchos::arcp_reinterpret_cast<const double>(coordinates->getData(0)); |
| 51 |
Teuchos::ArrayRCP<const double> yCoords = Teuchos::arcp_reinterpret_cast<const double>(coordinates->getData(1)); |
| 52 |
Teuchos::ArrayRCP<const double> zCoords = Teuchos::null; |
| 53 |
if (coordinates->getNumVectors() == 3) { |
| 54 |
zCoords = Teuchos::arcp_reinterpret_cast<const double>(coordinates->getData(2)); |
| 55 |
} |
| 56 |
Teuchos::ArrayRCP<const double> solData = Teuchos::arcp_reinterpret_cast<const double>(sol->getData(0)); |
| 57 |
|
| 58 |
std::vector<int> uniqueFine = this->makeUnique(vertices); |
| 59 |
this->writeFileVTKOpening(fout, uniqueFine, geomSize); |
| 60 |
this->writeFileVTKNodes(fout, uniqueFine, nodeMap); |
| 61 |
|
| 62 |
std::string indent = " "; |
| 63 |
fout << " <DataArray type=\"Int32\" Name=\"Processor\" format=\"ascii\">" << std::endl; |
| 64 |
fout << indent; |
| 65 |
int myRank = coordinates->getMap()->getComm()->getRank(); |
| 66 |
for (int i = 0; i < int(uniqueFine.size()); i++) { |
| 67 |
fout << myRank << " "; |
| 68 |
if (i % 20 == 19) |
| 69 |
fout << std::endl |
| 70 |
<< indent; |
| 71 |
} |
| 72 |
fout << std::endl; |
| 73 |
fout << " </DataArray>" << std::endl; |
| 74 |
// solution vector |
| 75 |
fout << " <DataArray type=\"Float64\" Name=\"Solution\" NumberOfComponents=\"3\" format=\"ascii\">" << std::endl; |
| 76 |
fout << indent; |
| 77 |
for (int i = 0; i < int(uniqueFine.size()); i++) { |
| 78 |
size_t numVec = coordinates->getNumVectors(); |
| 79 |
for (int d = 0; d < numVec; d++) |
| 80 |
fout << solData[i * numVec + d] << " "; |
| 81 |
if (i % 3 == 0) |
| 82 |
fout << std::endl |
| 83 |
<< indent; |
| 84 |
} |
| 85 |
fout << std::endl; |
| 86 |
fout << " </DataArray>" << std::endl; |
| 87 |
fout << " </PointData>" << std::endl; // that is annoying |
| 88 |
|
| 89 |
this->writeFileVTKCoordinates(fout, uniqueFine, xCoords, yCoords, zCoords, coordinates->getNumVectors()); |
| 90 |
this->writeFileVTKCells(fout, uniqueFine, vertices, geomSize); |
| 91 |
this->writeFileVTKClosing(fout); |
| 92 |
fout.close(); |
| 93 |
}; |
| 94 |
}; |
| 95 |
|
| 96 |
template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node> |
| 97 |
int main_(Teuchos::CommandLineProcessor& clp, Xpetra::UnderlyingLib lib, int argc, char* argv[]) { |
| 98 |
#include <MueLu_UseShortNames.hpp> |
| 99 |
|
| 100 |
using Teuchos::RCP; |
| 101 |
using Teuchos::rcp; |
| 102 |
using Teuchos::TimeMonitor; |
| 103 |
|
| 104 |
bool success = false; |
| 105 |
bool verbose = true; |
| 106 |
|
| 107 |
try { |
| 108 |
RCP<const Teuchos::Comm<int> > comm = Teuchos::DefaultComm<int>::getComm(); |
| 109 |
|
| 110 |
// ========================================================================= |
| 111 |
// Convenient definitions |
| 112 |
// ========================================================================= |
| 113 |
SC zero = Teuchos::ScalarTraits<SC>::zero(); |
| 114 |
|
| 115 |
// Instead of checking each time for rank, create a rank 0 stream |
| 116 |
RCP<Teuchos::FancyOStream> fancy = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout)); |
| 117 |
Teuchos::FancyOStream& out = *fancy; |
| 118 |
out.setOutputToRootOnly(0); |
| 119 |
|
| 120 |
// ========================================================================= |
| 121 |
// Parameters initialization |
| 122 |
// ========================================================================= |
| 123 |
|
| 124 |
// GO nx = 100, ny = 100, nz = 100; |
| 125 |
// Galeri::Xpetra::Parameters<GO> matrixParameters(clp, nx, ny, nz, "Laplace2D"); // manage parameters of the test case |
| 126 |
Xpetra::Parameters xpetraParameters(clp); // manage parameters of Xpetra |
| 127 |
|
| 128 |
std::string xmlFileName = "driver.xml"; |
| 129 |
clp.setOption("xml", &xmlFileName, "read parameters from a file. Otherwise, this example uses by default 'scalingTest.xml'"); |
| 130 |
|
| 131 |
switch (clp.parse(argc, argv)) { |
| 132 |
case Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED: return EXIT_SUCCESS; break; |
| 133 |
case Teuchos::CommandLineProcessor::PARSE_ERROR: |
| 134 |
case Teuchos::CommandLineProcessor::PARSE_UNRECOGNIZED_OPTION: return EXIT_FAILURE; break; |
| 135 |
case Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL: break; |
| 136 |
} |
| 137 |
|
| 138 |
// ========================================================================= |
| 139 |
// Read in problem |
| 140 |
// ========================================================================= |
| 141 |
RCP<TimeMonitor> globalTimeMonitor = rcp(new TimeMonitor(*TimeMonitor::getNewTimer("MatrixRead: S - Global Time"))), tm; |
| 142 |
|
| 143 |
GlobalOrdinal nGlobalNodes = 0; |
| 144 |
if (comm->getRank() == 0) { |
| 145 |
std::ifstream data_file; |
| 146 |
data_file.open("xxx.mm"); |
| 147 |
TEUCHOS_TEST_FOR_EXCEPTION(data_file.good() == false, MueLu::Exceptions::RuntimeError, "Problem opening file xxx.mm"); |
| 148 |
std::string line; |
| 149 |
getline(data_file, line); |
| 150 |
data_file >> nGlobalNodes; |
| 151 |
data_file.close(); |
| 152 |
} |
| 153 |
Teuchos::broadcast(*comm, 0, 1, &nGlobalNodes); |
| 154 |
|
| 155 |
out << "Found " << nGlobalNodes << " nodes " << std::endl; |
| 156 |
|
| 157 |
// each processor reads in its dofPresent array |
| 158 |
LocalOrdinal nNodes = 0; |
| 159 |
LocalOrdinal nDofs = 0; |
| 160 |
int maxDofPerNode = -1; |
| 161 |
Teuchos::ArrayRCP<LocalOrdinal> dofPresent; |
| 162 |
{ |
| 163 |
std::stringstream ss; |
| 164 |
ss << comm->getSize() << "dofPresent" << comm->getRank(); |
| 165 |
|
| 166 |
try { |
| 167 |
std::ifstream data_file(ss.str()); |
| 168 |
// read in first line containing number of local nodes and maxDofPerNode |
| 169 |
data_file >> nNodes >> maxDofPerNode; |
| 170 |
dofPresent = Teuchos::ArrayRCP<LocalOrdinal>(nNodes * maxDofPerNode, 0); |
| 171 |
// loop over all local nodes |
| 172 |
for (LocalOrdinal i = 0; i < nNodes; i++) { |
| 173 |
for (int j = 0; j < maxDofPerNode; j++) { |
| 174 |
int tmp = -1; |
| 175 |
data_file >> tmp; |
| 176 |
if (tmp == 1) { |
| 177 |
dofPresent[i * maxDofPerNode + j] = 1; |
| 178 |
nDofs++; |
| 179 |
} else { |
| 180 |
dofPresent[i * maxDofPerNode + j] = 0; |
| 181 |
} |
| 182 |
} |
| 183 |
} |
| 184 |
} catch (const std::exception& e) { |
| 185 |
TEUCHOS_TEST_FOR_EXCEPTION(true, MueLu::Exceptions::RuntimeError, "Problem opening/reading file " << ss.str()); |
| 186 |
} |
| 187 |
} |
| 188 |
|
| 189 |
out << "PROC " << comm->getRank() << "/" << comm->getSize() << " " << nNodes << " " << maxDofPerNode << std::endl; |
| 190 |
|
| 191 |
/*for(LocalOrdinal i = 0; i < nNodes; i++) { |
| 192 |
for(int j=0; j<maxDofPerNode; j++) { |
| 193 |
std::cout << i << " " << dofPresent[i*maxDofPerNode+j] << std::endl; |
| 194 |
} |
| 195 |
}*/ |
| 196 |
|
| 197 |
// read in dofs |
| 198 |
|
| 199 |
Teuchos::Array<GlobalOrdinal> dofGlobals; |
| 200 |
Teuchos::Array<GlobalOrdinal> nodalGlobals; // nodal GIDs for laplacian (with holes) |
| 201 |
{ |
| 202 |
std::stringstream ss; |
| 203 |
ss << comm->getSize() << "proc" << comm->getRank(); |
| 204 |
try { |
| 205 |
std::ifstream data_file(ss.str()); |
| 206 |
|
| 207 |
// read in first line containing number of local nodes and maxDofPerNode |
| 208 |
LocalOrdinal tmpDofs = 0; |
| 209 |
data_file >> tmpDofs; |
| 210 |
TEUCHOS_TEST_FOR_EXCEPTION(tmpDofs != nDofs, MueLu::Exceptions::RuntimeError, "Number of gid entries in map file is " << tmpDofs << " but should be " << nDofs); |
| 211 |
|
| 212 |
dofGlobals = Teuchos::Array<GlobalOrdinal>(nDofs); |
| 213 |
|
| 214 |
// loop over all local nodes |
| 215 |
for (GlobalOrdinal i = 0; i < nDofs; i++) { |
| 216 |
int data; |
| 217 |
data_file >> data; |
| 218 |
dofGlobals[i] = Teuchos::as<GlobalOrdinal>(data); |
| 219 |
} |
| 220 |
} catch (const std::exception& e) { |
| 221 |
TEUCHOS_TEST_FOR_EXCEPTION(true, MueLu::Exceptions::RuntimeError, "Problem opening/reading file " << ss.str()); |
| 222 |
} |
| 223 |
|
| 224 |
nodalGlobals = Teuchos::Array<GlobalOrdinal>(nNodes); |
| 225 |
|
| 226 |
GlobalOrdinal count = nDofs - 1; |
| 227 |
for (GlobalOrdinal i = nNodes - 1; i >= 0; i--) { |
| 228 |
for (int j = maxDofPerNode - 1; j >= 0; j--) { |
| 229 |
if (dofPresent[i * maxDofPerNode + j] == 1) |
| 230 |
nodalGlobals[i] = dofGlobals[count--]; |
| 231 |
} |
| 232 |
} |
| 233 |
} |
| 234 |
|
| 235 |
Teuchos::RCP<Map> LapMap = MapFactory::Build(lib, nGlobalNodes, nodalGlobals(), 0, comm); |
| 236 |
|
| 237 |
// LapMap->describe(out, Teuchos::VERB_EXTREME); |
| 238 |
|
| 239 |
// |
| 240 |
|
| 241 |
{ |
| 242 |
std::stringstream ss; |
| 243 |
ss << comm->getSize() << "ProcLinear" << comm->getRank(); |
| 244 |
try { |
| 245 |
std::ifstream data_file(ss.str()); |
| 246 |
|
| 247 |
// loop over all local nodes |
| 248 |
for (GlobalOrdinal i = 0; i < nNodes; i++) { |
| 249 |
int data; |
| 250 |
data_file >> data; |
| 251 |
nodalGlobals[i] = Teuchos::as<GlobalOrdinal>(data); |
| 252 |
} |
| 253 |
} catch (const std::exception& e) { |
| 254 |
TEUCHOS_TEST_FOR_EXCEPTION(true, MueLu::Exceptions::RuntimeError, "Problem opening/reading file " << ss.str()); |
| 255 |
} |
| 256 |
for (GlobalOrdinal i = 0; i < nNodes; i++) { |
| 257 |
nodalGlobals[i] = nodalGlobals[i] - 1; |
| 258 |
} |
| 259 |
} |
| 260 |
|
| 261 |
Teuchos::RCP<Map> LinearMap = MapFactory::Build(lib, nGlobalNodes, nodalGlobals(), 0, comm); |
| 262 |
// LinearMap->describe(out, Teuchos::VERB_EXTREME);LapMap->describe(out, Teuchos::VERB_EXTREME); |
| 263 |
|
| 264 |
// LapMap->describe(out, Teuchos::VERB_EXTREME);LapMap->describe(out, Teuchos::VERB_EXTREME); |
| 265 |
|
| 266 |
Teuchos::RCP<Import> Importer = ImportFactory::Build(LinearMap, LapMap); |
| 267 |
|
| 268 |
Teuchos::RCP<MultiVector> xpetraXXX = MultiVectorFactory::Build(LapMap, 1); |
| 269 |
Teuchos::RCP<MultiVector> xpetraYYY = MultiVectorFactory::Build(LapMap, 1); |
| 270 |
|
| 271 |
RCP<MultiVector> temp = IO::ReadMultiVector("xxx.mm", LinearMap); |
| 272 |
xpetraXXX->doImport(*temp, *Importer, Xpetra::INSERT); |
| 273 |
temp = IO::ReadMultiVector("yyy.mm", LinearMap); |
| 274 |
xpetraYYY->doImport(*temp, *Importer, Xpetra::INSERT); |
| 275 |
|
| 276 |
Teuchos::RCP<MultiVector> coordinates = MultiVectorFactory::Build(LapMap, 2); |
| 277 |
Teuchos::ArrayRCP<const Scalar> srcX = xpetraXXX->getData(0); |
| 278 |
Teuchos::ArrayRCP<const Scalar> srcY = xpetraYYY->getData(0); |
| 279 |
Teuchos::ArrayRCP<Scalar> dataX = coordinates->getDataNonConst(0); |
| 280 |
Teuchos::ArrayRCP<Scalar> dataY = coordinates->getDataNonConst(1); |
| 281 |
for (decltype(coordinates->getLocalLength()) i = 0; i < coordinates->getLocalLength(); i++) { |
| 282 |
dataX[i] = srcX[i]; |
| 283 |
dataY[i] = srcY[i]; |
| 284 |
} |
| 285 |
|
| 286 |
// read in matrix |
| 287 |
Teuchos::RCP<const Map> DistributedMap = Teuchos::null; |
| 288 |
Teuchos::RCP<Matrix> DistributedMatrix = Teuchos::null; |
| 289 |
|
| 290 |
// read in matrix to determine number of rows |
| 291 |
Teuchos::RCP<Matrix> SerialMatrix = Xpetra::IO<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Read("theMatrix.m", lib, comm); |
| 292 |
GlobalOrdinal NumRows = SerialMatrix->getRowMap()->getGlobalNumElements(); |
| 293 |
|
| 294 |
// re-read in matrix and distribute it using the user-given distribution over processors |
| 295 |
DistributedMap = MapFactory::Build(lib, NumRows, dofGlobals(), 0, comm); |
| 296 |
DistributedMatrix = Xpetra::IO<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Read("theMatrix.m", |
| 297 |
DistributedMap, |
| 298 |
Teuchos::null, |
| 299 |
DistributedMap, |
| 300 |
DistributedMap, |
| 301 |
true, // callFillComplete = true, |
| 302 |
false, // binary = false, |
| 303 |
false, // tolerant = false, |
| 304 |
false); // debug = false) |
| 305 |
|
| 306 |
// read in global vectors (e.g. rhs) |
| 307 |
GlobalOrdinal nGlobalDof = 0; |
| 308 |
GlobalOrdinal nLocalDofs = Teuchos::as<GlobalOrdinal>(nDofs); |
| 309 |
|
| 310 |
Teuchos::reduceAll(*comm, Teuchos::REDUCE_SUM, comm->getSize(), &nLocalDofs, &nGlobalDof); |
| 311 |
|
| 312 |
Teuchos::RCP<const Map> dofLinearMap = Teuchos::null; |
| 313 |
{ |
| 314 |
std::stringstream ss; |
| 315 |
ss << comm->getSize() << "ProcLinear" << comm->getRank(); |
| 316 |
try { |
| 317 |
std::ifstream data_file(ss.str()); |
| 318 |
// loop over all local nodes |
| 319 |
data_file >> dofGlobals[0]; |
| 320 |
} catch (const std::exception& e) { |
| 321 |
TEUCHOS_TEST_FOR_EXCEPTION(true, MueLu::Exceptions::RuntimeError, "Problem opening/reading file " << ss.str()); |
| 322 |
} |
| 323 |
for (decltype(nDofs) i = 0; i < nDofs; i++) dofGlobals[i] = i + dofGlobals[0]; |
| 324 |
for (decltype(nDofs) i = 0; i < nDofs; i++) dofGlobals[i] = dofGlobals[i] - 1; |
| 325 |
dofLinearMap = MapFactory::Build(lib, nGlobalDof, dofGlobals(), 0, comm); |
| 326 |
} |
| 327 |
|
| 328 |
Teuchos::RCP<Import> dofImporter = ImportFactory::Build(dofLinearMap, DistributedMap); |
| 329 |
|
| 330 |
RCP<MultiVector> RHS = MultiVectorFactory::Build(DistributedMap, 1); |
| 331 |
RCP<MultiVector> LHS = MultiVectorFactory::Build(DistributedMap, 1); |
| 332 |
|
| 333 |
temp = IO::ReadMultiVector("rhs.mm", dofLinearMap); |
| 334 |
RHS->doImport(*temp, *dofImporter, Xpetra::INSERT); |
| 335 |
LHS->putScalar(zero); |
| 336 |
|
| 337 |
// MueLu part |
| 338 |
|
| 339 |
Teuchos::ParameterList paramList; |
| 340 |
Teuchos::updateParametersFromXmlFileAndBroadcast(xmlFileName, Teuchos::Ptr<Teuchos::ParameterList>(¶mList), *comm); |
| 341 |
|
| 342 |
const std::string userName = "user data"; |
| 343 |
Teuchos::ParameterList& userParamList = paramList.sublist(userName); |
| 344 |
userParamList.set("multivector Coordinates", coordinates); |
| 345 |
userParamList.set("ArrayRCP<LO> DofPresent", dofPresent); |
| 346 |
|
| 347 |
RCP<Hierarchy> H; |
| 348 |
H = MueLu::CreateXpetraPreconditioner(DistributedMatrix, paramList); |
| 349 |
|
| 350 |
#ifdef HAVE_MUELU_BELOS |
| 351 |
{ |
| 352 |
tm = rcp(new TimeMonitor(*TimeMonitor::getNewTimer("Driver: 4 - Belos Solve"))); |
| 353 |
// Operator and Multivector type that will be used with Belos |
| 354 |
typedef MultiVector MV; |
| 355 |
typedef Belos::OperatorT<MV> OP; |
| 356 |
H->IsPreconditioner(true); |
| 357 |
|
| 358 |
// Define Operator and Preconditioner |
| 359 |
Teuchos::RCP<OP> belosOp = Teuchos::rcp(new Belos::XpetraOp<SC, LO, GO, NO>(DistributedMatrix)); // Turns a Xpetra::Matrix object into a Belos operator |
| 360 |
Teuchos::RCP<OP> belosPrec = Teuchos::rcp(new Belos::MueLuOp<SC, LO, GO, NO>(H)); // Turns a MueLu::Hierarchy object into a Belos operator |
| 361 |
// Construct a Belos LinearProblem object |
| 362 |
RCP<Belos::LinearProblem<SC, MV, OP> > belosProblem = rcp(new Belos::LinearProblem<SC, MV, OP>(belosOp, LHS, RHS)); |
| 363 |
belosProblem->setRightPrec(belosPrec); |
| 364 |
bool set = belosProblem->setProblem(); |
| 365 |
if (set == false) { |
| 366 |
out << "\nERROR: Belos::LinearProblem failed to set up correctly!" << std::endl; |
| 367 |
return EXIT_FAILURE; |
| 368 |
} |
| 369 |
|
| 370 |
// Belos parameter list |
| 371 |
Teuchos::ParameterList belosList; |
| 372 |
belosList.set("Maximum Iterations", 300); // Maximum number of iterations allowed |
| 373 |
belosList.set("Convergence Tolerance", 1e-8); // Relative convergence tolerance requested |
| 374 |
belosList.set("Verbosity", Belos::Errors + Belos::Warnings + Belos::StatusTestDetails); |
| 375 |
belosList.set("Output Frequency", 1); |
| 376 |
belosList.set("Output Style", Belos::Brief); |
| 377 |
|
| 378 |
// Create an iterative solver manager |
| 379 |
RCP<Belos::SolverManager<SC, MV, OP> > solver; |
| 380 |
solver = rcp(new Belos::PseudoBlockGmresSolMgr<SC, MV, OP>(belosProblem, rcp(&belosList, false))); |
| 381 |
|
| 382 |
// Perform solve |
| 383 |
Belos::ReturnType ret = Belos::Unconverged; |
| 384 |
try { |
| 385 |
ret = solver->solve(); |
| 386 |
|
| 387 |
// Get the number of iterations for this solve. |
| 388 |
out << "Number of iterations performed for this solve: " << solver->getNumIters() << std::endl; |
| 389 |
|
| 390 |
} catch (...) { |
| 391 |
out << std::endl |
| 392 |
<< "ERROR: Belos threw an error! " << std::endl; |
| 393 |
} |
| 394 |
// Check convergence |
| 395 |
if (ret != Belos::Converged) |
| 396 |
out << std::endl |
| 397 |
<< "ERROR: Belos did not converge or a warning occured! " << std::endl; |
| 398 |
else |
| 399 |
out << std::endl |
| 400 |
<< "SUCCESS: Belos converged!" << std::endl; |
| 401 |
} |
| 402 |
#endif |
| 403 |
|
| 404 |
success = true; |
| 405 |
} |
| 406 |
TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose, std::cerr, success); |
| 407 |
|
| 408 |
return (success ? EXIT_SUCCESS : EXIT_FAILURE); |
| 409 |
} // main |
| 410 |
|
| 411 |
int main(int argc, char* argv[]) { |
| 412 |
bool success = false; |
| 413 |
bool verbose = true; |
| 414 |
|
| 415 |
Teuchos::GlobalMPISession mpiSession(&argc, &argv); |
| 416 |
|
| 417 |
try { |
| 418 |
const bool throwExceptions = false; |
| 419 |
const bool recogniseAllOptions = false; |
| 420 |
|
| 421 |
Teuchos::CommandLineProcessor clp(throwExceptions, recogniseAllOptions); |
| 422 |
Xpetra::Parameters xpetraParameters(clp); |
| 423 |
|
| 424 |
std::string node = ""; |
| 425 |
clp.setOption("node", &node, "node type (serial | openmp | cuda | hip)"); |
| 426 |
|
| 427 |
switch (clp.parse(argc, argv, NULL)) { |
| 428 |
case Teuchos::CommandLineProcessor::PARSE_ERROR: return EXIT_FAILURE; |
| 429 |
case Teuchos::CommandLineProcessor::PARSE_HELP_PRINTED: |
| 430 |
case Teuchos::CommandLineProcessor::PARSE_UNRECOGNIZED_OPTION: |
| 431 |
case Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL: break; |
| 432 |
} |
| 433 |
|
| 434 |
Xpetra::UnderlyingLib lib = xpetraParameters.GetLib(); |
| 435 |
|
| 436 |
if (lib == Xpetra::UseEpetra) { |
| 437 |
#ifdef HAVE_MUELU_EPETRA |
| 438 |
return main_<double, int, int, Xpetra::EpetraNode>(clp, lib, argc, argv); |
| 439 |
#else |
| 440 |
throw MueLu::Exceptions::RuntimeError("Epetra is not available"); |
| 441 |
#endif |
| 442 |
} |
| 443 |
|
| 444 |
if (lib == Xpetra::UseTpetra) { |
| 445 |
if (node == "") { |
| 446 |
typedef Tpetra::KokkosClassic::DefaultNode::DefaultNodeType Node; |
| 447 |
|
| 448 |
#ifndef HAVE_MUELU_EXPLICIT_INSTANTIATION |
| 449 |
return main_<double, int, long, Node>(clp, lib, argc, argv); |
| 450 |
#else |
| 451 |
#if defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_INT_INT) |
| 452 |
return main_<double, int, int, Node>(clp, lib, argc, argv); |
| 453 |
#elif defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_INT_LONG) |
| 454 |
return main_<double, int, long, Node>(clp, lib, argc, argv); |
| 455 |
#elif defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_INT_LONG_LONG) |
| 456 |
return main_<double, int, long long, Node>(clp, lib, argc, argv); |
| 457 |
#else |
| 458 |
throw MueLu::Exceptions::RuntimeError("Found no suitable instantiation"); |
| 459 |
#endif |
| 460 |
#endif |
| 461 |
} else if (node == "serial") { |
| 462 |
#ifdef KOKKOS_ENABLE_SERIAL |
| 463 |
typedef Tpetra::KokkosCompat::KokkosSerialWrapperNode Node; |
| 464 |
|
| 465 |
#ifndef HAVE_MUELU_EXPLICIT_INSTANTIATION |
| 466 |
return main_<double, int, long, Node>(clp, lib, argc, argv); |
| 467 |
#else |
| 468 |
#if defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_INT) |
| 469 |
return main_<double, int, int, Node>(clp, lib, argc, argv); |
| 470 |
#elif defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_LONG) |
| 471 |
return main_<double, int, long, Node>(clp, lib, argc, argv); |
| 472 |
#elif defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_SERIAL) && defined(HAVE_TPETRA_INST_INT_LONG_LONG) |
| 473 |
return main_<double, int, long long, Node>(clp, lib, argc, argv); |
| 474 |
#else |
| 475 |
throw MueLu::Exceptions::RuntimeError("Found no suitable instantiation"); |
| 476 |
#endif |
| 477 |
#endif |
| 478 |
#else |
| 479 |
throw MueLu::Exceptions::RuntimeError("Serial node type is disabled"); |
| 480 |
#endif |
| 481 |
} else if (node == "openmp") { |
| 482 |
#ifdef KOKKOS_ENABLE_OPENMP |
| 483 |
typedef Tpetra::KokkosCompat::KokkosOpenMPWrapperNode Node; |
| 484 |
|
| 485 |
#ifndef HAVE_MUELU_EXPLICIT_INSTANTIATION |
| 486 |
return main_<double, int, long, Node>(clp, argc, argv); |
| 487 |
#else |
| 488 |
#if defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_INT) |
| 489 |
return main_<double, int, int, Node>(clp, lib, argc, argv); |
| 490 |
#elif defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_LONG) |
| 491 |
return main_<double, int, long, Node>(clp, lib, argc, argv); |
| 492 |
#elif defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_OPENMP) && defined(HAVE_TPETRA_INST_INT_LONG_LONG) |
| 493 |
return main_<double, int, long long, Node>(clp, lib, argc, argv); |
| 494 |
#else |
| 495 |
throw MueLu::Exceptions::RuntimeError("Found no suitable instantiation"); |
| 496 |
#endif |
| 497 |
#endif |
| 498 |
#else |
| 499 |
throw MueLu::Exceptions::RuntimeError("OpenMP node type is disabled"); |
| 500 |
#endif |
| 501 |
} else if (node == "cuda") { |
| 502 |
#ifdef KOKKOS_ENABLE_CUDA |
| 503 |
typedef Tpetra::KokkosCompat::KokkosCudaWrapperNode Node; |
| 504 |
|
| 505 |
#ifndef HAVE_MUELU_EXPLICIT_INSTANTIATION |
| 506 |
return main_<double, int, long, Node>(clp, argc, argv); |
| 507 |
#else |
| 508 |
#if defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_CUDA) && defined(HAVE_TPETRA_INST_INT_INT) |
| 509 |
return main_<double, int, int, Node>(clp, lib, argc, argv); |
| 510 |
#elif defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_CUDA) && defined(HAVE_TPETRA_INST_INT_LONG) |
| 511 |
return main_<double, int, long, Node>(clp, lib, argc, argv); |
| 512 |
#elif defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_CUDA) && defined(HAVE_TPETRA_INST_INT_LONG_LONG) |
| 513 |
return main_<double, int, long long, Node>(clp, lib, argc, argv); |
| 514 |
#else |
| 515 |
throw MueLu::Exceptions::RuntimeError("Found no suitable instantiation"); |
| 516 |
#endif |
| 517 |
#endif |
| 518 |
#else |
| 519 |
throw MueLu::Exceptions::RuntimeError("CUDA node type is disabled"); |
| 520 |
#endif |
| 521 |
} else if (node == "hip") { |
| 522 |
#ifdef KOKKOS_ENABLE_HIP |
| 523 |
typedef Tpetra::KokkosCompat::KokkosHIPWrapperNode Node; |
| 524 |
|
| 525 |
#ifndef HAVE_MUELU_EXPLICIT_INSTANTIATION |
| 526 |
return main_<double, int, long, Node>(clp, argc, argv); |
| 527 |
#else |
| 528 |
#if defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_HIP) && defined(HAVE_TPETRA_INST_INT_INT) |
| 529 |
return main_<double, int, int, Node>(clp, lib, argc, argv); |
| 530 |
#elif defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_HIP) && defined(HAVE_TPETRA_INST_INT_LONG) |
| 531 |
return main_<double, int, long, Node>(clp, lib, argc, argv); |
| 532 |
#elif defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_HIP) && defined(HAVE_TPETRA_INST_INT_LONG_LONG) |
| 533 |
return main_<double, int, long long, Node>(clp, lib, argc, argv); |
| 534 |
#else |
| 535 |
throw MueLu::Exceptions::RuntimeError("Found no suitable instantiation"); |
| 536 |
#endif |
| 537 |
#endif |
| 538 |
#else |
| 539 |
throw MueLu::Exceptions::RuntimeError("HIP node type is disabled"); |
| 540 |
#endif |
| 541 |
} else if (node == "sycl") { |
| 542 |
#ifdef KOKKOS_ENABLE_SYCL |
| 543 |
typedef Tpetra::KokkosCompatKokkosSYCLWrapperNode Node; |
| 544 |
|
| 545 |
#ifndef HAVE_MUELU_EXPLICIT_INSTANTIATION |
| 546 |
return main_<double, int, long, Node>(clp, argc, argv); |
| 547 |
#else |
| 548 |
#if defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_SYCL) && defined(HAVE_TPETRA_INST_INT_INT) |
| 549 |
return main_<double, int, int, Node>(clp, lib, argc, argv); |
| 550 |
#elif defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_SYCL) && defined(HAVE_TPETRA_INST_INT_LONG) |
| 551 |
return main_<double, int, long, Node>(clp, lib, argc, argv); |
| 552 |
#elif defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_SYCL) && defined(HAVE_TPETRA_INST_INT_LONG_LONG) |
| 553 |
return main_<double, int, long long, Node>(clp, lib, argc, argv); |
| 554 |
#else |
| 555 |
throw MueLu::Exceptions::RuntimeError("Found no suitable instantiation"); |
| 556 |
#endif |
| 557 |
#endif |
| 558 |
#else |
| 559 |
throw MueLu::Exceptions::RuntimeError("SYCL node type is disabled"); |
| 560 |
#endif |
| 561 |
} else { |
| 562 |
throw MueLu::Exceptions::RuntimeError("Unrecognized node type"); |
| 563 |
} |
| 564 |
} |
| 565 |
} |
| 566 |
TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose, std::cerr, success); |
| 567 |
|
| 568 |
return (success ? EXIT_SUCCESS : EXIT_FAILURE); |
| 569 |
} |