FEI Version of the Day
fei_Matrix_core.hpp
00001 #ifndef _fei_Matrix_core_hpp_
00002 #define _fei_Matrix_core_hpp_
00003 
00004 /*--------------------------------------------------------------------*/
00005 /*    Copyright 2005 Sandia Corporation.                              */
00006 /*    Under the terms of Contract DE-AC04-94AL85000, there is a       */
00007 /*    non-exclusive license for use of this work by or on behalf      */
00008 /*    of the U.S. Government.  Export of this program may require     */
00009 /*    a license from the United States Government.                    */
00010 /*--------------------------------------------------------------------*/
00011 
00012 #include <fei_macros.hpp>
00013 #include <fei_mpi.h>
00014 #include <fei_EqnComm.hpp>
00015 #include <fei_fwd.hpp>
00016 #include <fei_Vector.hpp>
00017 #include <fei_CommUtils.hpp>
00018 #include <fei_FillableMat.hpp>
00019 #include <fei_MatrixGraph.hpp>
00020 #include <fei_Logger.hpp>
00021 
00022 #include <vector>
00023 
00024 namespace fei {
00025 class Matrix_core : protected fei::Logger {
00026  public:
00027 
00028   Matrix_core(fei::SharedPtr<fei::MatrixGraph> matrixGraph, int numLocalEqns);
00029 
00030   virtual ~Matrix_core();
00031 
00032   virtual int giveToMatrix(int numRows, const int* rows,
00033                            int numCols, const int* cols,
00034                            const double* const* values,
00035                            bool sumInto,
00036                            int format) = 0;
00037 
00062   static void copyTransposeToWorkArrays(int numRows, int numCols,
00063                                        const double*const* values,
00064                                        std::vector<double>& work_1D,
00065                                        std::vector<const double*>& work_2D);
00066 
00073   void setRHS(fei::SharedPtr<fei::Vector> rhsvector);
00074 
00079   void setSlaveInfo(fei::SharedPtr<fei::MatrixGraph> matrixGraph);
00080 
00081   fei::SharedPtr<fei::MatrixGraph> getMatrixGraph() const { return( matrixGraph_ ); }
00082 
00083   const FillableMat* getRemotelyOwnedMatrix(int proc) const
00084   {
00085     if (proc_last_requested_ == proc) {
00086       return remotelyOwned_last_requested_;
00087     }
00088     FillableMat* remote_mat = NULL;
00089     std::map<int,FillableMat*>::const_iterator it = remotelyOwned_.find(proc);
00090     if (it != remotelyOwned_.end()) {
00091       remote_mat = it->second;
00092       remotelyOwned_last_requested_ = remote_mat;
00093       proc_last_requested_ = proc;
00094     }
00095     return( remote_mat );
00096   }
00097 
00098   FillableMat* getRemotelyOwnedMatrix(int proc)
00099   {
00100     if (proc_last_requested_ == proc) {
00101       return remotelyOwned_last_requested_;
00102     }
00103     proc_last_requested_ = proc;
00104     FillableMat* remote_mat = NULL;
00105     std::map<int,FillableMat*>::iterator it = remotelyOwned_.find(proc);
00106     if (it == remotelyOwned_.end()) {
00107       remote_mat = new FillableMat;
00108       remotelyOwned_.insert(std::make_pair(proc, remote_mat));
00109     }
00110     else {
00111       remote_mat = it->second;
00112     }
00113     remotelyOwned_last_requested_ = remote_mat;
00114     return( remote_mat );
00115   }
00116 
00117   std::map<int,FillableMat*>& getRemotelyOwnedMatrices();
00118 
00119   void putScalar_remotelyOwned(double scalar);
00120 
00121   void setEqnComm(fei::SharedPtr<fei::EqnComm> eqnComm);
00122 
00123  protected:
00124   void parameters(const fei::ParameterSet& paramset);
00125 
00126   virtual int giveToUnderlyingMatrix(int numRows, const int* rows,
00127                                      int numCols, const int* cols,
00128                                      const double* const* values,
00129                                      bool sumInto,
00130                                      int format) = 0;
00131 
00132   virtual int giveToBlockMatrix(int numRows, const int* rows,
00133                                           int numCols, const int* cols,
00134                                           const double* const* values,
00135                                           bool sumInto) = 0;
00136 
00137   virtual int giveToUnderlyingBlockMatrix(int row,
00138                                           int rowDim,
00139                                           int numCols,
00140                                           const int* cols,
00141                                           const int* LDAs,
00142                                           const int* colDims,
00143                                           const double* const* values,
00144                                           bool sumInto) = 0;
00145 
00146   void setName(const char* name);
00147 
00148   int gatherFromOverlap(bool accumulate);
00149 
00150   void setMatrixGraph(fei::SharedPtr<fei::MatrixGraph> matrixGraph);
00151 
00161   int copyPointRowsToBlockRow(int numPtRows,
00162                               int numPtCols,
00163                               const double*const* ptValues,
00164                               int numBlkCols,
00165                               const int* blkColDims,
00166                               double** blkValues);
00167 
00168   int convertPtToBlk(int numRows,
00169                        const int* rows,
00170                        int numCols,
00171                        const int* cols,
00172                        int* blkRows,
00173                        int* blkRowOffsets,
00174                        int* blkCols,
00175                        int* blkColOffsets);
00176 
00177   MPI_Comm getCommunicator() const { return( comm_ ); }
00178 
00179   const fei::SharedPtr<fei::VectorSpace> vecSpace() const { return( vecSpace_ ); }
00180   fei::SharedPtr<fei::VectorSpace> vecSpace() { return( vecSpace_ ); }
00181 
00182   std::vector<int>& globalOffsets() { return( globalOffsets_ ); }
00183   const std::vector<int>& globalOffsets() const { return( globalOffsets_ ); }
00184 
00185   int firstLocalOffset() const { return( firstLocalOffset_ ); }
00186   int lastLocalOffset() const  { return( lastLocalOffset_ ); }
00187 
00188   int numProcs() const { return( numProcs_ ); }
00189   int localProc() const { return( localProc_ ); }
00190 
00191   bool haveBlockMatrix() const { return( haveBlockMatrix_ ); }
00192   void setBlockMatrix(bool flag) {haveBlockMatrix_ = flag; }
00193 
00194   bool haveFEMatrix() const { return( haveFEMatrix_ ); }
00195   void setFEMatrix(bool flag) {haveFEMatrix_ = flag; }
00196 
00197   int getOwnerProc(int globalEqn) const;
00198 
00199   std::string name_;
00200 
00201   std::vector<int> work_indices_;
00202   std::vector<int> work_indices2_;
00203 
00204   std::vector<int> work_ints_;
00205 
00206   std::vector<double> work_data1D_;
00207   std::vector<const double*> work_data2D_;
00208 
00209  protected:
00210   fei::SharedPtr<fei::EqnComm> eqnComm_;
00211 
00212  private:
00213   fei::SharedPtr<fei::Vector> rhsVector_;
00214 
00215   MPI_Comm comm_;
00216 
00217   int localProc_, numProcs_;
00218 
00219   fei::SharedPtr<fei::VectorSpace> vecSpace_;
00220   fei::SharedPtr<fei::MatrixGraph> matrixGraph_;
00221 
00222   std::map<int,FillableMat*> remotelyOwned_;
00223   mutable FillableMat* remotelyOwned_last_requested_;
00224   std::vector<int> sendProcs_;
00225   std::vector<int> recvProcs_;
00226   bool sendRecvProcsNeedUpdated_;
00227   mutable int proc_last_requested_;
00228 
00229   bool haveBlockMatrix_;
00230   bool haveFEMatrix_;
00231 
00232   std::vector<int> globalOffsets_;
00233   int firstLocalOffset_, lastLocalOffset_;
00234 };//class Matrix_core
00235 }//namespace fei
00236 
00237 #endif
00238 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends