Tpetra Matrix/Vector Services Version of the Day
RTIInlineCG_qd.cpp
00001 /*
00002 // @HEADER
00003 // ***********************************************************************
00004 // 
00005 //          Tpetra: Templated Linear Algebra Services Package
00006 //                 Copyright (2008) Sandia Corporation
00007 // 
00008 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00009 // the U.S. Government retains certain rights in this software.
00010 // 
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are
00013 // met:
00014 //
00015 // 1. Redistributions of source code must retain the above copyright
00016 // notice, this list of conditions and the following disclaimer.
00017 //
00018 // 2. Redistributions in binary form must reproduce the above copyright
00019 // notice, this list of conditions and the following disclaimer in the
00020 // documentation and/or other materials provided with the distribution.
00021 //
00022 // 3. Neither the name of the Corporation nor the names of the
00023 // contributors may be used to endorse or promote products derived from
00024 // this software without specific prior written permission.
00025 //
00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 //
00038 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00039 // 
00040 // ************************************************************************
00041 // @HEADER
00042 */
00043 
00044 #include "RTIInlineCG.hpp"
00045 #include <qd/qd_real.h>
00046 
00047 int main(int argc, char *argv[])
00048 {
00049   using Tpetra::global_size_t;
00050   using Teuchos::RCP;
00051   using Teuchos::rcp;
00052   using Teuchos::Comm;
00053   using Teuchos::ParameterList;
00054 
00055   // 
00056   // Get the communicator
00057   //
00058   Teuchos::oblackholestream blackhole;
00059   Teuchos::GlobalMPISession mpiSession(&argc,&argv,&blackhole);
00060   auto comm = Tpetra::DefaultPlatform::getDefaultPlatform().getComm();
00061   const int myImageID = comm->getRank();
00062 
00063   //
00064   // Get example parameters from command-line processor
00065   //  
00066   bool verbose = (myImageID==0);
00067   std::string xmlfile;
00068   std::string machineFile;
00069 
00070   Teuchos::CommandLineProcessor cmdp(false,true);
00071   cmdp.setOption("verbose","quiet",&verbose,"Print messages and results.");
00072   cmdp.setOption("param-file", &xmlfile,"XML file for solver parameters");
00073   cmdp.setOption("machine-file",&machineFile,"Filename for XML machine description file.");
00074   if (cmdp.parse(argc,argv) != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL) {
00075     return -1;
00076   }
00077 
00078   // 
00079   // read machine file and initialize platform
00080   // 
00081   RCP<Teuchos::ParameterList> machinePL = Teuchos::parameterList();
00082   std::string defaultMachine(
00083     " <ParameterList>                                                               "
00084     "   <ParameterList name='%1=0'>                                                 "
00085     "     <Parameter name='NodeType'     type='string' value='Kokkos::SerialNode'/> "
00086     "   </ParameterList>                                                            "
00087     " </ParameterList>                                                              "
00088   );
00089   Teuchos::updateParametersFromXmlString(defaultMachine,machinePL.getRawPtr());
00090   if (machineFile != "") Teuchos::updateParametersFromXmlFile(machineFile,machinePL.getRawPtr());
00091 
00092   // 
00093   // create the platform object
00094   // 
00095   Tpetra::HybridPlatform platform(comm,*machinePL);
00096 
00097   //
00098   // instantiate a driver on the scalar stack
00099   //
00100   CGDriver<qd_real> driver;
00101   // hand output stream to driver
00102   if (verbose) driver.out = Teuchos::getFancyOStream(Teuchos::rcp(&std::cout,false));
00103   else         driver.out = Teuchos::getFancyOStream(Teuchos::rcp(new Teuchos::oblackholestream()));
00104 
00105   //
00106   // get the solver parameters
00107   // 
00108   RCP<Teuchos::ParameterList> params = Teuchos::parameterList();
00109   // default solver stack parameters
00110   std::string xmlString(
00111     " <ParameterList>                                                  \n"
00112     "   <Parameter name='tolerance' value='5e-15' type='double'/>      \n"
00113     "   <Parameter name='verbose' value='1' type='int'/>               \n"
00114     "   <Parameter name='kappa' value='100' type='double'/>            \n"
00115     "   <Parameter name='size'  value='100' type='int'/>               \n"
00116     "   <Parameter name='numIters' value='100' type='int'/>            \n"
00117     " </ParameterList>                                                 \n"
00118   );
00119   Teuchos::updateParametersFromXmlString(xmlString,params.getRawPtr());
00120   if (xmlfile != "") Teuchos::updateParametersFromXmlFile(xmlfile,params.getRawPtr());
00121   // hand solver parameters to driver
00122   driver.params = params;
00123 
00124   // 
00125   // run the driver
00126   // 
00127   unsigned int old_cw;
00128   fpu_fix_start(&old_cw);
00129   platform.runUserCode(driver);
00130   fpu_fix_end(&old_cw);
00131 
00132   //
00133   // Print result
00134   if (driver.testPassed) {
00135     *driver.out << "End Result: TEST PASSED" << std::endl;
00136   }
00137 
00138   return 0;
00139 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines