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   void setCommSizes();
00149   int gatherFromOverlap(bool accumulate);
00150 
00151   void setMatrixGraph(fei::SharedPtr<fei::MatrixGraph> matrixGraph);
00152 
00162   int copyPointRowsToBlockRow(int numPtRows,
00163                               int numPtCols,
00164                               const double*const* ptValues,
00165                               int numBlkCols,
00166                               const int* blkColDims,
00167                               double** blkValues);
00168 
00169   int convertPtToBlk(int numRows,
00170                        const int* rows,
00171                        int numCols,
00172                        const int* cols,
00173                        int* blkRows,
00174                        int* blkRowOffsets,
00175                        int* blkCols,
00176                        int* blkColOffsets);
00177 
00178   MPI_Comm getCommunicator() const { return( comm_ ); }
00179 
00180   const fei::SharedPtr<fei::VectorSpace> vecSpace() const { return( vecSpace_ ); }
00181   fei::SharedPtr<fei::VectorSpace> vecSpace() { return( vecSpace_ ); }
00182 
00183   std::vector<int>& globalOffsets() { return( globalOffsets_ ); }
00184   const std::vector<int>& globalOffsets() const { return( globalOffsets_ ); }
00185 
00186   int firstLocalOffset() const { return( firstLocalOffset_ ); }
00187   int lastLocalOffset() const  { return( lastLocalOffset_ ); }
00188 
00189   int numProcs() const { return( numProcs_ ); }
00190   int localProc() const { return( localProc_ ); }
00191 
00192   bool haveBlockMatrix() const { return( haveBlockMatrix_ ); }
00193   void setBlockMatrix(bool flag) {haveBlockMatrix_ = flag; }
00194 
00195   bool haveFEMatrix() const { return( haveFEMatrix_ ); }
00196   void setFEMatrix(bool flag) {haveFEMatrix_ = flag; }
00197 
00198   int getOwnerProc(int globalEqn) const;
00199 
00200   std::string name_;
00201 
00202   std::vector<int> work_indices_;
00203   std::vector<int> work_indices2_;
00204 
00205   std::vector<int> work_ints_;
00206 
00207   std::vector<double> work_data1D_;
00208   std::vector<const double*> work_data2D_;
00209 
00210  protected:
00211   fei::SharedPtr<fei::EqnComm> eqnComm_;
00212 
00213  private:
00214   fei::SharedPtr<fei::Vector> rhsVector_;
00215 
00216   MPI_Comm comm_;
00217 
00218   int localProc_, numProcs_;
00219 
00220   fei::SharedPtr<fei::VectorSpace> vecSpace_;
00221   fei::SharedPtr<fei::MatrixGraph> matrixGraph_;
00222 
00223   std::map<int,FillableMat*> remotelyOwned_;
00224   mutable FillableMat* remotelyOwned_last_requested_;
00225   std::vector<int> sendProcs_;
00226   std::vector<int> recvProcs_;
00227   std::vector<std::vector<char> > recv_chars_;
00228   std::vector<std::vector<char> > send_chars_;
00229   bool sendRecvProcsNeedUpdated_;
00230   mutable int proc_last_requested_;
00231 
00232   bool haveBlockMatrix_;
00233   bool haveFEMatrix_;
00234 
00235   std::vector<int> globalOffsets_;
00236   int firstLocalOffset_, lastLocalOffset_;
00237 };//class Matrix_core
00238 }//namespace fei
00239 
00240 #endif
00241 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends