ExampleNLPDirectMain.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_ExampleNLPDirectRun.hpp"
00038 #include "AbstractLinAlgPack_exampleNLPDiagSetup.hpp"
00039 #include "AbstractLinAlgPack_VectorSpace.hpp"
00040 #include "Teuchos_Workspace.hpp"
00041 #include "Teuchos_oblackholestream.hpp"
00042 
00043 int main( int argc, char* argv[] ) {
00044 
00045   using std::endl;
00046   using std::setw;
00047   namespace mmp = MemMngPack;
00048   using Teuchos::RCP;
00049   typedef AbstractLinAlgPack::size_type size_type;
00050   typedef AbstractLinAlgPack::value_type value_type;
00051   namespace NLPIP = NLPInterfacePack;
00052   namespace rsqp = MoochoPack;
00053   using rsqp::MoochoSolver;
00054 
00055   using AbstractLinAlgPack::VectorSpace;
00056 
00057   using Teuchos::Workspace;
00058   Teuchos::WorkspaceStore* wss = Teuchos::get_default_workspace_store().get();
00059 
00060   int err = 0;
00061 
00062 /*
00063   // Print out the input arguments
00064   printf("argc = %d\n",argc);
00065   {for( int i = 0; i < argc; ++i) {
00066     printf("argv[%d] = %s\n",i,argv[i]);
00067   }}
00068 */
00069   // Get an idea of what processors we have.
00070   MPI_Init(&argc,&argv);
00071   int num_proc, proc_rank;
00072   MPI_Comm_size( MPI_COMM_WORLD, &num_proc );
00073   MPI_Comm_rank( MPI_COMM_WORLD, &proc_rank );
00074 /*
00075   // Print out the input arguments
00076   printf("\nproc_rank = %d\n",proc_rank);
00077   printf("argc = %d\n",argc);
00078   {for( int i = 0; i < argc; ++i) {
00079     printf("argv[%d] = %s\n",i,argv[i]);
00080   }}
00081 */
00082 
00083   // Define program return values
00084   const int
00085     PROG_SUCCESS        =  0,
00086     PROG_NLP_TEST_ERR     = -1,
00087     PROG_EXCEPTION        = -2,
00088     PROG_MAX_ITER_EXEEDED   = -3,
00089     PROG_MAX_TIME_EXEEDED   = -4;
00090 
00091   int prog_return = PROG_SUCCESS;
00092 
00093   // Set the output stream
00094   std::ostream &out  = std::cout;
00095   std::ostream &eout = std::cerr;
00096   Teuchos::oblackholestream  blackhole;
00097 
00098   try {
00099   
00100     //
00101     // Initialize stuff
00102     //
00103 
00104     size_type n;
00105     value_type xo;
00106     bool has_bounds;
00107     bool dep_bounded;
00108     
00109     VectorSpace::space_ptr_t    vec_space;
00110     const int err = AbstractLinAlgPack::exampleNLPDiagSetup(argc,argv,MPI_COMM_WORLD,&vec_space,&n,&xo,&has_bounds,&dep_bounded);
00111     if(err) return err;
00112     
00113     // Create and test the NLP using this vector space object
00114     const MoochoSolver::ESolutionStatus
00115       solve_return = NLPIP::ExampleNLPDirectRun(
00116         *vec_space, xo, has_bounds, dep_bounded
00117         ,proc_rank == 0 ? &out  : &blackhole  // console_out
00118         ,proc_rank == 0 ? &eout : &blackhole  // error_out
00119         ,proc_rank == 0 ? false : true        // throw_solve_exception
00120         ,proc_rank == 0 ? NULL  : &blackhole  // algo_out
00121         ,proc_rank == 0 ? NULL  : &blackhole  // summary_out
00122         ,proc_rank == 0 ? NULL  : &blackhole  // journal_out
00123         );
00124     
00125     switch(solve_return) {
00126       case MoochoSolver::SOLVE_RETURN_SOLVED:
00127         prog_return = PROG_SUCCESS;
00128         break;
00129       case MoochoSolver::SOLVE_RETURN_MAX_ITER:
00130         prog_return = PROG_MAX_ITER_EXEEDED;
00131         break;
00132       case MoochoSolver::SOLVE_RETURN_MAX_RUN_TIME:
00133         prog_return = PROG_MAX_TIME_EXEEDED;
00134         break;
00135       case MoochoSolver::SOLVE_RETURN_NLP_TEST_FAILED:
00136         prog_return = PROG_NLP_TEST_ERR;
00137         break;
00138       case MoochoSolver::SOLVE_RETURN_EXCEPTION:
00139         prog_return = PROG_EXCEPTION;
00140         break;
00141       default:
00142         TEST_FOR_EXCEPT(true);
00143     }
00144     
00145   } // end try
00146   catch(const std::exception& excpt) {
00147     eout << "\nCaught a std::exception on process " << proc_rank<< ": " << excpt.what() << endl;
00148     prog_return = PROG_EXCEPTION;
00149   }
00150   catch(...) {
00151     eout << "\nCaught an unknown exception on process " << proc_rank<< "\n";
00152     prog_return = PROG_EXCEPTION;
00153   }
00154 
00155    MPI_Finalize();
00156 
00157   return prog_return;
00158 }
 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