Epetra Package Browser (Single Doxygen Collection) Development
Epetra_CrsGraphData.h
Go to the documentation of this file.
00001 /*
00002 //@HEADER
00003 // ************************************************************************
00004 // 
00005 //               Epetra: Linear Algebra Services Package 
00006 //                 Copyright 2011 Sandia Corporation
00007 // 
00008 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00009 // the U.S. Government retains certain rights in this software.
00010 //
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are
00013 // met:
00014 //
00015 // 1. Redistributions of source code must retain the above copyright
00016 // notice, this list of conditions and the following disclaimer.
00017 //
00018 // 2. Redistributions in binary form must reproduce the above copyright
00019 // notice, this list of conditions and the following disclaimer in the
00020 // documentation and/or other materials provided with the distribution.
00021 //
00022 // 3. Neither the name of the Corporation nor the names of the
00023 // contributors may be used to endorse or promote products derived from
00024 // this software without specific prior written permission.
00025 //
00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 //
00038 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00039 // 
00040 // ************************************************************************
00041 //@HEADER
00042 */
00043 
00044 #ifndef EPETRA_CRSGRAPHDATA_H
00045 #define EPETRA_CRSGRAPHDATA_H
00046 
00047 #include "Epetra_ConfigDefs.h"
00048 #include "Epetra_Data.h"
00049 #include "Epetra_DataAccess.h"
00050 #include "Epetra_BlockMap.h"
00051 #include "Epetra_IntSerialDenseVector.h"
00052 
00053 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00054 #include "Epetra_LongLongSerialDenseVector.h"
00055 #endif
00056 
00057 // include STL vector
00058 #include <vector>
00059 class Epetra_Import;
00060 class Epetra_Export;
00061 
00063 
00068 class EPETRA_LIB_DLL_EXPORT Epetra_CrsGraphData : public Epetra_Data {
00069   friend class Epetra_CrsGraph;
00070   friend class Epetra_FECrsGraph;
00071   friend class Epetra_CrsMatrix;
00072  private:
00073 
00075 
00076 
00078   Epetra_CrsGraphData(Epetra_DataAccess CV, const Epetra_BlockMap& RowMap, bool StaticProfile);
00079 
00081   Epetra_CrsGraphData(Epetra_DataAccess CV, const Epetra_BlockMap& RowMap, const Epetra_BlockMap& ColMap, bool StaticProfile);
00082 
00084   Epetra_CrsGraphData(const Epetra_CrsGraphData& CrsGraphData);
00085 
00087   ~Epetra_CrsGraphData();
00088 
00090 
00092 
00098   void Print(std::ostream& os, int level = 3) const;
00099 
00101   Epetra_CrsGraphData& operator=(const Epetra_CrsGraphData& CrsGraphData);
00102   
00104 
00105 
00116   template<typename int_type>
00117   struct EntriesInOneRow
00118   {
00119     public:
00125       std::vector<int_type> entries_;
00126        
00131       void AddEntry (const int_type col_num);
00132 
00136       void AddEntries (const int  n_cols,
00137           const int_type *col_nums);
00138   };
00139   
00141   int MakeImportExport();
00142   
00144   int ReAllocateAndCast(char*& UserPtr, int& Length, const int IntPacketSizeTimesNumTrans);
00145   
00147   
00148   // Defined by CrsGraph::FillComplete and related
00149   Epetra_BlockMap RowMap_;
00150   Epetra_BlockMap ColMap_;
00151   Epetra_BlockMap DomainMap_;
00152   Epetra_BlockMap RangeMap_;
00153   
00154   const Epetra_Import* Importer_;
00155   const Epetra_Export* Exporter_;
00156 
00157   bool HaveColMap_;
00158   bool Filled_;
00159   bool Allocated_;
00160   bool Sorted_;
00161   bool StorageOptimized_;
00162   bool NoRedundancies_;
00163   bool IndicesAreGlobal_;
00164   bool IndicesAreLocal_;
00165   bool IndicesAreContiguous_;
00166   bool LowerTriangular_;
00167   bool UpperTriangular_;
00168   bool NoDiagonal_;
00169   bool GlobalConstantsComputed_;
00170   bool StaticProfile_;
00171   bool SortGhostsAssociatedWithEachProcessor_;
00172 
00173   long long IndexBase_;
00174 
00175   long long NumGlobalEntries_;
00176   long long NumGlobalBlockRows_;
00177   long long NumGlobalBlockCols_;
00178   long long NumGlobalBlockDiagonals_;
00179   int NumMyEntries_;
00180   int NumMyBlockRows_;
00181   int NumMyBlockCols_;
00182   int NumMyBlockDiagonals_;
00183   
00184   int MaxRowDim_;
00185   int MaxColDim_;
00186   int GlobalMaxRowDim_;
00187   int GlobalMaxColDim_;
00188   int MaxNumNonzeros_;
00189   int GlobalMaxNumNonzeros_;
00190   
00191   long long NumGlobalNonzeros_;
00192   long long NumGlobalRows_;
00193   long long NumGlobalCols_;
00194   long long NumGlobalDiagonals_;
00195   int NumMyNonzeros_;
00196   int NumMyRows_;
00197   int NumMyCols_;
00198   int NumMyDiagonals_;
00199 
00200   int MaxNumIndices_;
00201   int GlobalMaxNumIndices_;
00202 
00203   int NumTempColIndices_;
00204   Epetra_IntSerialDenseVector NumAllocatedIndicesPerRow_;
00205   Epetra_IntSerialDenseVector NumIndicesPerRow_;
00206   Epetra_IntSerialDenseVector IndexOffset_;
00207   Epetra_DataAccess CV_;
00208 
00209   template<typename int_type>
00210   struct IndexData;
00211 
00212   IndexData<int>* data;
00213 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00214   IndexData<long long>* LL_data;
00215 #endif
00216 
00217   template<typename int_type>
00218   IndexData<int_type>& Data();
00219 };
00220 
00221 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00222 
00223 template<>
00224 struct Epetra_CrsGraphData::IndexData<long long>
00225 {
00226   long long** Indices_;
00227   std::vector< EntriesInOneRow<long long> > SortedEntries_;
00228   long long* TempColIndices_;
00229   Epetra_LongLongSerialDenseVector All_Indices_;
00230 
00231   IndexData(int NumMyBlockRows, bool AllocSorted)
00232     :
00233     Indices_(NULL),
00234     SortedEntries_(),
00235     TempColIndices_(NULL),
00236     All_Indices_(0)
00237   {
00238     Allocate(NumMyBlockRows, AllocSorted);
00239   }
00240 
00241   void Allocate(int NumMyBlockRows, bool AllocSorted)
00242   {
00243     Deallocate();
00244 
00245     if(AllocSorted)
00246       SortedEntries_.resize(NumMyBlockRows);
00247     if(NumMyBlockRows > 0)
00248       Indices_ = new long long *[NumMyBlockRows];
00249   }
00250 
00251   void Deallocate()
00252   {
00253     delete[] Indices_;
00254     Indices_ = 0;
00255 
00256     std::vector< EntriesInOneRow<long long> > empty;
00257     SortedEntries_.swap(empty);
00258 
00259     delete [] TempColIndices_;
00260     TempColIndices_ = 0;
00261 
00262     All_Indices_.Resize(0);
00263   }
00264 };
00265 
00266 #endif
00267 
00268 template<>
00269 struct Epetra_CrsGraphData::IndexData<int>
00270 {
00271   int** Indices_;
00272   std::vector< EntriesInOneRow<int> > SortedEntries_;
00273   int* TempColIndices_;
00274   Epetra_IntSerialDenseVector All_Indices_;
00275   Epetra_IntSerialDenseVector All_IndicesPlus1_;
00276 
00277   IndexData(int NumMyBlockRows, bool AllocSorted)
00278     :
00279     Indices_(NULL),
00280     SortedEntries_(),
00281     TempColIndices_(NULL),
00282     All_Indices_(0),
00283     All_IndicesPlus1_(0)
00284   {
00285     Allocate(NumMyBlockRows, AllocSorted);
00286   }
00287 
00288   void Allocate(int NumMyBlockRows, bool AllocSorted)
00289   {
00290     Deallocate();
00291 
00292     if(AllocSorted)
00293       SortedEntries_.resize(NumMyBlockRows);
00294 
00295     if(NumMyBlockRows > 0)
00296       Indices_ = new int *[NumMyBlockRows];
00297   }
00298 
00299   void Deallocate()
00300   {
00301     delete[] Indices_;
00302     Indices_ = 0;
00303 
00304     std::vector< EntriesInOneRow<int> > empty;
00305     SortedEntries_.swap(empty);
00306 
00307     delete [] TempColIndices_;
00308     TempColIndices_ = 0;
00309 
00310     All_Indices_.Resize(0);
00311     All_IndicesPlus1_.Resize(0);
00312   }
00313 };
00314 
00315 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00316 template<>
00317 inline Epetra_CrsGraphData::IndexData<long long>& Epetra_CrsGraphData::Data<long long>()
00318 {
00319   if(RowMap_.GlobalIndicesLongLong() && !IndicesAreLocal_)
00320     return *LL_data;
00321   else
00322     throw "Epetra_CrsGraphData::Data<long long>: Map indices not long long or are local";
00323 }
00324 #endif
00325 
00326 template<>
00327 inline Epetra_CrsGraphData::IndexData<int>& Epetra_CrsGraphData::Data<int>()
00328 {
00329   if(RowMap_.GlobalIndicesInt() || (RowMap_.GlobalIndicesLongLong() && !IndicesAreGlobal_))
00330     return *data;
00331   else
00332     throw "Epetra_CrsGraphData::Data<int>: Map indices not int or are global long long";
00333 }
00334 
00335 
00336 #endif /* EPETRA_CRSGRAPHDATA_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines