MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AbstractLinAlgPack_exampleNLPDiagSetup.cpp
Go to the documentation of this file.
1 /*
2 // @HEADER
3 // ***********************************************************************
4 //
5 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
6 // Copyright (2003) Sandia Corporation
7 //
8 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
9 // license for use of this work by or on behalf of the U.S. Government.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
39 //
40 // ***********************************************************************
41 // @HEADER
42 */
43 
44 // ////////////////////////////////////////////////////////////////////
45 // AbstractLinAlgPack_exampleNLPDiagSetup.hpp
46 
47 #include <assert.h>
48 
49 #include <fstream>
50 #include <fstream>
51 #include <iostream>
52 #include <iomanip>
53 
58 
59 #ifdef USE_EPETRA_THYRA
60 
61 #include "TSFCoreSerialVectorSpaceStd.hpp"
62 #include "AbstractLinAlgPack_VectorSpaceTSFCore.hpp"
63 #include "TSFCoreEpetraVectorSpace.hpp"
64 #include "Epetra_Map.h"
65 #ifdef HAVE_MPI
66 #include "Epetra_MpiComm.h"
67 #else
68 #include "Epetra_SerialComm.h"
69 #endif
70 
71 #endif // USE_EPETRA_THYRA
72 
75  int argc, char* argv[], MPI_Comm comm
77  ,int *n, value_type *xo, bool *has_bounds, bool *dep_bounded
78  )
79 {
80 
81  using std::endl;
82  using std::setw;
83  namespace mmp = MemMngPack;
84  using Teuchos::RCP;
87 
91 
93 
94  // Get an idea of what processors we have.
95  int num_proc, proc_rank;
96  MPI_Comm_size( comm, &num_proc );
97  MPI_Comm_rank( comm, &proc_rank );
98 
99  // Get the size of the problem to solve
100  *n = 4;
101  // Get the starting point
102  *xo = 0.1;
103  // Determine if the NLP has bounds or not.
104  *has_bounds = false;
105  // Make the dependent or independent variables bounded.
106  *dep_bounded = true;
107 #ifdef USE_EPETRA_THYRA
108  // Serial or parallel?
109  bool in_parallel = false;
110  // Use TSF?
111  bool use_tsf = false;
112 #endif // USE_EPETRA_THYRA
113 
114  CommandLineProcessor command_line_processor;
115 
116  command_line_processor.setOption( "n", n, "Global number of dependent (and independent) variables" );
117  command_line_processor.setOption( "xo", xo, "Initial guess of the solution" );
118  command_line_processor.setOption(
119  "has-bounds", "no-has-bounds", has_bounds
120  ,"Determine if the NLP has bounds or not" );
121  command_line_processor.setOption(
122  "dep-bounded", "indep-bounded", dep_bounded
123  ,"Determine if the dependent or independent variables are bounded" );
124 #ifdef USE_EPETRA_THYRA
125  command_line_processor.setOption(
126  "in-parallel", "in-serial", &in_parallel
127  ,"Determine if computations are performed in parallel or not" );
128  command_line_processor.setOption(
129  "use-tsf", "no-use-tsf", &use_tsf
130  ,"Determine whether to use TSF vectors or not" );
131 #endif // USE_EPETRA_THYRA
132 
133  CommandLineProcessor::EParseCommandLineReturn
134  parse_return = command_line_processor.parse(argc,argv,&std::cerr);
135 
136  if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL )
137  return parse_return;
138 
139  // Create the vector space object to use.
140 
141 #ifdef USE_EPETRA_THYRA
142 
143  using AbstractLinAlgPack::VectorSpaceTSFCore;
144 
145  if(in_parallel) {
146  //
147  // Use parallel vectors!
148  //
150 #ifdef HAVE_MPI
152 #else
153  comm = Teuchos::rcp(new Epetra_SerialComm());
154 #endif
155  Teuchos::RCP<Epetra_Map> map = Teuchos::rcp(new Epetra_Map(*n,0,*comm));
156  Teuchos::set_extra_data(comm, "comm", Teuchos::outArg(map));
157  *vec_space = Teuchos::rcp(new VectorSpaceTSFCore(Teuchos::rcp(new TSFCore::EpetraVectorSpace(map))));
158  }
159  else {
160  //
161  // Use serial vectors
162  //
163  if( use_tsf ) {
164  *vec_space = Teuchos::rcp(new VectorSpaceTSFCore(Teuchos::rcp(new TSFCore::SerialVectorSpaceStd<value_type>(*n))));
165  }
166  else {
168  }
169  }
170 
171 #else // USE_EPETRA_THYRA
172 
174 
175 #endif // USE_EPETRA_THYRA
176 
177  return 0;
178 }
AbstractLinAlgPack::size_type size_type
Abstract interface for immutable, finite dimensional, coordinate vectors {abstract}.
int MPI_Comm_size(MPI_Comm comm, int *size)
Definition: RTOp_mpi.c:71
int MPI_Comm_rank(MPI_Comm comm, int *rank)
Definition: RTOp_mpi.c:77
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
int MPI_Comm
Definition: RTOp_mpi.h:67
int exampleNLPDiagSetup(int argc, char *argv[], MPI_Comm comm, Teuchos::RCP< const VectorSpace > *vec_space, int *n, value_type *xo, bool *has_bounds, bool *dep_bounded)
Create a vector space given the input arguments argc, argv[] and an MPI communicator.
Abstract interface for objects that represent a space for mutable coordinate vectors.
AbstractLinAlgPack::value_type value_type
Abstract interface for mutable coordinate vectors {abstract}.
Subclass for serial vector space objects that create VectorMutableDense vector and MultiVectorMutable...
#define MPI_COMM_WORLD
Definition: RTOp_mpi.h:68