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   virtual ~IndexData()
00242   {
00243     Deallocate();
00244   }
00245 
00246   void Allocate(int NumMyBlockRows, bool AllocSorted)
00247   {
00248     Deallocate();
00249 
00250     if(AllocSorted)
00251       SortedEntries_.resize(NumMyBlockRows);
00252     if(NumMyBlockRows > 0)
00253       Indices_ = new long long *[NumMyBlockRows];
00254   }
00255 
00256   void Deallocate()
00257   {
00258     delete[] Indices_;
00259     Indices_ = 0;
00260 
00261     std::vector< EntriesInOneRow<long long> > empty;
00262     SortedEntries_.swap(empty);
00263 
00264     delete [] TempColIndices_;
00265     TempColIndices_ = 0;
00266 
00267     All_Indices_.Resize(0);
00268   }
00269 };
00270 
00271 #endif
00272 
00273 template<>
00274 struct Epetra_CrsGraphData::IndexData<int>
00275 {
00276   int** Indices_;
00277   std::vector< EntriesInOneRow<int> > SortedEntries_;
00278   int* TempColIndices_;
00279   Epetra_IntSerialDenseVector All_Indices_;
00280   Epetra_IntSerialDenseVector All_IndicesPlus1_;
00281 
00282   IndexData(int NumMyBlockRows, bool AllocSorted)
00283     :
00284     Indices_(NULL),
00285     SortedEntries_(),
00286     TempColIndices_(NULL),
00287     All_Indices_(0),
00288     All_IndicesPlus1_(0)
00289   {
00290     Allocate(NumMyBlockRows, AllocSorted);
00291   }
00292 
00293   void Allocate(int NumMyBlockRows, bool AllocSorted)
00294   {
00295     Deallocate();
00296 
00297     if(AllocSorted)
00298       SortedEntries_.resize(NumMyBlockRows);
00299 
00300     if(NumMyBlockRows > 0)
00301       Indices_ = new int *[NumMyBlockRows];
00302   }
00303 
00304   void Deallocate()
00305   {
00306     delete[] Indices_;
00307     Indices_ = 0;
00308 
00309     std::vector< EntriesInOneRow<int> > empty;
00310     SortedEntries_.swap(empty);
00311 
00312     delete [] TempColIndices_;
00313     TempColIndices_ = 0;
00314 
00315     All_Indices_.Resize(0);
00316     All_IndicesPlus1_.Resize(0);
00317   }
00318 };
00319 
00320 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00321 template<>
00322 inline Epetra_CrsGraphData::IndexData<long long>& Epetra_CrsGraphData::Data<long long>()
00323 {
00324   if(RowMap_.GlobalIndicesLongLong() && !IndicesAreLocal_)
00325     return *LL_data;
00326   else
00327     throw "Epetra_CrsGraphData::Data<long long>: Map indices not long long or are local";
00328 }
00329 #endif
00330 
00331 template<>
00332 inline Epetra_CrsGraphData::IndexData<int>& Epetra_CrsGraphData::Data<int>()
00333 {
00334   if(RowMap_.GlobalIndicesInt() || (RowMap_.GlobalIndicesLongLong() && !IndicesAreGlobal_))
00335     return *data;
00336   else
00337     throw "Epetra_CrsGraphData::Data<int>: Map indices not int or are global long long";
00338 }
00339 
00340 
00341 #endif /* EPETRA_CRSGRAPHDATA_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines