Epetra Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Epetra_CrsGraphData.h
Go to the documentation of this file.
1 /*
2 //@HEADER
3 // ************************************************************************
4 //
5 // Epetra: Linear Algebra Services Package
6 // Copyright 2011 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
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 Michael A. Heroux (maherou@sandia.gov)
39 //
40 // ************************************************************************
41 //@HEADER
42 */
43 
44 #ifndef EPETRA_CRSGRAPHDATA_H
45 #define EPETRA_CRSGRAPHDATA_H
46 
47 #include "Epetra_ConfigDefs.h"
48 #include "Epetra_Data.h"
49 #include "Epetra_DataAccess.h"
50 #include "Epetra_BlockMap.h"
52 
53 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
55 #endif
56 
57 // include STL vector
58 #include <vector>
59 class Epetra_Import;
60 class Epetra_Export;
61 
63 
68 class EPETRA_LIB_DLL_EXPORT Epetra_CrsGraphData : public Epetra_Data {
69  friend class Epetra_CrsGraph;
70  friend class Epetra_FECrsGraph;
71  friend class Epetra_CrsMatrix;
72  private:
73 
75 
76 
78  Epetra_CrsGraphData(Epetra_DataAccess CV, const Epetra_BlockMap& RowMap, bool StaticProfile);
79 
81  Epetra_CrsGraphData(Epetra_DataAccess CV, const Epetra_BlockMap& RowMap, const Epetra_BlockMap& ColMap, bool StaticProfile);
82 
84  Epetra_CrsGraphData(const Epetra_CrsGraphData& CrsGraphData);
85 
88 
90 
92 
98  void Print(std::ostream& os, int level = 3) const;
99 
101  Epetra_CrsGraphData& operator=(const Epetra_CrsGraphData& CrsGraphData);
102 
104 
105 
116  template<typename int_type>
118  {
119  public:
125  std::vector<int_type> entries_;
126 
131  void AddEntry (const int_type col_num);
132 
136  void AddEntries (const int n_cols,
137  const int_type *col_nums);
138  };
139 
141  int MakeImportExport();
142 
144  int ReAllocateAndCast(char*& UserPtr, int& Length, const int IntPacketSizeTimesNumTrans);
145 
147 
148  // Defined by CrsGraph::FillComplete and related
153 
156 
158  bool Filled_;
160  bool Sorted_;
172 
173  long long IndexBase_;
174 
175  long long NumGlobalEntries_;
183 
190 
192  long long NumGlobalRows_;
193  long long NumGlobalCols_;
199 
202 
208 
209  template<typename int_type>
210  struct IndexData;
211 
213 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
215 #endif
216 
217  template<typename int_type>
218  IndexData<int_type>& Data();
219 };
220 
221 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
222 
223 template<>
225 {
226  long long** Indices_;
227  std::vector< EntriesInOneRow<long long> > SortedEntries_;
228  long long* TempColIndices_;
230 
231  IndexData(int NumMyBlockRows, bool AllocSorted)
232  :
233  Indices_(NULL),
234  SortedEntries_(),
235  TempColIndices_(NULL),
236  All_Indices_(0)
237  {
238  Allocate(NumMyBlockRows, AllocSorted);
239  }
240 
241  virtual ~IndexData()
242  {
243  Deallocate();
244  }
245 
246  void Allocate(int NumMyBlockRows, bool AllocSorted)
247  {
248  Deallocate();
249 
250  if(AllocSorted)
251  SortedEntries_.resize(NumMyBlockRows);
252  if(NumMyBlockRows > 0)
253  Indices_ = new long long *[NumMyBlockRows];
254  }
255 
256  void Deallocate()
257  {
258  delete[] Indices_;
259  Indices_ = 0;
260 
261  std::vector< EntriesInOneRow<long long> > empty;
262  SortedEntries_.swap(empty);
263 
264  delete [] TempColIndices_;
265  TempColIndices_ = 0;
266 
267  All_Indices_.Resize(0);
268  }
269 };
270 
271 #endif
272 
273 template<>
275 {
276  int** Indices_;
277  std::vector< EntriesInOneRow<int> > SortedEntries_;
281 
282  IndexData(int NumMyBlockRows, bool AllocSorted)
283  :
284  Indices_(NULL),
285  SortedEntries_(),
286  TempColIndices_(NULL),
287  All_Indices_(0),
288  All_IndicesPlus1_(0)
289  {
290  Allocate(NumMyBlockRows, AllocSorted);
291  }
292 
293  void Allocate(int NumMyBlockRows, bool AllocSorted)
294  {
295  Deallocate();
296 
297  if(AllocSorted)
298  SortedEntries_.resize(NumMyBlockRows);
299 
300  if(NumMyBlockRows > 0)
301  Indices_ = new int *[NumMyBlockRows];
302  }
303 
304  void Deallocate()
305  {
306  delete[] Indices_;
307  Indices_ = 0;
308 
309  std::vector< EntriesInOneRow<int> > empty;
310  SortedEntries_.swap(empty);
311 
312  delete [] TempColIndices_;
313  TempColIndices_ = 0;
314 
315  All_Indices_.Resize(0);
316  All_IndicesPlus1_.Resize(0);
317  }
318 };
319 
320 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
321 template<>
322 inline Epetra_CrsGraphData::IndexData<long long>& Epetra_CrsGraphData::Data<long long>()
323 {
324  if(RowMap_.GlobalIndicesLongLong() && !IndicesAreLocal_)
325  return *LL_data;
326  else
327  throw "Epetra_CrsGraphData::Data<long long>: Map indices not long long or are local";
328 }
329 #endif
330 
331 template<>
332 inline Epetra_CrsGraphData::IndexData<int>& Epetra_CrsGraphData::Data<int>()
333 {
334  if(RowMap_.GlobalIndicesInt() || (RowMap_.GlobalIndicesLongLong() && !IndicesAreGlobal_))
335  return *data;
336  else
337  throw "Epetra_CrsGraphData::Data<int>: Map indices not int or are global long long";
338 }
339 
340 
341 #endif /* EPETRA_CRSGRAPHDATA_H */
const Epetra_Export * Exporter_
void Allocate(int NumMyBlockRows, bool AllocSorted)
Epetra_IntSerialDenseVector: A class for constructing and using dense vectors.
Epetra_BlockMap RangeMap_
Epetra_IntSerialDenseVector NumIndicesPerRow_
Store some data for each row describing which entries of this row are nonzero.
Epetra_Data: The Epetra Base Data Class.
Definition: Epetra_Data.h:73
Epetra Finite-Element CrsGraph.
IndexData< long long > * LL_data
Epetra_BlockMap DomainMap_
Epetra_Export: This class builds an export object for efficient exporting of off-processor elements...
Definition: Epetra_Export.h:62
const Epetra_Map & ColMap() const
Returns the Epetra_Map object that describes the set of column-indices that appear in each processor&#39;...
Epetra_LongLongSerialDenseVector All_Indices_
Epetra_Import: This class builds an import object for efficient importing of off-processor elements...
Definition: Epetra_Import.h:63
IndexData< int > * data
Epetra_CrsGraphData: The Epetra CrsGraph Data Class.
const Epetra_Map & RowMap() const
Returns the Epetra_Map object associated with the rows of this matrix.
std::vector< EntriesInOneRow< long long > > SortedEntries_
std::vector< EntriesInOneRow< int > > SortedEntries_
Epetra_IntSerialDenseVector NumAllocatedIndicesPerRow_
Epetra_BlockMap: A class for partitioning block element vectors and matrices.
Epetra_LongLongSerialDenseVector: A class for constructing and using dense vectors.
std::vector< int_type > entries_
Storage for the column indices of this row.
virtual void Print(std::ostream &os) const
Print method.
void Allocate(int NumMyBlockRows, bool AllocSorted)
Epetra_IntSerialDenseVector All_Indices_
Epetra_IntSerialDenseVector All_IndicesPlus1_
Epetra_IntSerialDenseVector IndexOffset_
Epetra_CrsMatrix: A class for constructing and using real-valued double-precision sparse compressed r...
Epetra_CrsMatrix & operator=(const Epetra_CrsMatrix &src)
Assignment operator.
Epetra_DataAccess CV_
const Epetra_Import * Importer_
Epetra_DataAccess
IndexData(int NumMyBlockRows, bool AllocSorted)
Epetra_CrsGraph: A class for constructing and using sparse compressed row graphs. ...
Epetra_DataAccess Mode enumerable type.
IndexData(int NumMyBlockRows, bool AllocSorted)