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