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 #if defined(Epetra_SHOW_DEPRECATED_WARNINGS)
48 #ifdef __GNUC__
49 #warning "The Epetra package is deprecated"
50 #endif
51 #endif
52 
53 
54 
55 #include "Epetra_ConfigDefs.h"
56 #include "Epetra_Data.h"
57 #include "Epetra_DataAccess.h"
58 #include "Epetra_BlockMap.h"
60 
61 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
63 #endif
64 
65 // include STL vector
66 #include <vector>
67 class Epetra_Import;
68 class Epetra_Export;
69 
71 
76 class EPETRA_LIB_DLL_EXPORT Epetra_CrsGraphData : public Epetra_Data {
77  friend class Epetra_CrsGraph;
78  friend class Epetra_FECrsGraph;
79  friend class Epetra_CrsMatrix;
80  private:
81 
83 
84 
86  Epetra_CrsGraphData(Epetra_DataAccess CV, const Epetra_BlockMap& RowMap, bool StaticProfile);
87 
89  Epetra_CrsGraphData(Epetra_DataAccess CV, const Epetra_BlockMap& RowMap, const Epetra_BlockMap& ColMap, bool StaticProfile);
90 
92  Epetra_CrsGraphData(const Epetra_CrsGraphData& CrsGraphData);
93 
96 
98 
100 
106  void Print(std::ostream& os, int level = 3) const;
107 
109  Epetra_CrsGraphData& operator=(const Epetra_CrsGraphData& CrsGraphData);
110 
112 
113 
124  template<typename int_type>
126  {
127  public:
133  std::vector<int_type> entries_;
134 
139  void AddEntry (const int_type col_num);
140 
144  void AddEntries (const int n_cols,
145  const int_type *col_nums);
146  };
147 
149  int MakeImportExport();
150 
152  int ReAllocateAndCast(char*& UserPtr, int& Length, const int IntPacketSizeTimesNumTrans);
153 
155 
156  // Defined by CrsGraph::FillComplete and related
161 
164 
166  bool Filled_;
168  bool Sorted_;
180 
181  long long IndexBase_;
182 
183  long long NumGlobalEntries_;
191 
198 
200  long long NumGlobalRows_;
201  long long NumGlobalCols_;
207 
210 
216 
217  template<typename int_type>
218  struct IndexData;
219 
221 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
223 #endif
224 
225  template<typename int_type>
226  IndexData<int_type>& Data();
227 };
228 
229 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
230 
231 template<>
233 {
234  long long** Indices_;
235  std::vector< EntriesInOneRow<long long> > SortedEntries_;
236  long long* TempColIndices_;
238 
239  IndexData(int NumMyBlockRows, bool AllocSorted)
240  :
241  Indices_(NULL),
242  SortedEntries_(),
243  TempColIndices_(NULL),
244  All_Indices_(0)
245  {
246  Allocate(NumMyBlockRows, AllocSorted);
247  }
248 
249  virtual ~IndexData()
250  {
251  Deallocate();
252  }
253 
254  void Allocate(int NumMyBlockRows, bool AllocSorted)
255  {
256  Deallocate();
257 
258  if(AllocSorted)
259  SortedEntries_.resize(NumMyBlockRows);
260  if(NumMyBlockRows > 0)
261  Indices_ = new long long *[NumMyBlockRows];
262  }
263 
264  void Deallocate()
265  {
266  delete[] Indices_;
267  Indices_ = 0;
268 
269  std::vector< EntriesInOneRow<long long> > empty;
270  SortedEntries_.swap(empty);
271 
272  delete [] TempColIndices_;
273  TempColIndices_ = 0;
274 
275  All_Indices_.Resize(0);
276  }
277 };
278 
279 #endif
280 
281 template<>
283 {
284  int** Indices_;
285  std::vector< EntriesInOneRow<int> > SortedEntries_;
289 
290  IndexData(int NumMyBlockRows, bool AllocSorted)
291  :
292  Indices_(NULL),
293  SortedEntries_(),
294  TempColIndices_(NULL),
295  All_Indices_(0),
296  All_IndicesPlus1_(0)
297  {
298  Allocate(NumMyBlockRows, AllocSorted);
299  }
300 
301  void Allocate(int NumMyBlockRows, bool AllocSorted)
302  {
303  Deallocate();
304 
305  if(AllocSorted)
306  SortedEntries_.resize(NumMyBlockRows);
307 
308  if(NumMyBlockRows > 0)
309  Indices_ = new int *[NumMyBlockRows];
310  }
311 
312  void Deallocate()
313  {
314  delete[] Indices_;
315  Indices_ = 0;
316 
317  std::vector< EntriesInOneRow<int> > empty;
318  SortedEntries_.swap(empty);
319 
320  delete [] TempColIndices_;
321  TempColIndices_ = 0;
322 
323  All_Indices_.Resize(0);
324  All_IndicesPlus1_.Resize(0);
325  }
326 };
327 
328 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
329 template<>
330 inline Epetra_CrsGraphData::IndexData<long long>& Epetra_CrsGraphData::Data<long long>()
331 {
332  if(RowMap_.GlobalIndicesLongLong() && !IndicesAreLocal_)
333  return *LL_data;
334  else
335  throw "Epetra_CrsGraphData::Data<long long>: Map indices not long long or are local";
336 }
337 #endif
338 
339 template<>
340 inline Epetra_CrsGraphData::IndexData<int>& Epetra_CrsGraphData::Data<int>()
341 {
342  if(RowMap_.GlobalIndicesInt() || (RowMap_.GlobalIndicesLongLong() && !IndicesAreGlobal_))
343  return *data;
344  else
345  throw "Epetra_CrsGraphData::Data<int>: Map indices not int or are global long long";
346 }
347 
348 
349 #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:81
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:70
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:71
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)