FEI  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
fei_Matrix_core.hpp
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 
79  void setSlaveInfo(fei::SharedPtr<fei::MatrixGraph> matrixGraph);
80 
81  fei::SharedPtr<fei::MatrixGraph> getMatrixGraph() const { return( matrixGraph_ ); }
82 
83  const FillableMat* getRemotelyOwnedMatrix(int proc) const
84  {
85  if (proc_last_requested_ == proc) {
86  return remotelyOwned_last_requested_;
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 
98  FillableMat* getRemotelyOwnedMatrix(int proc)
99  {
100  if (proc_last_requested_ == proc) {
101  return remotelyOwned_last_requested_;
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 
121  void setEqnComm(fei::SharedPtr<fei::EqnComm> eqnComm);
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 
151  void setMatrixGraph(fei::SharedPtr<fei::MatrixGraph> matrixGraph);
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 
180  const fei::SharedPtr<fei::VectorSpace> vecSpace() const { return( vecSpace_ ); }
181  fei::SharedPtr<fei::VectorSpace> vecSpace() { return( vecSpace_ ); }
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:
214  fei::SharedPtr<fei::Vector> rhsVector_;
215 
216  MPI_Comm comm_;
217 
218  int localProc_, numProcs_;
219 
222 
223  std::map<int,FillableMat*> remotelyOwned_;
224  mutable FillableMat* remotelyOwned_last_requested_;
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_;
229  bool sendRecvProcsNeedUpdated_;
230  mutable int proc_last_requested_;
231 
232  bool haveBlockMatrix_;
233  bool haveFEMatrix_;
234 
235  std::vector<int> globalOffsets_;
236  int firstLocalOffset_, lastLocalOffset_;
237 };//class Matrix_core
238 }//namespace fei
239 
240 #endif
241 
int localProc(MPI_Comm comm)
int numProcs(MPI_Comm comm)