FEI Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fei_Matrix_core.hpp
Go to the documentation of this file.
1 #ifndef _fei_Matrix_core_hpp_
2 #define _fei_Matrix_core_hpp_
3 
4 /*--------------------------------------------------------------------*/
5 /* Copyright 2005 Sandia Corporation. */
6 /* Under the terms of Contract DE-AC04-94AL85000, there is a */
7 /* non-exclusive license for use of this work by or on behalf */
8 /* of the U.S. Government. Export of this program may require */
9 /* a license from the United States Government. */
10 /*--------------------------------------------------------------------*/
11 
12 #include <fei_macros.hpp>
13 #include <fei_mpi.h>
14 #include <fei_EqnComm.hpp>
15 #include <fei_fwd.hpp>
16 #include <fei_Vector.hpp>
17 #include <fei_CommUtils.hpp>
18 #include <fei_FillableMat.hpp>
19 #include <fei_MatrixGraph.hpp>
20 #include <fei_Logger.hpp>
21 
22 #include <vector>
23 
24 namespace fei {
25 class Matrix_core : protected fei::Logger {
26  public:
27 
28  Matrix_core(fei::SharedPtr<fei::MatrixGraph> matrixGraph, int numLocalEqns);
29 
30  virtual ~Matrix_core();
31 
32  virtual int giveToMatrix(int numRows, const int* rows,
33  int numCols, const int* cols,
34  const double* const* values,
35  bool sumInto,
36  int format) = 0;
37 
62  static void copyTransposeToWorkArrays(int numRows, int numCols,
63  const double*const* values,
64  std::vector<double>& work_1D,
65  std::vector<const double*>& work_2D);
66 
73  void setRHS(fei::SharedPtr<fei::Vector> rhsvector);
74 
80 
82 
83  const FillableMat* getRemotelyOwnedMatrix(int proc) const
84  {
85  if (proc_last_requested_ == proc) {
87  }
88  FillableMat* remote_mat = NULL;
89  std::map<int,FillableMat*>::const_iterator it = remotelyOwned_.find(proc);
90  if (it != remotelyOwned_.end()) {
91  remote_mat = it->second;
92  remotelyOwned_last_requested_ = remote_mat;
93  proc_last_requested_ = proc;
94  }
95  return( remote_mat );
96  }
97 
99  {
100  if (proc_last_requested_ == proc) {
102  }
103  proc_last_requested_ = proc;
104  FillableMat* remote_mat = NULL;
105  std::map<int,FillableMat*>::iterator it = remotelyOwned_.find(proc);
106  if (it == remotelyOwned_.end()) {
107  remote_mat = new FillableMat;
108  remotelyOwned_.insert(std::make_pair(proc, remote_mat));
109  }
110  else {
111  remote_mat = it->second;
112  }
113  remotelyOwned_last_requested_ = remote_mat;
114  return( remote_mat );
115  }
116 
117  std::map<int,FillableMat*>& getRemotelyOwnedMatrices();
118 
119  void putScalar_remotelyOwned(double scalar);
120 
122 
123  protected:
124  void parameters(const fei::ParameterSet& paramset);
125 
126  virtual int giveToUnderlyingMatrix(int numRows, const int* rows,
127  int numCols, const int* cols,
128  const double* const* values,
129  bool sumInto,
130  int format) = 0;
131 
132  virtual int giveToBlockMatrix(int numRows, const int* rows,
133  int numCols, const int* cols,
134  const double* const* values,
135  bool sumInto) = 0;
136 
137  virtual int giveToUnderlyingBlockMatrix(int row,
138  int rowDim,
139  int numCols,
140  const int* cols,
141  const int* LDAs,
142  const int* colDims,
143  const double* const* values,
144  bool sumInto) = 0;
145 
146  void setName(const char* name);
147 
148  void setCommSizes();
149  int gatherFromOverlap(bool accumulate);
150 
152 
162  int copyPointRowsToBlockRow(int numPtRows,
163  int numPtCols,
164  const double*const* ptValues,
165  int numBlkCols,
166  const int* blkColDims,
167  double** blkValues);
168 
169  int convertPtToBlk(int numRows,
170  const int* rows,
171  int numCols,
172  const int* cols,
173  int* blkRows,
174  int* blkRowOffsets,
175  int* blkCols,
176  int* blkColOffsets);
177 
178  MPI_Comm getCommunicator() const { return( comm_ ); }
179 
182 
183  std::vector<int>& globalOffsets() { return( globalOffsets_ ); }
184  const std::vector<int>& globalOffsets() const { return( globalOffsets_ ); }
185 
186  int firstLocalOffset() const { return( firstLocalOffset_ ); }
187  int lastLocalOffset() const { return( lastLocalOffset_ ); }
188 
189  int numProcs() const { return( numProcs_ ); }
190  int localProc() const { return( localProc_ ); }
191 
192  bool haveBlockMatrix() const { return( haveBlockMatrix_ ); }
193  void setBlockMatrix(bool flag) {haveBlockMatrix_ = flag; }
194 
195  bool haveFEMatrix() const { return( haveFEMatrix_ ); }
196  void setFEMatrix(bool flag) {haveFEMatrix_ = flag; }
197 
198  int getOwnerProc(int globalEqn) const;
199 
200  std::string name_;
201 
202  std::vector<int> work_indices_;
203  std::vector<int> work_indices2_;
204 
205  std::vector<int> work_ints_;
206 
207  std::vector<double> work_data1D_;
208  std::vector<const double*> work_data2D_;
209 
210  protected:
212 
213  private:
215 
217 
219 
222 
223  std::map<int,FillableMat*> remotelyOwned_;
225  std::vector<int> sendProcs_;
226  std::vector<int> recvProcs_;
227  std::vector<std::vector<char> > recv_chars_;
228  std::vector<std::vector<char> > send_chars_;
230  mutable int proc_last_requested_;
231 
234 
235  std::vector<int> globalOffsets_;
237 };//class Matrix_core
238 }//namespace fei
239 
240 #endif
241 
int lastLocalOffset() const
const FillableMat * getRemotelyOwnedMatrix(int proc) const
std::map< int, FillableMat * > & getRemotelyOwnedMatrices()
int localProc() const
MPI_Comm getCommunicator() const
FillableMat * remotelyOwned_last_requested_
std::vector< std::vector< char > > send_chars_
fei::SharedPtr< fei::Vector > rhsVector_
int getOwnerProc(int globalEqn) const
Matrix_core(fei::SharedPtr< fei::MatrixGraph > matrixGraph, int numLocalEqns)
virtual int giveToMatrix(int numRows, const int *rows, int numCols, const int *cols, const double *const *values, bool sumInto, int format)=0
std::map< int, FillableMat * > remotelyOwned_
std::vector< int > & globalOffsets()
std::vector< int > work_indices2_
fei::SharedPtr< fei::MatrixGraph > matrixGraph_
void setMatrixGraph(fei::SharedPtr< fei::MatrixGraph > matrixGraph)
bool haveBlockMatrix() const
#define MPI_Comm
Definition: fei_mpi.h:56
int gatherFromOverlap(bool accumulate)
std::vector< int > work_ints_
const fei::SharedPtr< fei::VectorSpace > vecSpace() const
std::vector< double > work_data1D_
void setRHS(fei::SharedPtr< fei::Vector > rhsvector)
int copyPointRowsToBlockRow(int numPtRows, int numPtCols, const double *const *ptValues, int numBlkCols, const int *blkColDims, double **blkValues)
std::vector< int > recvProcs_
std::vector< int > globalOffsets_
int convertPtToBlk(int numRows, const int *rows, int numCols, const int *cols, int *blkRows, int *blkRowOffsets, int *blkCols, int *blkColOffsets)
int firstLocalOffset() const
virtual int giveToUnderlyingBlockMatrix(int row, int rowDim, int numCols, const int *cols, const int *LDAs, const int *colDims, const double *const *values, bool sumInto)=0
static void copyTransposeToWorkArrays(int numRows, int numCols, const double *const *values, std::vector< double > &work_1D, std::vector< const double * > &work_2D)
int numProcs() const
FillableMat * getRemotelyOwnedMatrix(int proc)
std::vector< const double * > work_data2D_
void setFEMatrix(bool flag)
void setEqnComm(fei::SharedPtr< fei::EqnComm > eqnComm)
virtual int giveToBlockMatrix(int numRows, const int *rows, int numCols, const int *cols, const double *const *values, bool sumInto)=0
fei::SharedPtr< fei::VectorSpace > vecSpace()
void parameters(const fei::ParameterSet &paramset)
virtual int giveToUnderlyingMatrix(int numRows, const int *rows, int numCols, const int *cols, const double *const *values, bool sumInto, int format)=0
bool haveFEMatrix() const
void setSlaveInfo(fei::SharedPtr< fei::MatrixGraph > matrixGraph)
std::vector< int > work_indices_
std::vector< int > sendProcs_
std::vector< std::vector< char > > recv_chars_
fei::SharedPtr< fei::EqnComm > eqnComm_
fei::SharedPtr< fei::VectorSpace > vecSpace_
fei::SharedPtr< fei::MatrixGraph > getMatrixGraph() const
const std::vector< int > & globalOffsets() const
void setName(const char *name)
void putScalar_remotelyOwned(double scalar)
void setBlockMatrix(bool flag)