ExampleNLPFirstOrderMain.cpp

Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
00005 //                  Copyright (2003) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 //
00029 
00030 #include <assert.h>
00031 
00032 #include <fstream>
00033 #include <fstream>
00034 #include <iostream>
00035 #include <iomanip>
00036 
00037 #include "NLPInterfacePack_ExampleNLPFirstOrderRun.hpp"
00038 #include "AbstractLinAlgPack_exampleNLPDiagSetup.hpp"
00039 #include "AbstractLinAlgPack_VectorSpace.hpp"
00040 #include "Teuchos_GlobalMPISession.hpp"
00041 #include "Teuchos_Workspace.hpp"
00042 #include "Teuchos_oblackholestream.hpp"
00043 
00044 int main(int argc, char* argv[]) {
00045 
00046   using std::endl;
00047   using std::setw;
00048   namespace mmp = MemMngPack;
00049   using Teuchos::RCP;
00050   typedef AbstractLinAlgPack::size_type size_type;
00051   typedef AbstractLinAlgPack::value_type value_type;
00052   namespace NLPIP = NLPInterfacePack;
00053   namespace rsqp = MoochoPack;
00054   using rsqp::MoochoSolver;
00055   using AbstractLinAlgPack::VectorSpace;
00056   using Teuchos::GlobalMPISession;
00057 
00058   GlobalMPISession mpiSession(&argc, &argv);
00059 
00060   // Get an idea of what processors we have.
00061   const int proc_rank = GlobalMPISession::getRank();
00062 
00063   // Define program return values
00064   const int
00065     PROG_SUCCESS        =  0,
00066     PROG_NLP_TEST_ERR     = -1,
00067     PROG_EXCEPTION        = -2,
00068     PROG_MAX_ITER_EXEEDED   = -3,
00069     PROG_MAX_TIME_EXEEDED   = -4;
00070 
00071   int prog_return = PROG_SUCCESS;
00072 
00073   // Set the output stream
00074   std::ostream &out  = std::cout;
00075   std::ostream &eout = std::cerr;
00076   Teuchos::oblackholestream  blackhole;
00077 
00078   try {
00079   
00080     //
00081     // Initialize stuff
00082     //
00083 
00084     int n;
00085     value_type xo;
00086     bool has_bounds;
00087     bool dep_bounded;
00088     
00089     VectorSpace::space_ptr_t    vec_space;
00090     const int err = AbstractLinAlgPack::exampleNLPDiagSetup(
00091       argc, argv, MPI_COMM_WORLD, &vec_space, &n, &xo, &has_bounds, &dep_bounded);
00092     if(err) return err;
00093     
00094 
00095     // Create and test the NLP using this vector space object
00096     const MoochoSolver::ESolutionStatus
00097       solve_return = NLPIP::ExampleNLPFirstOrderRun(
00098         *vec_space, xo, has_bounds, dep_bounded
00099         ,proc_rank == 0 ? &out  : &blackhole  // console_out
00100         ,proc_rank == 0 ? &eout : &blackhole  // error_out
00101         ,proc_rank == 0 ? false : true        // throw_solve_exception
00102         ,proc_rank == 0 ? NULL  : &blackhole  // algo_out
00103         ,proc_rank == 0 ? NULL  : &blackhole  // summary_out
00104         ,proc_rank == 0 ? NULL  : &blackhole  // journal_out
00105         );
00106     
00107     switch(solve_return) {
00108       case MoochoSolver::SOLVE_RETURN_SOLVED:
00109         prog_return = PROG_SUCCESS;
00110         break;
00111       case MoochoSolver::SOLVE_RETURN_MAX_ITER:
00112         prog_return = PROG_MAX_ITER_EXEEDED;
00113         break;
00114       case MoochoSolver::SOLVE_RETURN_MAX_RUN_TIME:
00115         prog_return = PROG_MAX_TIME_EXEEDED;
00116         break;
00117       case MoochoSolver::SOLVE_RETURN_NLP_TEST_FAILED:
00118         prog_return = PROG_NLP_TEST_ERR;
00119         break;
00120       case MoochoSolver::SOLVE_RETURN_EXCEPTION:
00121         prog_return = PROG_EXCEPTION;
00122         break;
00123       default:
00124         TEST_FOR_EXCEPT(true);
00125     }
00126     
00127   } // end try
00128   catch(const std::exception& excpt) {
00129     eout << "\nCaught a std::exception on process " << proc_rank<< ": " << excpt.what() << endl;
00130     prog_return = PROG_EXCEPTION;
00131   }
00132   catch(...) {
00133     eout << "\nCaught an unknown exception on process " << proc_rank<< "\n";
00134     prog_return = PROG_EXCEPTION;
00135   }
00136 
00137   return prog_return;
00138 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Wed Apr 13 10:10:59 2011 for MOOCHO (Single Doxygen Collection) by  doxygen 1.6.3