Epetra Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IntMultiVector/ExecuteTestProblems.cpp
Go to the documentation of this file.
1 //@HEADER
2 // ************************************************************************
3 //
4 // Epetra: 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 
43 #include "Epetra_BLAS.h"
44 #include "ExecuteTestProblems.h"
45 #include "Epetra_Comm.h"
46 #include "Epetra_Vector.h"
47 #include "Epetra_IntVector.h"
48 #include "Epetra_Import.h"
49 
50 int IntMultiVectorTests(const Epetra_BlockMap & Map, int NumVectors, bool verbose)
51 {
52  int ierr = 0;
53 
54  Epetra_BLAS BLAS;
55 
56  //*******************************************************************
57  // Post-construction modification tests
58  //*******************************************************************
59 
60  if (verbose) cout << "\n\nXXXXX Testing Post-construction modification of a multivector"
61  <<endl<<endl;
62 
63  int err = 0;
64 
65  Epetra_IntMultiVector X(Map, NumVectors);
66 
67  // Pick middle range values for GID, LID and Vector Index
68  int testGID = Map.NumGlobalElements()/2;
69  int testVecIndex = NumVectors/2;
70 
71  int GIDSize = 1;
72  int LIDOfGID = 0;
73  int FirstEntryOfGID = 0;
74 
75  if (Map.MyGID(testGID)) {
76  LIDOfGID = Map.LID(testGID);
77  GIDSize = Map.ElementSize(LIDOfGID);
78  FirstEntryOfGID = Map.FirstPointInElement(LIDOfGID);
79  }
80 
81  // ========================================================================
82  // Test int ReplaceGlobalValue (int GlobalRow, int VectorIndex, int OrdinalValue)
83  // ========================================================================
84 
85  int newGIDValue = 4;
86  int locerr = 0;
87  locerr = X.ReplaceGlobalValue(testGID, testVecIndex, newGIDValue);
88 
89  if (Map.MyGID(testGID)) {
90  if (X[testVecIndex][FirstEntryOfGID]!=newGIDValue) err++;
91  if (verbose) cout << "X["<<testVecIndex<<"]["<<FirstEntryOfGID<<"] = "
92  << X[testVecIndex][FirstEntryOfGID]
93  << " should = " << newGIDValue << endl;
94  }
95  else
96  if (locerr!=0) err++; // Test for GID out of range error (=1)
97 
98  // ========================================================================
99  // Test int ReplaceGlobalValue (int GlobalRow, intBlockRowOffset, int VectorIndex, int OrdinalValue)
100  // ========================================================================
101  newGIDValue = 8;
102  locerr = X.ReplaceGlobalValue(testGID, GIDSize-1, testVecIndex, newGIDValue);
103 
104  if (Map.MyGID(testGID)) {
105  if (X[testVecIndex][FirstEntryOfGID+GIDSize-1]!=newGIDValue) err++;
106  if (verbose) cout << "X["<<testVecIndex<<"]["<<FirstEntryOfGID+GIDSize-1<<"] = "
107  << X[testVecIndex][FirstEntryOfGID+GIDSize-1]
108  << " should = " << newGIDValue << endl;
109  }
110  else
111  if (locerr!=0) err++; // Test for GID out of range error (=1)
112 
113  // ========================================================================
114  // Test int SumIntoGlobalValue (int GlobalRow, int VectorIndex, int OrdinalValue)
115  // ========================================================================
116 
117  newGIDValue = 1;
118  locerr = X.ReplaceGlobalValue(testGID, testVecIndex, newGIDValue);
119  locerr = X.SumIntoGlobalValue(testGID, testVecIndex, newGIDValue);
120  if (Map.MyGID(testGID)) {
121  if (X[testVecIndex][FirstEntryOfGID]!=(newGIDValue+newGIDValue)) err++;
122  if (verbose) cout << "X["<<testVecIndex<<"]["<<FirstEntryOfGID<<"] = "
123  << X[testVecIndex][FirstEntryOfGID]
124  << " should = " << newGIDValue+newGIDValue << endl;
125  }
126  else
127  if (locerr!=0) err++; // Test for GID out of range error (=1)
128 
129  // ========================================================================
130  // Test int SumIntoGlobalValue (int GlobalRow, intBlockRowOffset, int VectorIndex, int OrdinalValue)
131  // ========================================================================
132 
133  newGIDValue = 1;
134  locerr = X.ReplaceGlobalValue(testGID, GIDSize-1, testVecIndex, newGIDValue);
135  locerr = X.SumIntoGlobalValue(testGID, GIDSize-1, testVecIndex, newGIDValue);
136 
137  if (Map.MyGID(testGID)) {
138  if (X[testVecIndex][FirstEntryOfGID+GIDSize-1]!=(newGIDValue+newGIDValue)) err++;
139  if (verbose) cout << "X["<<testVecIndex<<"]["<<FirstEntryOfGID+GIDSize-1<<"] = "
140  << X[testVecIndex][FirstEntryOfGID+GIDSize-1]
141  << " should = " << newGIDValue+newGIDValue << endl;
142  }
143  else
144  if (locerr!=0) err++; // Test for GID out of range error (=1)
145 
146  // ========================================================================
147  // Test Local "My" versions of same routine (less complicated)
148  // ========================================================================
149 
150  // Pick middle range values for LID
151  int testLID = Map.NumMyElements()/2;
152 
153  int LIDSize = Map.ElementSize(testLID);
154  int FirstEntryOfLID = Map.FirstPointInElement(testLID);
155 
156 
157  int newLIDValue = 4;
158  locerr = X.ReplaceMyValue(testLID, testVecIndex, newLIDValue);
159 
160  if (X[testVecIndex][FirstEntryOfLID]!=newLIDValue) err++;
161  if (verbose) cout << "X["<<testVecIndex<<"]["<<FirstEntryOfLID<<"] = "
162  << X[testVecIndex][FirstEntryOfLID]
163  << " should = " << newLIDValue << endl;
164 
165  newLIDValue = 8;
166  locerr = X.ReplaceMyValue(testLID, LIDSize-1, testVecIndex, newLIDValue);
167  if (X[testVecIndex][FirstEntryOfLID+LIDSize-1]!=newLIDValue) err++;
168  if (verbose) cout << "X["<<testVecIndex<<"]["<<FirstEntryOfLID+LIDSize-1<<"] = "
169  << X[testVecIndex][FirstEntryOfLID+LIDSize-1]
170  << " should = " << newLIDValue << endl;
171  newLIDValue = 1;
172  locerr = X.ReplaceMyValue(testLID, testVecIndex, newLIDValue);
173  locerr = X.SumIntoMyValue(testLID, testVecIndex, newLIDValue);
174  if (X[testVecIndex][FirstEntryOfLID]!=(newLIDValue+newLIDValue)) err++;
175  if (verbose) cout << "X["<<testVecIndex<<"]["<<FirstEntryOfLID<<"] = "
176  << X[testVecIndex][FirstEntryOfLID]
177  << " should = " << newLIDValue+newLIDValue << endl;
178  newLIDValue = 2;
179  locerr = X.ReplaceMyValue(testLID, LIDSize-1, testVecIndex, newLIDValue);
180  locerr = X.SumIntoMyValue(testLID, LIDSize-1, testVecIndex, newLIDValue);
181  if (X[testVecIndex][FirstEntryOfLID+LIDSize-1]!=(newLIDValue+newLIDValue)) err++;
182  if (verbose) cout << "X["<<testVecIndex<<"]["<<FirstEntryOfLID+LIDSize-1<<"] = "
183  << X[testVecIndex][FirstEntryOfLID+LIDSize-1]
184  << " should = " << newLIDValue+newLIDValue << endl;
185 
186  ierr += err;
187 
188  return(ierr);
189 }
int NumGlobalElements() const
Number of elements across all processors.
int ElementSize() const
Returns the size of elements in the map; only valid if map has constant element size.
Epetra_IntMultiVector: A class for constructing and using dense multi-vectors, vectors and matrices i...
int ReplaceGlobalValue(int GlobalRow, int VectorIndex, int OrdinalValue)
Replace current value at the specified (GlobalRow, VectorIndex) location with OrdinalValue.
Epetra_BLAS: The Epetra BLAS Wrapper Class.
Definition: Epetra_BLAS.h:70
int NumMyElements() const
Number of elements on the calling processor.
int FirstPointInElement(int LID) const
Returns the requested entry in the FirstPointInElementList; see FirstPointInElementList() for details...
int IntMultiVectorTests(const Epetra_BlockMap &Map, int NumVectors, bool verbose)
Epetra_BlockMap: A class for partitioning block element vectors and matrices.
int LID(int GID) const
Returns local ID of global ID, return -1 if not found on this processor.
bool MyGID(int GID_in) const
Returns true if the GID passed in belongs to the calling processor in this map, otherwise returns fal...
int SumIntoGlobalValue(int GlobalRow, int VectorIndex, int OrdinalValue)
Adds OrdinalValue to existing value at the specified (GlobalRow, VectorIndex) location.
int SumIntoMyValue(int MyRow, int VectorIndex, int OrdinalValue)
Adds OrdinalValue to existing value at the specified (MyRow, VectorIndex) location.
int ReplaceMyValue(int MyRow, int VectorIndex, int OrdinalValue)
Replace current value at the specified (MyRow, VectorIndex) location with OrdinalValue.