MOOCHO (Single Doxygen Collection) Version of the Day
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 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00038 // 
00039 // ***********************************************************************
00040 // @HEADER
00041 //
00042 
00043 #include <assert.h>
00044 
00045 #include <fstream>
00046 #include <fstream>
00047 #include <iostream>
00048 #include <iomanip>
00049 
00050 #include "NLPInterfacePack_ExampleNLPDirectRun.hpp"
00051 #include "AbstractLinAlgPack_exampleNLPDiagSetup.hpp"
00052 #include "AbstractLinAlgPack_VectorSpace.hpp"
00053 #include "Teuchos_Workspace.hpp"
00054 #include "Teuchos_oblackholestream.hpp"
00055 
00056 int main( int argc, char* argv[] ) {
00057 
00058   using std::endl;
00059   using std::setw;
00060   namespace mmp = MemMngPack;
00061   using Teuchos::RCP;
00062   typedef AbstractLinAlgPack::size_type size_type;
00063   typedef AbstractLinAlgPack::value_type value_type;
00064   namespace NLPIP = NLPInterfacePack;
00065   namespace rsqp = MoochoPack;
00066   using rsqp::MoochoSolver;
00067 
00068   using AbstractLinAlgPack::VectorSpace;
00069 
00070   using Teuchos::Workspace;
00071   Teuchos::WorkspaceStore* wss = Teuchos::get_default_workspace_store().get();
00072 
00073   int err = 0;
00074 
00075 /*
00076   // Print out the input arguments
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   // Get an idea of what processors we have.
00083   MPI_Init(&argc,&argv);
00084   int num_proc, proc_rank;
00085   MPI_Comm_size( MPI_COMM_WORLD, &num_proc );
00086   MPI_Comm_rank( MPI_COMM_WORLD, &proc_rank );
00087 /*
00088   // Print out the input arguments
00089   printf("\nproc_rank = %d\n",proc_rank);
00090   printf("argc = %d\n",argc);
00091   {for( int i = 0; i < argc; ++i) {
00092     printf("argv[%d] = %s\n",i,argv[i]);
00093   }}
00094 */
00095 
00096   // Define program return values
00097   const int
00098     PROG_SUCCESS        =  0,
00099     PROG_NLP_TEST_ERR     = -1,
00100     PROG_EXCEPTION        = -2,
00101     PROG_MAX_ITER_EXEEDED   = -3,
00102     PROG_MAX_TIME_EXEEDED   = -4;
00103 
00104   int prog_return = PROG_SUCCESS;
00105 
00106   // Set the output stream
00107   std::ostream &out  = std::cout;
00108   std::ostream &eout = std::cerr;
00109   Teuchos::oblackholestream  blackhole;
00110 
00111   try {
00112   
00113     //
00114     // Initialize stuff
00115     //
00116 
00117     size_type n;
00118     value_type xo;
00119     bool has_bounds;
00120     bool dep_bounded;
00121     
00122     VectorSpace::space_ptr_t    vec_space;
00123     const int err = AbstractLinAlgPack::exampleNLPDiagSetup(argc,argv,MPI_COMM_WORLD,&vec_space,&n,&xo,&has_bounds,&dep_bounded);
00124     if(err) return err;
00125     
00126     // Create and test the NLP using this vector space object
00127     const MoochoSolver::ESolutionStatus
00128       solve_return = NLPIP::ExampleNLPDirectRun(
00129         *vec_space, xo, has_bounds, dep_bounded
00130         ,proc_rank == 0 ? &out  : &blackhole  // console_out
00131         ,proc_rank == 0 ? &eout : &blackhole  // error_out
00132         ,proc_rank == 0 ? false : true        // throw_solve_exception
00133         ,proc_rank == 0 ? NULL  : &blackhole  // algo_out
00134         ,proc_rank == 0 ? NULL  : &blackhole  // summary_out
00135         ,proc_rank == 0 ? NULL  : &blackhole  // journal_out
00136         );
00137     
00138     switch(solve_return) {
00139       case MoochoSolver::SOLVE_RETURN_SOLVED:
00140         prog_return = PROG_SUCCESS;
00141         break;
00142       case MoochoSolver::SOLVE_RETURN_MAX_ITER:
00143         prog_return = PROG_MAX_ITER_EXEEDED;
00144         break;
00145       case MoochoSolver::SOLVE_RETURN_MAX_RUN_TIME:
00146         prog_return = PROG_MAX_TIME_EXEEDED;
00147         break;
00148       case MoochoSolver::SOLVE_RETURN_NLP_TEST_FAILED:
00149         prog_return = PROG_NLP_TEST_ERR;
00150         break;
00151       case MoochoSolver::SOLVE_RETURN_EXCEPTION:
00152         prog_return = PROG_EXCEPTION;
00153         break;
00154       default:
00155         TEUCHOS_TEST_FOR_EXCEPT(true);
00156     }
00157     
00158   } // end try
00159   catch(const std::exception& excpt) {
00160     eout << "\nCaught a std::exception on process " << proc_rank<< ": " << excpt.what() << endl;
00161     prog_return = PROG_EXCEPTION;
00162   }
00163   catch(...) {
00164     eout << "\nCaught an unknown exception on process " << proc_rank<< "\n";
00165     prog_return = PROG_EXCEPTION;
00166   }
00167 
00168    MPI_Finalize();
00169 
00170   return prog_return;
00171 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines