EpetraExt Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
test/Composite/cxx_main.cpp
Go to the documentation of this file.
1 //@HEADER
2 // ***********************************************************************
3 //
4 // EpetraExt: Epetra Extended - Linear Algebra Services Package
5 // Copyright (2011) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
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 // Transform_Composite Test routine
43 
44 #include <EpetraExt_ConfigDefs.h>
45 #include "EpetraExt_Version.h"
46 
47 #include "Epetra_SerialComm.h"
48 #include "Epetra_Time.h"
49 
50 #ifdef EPETRA_MPI
51 #include "Epetra_MpiComm.h"
52 #include <mpi.h>
53 #endif
54 
55 #include "Epetra_Map.h"
56 #include "Epetra_CrsGraph.h"
57 #include "Epetra_CrsMatrix.h"
58 #include "Epetra_Vector.h"
59 #include "Epetra_LinearProblem.h"
60 
65 //#include "EpetraExt_CrsSingletonFilter_LinearProblem.h"
66 
67 #ifdef EPETRA_MPI
69 #endif
70 
71 #include "../epetra_test_err.h"
72 
73 int main(int argc, char *argv[]) {
74 
75  int i, ierr=0, returnierr=0;
76 
77 #ifdef EPETRA_MPI
78 
79  // Initialize MPI
80 
81  MPI_Init(&argc,&argv);
82  int size, rank; // Number of MPI processes, My process ID
83 
84  MPI_Comm_size(MPI_COMM_WORLD, &size);
85  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
86 
87 #else
88 
89  int size = 1; // Serial case (not using MPI)
90  int rank = 0;
91 
92 #endif
93 
94  bool verbose = false;
95 
96  // Check if we should print results to standard out
97  if (argc>1) if (argv[1][0]=='-' && argv[1][1]=='v') verbose = true;
98 
99 
100 #ifdef EPETRA_MPI
101  Epetra_MpiComm Comm(MPI_COMM_WORLD);
102 #else
103  Epetra_SerialComm Comm;
104 #endif
105  if (!verbose) Comm.SetTracebackMode(0); // This should shut down any error traceback reporting
106 
107  int MyPID = Comm.MyPID();
108  int NumProc = Comm.NumProc();
109 
110  bool verbose1 = verbose;
111  if( verbose ) verbose = (MyPID==0);
112 
113  if ( verbose )
114  cout << EpetraExt::EpetraExt_Version() << endl << endl;
115 
116  Comm.Barrier();
117 
118  if( verbose1 ) cout << Comm << endl << flush;
119 
120  int NumMyElements = 3;
121  int NumGlobalElements = NumProc*NumMyElements;
122  int IndexBase = 0;
123 
124  Epetra_Map Map( NumGlobalElements, NumMyElements, 0, Comm );
125  if( verbose1 ) cout << Map << endl << flush;
126 
127  Epetra_CrsGraph Graph( Copy, Map, 1 );
128 
129  int PIDFac = 10*MyPID;
130  int index = PIDFac+2;
131  Graph.InsertGlobalIndices( PIDFac+0, 1, &index );
132  index = PIDFac+0;
133  Graph.InsertGlobalIndices( PIDFac+1, 1, &index );
134  index = PIDFac+1;
135  Graph.InsertGlobalIndices( PIDFac+2, 1, &index );
136 
137  Graph.FillComplete();
138  if( verbose1 ) cout << Graph << endl << flush;
139 
141 
142 // EpetraExt::LinearProblem_CrsSingletonFilter CSF_LPTrans;
143 // EpetraExt::SameTypeTransform<Epetra_LinearProblem> * CSF_LPTransPtr = &CSF_LPTrans;
144 // CompTrans.addTransform( CSF_LPTransPtr );
145 
148  CompTrans.addTransform( RI_LPTrans );
149 
150  EpetraExt::CrsGraph_SymmRCM RCM_Trans;
152  RCM_LPTrans = new EpetraExt::LinearProblem_GraphTrans( RCM_Trans );
153  CompTrans.addTransform( RCM_LPTrans );
154 
155 #ifdef EPETRA_MPI
156  EpetraExt::CrsGraph_Overlap Overlap_Trans(1);
158  Overlap_LPTrans = new EpetraExt::LinearProblem_GraphTrans( Overlap_Trans );
159  CompTrans.addTransform( Overlap_LPTrans );
160 #endif
161 
162  Epetra_CrsMatrix Matrix( Copy, Graph );
163  index = 2;
164  double val = 2;
165  Matrix.ReplaceMyValues( 0, 1, &val, &index );
166  index = 0;
167  val = 0;
168  Matrix.ReplaceMyValues( 1, 1, &val, &index );
169  index = 1;
170  val = 1;
171  Matrix.ReplaceMyValues( 2, 1, &val, &index);
172 
173  vector<double> valA(3);
174  valA[0]=0; valA[1]=1; valA[2]=2;
175  Epetra_BlockMap & MapRef = Map;
176  Epetra_Vector LHS( Copy, MapRef, &valA[0] );
177  Epetra_Vector RHS( Copy, MapRef, &valA[0] );
178 
179  Epetra_LinearProblem Prob( &Matrix, &LHS, &RHS );
180 
181  Epetra_LinearProblem & NewProb = CompTrans( Prob );
182 
183  CompTrans.fwd();
184  CompTrans.rvs();
185 
186 #ifdef EPETRA_MPI
187  MPI_Finalize();
188 #endif
189 
190  return ierr;
191 }
192 
Composition Class for Epetra Transform SameType Operators.
virtual bool fwd()
Forward Data Transfer.
Generates the symmetric RCM reordered version of a Epetra_CrsGraph.
std::string EpetraExt_Version()
Given an input Epetra_CrsGraph, a &quot;overlapped&quot; Epetra_CrsGraph is generated including rows associated...
int MyPID() const
int InsertGlobalIndices(int_type GlobalRow, int NumIndices, int_type *Indices)
void addTransform(TransformTypePtr new_trans)
Transform Addition.
int main(int argc, char **argv)
Definition: HDF5_IO.cpp:67
EpetraExt::LinearProblem_GraphTrans: Adaptation of a Epetra_CrsGraph Transform to a Epetra_LinearProb...
Given and input Epetra_LinearProblem, a &quot;reindexed&quot; version will be returned using the given NewRowMa...
int NumProc() const
void Barrier() const
int ReplaceMyValues(int MyRow, int NumEntries, const double *Values, const int *Indices)