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     SortGhostsAssociatedWithEachProcessor_(false),
00061 
00062     // ints
00063     IndexBase_(RowMap.IndexBase()),
00064     NumGlobalEntries_(0),
00065     NumGlobalBlockRows_(RowMap.NumGlobalElements()),
00066     NumGlobalBlockCols_(NumGlobalBlockRows_),
00067     NumGlobalBlockDiagonals_(0),
00068     NumMyEntries_(0),
00069     NumMyBlockRows_(RowMap.NumMyElements()),
00070     NumMyBlockCols_(NumMyBlockRows_),
00071     NumMyBlockDiagonals_(0),
00072     MaxRowDim_(RowMap.MaxElementSize()),
00073     MaxColDim_(MaxRowDim_),
00074     GlobalMaxRowDim_(RowMap.MaxElementSize()),
00075     GlobalMaxColDim_(GlobalMaxRowDim_),
00076     MaxNumNonzeros_(0),
00077     GlobalMaxNumNonzeros_(0),
00078     NumGlobalNonzeros_(0),
00079     NumGlobalRows_(RowMap.NumGlobalPoints()),
00080     NumGlobalCols_(NumGlobalRows_),
00081     NumGlobalDiagonals_(0),
00082     NumMyNonzeros_(0),
00083     NumMyRows_(RowMap.NumMyPoints()),
00084     NumMyCols_(NumMyRows_),
00085     NumMyDiagonals_(0), 
00086     MaxNumIndices_(0),
00087     GlobalMaxNumIndices_(0),
00088     Indices_(new int *[NumMyBlockRows_]),
00089     NumAllocatedIndicesPerRow_(0),
00090     NumIndicesPerRow_(0),
00091     IndexOffset_(0),
00092     All_Indices_(0),
00093     CV_(CV)
00094 {
00095   //cout << "--CRSGD created(rowmap ctr), addr: " << this << endl; //DATA_DEBUG
00096 }
00097 
00098 //=============================================================================
00099 Epetra_CrsGraphData::Epetra_CrsGraphData(Epetra_DataAccess CV, 
00100            const Epetra_BlockMap& RowMap, 
00101            const Epetra_BlockMap& ColMap, bool StaticProfile)
00102   // maps
00103   : RowMap_(RowMap),
00104     ColMap_(ColMap),
00105     DomainMap_(ColMap),
00106     RangeMap_(RowMap),
00107     // importer & exporter
00108     Importer_(0),
00109     Exporter_(0),
00110     // booleans
00111     HaveColMap_(true),
00112     Filled_(false),
00113     Allocated_(false),
00114     Sorted_(false),
00115     StorageOptimized_(false),
00116     NoRedundancies_(false),
00117     IndicesAreGlobal_(false),
00118     IndicesAreLocal_(false),
00119     IndicesAreContiguous_(false),
00120     LowerTriangular_(true),
00121     UpperTriangular_(true),
00122     NoDiagonal_(true),
00123     GlobalConstantsComputed_(false),
00124     StaticProfile_(StaticProfile),
00125     SortGhostsAssociatedWithEachProcessor_(false),
00126     // ints
00127     IndexBase_(RowMap.IndexBase()),
00128     NumGlobalEntries_(0),
00129     NumGlobalBlockRows_(RowMap.NumGlobalElements()),
00130     NumGlobalBlockCols_(ColMap.NumGlobalElements()),
00131     NumGlobalBlockDiagonals_(0),
00132     NumMyEntries_(0),
00133     NumMyBlockRows_(RowMap.NumMyElements()),
00134     NumMyBlockCols_(ColMap.NumMyElements()),
00135     NumMyBlockDiagonals_(0),
00136     MaxRowDim_(RowMap.MaxElementSize()),
00137     MaxColDim_(ColMap.MaxElementSize()),
00138     GlobalMaxRowDim_(RowMap.MaxElementSize()),
00139     GlobalMaxColDim_(ColMap.MaxElementSize()),
00140     MaxNumNonzeros_(0),
00141     GlobalMaxNumNonzeros_(0),
00142     NumGlobalNonzeros_(0),
00143     NumGlobalRows_(RowMap.NumGlobalPoints()),
00144     NumGlobalCols_(ColMap.NumGlobalPoints()),
00145     NumGlobalDiagonals_(0),
00146     NumMyNonzeros_(0),
00147     NumMyRows_(RowMap.NumMyPoints()),
00148     NumMyCols_(ColMap.NumMyPoints()),
00149     NumMyDiagonals_(0), 
00150     MaxNumIndices_(0),
00151     GlobalMaxNumIndices_(0),
00152     Indices_(new int *[NumMyBlockRows_]),
00153     NumAllocatedIndicesPerRow_(0),
00154     NumIndicesPerRow_(0),
00155     IndexOffset_(0),
00156     All_Indices_(0),
00157     CV_(CV)
00158 {
00159   //cout << "--CRSGD created(rowmap&colmap ctr), addr: " << this << endl; //DATA_DEBUG
00160 }
00161 
00162 //=============================================================================
00163 Epetra_CrsGraphData::~Epetra_CrsGraphData() {
00164 
00165   if(Indices_ != 0 && !StorageOptimized_) {
00166     for (int i=0; i<NumMyBlockRows_; i++) {
00167       if (Indices_[i]!=0 && CV_==Copy && !StaticProfile_) 
00168   delete [] Indices_[i]; 
00169       Indices_[i] = 0;
00170     } 
00171     delete[] Indices_;
00172     Indices_ = 0;
00173   }
00174 
00175   if(Importer_ != 0) {
00176     delete Importer_;
00177     Importer_ = 0;
00178   }
00179   if(Exporter_ != 0) {
00180     delete Exporter_;
00181     Importer_ = 0;
00182   }
00183 
00184   NumMyBlockRows_ = 0;  // are these needed?
00185   Filled_ = false;      // they're about to go out of scope, after all
00186   Allocated_ = false;
00187 
00188   //cout << "--CRSGD destroyed, addr: " << this << endl; //DATA_DEBUG
00189 }
00190 
00191 //==========================================================================
00192 int Epetra_CrsGraphData::MakeImportExport() {
00193   // Create Import object for use by matrix classes.    This is only needed if ColMap and DomainMap are different
00194   if (!ColMap_.SameAs(DomainMap_)) {
00195     if (Importer_ != 0) {
00196       delete Importer_;
00197       Importer_ = 0;
00198     }
00199     Importer_ = new Epetra_Import(ColMap_, DomainMap_);
00200   }
00201   
00202   // Now see if we need to define an export map.  This is only needed if RowMap and RangeMap are different
00203   if (!RowMap_.SameAs(RangeMap_)) {
00204     if (Exporter_ != 0) {
00205       delete Exporter_;
00206       Exporter_ = 0;
00207     }
00208     Exporter_ = new Epetra_Export(RowMap_, RangeMap_); // Create Export object. 
00209   }
00210    
00211   return(0);
00212 }
00213 
00214 //==========================================================================
00215 int Epetra_CrsGraphData::ReAllocateAndCast(char*& UserPtr, int& Length, const int IntPacketSizeTimesNumTrans) {
00216   if(IntPacketSizeTimesNumTrans > Length) {
00217     if(Length > 0) 
00218       delete[] UserPtr;
00219     Length = IntPacketSizeTimesNumTrans;
00220     int* newPtr = new int[Length];
00221     UserPtr = reinterpret_cast<char*> (newPtr);
00222   }
00223   return(0);
00224 }
00225 
00226 //==========================================================================
00227 void Epetra_CrsGraphData::Print(ostream& os, int level) const {
00228   bool four_bit = (level >= 4);      // 4-bit = BlockMaps
00229   bool two_bit = ((level % 4) >= 2); // 2-bit = Indices
00230   bool one_bit = ((level % 2) == 1); // 1-bit = Everything else
00231 
00232   os << "\n***** CrsGraphData (output level " << level << ") *****" << endl;
00233 
00234   if(four_bit) {
00235     os << "RowMap_:\n" << RowMap_ << endl;
00236     os << "ColMap_:\n" << ColMap_ << endl;
00237     os << "DomainMap_:\n" << DomainMap_ << endl;
00238     os << "RangeMap_:\n" << RangeMap_ << endl;
00239   }
00240   
00241   if(one_bit) {
00242     os.width(26); os << "HaveColMap_: "              << HaveColMap_;
00243     os.width(25); os << "Filled_: "                  << Filled_;
00244     os.width(25); os << "Allocated_: "               << Allocated_;
00245     os.width(25); os << "Sorted_: "                  << Sorted_ << endl;
00246     os.width(26); os << "StorageOptimized_: "        << StorageOptimized_;
00247     os.width(25); os << "SortGhostsAssociatedWithEachProcessor_: " << SortGhostsAssociatedWithEachProcessor_;
00248     os.width(25); os << "NoRedundancies_: "          << NoRedundancies_;
00249     os.width(25); os << "IndicesAreGlobal_: "        << IndicesAreGlobal_;
00250     os.width(25); os << "IndicesAreLocal_: "         << IndicesAreLocal_ << endl;
00251     os.width(26); os << "IndicesAreContiguous_: "    << IndicesAreContiguous_;
00252     os.width(25); os << "LowerTriangular_: "         << LowerTriangular_;
00253     os.width(25); os << "UpperTriangular_: "         << UpperTriangular_;
00254     os.width(25); os << "NoDiagonal_: "              << NoDiagonal_ << endl;
00255     os.width(25); os << "GlobalConstantsComputed_: " << GlobalConstantsComputed_ << endl;
00256     os.width(25); os << "StaticProfile_: " << StaticProfile_ << endl << endl;
00257     
00258     os.width(10); os << "NGBR_: " << NumGlobalBlockRows_;
00259     os.width(10); os << "NGBC_: " << NumGlobalBlockCols_;
00260     os.width(10); os << "NGBD_: " << NumGlobalBlockDiagonals_;
00261     os.width(10); os << "NGE_: "  << NumGlobalEntries_;
00262     os.width(10); os << "NGR_: "  << NumGlobalRows_;
00263     os.width(10); os << "NGC_: "  << NumGlobalCols_;
00264     os.width(10); os << "NGD_: "  << NumGlobalDiagonals_;
00265     os.width(10); os << "NGN_: "  << NumGlobalNonzeros_;
00266     os.width(10); os << "IB_: "   << IndexBase_ << endl;
00267     os.width(10); os << "GMRD_: " << GlobalMaxRowDim_;
00268     os.width(11); os << "GMCD_: " << GlobalMaxColDim_;
00269     os.width(11); os << "GMNI_: " << GlobalMaxNumIndices_;
00270     os.width(11); os << "NMBR_: " << NumMyBlockRows_;
00271     os.width(10); os << "NMBC_: " << NumMyBlockCols_;
00272     os.width(10); os << "NMBD_: " << NumMyBlockDiagonals_;
00273     os.width(10); os << "NME_: "  << NumMyEntries_;
00274     os.width(10); os << "NMR_: "  << NumMyRows_;
00275     os.width(10); os << "CV_: " << CV_ << endl;
00276     os.width(10); os << "NMC_: "  << NumMyCols_;
00277     os.width(10); os << "NMD_: "  << NumMyDiagonals_;
00278     os.width(10); os << "NMN_: "  << NumMyNonzeros_;
00279     os.width(10); os << "MRD_: "  << MaxRowDim_;
00280     os.width(11); os << "MCD_: "  << MaxColDim_;
00281     os.width(11); os << "MNI_: "  << MaxNumIndices_;
00282     os.width(11); os << "MNN_: "  << MaxNumNonzeros_;
00283     os.width(11); os << "GMNN_: " << GlobalMaxNumNonzeros_;
00284     os.width(11); os << "RC: " << ReferenceCount() << endl << endl;
00285     
00286     os << "NIPR_: " << NumIndicesPerRow_ << endl;
00287     os << "NAIPR_: " << NumAllocatedIndicesPerRow_ << endl;
00288     os << "IndexOffset_: " << IndexOffset_ << endl;
00289     os << "All_Indices_: " << All_Indices_ << endl;
00290   }
00291     
00292   if(two_bit) {
00293     os << "Indices_: " << Indices_ << endl;
00294     if(Indices_ != 0) {
00295       for(int i = 0; i < NumMyBlockRows_; i++) {
00296   os << "Indices_[" << i << "]: (" << Indices_[i] << ") ";
00297   if(Indices_[i] != 0) {
00298     for(int j = 0; j < NumAllocatedIndicesPerRow_[i]; j++)
00299       os << Indices_[i][j] << " ";
00300   }
00301   os << endl;
00302       }
00303     }
00304   }
00305   
00306   os << "***** End CrsGraphData *****" << endl;
00307 }

Generated on Wed May 12 21:41:05 2010 for Epetra Package Browser (Single Doxygen Collection) by  doxygen 1.4.7