Xpetra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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>
15 #include <Teuchos_CommandLineProcessor.hpp>
16 
17 #include <Xpetra_Map.hpp> // for UnderlyingLib definition
18 #include <Xpetra_Utils.hpp> // for toString(lib_)
19 
20 namespace Xpetra {
21 
28 };
29 
31  : public Teuchos::VerboseObject<Parameters>,
32  public Teuchos::Describable {
33  public:
34  Parameters(Teuchos::CommandLineProcessor& clp) {
35  setCLP(clp);
36  }
37 
38  void setCLP(Teuchos::CommandLineProcessor& clp) {
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 #if defined(HAVE_XPETRA_EPETRA)
50  documentation << "Epetra";
51  lib_ = Xpetra::UseEpetra; // set default (if Tpetra support is missing)
52  optionValues[nOptions] = Xpetra::UseEpetra;
53  // optionValues[nOptions] = "epetra"; //TODO: do not break compatibility right now
54  optionNames[nOptions] = "Epetra";
55  nOptions++;
56 #endif
57 #if defined(HAVE_XPETRA_TPETRA)
58 #if defined(HAVE_XPETRA_EPETRA)
59  documentation << ", ";
60 #endif
61  documentation << "Tpetra";
62  lib_ = Xpetra::UseTpetra; // set default
63  optionValues[nOptions] = Xpetra::UseTpetra;
64  // optionsValues[nOptions] = "tpetra"; //TODO: do not break compatibility right now
65  optionNames[nOptions] = "Tpetra";
66  nOptions++;
67 #endif
68  documentation << ")";
69 
70  clp.setOption<Xpetra::UnderlyingLib>("linAlgebra", &lib_, nOptions, optionValues, optionNames, documentation.str().c_str());
71 
72 #if defined(HAVE_XPETRA_TPETRA)
73  int nInstOptions = 0; // Gives the number of possible option values to select
74  const int maxInstOptions = 5; // No more than 5 instantiations are supported right now
75  Xpetra::Instantiation instOptionValues[maxInstOptions]; // Array that gives the numeric values for each option.
76  const char* instOptionNames[maxInstOptions]; // Array that gives the name used in the commandline for each option.
77 
78  // The ordering of these blocks determines the default behavior.
79  // We test the first available instantiation from the bottom
80  // (i.e. DOUBLE_INT_INT runs if nothing else is available).
81 #if defined(HAVE_MUELU_INST_DOUBLE_INT_INT) || defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_INT_INT)
82  inst_ = Xpetra::DOUBLE_INT_INT; // set default
83  instOptionValues[nInstOptions] = Xpetra::DOUBLE_INT_INT;
84  instOptionNames[nInstOptions] = "DOUBLE_INT_INT";
85  nInstOptions++;
86 #endif
87 #if defined(HAVE_MUELU_INST_DOUBLE_INT_LONGINT) || defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_INT_LONG)
88  inst_ = Xpetra::DOUBLE_INT_LONGINT; // set default
89  instOptionValues[nInstOptions] = Xpetra::DOUBLE_INT_LONGINT;
90  instOptionNames[nInstOptions] = "DOUBLE_INT_LONGINT";
91  nInstOptions++;
92 #endif
93 #if defined(HAVE_MUELU_INST_DOUBLE_INT_LONGLONGINT) || defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_INT_LONG_LONG)
94  inst_ = Xpetra::DOUBLE_INT_LONGLONGINT; // set default
95  instOptionValues[nInstOptions] = Xpetra::DOUBLE_INT_LONGLONGINT;
96  instOptionNames[nInstOptions] = "DOUBLE_INT_LONGLONGINT";
97  nInstOptions++;
98 #endif
99 #if defined(HAVE_MUELU_INST_COMPLEX_INT_INT) || defined(HAVE_TPETRA_INST_COMPLEX_DOUBLE) && defined(HAVE_TPETRA_INST_INT_INT)
100  inst_ = Xpetra::COMPLEX_INT_INT; // set default
101  instOptionValues[nInstOptions] = Xpetra::COMPLEX_INT_INT;
102  instOptionNames[nInstOptions] = "COMPLEX_INT_INT";
103  nInstOptions++;
104 #endif
105 #if defined(HAVE_MUELU_INST_FLOAT_INT_INT) || defined(HAVE_TPETRA_INST_FLOAT) && defined(HAVE_TPETRA_INST_INT_INT)
106  inst_ = Xpetra::FLOAT_INT_INT; // set default
107  instOptionValues[nInstOptions] = Xpetra::FLOAT_INT_INT;
108  instOptionNames[nInstOptions] = "FLOAT_INT_INT";
109  nInstOptions++;
110 #endif
111  std::stringstream instDocumentation; // documentation for the option
112  instDocumentation << "choice of instantiation";
113 
114  clp.setOption<Xpetra::Instantiation>("instantiation", &inst_, nInstOptions, instOptionValues, instOptionNames, instDocumentation.str().c_str());
115 #endif
116  }
117 
118  void check() const {
119  // TODO with ifdef...
120  }
121 
123  check();
124  return lib_;
125  }
126 
128  check();
129  return inst_;
130  }
131 
133 
134 
136  std::string description() const {
137  std::ostringstream out;
138  out << Teuchos::Describable::description();
139  out << "{lib = " << toString(lib_) << "} ";
140  return out.str();
141  }
142 
144  void describe(Teuchos::FancyOStream& out, const Teuchos::EVerbosityLevel verbLevel = verbLevel_default) const {
145  using std::endl;
146  int vl = (verbLevel == Teuchos::VERB_DEFAULT) ? Teuchos::VERB_LOW : verbLevel;
147  if (vl == Teuchos::VERB_NONE) return;
148 
149  if (vl == Teuchos::VERB_LOW) {
150  out << description() << endl;
151  } else {
152  out << Teuchos::Describable::description() << endl;
153  }
154 
155  if (vl == Teuchos::VERB_MEDIUM || vl == Teuchos::VERB_HIGH || vl == Teuchos::VERB_EXTREME) {
156  Teuchos::OSTab tab1(out);
157  out << "Linear algebra library: " << toString(lib_) << endl;
158  }
159  }
160 
162 
163  private:
166 };
167 
168 } // namespace Xpetra
169 
170 #endif
std::string toString(Xpetra::UnderlyingLib lib)
Convert a Xpetra::UnderlyingLib to a std::string.
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::Instantiation GetInstantiation() const
Xpetra::UnderlyingLib lib_
Xpetra::UnderlyingLib GetLib() const
Xpetra::Instantiation inst_
Parameters(Teuchos::CommandLineProcessor &clp)