Tpetra Matrix/Vector Services Version of the Day
MultiPrecExample_double_float.cpp
Go to the documentation of this file.
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 <Teuchos_CommandLineProcessor.hpp>
00045 #include <Teuchos_GlobalMPISession.hpp>
00046 #include <Teuchos_oblackholestream.hpp>
00047 #include <Teuchos_XMLParameterListHelpers.hpp>
00048 
00049 #include <Tpetra_DefaultPlatform.hpp>
00050 
00051 // no CXX11 on the GPU
00052 #undef HAVE_KOKKOSCLASSIC_THRUST
00053 #include <Tpetra_HybridPlatform.hpp>
00054 #include <TpetraExt_TypeStack.hpp>
00055 
00056 #include <iostream>
00057 
00058 #include "MultiPrecDriver.hpp"
00059 
00064 int main(int argc, char *argv[])
00065 {
00066   using Teuchos::RCP;
00067   using Teuchos::rcp;
00068   using Teuchos::Comm;
00069   using Teuchos::ParameterList;
00070 
00071   // 
00072   // Get the communicator
00073   //
00074   Teuchos::oblackholestream blackhole;
00075   Teuchos::GlobalMPISession mpiSession(&argc,&argv,&blackhole);
00076   auto comm = Tpetra::DefaultPlatform::getDefaultPlatform().getComm();
00077   const int myImageID = comm->getRank();
00078 
00079   //
00080   // Get example parameters from command-line processor
00081   //  
00082   bool verbose = (myImageID==0);
00083   bool unfused = false;
00084   std::string matfile;
00085   std::string xmlfile;
00086   std::string machineFile;
00087   Teuchos::CommandLineProcessor cmdp(false,true);
00088   cmdp.setOption("verbose","quiet",&verbose,"Print messages and results.");
00089   cmdp.setOption("matrix-file",&matfile,"Filename for matrix");
00090   cmdp.setOption("param-file", &xmlfile,"XML file for solver parameters");
00091   cmdp.setOption("machine-file",&machineFile,"Filename for XML machine description file.");
00092   cmdp.setOption("unfused","no-unfused",&unfused,"Test unfused iteration.");
00093   if (cmdp.parse(argc,argv) != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL) {
00094     return -1;
00095   }
00096 
00097   // 
00098   // read machine file and initialize platform
00099   // 
00100   RCP<Teuchos::ParameterList> machinePL = Teuchos::parameterList();
00101   std::string defaultMachine(
00102     " <ParameterList>                                                               "
00103     "   <ParameterList name='%1=0'>                                                 "
00104     "     <Parameter name='NodeType'     type='string' value='KokkosClassic::SerialNode'/> "
00105     "   </ParameterList>                                                            "
00106     " </ParameterList>                                                              "
00107   );
00108   Teuchos::updateParametersFromXmlString(defaultMachine,machinePL.ptr());
00109   if (machineFile != "") Teuchos::updateParametersFromXmlFile(machineFile,machinePL.ptr());
00110 
00111   // 
00112   // create the platform object
00113   // 
00114   Tpetra::HybridPlatform platform(comm,*machinePL);
00115 
00116   // 
00117   // Define the type stack
00118   // 
00119   TPETRAEXT_TYPESTACK2(MPStack, double, float)
00120 
00121   //
00122   // instantiate a driver on the scalar stack
00123   //
00124   MultiPrecDriver<MPStack> driver;
00125   // hand output stream to driver
00126   if (verbose) driver.out = Teuchos::getFancyOStream(Teuchos::rcp(&std::cout,false));
00127   else         driver.out = Teuchos::getFancyOStream(Teuchos::rcp(new Teuchos::oblackholestream()));
00128   // hand matrix file to driver
00129   driver.matrixFile = matfile;
00130   // other params
00131   driver.unfusedTest = unfused;
00132 
00133   //
00134   // get the solver parameters
00135   // 
00136   RCP<Teuchos::ParameterList> params = Teuchos::parameterList();
00137   // default solver stack parameters
00138   std::string xmlString(
00139     " <ParameterList>                                                    \n"
00140     "   <Parameter name='tolerance' value='1e-15' type='double'/>        \n"
00141     "   <Parameter name='verbose' value='2' type='int'/>                 \n"
00142     "   <ParameterList name='child'>                                     \n"
00143     "     <Parameter name='tolerance' value='1e-7' type='double'/>       \n"
00144     "     <Parameter name='verbose' value='1' type='int'/>               \n"
00145     "     <Parameter name='Extract Diagonal' value='true' type='bool'/>  \n" 
00146     "   </ParameterList>                                                 \n"
00147     " </ParameterList>                                                   \n"
00148   );
00149   Teuchos::updateParametersFromXmlString(xmlString,params.ptr());
00150   if (xmlfile != "") Teuchos::updateParametersFromXmlFile(xmlfile,params.ptr());
00151   // hand solver parameters to driver
00152   driver.params = params;
00153 
00154   // 
00155   // run the driver
00156   // 
00157   platform.runUserCode(driver);
00158 
00159   //
00160   // Print result
00161   if (driver.testPassed) {
00162     *driver.out << "End Result: TEST PASSED" << std::endl;
00163   }
00164 
00165   return 0;
00166 }
00167 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines