Tpetra Matrix/Vector Services  Version of the Day
MultiPrecExample_double_float.cpp
Go to the documentation of this file.
1 /*
2 // @HEADER
3 // ***********************************************************************
4 //
5 // Tpetra: Templated Linear Algebra Services Package
6 // Copyright (2008) 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 Michael A. Heroux (maherou@sandia.gov)
39 //
40 // ************************************************************************
41 // @HEADER
42 */
43 
46 #include <Teuchos_oblackholestream.hpp>
48 
49 #include <Tpetra_DefaultPlatform.hpp>
50 
51 // no CXX11 on the GPU
52 #undef HAVE_KOKKOSCLASSIC_THRUST
53 #include <Tpetra_HybridPlatform.hpp>
54 #include <TpetraExt_TypeStack.hpp>
55 
56 #include <iostream>
57 
58 #include "MultiPrecDriver.hpp"
59 
64 int main(int argc, char *argv[])
65 {
66  using Teuchos::RCP;
67  using Teuchos::rcp;
68  using Teuchos::Comm;
70 
71  //
72  // Get the communicator
73  //
74  Teuchos::oblackholestream blackhole;
75  Teuchos::GlobalMPISession mpiSession(&argc,&argv,&blackhole);
77  const int myImageID = comm->getRank();
78 
79  //
80  // Get example parameters from command-line processor
81  //
82  bool verbose = (myImageID==0);
83  bool unfused = false;
84  std::string matfile;
85  std::string xmlfile;
86  std::string machineFile;
87  Teuchos::CommandLineProcessor cmdp(false,true);
88  cmdp.setOption("verbose","quiet",&verbose,"Print messages and results.");
89  cmdp.setOption("matrix-file",&matfile,"Filename for matrix");
90  cmdp.setOption("param-file", &xmlfile,"XML file for solver parameters");
91  cmdp.setOption("machine-file",&machineFile,"Filename for XML machine description file.");
92  cmdp.setOption("unfused","no-unfused",&unfused,"Test unfused iteration.");
93  if (cmdp.parse(argc,argv) != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL) {
94  return -1;
95  }
96 
97  //
98  // read machine file and initialize platform
99  //
100  RCP<Teuchos::ParameterList> machinePL = Teuchos::parameterList();
101  std::string defaultMachine(
102  " <ParameterList> "
103  " <ParameterList name='%1=0'> "
104  " <Parameter name='NodeType' type='string' value='Kokkos::SerialNode'/> "
105  " </ParameterList> "
106  " </ParameterList> "
107  );
108  Teuchos::updateParametersFromXmlString(defaultMachine,machinePL.ptr());
109  if (machineFile != "") Teuchos::updateParametersFromXmlFile(machineFile,machinePL.ptr());
110 
111  //
112  // create the platform object
113  //
114  Tpetra::HybridPlatform platform(comm,*machinePL);
115 
116  //
117  // Define the type stack
118  //
119  TPETRAEXT_TYPESTACK2(MPStack, double, float)
120 
121  //
122  // instantiate a driver on the scalar stack
123  //
124  MultiPrecDriver<MPStack> driver;
125  // hand output stream to driver
126  if (verbose) driver.out = Teuchos::getFancyOStream(Teuchos::rcp(&std::cout,false));
127  else driver.out = Teuchos::getFancyOStream(Teuchos::rcp(new Teuchos::oblackholestream()));
128  // hand matrix file to driver
129  driver.matrixFile = matfile;
130  // other params
131  driver.unfusedTest = unfused;
132 
133  //
134  // get the solver parameters
135  //
136  RCP<Teuchos::ParameterList> params = Teuchos::parameterList();
137  // default solver stack parameters
138  std::string xmlString(
139  " <ParameterList> \n"
140  " <Parameter name='tolerance' value='1e-15' type='double'/> \n"
141  " <Parameter name='verbose' value='2' type='int'/> \n"
142  " <ParameterList name='child'> \n"
143  " <Parameter name='tolerance' value='1e-7' type='double'/> \n"
144  " <Parameter name='verbose' value='1' type='int'/> \n"
145  " <Parameter name='Extract Diagonal' value='true' type='bool'/> \n"
146  " </ParameterList> \n"
147  " </ParameterList> \n"
148  );
149  Teuchos::updateParametersFromXmlString(xmlString,params.ptr());
150  if (xmlfile != "") Teuchos::updateParametersFromXmlFile(xmlfile,params.ptr());
151  // hand solver parameters to driver
152  driver.params = params;
153 
154  //
155  // run the driver
156  //
157  platform.runUserCode(driver);
158 
159  //
160  // Print result
161  if (driver.testPassed) {
162  *driver.out << "End Result: TEST PASSED" << std::endl;
163  }
164 
165  return 0;
166 }
167 
RCP< const Teuchos::Comm< int > > getComm() const
The Teuchos::Comm instance with which this object was created.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Ptr< Teuchos::ParameterList > ptr() const
static DefaultPlatformType & getDefaultPlatform()
Return the default platform.
A platform class for hybrid nodes.
basic_oblackholestream< char, std::char_traits< char > > oblackholestream