Xpetra  Version of the Day
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>
52 
53 #include <Xpetra_Map.hpp> // for UnderlyingLib definition
54 #include <Xpetra_Utils.hpp> // for toString(lib_)
55 
56 namespace Xpetra {
57 
64  };
65 
66  class Parameters
67  : public Teuchos::VerboseObject<Parameters>, public Teuchos::Describable
68  {
69 
70  public:
71 
73  setCLP(clp);
74  }
75 
77  int nOptions=0; // Gives the number of possible option values to select
78  const int maxOptions=2; // No more than 2 libraries are supported right now
79  Xpetra::UnderlyingLib optionValues[maxOptions]; // Array that gives the numeric values for each option.
80  const char* optionNames [maxOptions]; // Array that gives the name used in the commandline for each option.
81 
82  std::stringstream documentation; // documentation for the option
83  //documentation << "linear algebra library (Epetra, Tpetra)";
84  documentation << "linear algebra library (";
85 
86  // Default is Tpetra if available. If not, default is Epetra
87 #if defined(HAVE_XPETRA_EPETRA)
88  documentation << "Epetra";
89  lib_ = Xpetra::UseEpetra; // set default (if Tpetra support is missing)
90  optionValues[nOptions] = Xpetra::UseEpetra;
91  //optionValues[nOptions] = "epetra"; //TODO: do not break compatibility right now
92  optionNames[nOptions] = "Epetra";
93  nOptions++;
94 #endif
95 #if defined(HAVE_XPETRA_TPETRA)
96 # if defined(HAVE_XPETRA_EPETRA)
97  documentation << ", ";
98 # endif
99  documentation << "Tpetra";
100  lib_ = Xpetra::UseTpetra; // set default
101  optionValues[nOptions] = Xpetra::UseTpetra;
102  //optionsValues[nOptions] = "tpetra"; //TODO: do not break compatibility right now
103  optionNames[nOptions] = "Tpetra";
104  nOptions++;
105 #endif
106  documentation << ")";
107 
108  clp.setOption<Xpetra::UnderlyingLib>("linAlgebra", &lib_, nOptions, optionValues, optionNames, documentation.str().c_str());
109 
110 #if defined(HAVE_XPETRA_TPETRA)
111  int nInstOptions=0; // Gives the number of possible option values to select
112  const int maxInstOptions=5; // No more than 5 instantiations are supported right now
113  Xpetra::Instantiation instOptionValues[maxInstOptions]; // Array that gives the numeric values for each option.
114  const char * instOptionNames [maxInstOptions]; // Array that gives the name used in the commandline for each option.
115 
116  // The ordering of these blocks determines the default behavior.
117  // We test the first available instantiation from the bottom
118  // (i.e. DOUBLE_INT_INT runs if nothing else is available).
119 # if defined(HAVE_MUELU_INST_DOUBLE_INT_INT) || defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_INT_INT)
120  inst_ = Xpetra::DOUBLE_INT_INT; // set default
121  instOptionValues[nInstOptions] = Xpetra::DOUBLE_INT_INT;
122  instOptionNames[nInstOptions] = "DOUBLE_INT_INT";
123  nInstOptions++;
124 # endif
125 # if defined(HAVE_MUELU_INST_DOUBLE_INT_LONGINT) || defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_INT_LONG)
126  inst_ = Xpetra::DOUBLE_INT_LONGINT; // set default
127  instOptionValues[nInstOptions] = Xpetra::DOUBLE_INT_LONGINT;
128  instOptionNames[nInstOptions] = "DOUBLE_INT_LONGINT";
129  nInstOptions++;
130 # endif
131 # if defined(HAVE_MUELU_INST_DOUBLE_INT_LONGLONGINT) || defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_INT_LONG_LONG)
132  inst_ = Xpetra::DOUBLE_INT_LONGLONGINT; // set default
133  instOptionValues[nInstOptions] = Xpetra::DOUBLE_INT_LONGLONGINT;
134  instOptionNames[nInstOptions] = "DOUBLE_INT_LONGLONGINT";
135  nInstOptions++;
136 # endif
137 # if defined(HAVE_MUELU_INST_COMPLEX_INT_INT) || defined(HAVE_TPETRA_INST_COMPLEX_DOUBLE) && defined(HAVE_TPETRA_INST_INT_INT)
138  inst_ = Xpetra::COMPLEX_INT_INT; // set default
139  instOptionValues[nInstOptions] = Xpetra::COMPLEX_INT_INT;
140  instOptionNames[nInstOptions] = "COMPLEX_INT_INT";
141  nInstOptions++;
142 # endif
143 # if defined(HAVE_MUELU_INST_FLOAT_INT_INT) || defined(HAVE_TPETRA_INST_FLOAT) && defined(HAVE_TPETRA_INST_INT_INT)
144  inst_ = Xpetra::FLOAT_INT_INT; // set default
145  instOptionValues[nInstOptions] = Xpetra::FLOAT_INT_INT;
146  instOptionNames[nInstOptions] = "FLOAT_INT_INT";
147  nInstOptions++;
148 # endif
149  std::stringstream instDocumentation; // documentation for the option
150  instDocumentation << "choice of instantiation";
151 
152  clp.setOption<Xpetra::Instantiation>("instantiation", &inst_, nInstOptions, instOptionValues, instOptionNames, instDocumentation.str().c_str());
153 #endif
154 
155  }
156 
157  void check() const {
158  //TODO with ifdef...
159  }
160 
162  check();
163  return lib_;
164  }
165 
167  check();
168  return inst_;
169  }
170 
172 
173 
175  std::string description() const {
176  std::ostringstream out;
178  out << "{lib = " << toString(lib_) << "} ";
179  return out.str();
180  }
181 
184  using std::endl;
185  int vl = (verbLevel == Teuchos::VERB_DEFAULT) ? Teuchos::VERB_LOW : verbLevel;
186  if (vl == Teuchos::VERB_NONE) return;
187 
188  if (vl == Teuchos::VERB_LOW) { out << description() << endl; } else { out << Teuchos::Describable::description() << endl; }
189 
190  if (vl == Teuchos::VERB_MEDIUM || vl == Teuchos::VERB_HIGH || vl == Teuchos::VERB_EXTREME) {
191  Teuchos::OSTab tab1(out);
192  out << "Linear algebra library: " << toString(lib_) << endl;
193  }
194  }
195 
197 
198  private:
201  };
202 
203 }
204 
205 #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_
Xpetra namespace
@ DOUBLE_INT_LONGLONGINT
std::string toString(Xpetra::UnderlyingLib lib)
Convert a Xpetra::UnderlyingLib to a std::string.