Xpetra Version of the Day
Loading...
Searching...
No Matches
Xpetra_Parameters.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Xpetra: A linear algebra interface package
4//
5// Copyright 2012 NTESS and the Xpetra contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef XPETRA_PARAMETERS_HPP
11#define XPETRA_PARAMETERS_HPP
12
13#include <Teuchos_Describable.hpp>
14#include <Teuchos_VerboseObject.hpp>
16
17#include <Xpetra_Map.hpp> // for UnderlyingLib definition
18#include <Xpetra_Utils.hpp> // for toString(lib_)
19
20namespace Xpetra {
21
29
31 : public Teuchos::VerboseObject<Parameters>,
33 public:
37
39 int nOptions = 0; // Gives the number of possible option values to select
40 const int maxOptions = 2; // No more than 2 libraries are supported right now
41 Xpetra::UnderlyingLib optionValues[maxOptions]; // Array that gives the numeric values for each option.
42 const char* optionNames[maxOptions]; // Array that gives the name used in the commandline for each option.
43
44 std::stringstream documentation; // documentation for the option
45 // documentation << "linear algebra library (Epetra, Tpetra)";
46 documentation << "linear algebra library (";
47
48 // Default is Tpetra if available. If not, default is Epetra
49 documentation << "Tpetra";
50 lib_ = Xpetra::UseTpetra; // set default
51 optionValues[nOptions] = Xpetra::UseTpetra;
52 // optionsValues[nOptions] = "tpetra"; //TODO: do not break compatibility right now
53 optionNames[nOptions] = "Tpetra";
54 nOptions++;
55 documentation << ")";
56
57 clp.setOption<Xpetra::UnderlyingLib>("linAlgebra", &lib_, nOptions, optionValues, optionNames, documentation.str().c_str());
58
59 int nInstOptions = 0; // Gives the number of possible option values to select
60 const int maxInstOptions = 5; // No more than 5 instantiations are supported right now
61 Xpetra::Instantiation instOptionValues[maxInstOptions]; // Array that gives the numeric values for each option.
62 const char* instOptionNames[maxInstOptions]; // Array that gives the name used in the commandline for each option.
63
64 // The ordering of these blocks determines the default behavior.
65 // We test the first available instantiation from the bottom
66 // (i.e. DOUBLE_INT_INT runs if nothing else is available).
67#if defined(HAVE_MUELU_INST_DOUBLE_INT_INT) || defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_INT_INT)
68 inst_ = Xpetra::DOUBLE_INT_INT; // set default
69 instOptionValues[nInstOptions] = Xpetra::DOUBLE_INT_INT;
70 instOptionNames[nInstOptions] = "DOUBLE_INT_INT";
71 nInstOptions++;
72#endif
73#if defined(HAVE_MUELU_INST_DOUBLE_INT_LONGINT) || defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_INT_LONG)
74 inst_ = Xpetra::DOUBLE_INT_LONGINT; // set default
75 instOptionValues[nInstOptions] = Xpetra::DOUBLE_INT_LONGINT;
76 instOptionNames[nInstOptions] = "DOUBLE_INT_LONGINT";
77 nInstOptions++;
78#endif
79#if defined(HAVE_MUELU_INST_DOUBLE_INT_LONGLONGINT) || defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_INT_LONG_LONG)
81 instOptionValues[nInstOptions] = Xpetra::DOUBLE_INT_LONGLONGINT;
82 instOptionNames[nInstOptions] = "DOUBLE_INT_LONGLONGINT";
83 nInstOptions++;
84#endif
85#if defined(HAVE_MUELU_INST_COMPLEX_INT_INT) || defined(HAVE_TPETRA_INST_COMPLEX_DOUBLE) && defined(HAVE_TPETRA_INST_INT_INT)
86 inst_ = Xpetra::COMPLEX_INT_INT; // set default
87 instOptionValues[nInstOptions] = Xpetra::COMPLEX_INT_INT;
88 instOptionNames[nInstOptions] = "COMPLEX_INT_INT";
89 nInstOptions++;
90#endif
91#if defined(HAVE_MUELU_INST_FLOAT_INT_INT) || defined(HAVE_TPETRA_INST_FLOAT) && defined(HAVE_TPETRA_INST_INT_INT)
92 inst_ = Xpetra::FLOAT_INT_INT; // set default
93 instOptionValues[nInstOptions] = Xpetra::FLOAT_INT_INT;
94 instOptionNames[nInstOptions] = "FLOAT_INT_INT";
95 nInstOptions++;
96#endif
97 std::stringstream instDocumentation; // documentation for the option
98 instDocumentation << "choice of instantiation";
99
100 clp.setOption<Xpetra::Instantiation>("instantiation", &inst_, nInstOptions, instOptionValues, instOptionNames, instDocumentation.str().c_str());
101 }
102
103 void check() const {
104 // TODO with ifdef...
105 }
106
108 check();
109 return lib_;
110 }
111
113 check();
114 return inst_;
115 }
116
118
119
121 std::string description() const {
122 std::ostringstream out;
124 out << "{lib = " << toString(lib_) << "} ";
125 return out.str();
126 }
127
130 using std::endl;
131 int vl = (verbLevel == Teuchos::VERB_DEFAULT) ? Teuchos::VERB_LOW : verbLevel;
132 if (vl == Teuchos::VERB_NONE) return;
133
134 if (vl == Teuchos::VERB_LOW) {
135 out << description() << endl;
136 } else {
137 out << Teuchos::Describable::description() << endl;
138 }
139
141 Teuchos::OSTab tab1(out);
142 out << "Linear algebra library: " << toString(lib_) << endl;
143 }
144 }
145
147
148 private:
151};
152
153} // namespace Xpetra
154
155#endif
void setOption(const char option_true[], const char option_false[], bool *option_val, const char documentation[]=NULL)
static const EVerbosityLevel verbLevel_default
virtual std::string description() const
Xpetra::UnderlyingLib lib_
Parameters(Teuchos::CommandLineProcessor &clp)
Xpetra::Instantiation GetInstantiation() const
void setCLP(Teuchos::CommandLineProcessor &clp)
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=verbLevel_default) const
Print the object with some verbosity level to an FancyOStream object.
std::string description() const
Return a simple one-line description of this object.
Xpetra::UnderlyingLib GetLib() const
Xpetra::Instantiation inst_
std::string toString(Xpetra::UnderlyingLib lib)
Convert a Xpetra::UnderlyingLib to a std::string.