Epetra Package Browser (Single Doxygen Collection) Development
Epetra_MultiVector.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_MULTIVECTOR_H
00045 #define EPETRA_MULTIVECTOR_H
00046 
00047 class Epetra_Comm;
00048 class Epetra_BlockMap;
00049 class Epetra_Map;
00050 class Epetra_Import;
00051 class Epetra_Export;
00052 class Epetra_Distributor;
00053 class Epetra_Vector;
00054 
00055 #include "Epetra_ConfigDefs.h"
00056 #include "Epetra_DistObject.h"
00057 #include "Epetra_CompObject.h"
00058 #include "Epetra_BLAS.h"
00059 #include "Epetra_Util.h"
00060 
00062 
00183 //==========================================================================
00184 class EPETRA_LIB_DLL_EXPORT Epetra_MultiVector: public Epetra_DistObject, public Epetra_CompObject, public Epetra_BLAS {
00185 
00186  public:
00187 
00189 
00190 
00191 
00208   Epetra_MultiVector(const Epetra_BlockMap& Map, int NumVectors, bool zeroOut = true);
00209 
00211 
00212   Epetra_MultiVector(const Epetra_MultiVector& Source);
00213 
00215 
00234   Epetra_MultiVector(Epetra_DataAccess CV, const Epetra_BlockMap& Map,
00235          double *A, int MyLDA, int NumVectors);
00236 
00238 
00253   Epetra_MultiVector(Epetra_DataAccess CV, const Epetra_BlockMap& Map,
00254          double **ArrayOfPointers, int NumVectors);
00255 
00257 
00271   Epetra_MultiVector(Epetra_DataAccess CV,
00272          const Epetra_MultiVector& Source, int *Indices, int NumVectors);
00273 
00275 
00289   Epetra_MultiVector(Epetra_DataAccess CV,
00290          const Epetra_MultiVector& Source, int StartIndex,
00291          int NumVectors);
00292 
00294   virtual ~Epetra_MultiVector();
00296 
00298 
00299 
00301 
00320 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00321   int ReplaceGlobalValue(int GlobalRow, int VectorIndex, double ScalarValue);
00322 #endif
00323 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00324   int ReplaceGlobalValue(long long GlobalRow, int VectorIndex, double ScalarValue);
00325 #endif
00326 
00327 
00329 
00347 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00348   int ReplaceGlobalValue(int GlobalBlockRow, int BlockRowOffset, int VectorIndex, double ScalarValue);
00349 #endif
00350 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00351   int ReplaceGlobalValue(long long GlobalBlockRow, int BlockRowOffset, int VectorIndex, double ScalarValue);
00352 #endif
00353 
00354 
00356 
00375 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00376   int SumIntoGlobalValue(int GlobalRow, int VectorIndex, double ScalarValue);
00377 #endif
00378 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00379   int SumIntoGlobalValue(long long GlobalRow, int VectorIndex, double ScalarValue);
00380 #endif
00381 
00382 
00384 
00402 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00403   int SumIntoGlobalValue(int GlobalBlockRow, int BlockRowOffset, int VectorIndex, double ScalarValue);
00404 #endif
00405 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
00406   int SumIntoGlobalValue(long long GlobalBlockRow, int BlockRowOffset, int VectorIndex, double ScalarValue);
00407 #endif
00408 
00410 
00434   int ReplaceMyValue(int MyRow, int VectorIndex, double ScalarValue);
00435 
00436 
00438 
00456   int ReplaceMyValue(int MyBlockRow, int BlockRowOffset, int VectorIndex, double ScalarValue);
00457 
00458 
00460 
00479   int SumIntoMyValue(int MyRow, int VectorIndex, double ScalarValue);
00480 
00481 
00483 
00501   int SumIntoMyValue(int MyBlockRow, int BlockRowOffset, int VectorIndex, double ScalarValue);
00502 
00504 
00510   int PutScalar (double ScalarConstant);
00511 
00513 
00519   int Random();
00520 
00522 
00524 
00525 
00527 
00541   int ExtractCopy(double *A, int MyLDA) const;
00542 
00544 
00554   int ExtractCopy(double **ArrayOfPointers) const;
00555 
00556   // ExtractView functions
00557 
00558 
00560 
00574   int ExtractView(double **A, int *MyLDA) const;
00575 
00577 
00587   int ExtractView(double ***ArrayOfPointers) const;
00588 
00590 
00592 
00593 
00595 
00603   int Dot(const Epetra_MultiVector& A, double *Result) const;
00604 
00606 
00616   int Abs(const Epetra_MultiVector& A);
00617 
00619 
00634   int Reciprocal(const Epetra_MultiVector& A);
00635 
00637 
00645   int Scale(double ScalarValue);
00646 
00648 
00658   int Scale(double ScalarA, const Epetra_MultiVector& A);
00659 
00661 
00673   int Update(double ScalarA, const Epetra_MultiVector& A, double ScalarThis);
00674 
00676 
00692   int Update(double ScalarA, const Epetra_MultiVector& A,
00693        double ScalarB, const Epetra_MultiVector& B, double ScalarThis);
00694 
00696 
00703   int Norm1   (double * Result) const;
00704 
00706 
00713   int Norm2   (double * Result) const;
00714 
00716 
00722   int NormInf (double * Result) const;
00723 
00725 
00740   int NormWeighted   (const Epetra_MultiVector& Weights, double * Result) const;
00741 
00743 
00752   int MinValue  (double * Result) const;
00753 
00755 
00764   int MaxValue  (double * Result) const;
00765 
00767 
00774   int MeanValue (double * Result) const;
00775 
00776 
00778 
00830   int Multiply(char TransA, char TransB, double ScalarAB,
00831          const Epetra_MultiVector& A, const Epetra_MultiVector& B,
00832          double ScalarThis );
00833 
00834 
00835 
00837 
00843   int Multiply(double ScalarAB, const Epetra_MultiVector& A, const Epetra_MultiVector& B,
00844          double ScalarThis );
00845 
00846 
00848 
00854   int ReciprocalMultiply(double ScalarAB, const Epetra_MultiVector& A, const Epetra_MultiVector& B,
00855        double ScalarThis );
00856 
00858 
00860 
00861 
00862 
00864 
00870   int SetSeed(unsigned int Seed_in){return(Util_.SetSeed(Seed_in));};
00871 
00873 
00876   unsigned int Seed(){return(Util_.Seed());};
00877 
00879 
00881 
00882 
00884 
00890   Epetra_MultiVector& operator = (const Epetra_MultiVector& Source);
00891 
00892   // Local element access functions
00893 
00894   //
00895 
00897 
00900   double*& operator [] (int i) { return Pointers_[i]; }
00902 
00905   //  const double*& operator [] (int i) const;
00906   double * const & operator [] (int i) const { return Pointers_[i]; }
00907 
00909 
00912   Epetra_Vector * & operator () (int i);
00914 
00917   const Epetra_Vector * & operator () (int i) const;
00918 
00920 
00922 
00923 
00925   int NumVectors() const {return(NumVectors_);};
00926 
00928   int MyLength() const {return(MyLength_);};
00929 
00931 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
00932   int GlobalLength() const {
00933     if(Map().GlobalIndicesInt())
00934       return (int) GlobalLength_;
00935     throw "Epetra_MultiVector::GlobalLength: GlobalIndices not int.";
00936   }
00937 #endif
00938   long long GlobalLength64() const {return(GlobalLength_);};
00939 
00941   int Stride() const {return(Stride_);};
00942 
00944   bool ConstantStride() const {return(ConstantStride_);};
00946 
00950   int ReplaceMap(const Epetra_BlockMap& map);
00951 
00953 
00954 
00956   virtual void Print(std::ostream & os) const;
00958 
00960 
00961 
00963 
00982   int ResetView(double ** ArrayOfPointers);
00983 
00985   double* Values() const {return Values_;};
00986 
00988   double** Pointers() const {return Pointers_;};
00990 
00991   // Expert-only function
00992   int Reduce();
00993 
00994  protected:
00995 
00996   // Internal utilities
00997   void Assign(const Epetra_MultiVector& rhs);
00998   int CheckInput();
00999 
01000   double *Values_;    // local MultiVector coefficients
01001 
01002  private:
01003 
01004 
01005   // Internal utilities
01006 
01007   int AllocateForCopy(void);
01008   int DoCopy(void);
01009 
01010   inline void UpdateDoubleTemp() const
01011   {if (DoubleTemp_==0) DoubleTemp_=new double[NumVectors_+1]; return;}
01012 
01013   inline void UpdateVectors()  const {if (Vectors_==0) { Vectors_ = new Epetra_Vector *[NumVectors_];
01014     for (int i=0; i<NumVectors_; i++) Vectors_[i] = 0;}
01015     return;
01016   }
01017 
01018   int AllocateForView(void);
01019   int DoView(void);
01020   template<typename int_type>
01021   int ChangeGlobalValue(int_type GlobalBlockRow,
01022                         int BlockRowOffset,
01023                         int VectorIndex,
01024                         double ScalarValue,
01025                         bool SumInto);
01026   int ChangeMyValue(int MyBlockRow,
01027                     int BlockRowOffset,
01028                     int VectorIndex,
01029                     double ScalarValue,
01030                     bool SumInto);
01031 
01032   int CheckSizes(const Epetra_SrcDistObject& A);
01033 
01034   int CopyAndPermute(const Epetra_SrcDistObject & Source,
01035                      int NumSameIDs,
01036                      int NumPermuteIDs,
01037                      int * PermuteToLIDs,
01038                      int * PermuteFromLIDs,
01039                      const Epetra_OffsetIndex * Indexor,
01040                      Epetra_CombineMode CombineMode = Zero);
01041 
01042   int PackAndPrepare(const Epetra_SrcDistObject & Source,
01043                      int NumExportIDs,
01044                      int * ExportLIDs,
01045                      int & LenExports,
01046                      char * & Exports,
01047                      int & SizeOfPacket,
01048                      int * Sizes,
01049                      bool & VarSizes,
01050                      Epetra_Distributor & Distor);
01051 
01052   int UnpackAndCombine(const Epetra_SrcDistObject & Source,
01053                        int NumImportIDs,
01054                        int * ImportLIDs,
01055                        int LenImports,
01056                        char * Imports,
01057                        int & SizeOfPacket,
01058                        Epetra_Distributor & Distor,
01059                        Epetra_CombineMode CombineMode,
01060                        const Epetra_OffsetIndex * Indexor );
01061 
01062   double **Pointers_;        // Pointers to each vector;
01063 
01064   int MyLength_;
01065   long long GlobalLength_;
01066   int NumVectors_;
01067   bool UserAllocated_;
01068   bool ConstantStride_;
01069   int Stride_;
01070   bool Allocated_;
01071   mutable double * DoubleTemp_;
01072   mutable Epetra_Vector ** Vectors_;
01073   Epetra_Util Util_;
01074 
01075 };
01076 
01077 #endif /* EPETRA_MULTIVECTOR_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines