Ifpack Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
test/SetParameters_LL/cxx_main.cpp
Go to the documentation of this file.
1 /*@HEADER
2 // ***********************************************************************
3 //
4 // Ifpack: Object-Oriented Algebraic Preconditioner Package
5 // Copyright (2002) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 //@HEADER
41 */
42 
43 // SetParameters Test routine
44 #include <Ifpack_ConfigDefs.h>
45 #include <Ifpack_IlukGraph.h>
46 #include <Ifpack_CrsRiluk.h>
47 #include <Ifpack_CrsIct.h>
48 #include <Ifpack_OverlapGraph.h>
49 
50 #include <Epetra_CombineMode.h>
51 #include <Epetra_CrsGraph.h>
52 #include <Epetra_CrsMatrix.h>
53 #include <Epetra_Map.h>
54 
55 #include <Teuchos_ParameterList.hpp>
56 
57 #include <ifp_parameters.h>
58 #include <Epetra_SerialComm.h>
59 
60 #ifdef HAVE_MPI
61 #include <mpi.h>
62 #include <Epetra_MpiComm.h>
63 #endif
64 
65 int main(int argc, char* argv[]) {
66  using std::cerr;
67  using std::cout;
68  using std::endl;
69 
70  //bool verbose = false; // used to set verbose false on non-root processors
71  bool verbose1 = false; // user's command-line argument
72 
73  int returnierr = 0;
74  //int size = 1;
75  //int rank = 0;
76 
77 #ifdef HAVE_MPI
78  MPI_Init(&argc, &argv);
79  Epetra_MpiComm Comm(MPI_COMM_WORLD);
80 #else
81  Epetra_SerialComm Comm;
82 #endif
83 
84  Ifpack::param_struct params;
86 
87  Teuchos::ParameterList paramlist;
88  paramlist.set("absolute_threshold", 44.0);
89  paramlist.set("level_fill", 2);
90  paramlist.set("LEVEL_OVERLAP", 2);
91  paramlist.set("relative_threshold", 1.e-2);
92  paramlist.set("fill_tolerance", 2.0);
93  paramlist.set("use_reciprocal", false);
94  paramlist.set("level_overlap", 2);
95  paramlist.set("overlap_mode", Add);
96 
97  Ifpack::set_parameters(paramlist, params);
98 
99  if (params.double_params[Ifpack::absolute_threshold] != 44.0) {
100  if (verbose1) {
101  cerr << "SetParameters test failed to correctly set absolute_threshold."<<endl;
102  }
103  return(-1);
104  }
105 
106  int i, local_n = 5;
107  int my_pid = Comm.MyPID();
108  int num_procs = Comm.NumProc();
109  int global_n = num_procs*local_n;
110 
111  Epetra_Map map(global_n, 0, Comm);
112  Epetra_CrsGraph graph(Copy, map, 1);
113  int first_global_row = my_pid*local_n;
114 
115  for(i=0; i<local_n; ++i) {
116  int row = first_global_row + i;
117  graph.InsertGlobalIndices(row, 1, &row);
118  }
119 
120  graph.FillComplete();
121 
122  Ifpack_IlukGraph ilukgraph(graph, 1,1);
123  Ifpack_CrsRiluk crsriluk(ilukgraph);
124  // MS // this was failing
125 #if 0
126  Ifpack_OverlapGraph overlapgraph(&graph, 1);
127 #endif
128 
129  Epetra_CrsMatrix A(Copy, graph);
130 
131  for(i=0; i<local_n; ++i) {
132  int row = first_global_row + i;
133  double val = 2.0;
134  A.SumIntoGlobalValues(row, 1, &val, &row);
135  }
136 
137  Ifpack_CrsIct crsict(A, 1.0, 1);
138 
139  ilukgraph.SetParameters(paramlist);
140 
141  int levelfill = ilukgraph.LevelFill();
142  if (levelfill != 2) {
143  cerr << "SetParameters test failed to correctly set level_fill."
144  << endl;
145  return(-1);
146  }
147 
148  int leveloverlap = ilukgraph.LevelOverlap();
149  if (leveloverlap != 2) {
150  cerr << "SetParameters test failed to correctly set level_overlap."
151  << endl;
152  return(-1);
153  }
154 
155  crsriluk.SetParameters(paramlist);
156 
157  double athresh = crsriluk.GetAbsoluteThreshold();
158  if (athresh != 44.0) {
159  cerr << "SetParameters test failed to correctly set absolute_threshold."
160  << endl;
161  return(-1);
162  }
163 
164  Epetra_CombineMode overlapmode = crsriluk.GetOverlapMode();
165  if (overlapmode != Add) {
166  cerr << "SetParameters test failed to correctly set overlapmode."
167  << endl;
168  return(-1);
169  }
170 
171  crsict.SetParameters(paramlist);
172 
173  double rthresh = crsict.GetRelativeThreshold();
174  if (rthresh != 1.e-2) {
175  cerr << "SetParameters test failed to correctly set relative_threshold."
176  << endl;
177  return(-1);
178  }
179 
180  overlapmode = crsict.GetOverlapMode();
181  if (overlapmode != Add) {
182  cerr << "SetParameters test failed to correctly set overlapmode."
183  << endl;
184  return(-1);
185  }
186 
187 #if 0
188  overlapgraph.SetParameters(paramlist);
189 
190  int overlaplevel = overlapgraph.OverlapLevel();
191  if (overlaplevel != 2) {
192  cerr << "SetParameters test failed to correctly set overlaplevel."
193  << endl;
194  return(-1);
195  }
196 #endif
197 
198  if (verbose1==true) {
199  cout << "********* Test passed **********" << endl;
200  }
201 
202 #ifdef HAVE_MPI
203  MPI_Finalize();
204 #endif
205 
206  return(returnierr);
207 }
208 
Ifpack_OverlapGraph: Constructs a graph for use with Ifpack preconditioners.
Ifpack_CrsRiluk: A class for constructing and using an incomplete lower/upper (ILU) factorization of ...
double double_params[FIRST_INT_PARAM]
Epetra_CombineMode GetOverlapMode()
Get overlap mode type.
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
int SetParameters(const Teuchos::ParameterList &parameterlist, bool cerr_warning_if_unused=false)
Set parameters using Teuchos::ParameterList object.
virtual int SumIntoGlobalValues(int GlobalRow, int NumEntries, const double *Values, const int *Indices)
Ifpack_IlukGraph: A class for constructing level filled graphs for use with ILU(k) class precondition...
int MyPID() const
int InsertGlobalIndices(int_type GlobalRow, int NumIndices, int_type *Indices)
virtual int LevelFill() const
Returns the level of fill used to construct this graph.
int SetParameters(const Teuchos::ParameterList &parameterlist, bool cerr_warning_if_unused=false)
Set parameters using a Teuchos::ParameterList object.
int main(int argc, char *argv[])
double GetAbsoluteThreshold()
Get absolute threshold value.
int SetParameters(const Teuchos::ParameterList &parameterlist, bool cerr_warning_if_unused=false)
Set parameters using a Teuchos::ParameterList object.
int NumProc() const
virtual int LevelOverlap() const
Returns the level of overlap used to construct this graph.
Epetra_CombineMode
void set_parameters(const Teuchos::ParameterList &parameterlist, param_struct &params, bool cerr_warning_if_unused)
int OverlapLevel() const
Returns the level of overlap used to create this graph.