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 // ***********************************************************************
4 //
5 // Xpetra: A linear algebra interface package
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact
39 // Jonathan Hu (jhu@sandia.gov)
40 // Andrey Prokopenko (aprokop@sandia.gov)
41 // Ray Tuminaro (rstumin@sandia.gov)
42 //
43 // ***********************************************************************
44 //
45 // @HEADER
46 #ifndef XPETRA_PARAMETERS_HPP
47 #define XPETRA_PARAMETERS_HPP
48 
49 #include <Teuchos_Describable.hpp>
50 #include <Teuchos_VerboseObject.hpp>
51 #include <Teuchos_CommandLineProcessor.hpp>
52 
53 #include <Xpetra_Map.hpp> // for UnderlyingLib definition
54 #include <Xpetra_Utils.hpp> // for toString(lib_)
55 
56 namespace Xpetra {
57 
64 };
65 
67  : public Teuchos::VerboseObject<Parameters>,
68  public Teuchos::Describable {
69  public:
70  Parameters(Teuchos::CommandLineProcessor& clp) {
71  setCLP(clp);
72  }
73 
74  void setCLP(Teuchos::CommandLineProcessor& clp) {
75  int nOptions = 0; // Gives the number of possible option values to select
76  const int maxOptions = 2; // No more than 2 libraries are supported right now
77  Xpetra::UnderlyingLib optionValues[maxOptions]; // Array that gives the numeric values for each option.
78  const char* optionNames[maxOptions]; // Array that gives the name used in the commandline for each option.
79 
80  std::stringstream documentation; // documentation for the option
81  // documentation << "linear algebra library (Epetra, Tpetra)";
82  documentation << "linear algebra library (";
83 
84  // Default is Tpetra if available. If not, default is Epetra
85 #if defined(HAVE_XPETRA_EPETRA)
86  documentation << "Epetra";
87  lib_ = Xpetra::UseEpetra; // set default (if Tpetra support is missing)
88  optionValues[nOptions] = Xpetra::UseEpetra;
89  // optionValues[nOptions] = "epetra"; //TODO: do not break compatibility right now
90  optionNames[nOptions] = "Epetra";
91  nOptions++;
92 #endif
93 #if defined(HAVE_XPETRA_TPETRA)
94 #if defined(HAVE_XPETRA_EPETRA)
95  documentation << ", ";
96 #endif
97  documentation << "Tpetra";
98  lib_ = Xpetra::UseTpetra; // set default
99  optionValues[nOptions] = Xpetra::UseTpetra;
100  // optionsValues[nOptions] = "tpetra"; //TODO: do not break compatibility right now
101  optionNames[nOptions] = "Tpetra";
102  nOptions++;
103 #endif
104  documentation << ")";
105 
106  clp.setOption<Xpetra::UnderlyingLib>("linAlgebra", &lib_, nOptions, optionValues, optionNames, documentation.str().c_str());
107 
108 #if defined(HAVE_XPETRA_TPETRA)
109  int nInstOptions = 0; // Gives the number of possible option values to select
110  const int maxInstOptions = 5; // No more than 5 instantiations are supported right now
111  Xpetra::Instantiation instOptionValues[maxInstOptions]; // Array that gives the numeric values for each option.
112  const char* instOptionNames[maxInstOptions]; // Array that gives the name used in the commandline for each option.
113 
114  // The ordering of these blocks determines the default behavior.
115  // We test the first available instantiation from the bottom
116  // (i.e. DOUBLE_INT_INT runs if nothing else is available).
117 #if defined(HAVE_MUELU_INST_DOUBLE_INT_INT) || defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_INT_INT)
118  inst_ = Xpetra::DOUBLE_INT_INT; // set default
119  instOptionValues[nInstOptions] = Xpetra::DOUBLE_INT_INT;
120  instOptionNames[nInstOptions] = "DOUBLE_INT_INT";
121  nInstOptions++;
122 #endif
123 #if defined(HAVE_MUELU_INST_DOUBLE_INT_LONGINT) || defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_INT_LONG)
124  inst_ = Xpetra::DOUBLE_INT_LONGINT; // set default
125  instOptionValues[nInstOptions] = Xpetra::DOUBLE_INT_LONGINT;
126  instOptionNames[nInstOptions] = "DOUBLE_INT_LONGINT";
127  nInstOptions++;
128 #endif
129 #if defined(HAVE_MUELU_INST_DOUBLE_INT_LONGLONGINT) || defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_INT_LONG_LONG)
130  inst_ = Xpetra::DOUBLE_INT_LONGLONGINT; // set default
131  instOptionValues[nInstOptions] = Xpetra::DOUBLE_INT_LONGLONGINT;
132  instOptionNames[nInstOptions] = "DOUBLE_INT_LONGLONGINT";
133  nInstOptions++;
134 #endif
135 #if defined(HAVE_MUELU_INST_COMPLEX_INT_INT) || defined(HAVE_TPETRA_INST_COMPLEX_DOUBLE) && defined(HAVE_TPETRA_INST_INT_INT)
136  inst_ = Xpetra::COMPLEX_INT_INT; // set default
137  instOptionValues[nInstOptions] = Xpetra::COMPLEX_INT_INT;
138  instOptionNames[nInstOptions] = "COMPLEX_INT_INT";
139  nInstOptions++;
140 #endif
141 #if defined(HAVE_MUELU_INST_FLOAT_INT_INT) || defined(HAVE_TPETRA_INST_FLOAT) && defined(HAVE_TPETRA_INST_INT_INT)
142  inst_ = Xpetra::FLOAT_INT_INT; // set default
143  instOptionValues[nInstOptions] = Xpetra::FLOAT_INT_INT;
144  instOptionNames[nInstOptions] = "FLOAT_INT_INT";
145  nInstOptions++;
146 #endif
147  std::stringstream instDocumentation; // documentation for the option
148  instDocumentation << "choice of instantiation";
149 
150  clp.setOption<Xpetra::Instantiation>("instantiation", &inst_, nInstOptions, instOptionValues, instOptionNames, instDocumentation.str().c_str());
151 #endif
152  }
153 
154  void check() const {
155  // TODO with ifdef...
156  }
157 
159  check();
160  return lib_;
161  }
162 
164  check();
165  return inst_;
166  }
167 
169 
170 
172  std::string description() const {
173  std::ostringstream out;
174  out << Teuchos::Describable::description();
175  out << "{lib = " << toString(lib_) << "} ";
176  return out.str();
177  }
178 
180  void describe(Teuchos::FancyOStream& out, const Teuchos::EVerbosityLevel verbLevel = verbLevel_default) const {
181  using std::endl;
182  int vl = (verbLevel == Teuchos::VERB_DEFAULT) ? Teuchos::VERB_LOW : verbLevel;
183  if (vl == Teuchos::VERB_NONE) return;
184 
185  if (vl == Teuchos::VERB_LOW) {
186  out << description() << endl;
187  } else {
188  out << Teuchos::Describable::description() << endl;
189  }
190 
191  if (vl == Teuchos::VERB_MEDIUM || vl == Teuchos::VERB_HIGH || vl == Teuchos::VERB_EXTREME) {
192  Teuchos::OSTab tab1(out);
193  out << "Linear algebra library: " << toString(lib_) << endl;
194  }
195  }
196 
198 
199  private:
202 };
203 
204 } // namespace Xpetra
205 
206 #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)