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 
66  class Parameters
67  : public Teuchos::VerboseObject<Parameters>, public Teuchos::Describable
68  {
69 
70  public:
71 
72  Parameters(Teuchos::CommandLineProcessor& clp) {
73  setCLP(clp);
74  }
75 
76  void setCLP(Teuchos::CommandLineProcessor& clp) {
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 
85  // Default is Tpetra if available. If not, default is Epetra
86 #if defined(HAVE_XPETRA_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  lib_ = Xpetra::UseTpetra; // set default
95  optionValues[nOptions] = Xpetra::UseTpetra;
96  //optionsValues[nOptions] = "tpetra"; //TODO: do not break compatibility right now
97  optionNames[nOptions] = "Tpetra";
98  nOptions++;
99 #endif
100 
101  clp.setOption<Xpetra::UnderlyingLib>("linAlgebra", &lib_, nOptions, optionValues, optionNames, documentation.str().c_str());
102 
103 #if defined(HAVE_XPETRA_TPETRA)
104  int nInstOptions=0; // Gives the number of possible option values to select
105  const int maxInstOptions=5; // No more than 5 instantiations are supported right now
106  Xpetra::Instantiation instOptionValues[maxInstOptions]; // Array that gives the numeric values for each option.
107  const char * instOptionNames [maxInstOptions]; // Array that gives the name used in the commandline for each option.
108 
109  // The ordering of these blocks determines the default behavior.
110  // We test the first available instantiation from the bottom
111  // (i.e. DOUBLE_INT_INT runs if nothing else is available).
112 # if defined(HAVE_MUELU_INST_DOUBLE_INT_INT) || defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_INT_INT)
113  inst_ = Xpetra::DOUBLE_INT_INT; // set default
114  instOptionValues[nInstOptions] = Xpetra::DOUBLE_INT_INT;
115  instOptionNames[nInstOptions] = "DOUBLE_INT_INT";
116  nInstOptions++;
117 # endif
118 # if defined(HAVE_MUELU_INST_DOUBLE_INT_LONGINT) || defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_INT_LONG)
119  inst_ = Xpetra::DOUBLE_INT_LONGINT; // set default
120  instOptionValues[nInstOptions] = Xpetra::DOUBLE_INT_LONGINT;
121  instOptionNames[nInstOptions] = "DOUBLE_INT_LONGINT";
122  nInstOptions++;
123 # endif
124 # if defined(HAVE_MUELU_INST_DOUBLE_INT_LONGLONGINT) || defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_INT_LONG_LONG)
125  inst_ = Xpetra::DOUBLE_INT_LONGLONGINT; // set default
126  instOptionValues[nInstOptions] = Xpetra::DOUBLE_INT_LONGLONGINT;
127  instOptionNames[nInstOptions] = "DOUBLE_INT_LONGLONGINT";
128  nInstOptions++;
129 # endif
130 # if defined(HAVE_MUELU_INST_COMPLEX_INT_INT) || defined(HAVE_TPETRA_INST_COMPLEX_DOUBLE) && defined(HAVE_TPETRA_INST_INT_INT)
131  inst_ = Xpetra::COMPLEX_INT_INT; // set default
132  instOptionValues[nInstOptions] = Xpetra::COMPLEX_INT_INT;
133  instOptionNames[nInstOptions] = "COMPLEX_INT_INT";
134  nInstOptions++;
135 # endif
136 # if defined(HAVE_MUELU_INST_FLOAT_INT_INT) || defined(HAVE_TPETRA_INST_FLOAT) && defined(HAVE_TPETRA_INST_INT_INT)
137  inst_ = Xpetra::FLOAT_INT_INT; // set default
138  instOptionValues[nInstOptions] = Xpetra::FLOAT_INT_INT;
139  instOptionNames[nInstOptions] = "FLOAT_INT_INT";
140  nInstOptions++;
141 # endif
142  std::stringstream instDocumentation; // documentation for the option
143  instDocumentation << "choice of instantiation";
144 
145  clp.setOption<Xpetra::Instantiation>("instantiation", &inst_, nInstOptions, instOptionValues, instOptionNames, instDocumentation.str().c_str());
146 #endif
147 
148  }
149 
150  void check() const {
151  //TODO with ifdef...
152  }
153 
155  check();
156  return lib_;
157  }
158 
160  check();
161  return inst_;
162  }
163 
165 
166 
168  std::string description() const {
169  std::ostringstream out;
170  out << Teuchos::Describable::description();
171  out << "{lib = " << toString(lib_) << "} ";
172  return out.str();
173  }
174 
176  void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel = verbLevel_default) const {
177  using std::endl;
178  int vl = (verbLevel == Teuchos::VERB_DEFAULT) ? Teuchos::VERB_LOW : verbLevel;
179  if (vl == Teuchos::VERB_NONE) return;
180 
181  if (vl == Teuchos::VERB_LOW) { out << description() << endl; } else { out << Teuchos::Describable::description() << endl; }
182 
183  if (vl == Teuchos::VERB_MEDIUM || vl == Teuchos::VERB_HIGH || vl == Teuchos::VERB_EXTREME) {
184  Teuchos::OSTab tab1(out);
185  out << "Linear algebra library: " << toString(lib_) << endl;
186  }
187  }
188 
190 
191  private:
194  };
195 
196 }
197 
198 #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)