Tpetra Matrix/Vector Services  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
RTIInlineCG_qd.cpp
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 
44 #include "RTIInlineCG.hpp"
45 #include <qd/qd_real.h>
46 
47 int main(int argc, char *argv[])
48 {
50  using Teuchos::RCP;
51  using Teuchos::rcp;
52  using Teuchos::Comm;
53  using Teuchos::ParameterList;
54 
55  //
56  // Get the communicator
57  //
58  Teuchos::oblackholestream blackhole;
59  Teuchos::GlobalMPISession mpiSession(&argc,&argv,&blackhole);
61  const int myImageID = comm->getRank();
62 
63  //
64  // Get example parameters from command-line processor
65  //
66  bool verbose = (myImageID==0);
67  std::string xmlfile;
68  std::string machineFile;
69 
70  Teuchos::CommandLineProcessor cmdp(false,true);
71  cmdp.setOption("verbose","quiet",&verbose,"Print messages and results.");
72  cmdp.setOption("param-file", &xmlfile,"XML file for solver parameters");
73  cmdp.setOption("machine-file",&machineFile,"Filename for XML machine description file.");
74  if (cmdp.parse(argc,argv) != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL) {
75  return -1;
76  }
77 
78  //
79  // read machine file and initialize platform
80  //
81  RCP<Teuchos::ParameterList> machinePL = Teuchos::parameterList();
82  std::string defaultMachine(
83  " <ParameterList> "
84  " <ParameterList name='%1=0'> "
85  " <Parameter name='NodeType' type='string' value='Kokkos::SerialNode'/> "
86  " </ParameterList> "
87  " </ParameterList> "
88  );
89  Teuchos::updateParametersFromXmlString(defaultMachine,machinePL.ptr());
90  if (machineFile != "") Teuchos::updateParametersFromXmlFile(machineFile,machinePL.ptr());
91 
92  //
93  // create the platform object
94  //
95  Tpetra::HybridPlatform platform(comm,*machinePL);
96 
97  //
98  // instantiate a driver on the scalar stack
99  //
100  CGDriver<qd_real> driver;
101  // hand output stream to driver
102  if (verbose) driver.out = Teuchos::getFancyOStream(Teuchos::rcp(&std::cout,false));
103  else driver.out = Teuchos::getFancyOStream(Teuchos::rcp(new Teuchos::oblackholestream()));
104 
105  //
106  // get the solver parameters
107  //
108  RCP<Teuchos::ParameterList> params = Teuchos::parameterList();
109  // default solver stack parameters
110  std::string xmlString(
111  " <ParameterList> \n"
112  " <Parameter name='tolerance' value='5e-15' type='double'/> \n"
113  " <Parameter name='verbose' value='1' type='int'/> \n"
114  " <Parameter name='kappa' value='100' type='double'/> \n"
115  " <Parameter name='size' value='100' type='int'/> \n"
116  " <Parameter name='numIters' value='100' type='int'/> \n"
117  " </ParameterList> \n"
118  );
119  Teuchos::updateParametersFromXmlString(xmlString,params.ptr());
120  if (xmlfile != "") Teuchos::updateParametersFromXmlFile(xmlfile,params.ptr());
121  // hand solver parameters to driver
122  driver.params = params;
123 
124  //
125  // run the driver
126  //
127  unsigned int old_cw;
128  fpu_fix_start(&old_cw);
129  platform.runUserCode(driver);
130  fpu_fix_end(&old_cw);
131 
132  //
133  // Print result
134  if (driver.testPassed) {
135  *driver.out << "End Result: TEST PASSED" << std::endl;
136  }
137 
138  return 0;
139 }
RCP< const Teuchos::Comm< int > > getComm() const
The Teuchos::Comm instance with which this object was created.
size_t global_size_t
Global size_t object.
static DefaultPlatformType & getDefaultPlatform()
Return the default platform.
A platform class for hybrid nodes.