Tpetra Matrix/Vector Services Version of the Day
MultiPrecExample_qd_dd.cpp
00001 #include <Teuchos_CommandLineProcessor.hpp>
00002 #include <Teuchos_GlobalMPISession.hpp>
00003 #include <Teuchos_oblackholestream.hpp>
00004 #include <Teuchos_XMLParameterListHelpers.hpp>
00005 
00006 #include <Tpetra_DefaultPlatform.hpp>
00007 #include <Tpetra_HybridPlatform.hpp>
00008 #include <TpetraExt_TypeStack.hpp>
00009 
00010 #include <iostream>
00011 
00012 #include <qd/qd_real.h>
00013 
00014 #include "MultiPrecDriver.hpp"
00015 
00020 int main(int argc, char *argv[])
00021 {
00022   using Teuchos::RCP;
00023   using Teuchos::rcp;
00024   using Teuchos::Comm;
00025   using Teuchos::ParameterList;
00026 
00027   // 
00028   // Get the communicator
00029   //
00030   Teuchos::oblackholestream blackhole;
00031   Teuchos::GlobalMPISession mpiSession(&argc,&argv,&blackhole);
00032   auto comm = Tpetra::DefaultPlatform::getDefaultPlatform().getComm();
00033   const int myImageID = comm->getRank();
00034 
00035   //
00036   // Get example parameters from command-line processor
00037   //  
00038   bool verbose = (myImageID==0);
00039   bool unfused = false;
00040   std::string matfile;
00041   std::string xmlfile;
00042   std::string machineFile;
00043   Teuchos::CommandLineProcessor cmdp(false,true);
00044   cmdp.setOption("verbose","quiet",&verbose,"Print messages and results.");
00045   cmdp.setOption("matrix-file",&matfile,"Filename for matrix");
00046   cmdp.setOption("param-file", &xmlfile,"XML file for solver parameters");
00047   cmdp.setOption("machine-file",&machineFile,"Filename for XML machine description file.");
00048   cmdp.setOption("unfused","no-unfused",&unfused,"Test unfused iteration.");
00049   if (cmdp.parse(argc,argv) != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL) {
00050     return -1;
00051   }
00052 
00053   // 
00054   // read machine file and initialize platform
00055   // 
00056   RCP<Teuchos::ParameterList> machinePL = Teuchos::parameterList();
00057   std::string defaultMachine(
00058     " <ParameterList>                                                               "
00059     "   <ParameterList name='%1=0'>                                                 "
00060     "     <Parameter name='NodeType'     type='string' value='Kokkos::SerialNode'/> "
00061     "   </ParameterList>                                                            "
00062     " </ParameterList>                                                              "
00063   );
00064   Teuchos::updateParametersFromXmlString(defaultMachine,machinePL.getRawPtr());
00065   if (machineFile != "") Teuchos::updateParametersFromXmlFile(machineFile,machinePL.getRawPtr());
00066 
00067   // 
00068   // create the platform object
00069   // 
00070   Tpetra::HybridPlatform platform(comm,*machinePL);
00071 
00072   // 
00073   // Define the type stack
00074   // 
00075   TPETRAEXT_TYPESTACK2(MPStack, qd_real, dd_real )
00076 
00077   //
00078   // instantiate a driver on the scalar stack
00079   //
00080   MultiPrecDriver<MPStack> driver;
00081   // hand output stream to driver
00082   if (verbose) driver.out = Teuchos::getFancyOStream(Teuchos::rcp(&std::cout,false));
00083   else         driver.out = Teuchos::getFancyOStream(Teuchos::rcp(new Teuchos::oblackholestream()));
00084   // hand matrix file to driver
00085   driver.matrixFile = matfile;
00086   // other params
00087   driver.unfusedTest = unfused;
00088 
00089   //
00090   // get the solver parameters
00091   // 
00092   RCP<Teuchos::ParameterList> params = Teuchos::parameterList();
00093   // default solver stack parameters
00094   std::string xmlString(
00095     " <ParameterList>                                                       \n"
00096     "   <Parameter name='tolerance' value='1e-60' type='double'/>           \n"
00097     "   <Parameter name='verbose' value='2' type='int'/>                    \n"
00098     "   <ParameterList name='child'>                                        \n"
00099     "     <Parameter name='tolerance' value='1e-28' type='double'/>         \n"
00100     "     <Parameter name='verbose' value='2' type='int'/>                  \n"
00101     "     <Parameter name='Extract Diagonal' value='true' type='bool'/>     \n"
00102     "   </ParameterList>                                                    \n"
00103     " </ParameterList>                                                      \n"
00104   );
00105   Teuchos::updateParametersFromXmlString(xmlString,params.getRawPtr());
00106   if (xmlfile != "") Teuchos::updateParametersFromXmlFile(xmlfile,params.getRawPtr());
00107   // hand solver parameters to driver
00108   driver.params = params;
00109 
00110   // 
00111   // run the driver
00112   // 
00113   platform.runUserCode(driver);
00114 
00115   //
00116   // Print result
00117   if (driver.testPassed) {
00118     *driver.out << "End Result: TEST PASSED" << std::endl;
00119   }
00120 
00121   return 0;
00122 }
00123 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines