Epetra_CrsGraphData.cpp

Go to the documentation of this file.
00001 
00002 //@HEADER
00003 // ************************************************************************
00004 // 
00005 //               Epetra: Linear Algebra Services Package 
00006 //                 Copyright (2001) Sandia Corporation
00007 // 
00008 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00009 // license for use of this work by or on behalf of the U.S. Government.
00010 // 
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //  
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //  
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA
00025 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00026 // 
00027 // ************************************************************************
00028 //@HEADER
00029 
00030 #include "Epetra_CrsGraphData.h"
00031 #include "Epetra_Import.h"
00032 #include "Epetra_Export.h"
00033 //#include "Epetra_ConfigDefs.h" //DATA_DEBUG
00034 
00035 //=============================================================================
00036 Epetra_CrsGraphData::Epetra_CrsGraphData(Epetra_DataAccess CV, const Epetra_BlockMap& RowMap, bool StaticProfile)
00037   // maps
00038   : RowMap_(RowMap),
00039     ColMap_(RowMap),
00040     DomainMap_(RowMap),
00041     RangeMap_(RowMap),
00042     // importer & exporter
00043     Importer_(0),
00044     Exporter_(0),
00045     // booleans
00046     HaveColMap_(false),
00047     Filled_(false),
00048     Allocated_(false),
00049     Sorted_(false),
00050     StorageOptimized_(false),
00051     NoRedundancies_(false),
00052     IndicesAreGlobal_(false),
00053     IndicesAreLocal_(false),
00054     IndicesAreContiguous_(false),
00055     LowerTriangular_(true),
00056     UpperTriangular_(true),
00057     NoDiagonal_(true),
00058     GlobalConstantsComputed_(false),
00059     StaticProfile_(StaticProfile),
00060     // ints
00061     IndexBase_(RowMap.IndexBase()),
00062     NumGlobalEntries_(0),
00063     NumGlobalBlockRows_(RowMap.NumGlobalElements()),
00064     NumGlobalBlockCols_(NumGlobalBlockRows_),
00065     NumGlobalBlockDiagonals_(0),
00066     NumMyEntries_(0),
00067     NumMyBlockRows_(RowMap.NumMyElements()),
00068     NumMyBlockCols_(NumMyBlockRows_),
00069     NumMyBlockDiagonals_(0),
00070     MaxRowDim_(RowMap.MaxElementSize()),
00071     MaxColDim_(MaxRowDim_),
00072     GlobalMaxRowDim_(RowMap.MaxElementSize()),
00073     GlobalMaxColDim_(GlobalMaxRowDim_),
00074     MaxNumNonzeros_(0),
00075     GlobalMaxNumNonzeros_(0),
00076     NumGlobalNonzeros_(0),
00077     NumGlobalRows_(RowMap.NumGlobalPoints()),
00078     NumGlobalCols_(NumGlobalRows_),
00079     NumGlobalDiagonals_(0),
00080     NumMyNonzeros_(0),
00081     NumMyRows_(RowMap.NumMyPoints()),
00082     NumMyCols_(NumMyRows_),
00083     NumMyDiagonals_(0), 
00084     MaxNumIndices_(0),
00085     GlobalMaxNumIndices_(0),
00086     Indices_(new int *[NumMyBlockRows_]),
00087     NumAllocatedIndicesPerRow_(0),
00088     NumIndicesPerRow_(0),
00089     IndexOffset_(0),
00090     All_Indices_(0),
00091     CV_(CV)
00092 {
00093   //cout << "--CRSGD created(rowmap ctr), addr: " << this << endl; //DATA_DEBUG
00094 }
00095 
00096 //=============================================================================
00097 Epetra_CrsGraphData::Epetra_CrsGraphData(Epetra_DataAccess CV, 
00098            const Epetra_BlockMap& RowMap, 
00099            const Epetra_BlockMap& ColMap, bool StaticProfile)
00100   // maps
00101   : RowMap_(RowMap),
00102     ColMap_(ColMap),
00103     DomainMap_(ColMap),
00104     RangeMap_(RowMap),
00105     // importer & exporter
00106     Importer_(0),
00107     Exporter_(0),
00108     // booleans
00109     HaveColMap_(true),
00110     Filled_(false),
00111     Allocated_(false),
00112     Sorted_(false),
00113     StorageOptimized_(false),
00114     NoRedundancies_(false),
00115     IndicesAreGlobal_(false),
00116     IndicesAreLocal_(false),
00117     IndicesAreContiguous_(false),
00118     LowerTriangular_(true),
00119     UpperTriangular_(true),
00120     NoDiagonal_(true),
00121     GlobalConstantsComputed_(false),
00122     StaticProfile_(StaticProfile),
00123     // ints
00124     IndexBase_(RowMap.IndexBase()),
00125     NumGlobalEntries_(0),
00126     NumGlobalBlockRows_(RowMap.NumGlobalElements()),
00127     NumGlobalBlockCols_(NumGlobalBlockRows_),
00128     NumGlobalBlockDiagonals_(0),
00129     NumMyEntries_(0),
00130     NumMyBlockRows_(RowMap.NumMyElements()),
00131     NumMyBlockCols_(NumMyBlockRows_),
00132     NumMyBlockDiagonals_(0),
00133     MaxRowDim_(RowMap.MaxElementSize()),
00134     MaxColDim_(MaxRowDim_),
00135     GlobalMaxRowDim_(RowMap.MaxElementSize()),
00136     GlobalMaxColDim_(GlobalMaxRowDim_),
00137     MaxNumNonzeros_(0),
00138     GlobalMaxNumNonzeros_(0),
00139     NumGlobalNonzeros_(0),
00140     NumGlobalRows_(RowMap.NumGlobalPoints()),
00141     NumGlobalCols_(NumGlobalRows_),
00142     NumGlobalDiagonals_(0),
00143     NumMyNonzeros_(0),
00144     NumMyRows_(RowMap.NumMyPoints()),
00145     NumMyCols_(NumMyRows_),
00146     NumMyDiagonals_(0), 
00147     MaxNumIndices_(0),
00148     GlobalMaxNumIndices_(0),
00149     Indices_(new int *[NumMyBlockRows_]),
00150     NumAllocatedIndicesPerRow_(0),
00151     NumIndicesPerRow_(0),
00152     IndexOffset_(0),
00153     All_Indices_(0),
00154     CV_(CV)
00155 {
00156   //cout << "--CRSGD created(rowmap&colmap ctr), addr: " << this << endl; //DATA_DEBUG
00157 }
00158 
00159 //=============================================================================
00160 Epetra_CrsGraphData::~Epetra_CrsGraphData() {
00161 
00162   if(Indices_ != 0 && !StorageOptimized_) {
00163     for (int i=0; i<NumMyBlockRows_; i++) {
00164       if (Indices_[i]!=0 && CV_==Copy && !StaticProfile_) 
00165   delete [] Indices_[i]; 
00166       Indices_[i] = 0;
00167     } 
00168     delete[] Indices_;
00169     Indices_ = 0;
00170   }
00171 
00172   if(Importer_ != 0) {
00173     delete Importer_;
00174     Importer_ = 0;
00175   }
00176   if(Exporter_ != 0) {
00177     delete Exporter_;
00178     Importer_ = 0;
00179   }
00180 
00181   NumMyBlockRows_ = 0;  // are these needed?
00182   Filled_ = false;      // they're about to go out of scope, after all
00183   Allocated_ = false;
00184 
00185   //cout << "--CRSGD destroyed, addr: " << this << endl; //DATA_DEBUG
00186 }
00187 
00188 //==========================================================================
00189 int Epetra_CrsGraphData::MakeImportExport() {
00190   // Create Import object for use by matrix classes.    This is only needed if ColMap and DomainMap are different
00191   if (!ColMap_.SameAs(DomainMap_)) {
00192     if (Importer_ != 0) {
00193       delete Importer_;
00194       Importer_ = 0;
00195     }
00196     Importer_ = new Epetra_Import(ColMap_, DomainMap_);
00197   }
00198   
00199   // Now see if we need to define an export map.  This is only needed if RowMap and RangeMap are different
00200   if (!RowMap_.SameAs(RangeMap_)) {
00201     if (Exporter_ != 0) {
00202       delete Exporter_;
00203       Exporter_ = 0;
00204     }
00205     Exporter_ = new Epetra_Export(RowMap_, RangeMap_); // Create Export object. 
00206   }
00207    
00208   return(0);
00209 }
00210 
00211 //==========================================================================
00212 int Epetra_CrsGraphData::ReAllocateAndCast(char*& UserPtr, int& Length, const int IntPacketSizeTimesNumTrans) {
00213   if(IntPacketSizeTimesNumTrans > Length) {
00214     if(Length > 0) 
00215       delete[] UserPtr;
00216     Length = IntPacketSizeTimesNumTrans;
00217     int* newPtr = new int[Length];
00218     UserPtr = reinterpret_cast<char*> (newPtr);
00219   }
00220   return(0);
00221 }
00222 
00223 //==========================================================================
00224 void Epetra_CrsGraphData::Print(ostream& os, int level) const {
00225   bool four_bit = (level >= 4);      // 4-bit = BlockMaps
00226   bool two_bit = ((level % 4) >= 2); // 2-bit = Indices
00227   bool one_bit = ((level % 2) == 1); // 1-bit = Everything else
00228 
00229   os << "\n***** CrsGraphData (output level " << level << ") *****" << endl;
00230 
00231   if(four_bit) {
00232     os << "RowMap_:\n" << RowMap_ << endl;
00233     os << "ColMap_:\n" << ColMap_ << endl;
00234     os << "DomainMap_:\n" << DomainMap_ << endl;
00235     os << "RangeMap_:\n" << RangeMap_ << endl;
00236   }
00237   
00238   if(one_bit) {
00239     os.width(26); os << "HaveColMap_: "              << HaveColMap_;
00240     os.width(25); os << "Filled_: "                  << Filled_;
00241     os.width(25); os << "Allocated_: "               << Allocated_;
00242     os.width(25); os << "Sorted_: "                  << Sorted_ << endl;
00243     os.width(26); os << "StorageOptimized_: "        << StorageOptimized_;
00244     os.width(25); os << "NoRedundancies_: "          << NoRedundancies_;
00245     os.width(25); os << "IndicesAreGlobal_: "        << IndicesAreGlobal_;
00246     os.width(25); os << "IndicesAreLocal_: "         << IndicesAreLocal_ << endl;
00247     os.width(26); os << "IndicesAreContiguous_: "    << IndicesAreContiguous_;
00248     os.width(25); os << "LowerTriangular_: "         << LowerTriangular_;
00249     os.width(25); os << "UpperTriangular_: "         << UpperTriangular_;
00250     os.width(25); os << "NoDiagonal_: "              << NoDiagonal_ << endl;
00251     os.width(25); os << "GlobalConstantsComputed_: " << GlobalConstantsComputed_ << endl;
00252     os.width(25); os << "StaticProfile_: " << StaticProfile_ << endl << endl;
00253     
00254     os.width(10); os << "NGBR_: " << NumGlobalBlockRows_;
00255     os.width(10); os << "NGBC_: " << NumGlobalBlockCols_;
00256     os.width(10); os << "NGBD_: " << NumGlobalBlockDiagonals_;
00257     os.width(10); os << "NGE_: "  << NumGlobalEntries_;
00258     os.width(10); os << "NGR_: "  << NumGlobalRows_;
00259     os.width(10); os << "NGC_: "  << NumGlobalCols_;
00260     os.width(10); os << "NGD_: "  << NumGlobalDiagonals_;
00261     os.width(10); os << "NGN_: "  << NumGlobalNonzeros_;
00262     os.width(10); os << "IB_: "   << IndexBase_ << endl;
00263     os.width(10); os << "GMRD_: " << GlobalMaxRowDim_;
00264     os.width(11); os << "GMCD_: " << GlobalMaxColDim_;
00265     os.width(11); os << "GMNI_: " << GlobalMaxNumIndices_;
00266     os.width(11); os << "NMBR_: " << NumMyBlockRows_;
00267     os.width(10); os << "NMBC_: " << NumMyBlockCols_;
00268     os.width(10); os << "NMBD_: " << NumMyBlockDiagonals_;
00269     os.width(10); os << "NME_: "  << NumMyEntries_;
00270     os.width(10); os << "NMR_: "  << NumMyRows_;
00271     os.width(10); os << "CV_: " << CV_ << endl;
00272     os.width(10); os << "NMC_: "  << NumMyCols_;
00273     os.width(10); os << "NMD_: "  << NumMyDiagonals_;
00274     os.width(10); os << "NMN_: "  << NumMyNonzeros_;
00275     os.width(10); os << "MRD_: "  << MaxRowDim_;
00276     os.width(11); os << "MCD_: "  << MaxColDim_;
00277     os.width(11); os << "MNI_: "  << MaxNumIndices_;
00278     os.width(11); os << "MNN_: "  << MaxNumNonzeros_;
00279     os.width(11); os << "GMNN_: " << GlobalMaxNumNonzeros_;
00280     os.width(11); os << "RC: " << ReferenceCount() << endl << endl;
00281     
00282     os << "NIPR_: " << NumIndicesPerRow_ << endl;
00283     os << "NAIPR_: " << NumAllocatedIndicesPerRow_ << endl;
00284     os << "IndexOffset_: " << IndexOffset_ << endl;
00285     os << "All_Indices_: " << All_Indices_ << endl;
00286   }
00287     
00288   if(two_bit) {
00289     os << "Indices_: " << Indices_ << endl;
00290     if(Indices_ != 0) {
00291       for(int i = 0; i < NumMyBlockRows_; i++) {
00292   os << "Indices_[" << i << "]: (" << Indices_[i] << ") ";
00293   if(Indices_[i] != 0) {
00294     for(int j = 0; j < NumAllocatedIndicesPerRow_[i]; j++)
00295       os << Indices_[i][j] << " ";
00296   }
00297   os << endl;
00298       }
00299     }
00300   }
00301   
00302   os << "***** End CrsGraphData *****" << endl;
00303 }

Generated on Thu Sep 18 12:37:57 2008 for Epetra Package Browser (Single Doxygen Collection) by doxygen 1.3.9.1