FEI Package Browser (Single Doxygen Collection)  Version of the Day
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 
fei::Matrix_core::giveToMatrix
virtual int giveToMatrix(int numRows, const int *rows, int numCols, const int *cols, const double *const *values, bool sumInto, int format)=0
fei::Matrix_core::name_
std::string name_
Definition: fei_Matrix_core.hpp:200
fei::Matrix_core::convertPtToBlk
int convertPtToBlk(int numRows, const int *rows, int numCols, const int *cols, int *blkRows, int *blkRowOffsets, int *blkCols, int *blkColOffsets)
Definition: fei_Matrix_core.cpp:350
fei::Matrix_core::gatherFromOverlap
int gatherFromOverlap(bool accumulate)
Definition: fei_Matrix_core.cpp:237
fei::Matrix_core::putScalar_remotelyOwned
void putScalar_remotelyOwned(double scalar)
Definition: fei_Matrix_core.cpp:93
fei::Matrix_core::eqnComm_
fei::SharedPtr< fei::EqnComm > eqnComm_
Definition: fei_Matrix_core.hpp:211
fei::Matrix_core::haveBlockMatrix_
bool haveBlockMatrix_
Definition: fei_Matrix_core.hpp:232
fei::Matrix_core::giveToUnderlyingMatrix
virtual int giveToUnderlyingMatrix(int numRows, const int *rows, int numCols, const int *cols, const double *const *values, bool sumInto, int format)=0
fei::Matrix_core::getRemotelyOwnedMatrix
FillableMat * getRemotelyOwnedMatrix(int proc)
Definition: fei_Matrix_core.hpp:98
fei::Matrix_core::localProc
int localProc() const
Definition: fei_Matrix_core.hpp:190
fei::Matrix_core::setBlockMatrix
void setBlockMatrix(bool flag)
Definition: fei_Matrix_core.hpp:193
fei::Matrix_core::work_indices_
std::vector< int > work_indices_
Definition: fei_Matrix_core.hpp:202
fei::FillableMat
Definition: fei_FillableMat.hpp:20
fei::Matrix_core::giveToBlockMatrix
virtual int giveToBlockMatrix(int numRows, const int *rows, int numCols, const int *cols, const double *const *values, bool sumInto)=0
fei::Matrix_core::setEqnComm
void setEqnComm(fei::SharedPtr< fei::EqnComm > eqnComm)
Definition: fei_Matrix_core.cpp:104
fei::Matrix_core::sendRecvProcsNeedUpdated_
bool sendRecvProcsNeedUpdated_
Definition: fei_Matrix_core.hpp:229
fei::Matrix_core::vecSpace
fei::SharedPtr< fei::VectorSpace > vecSpace()
Definition: fei_Matrix_core.hpp:181
fei::SharedPtr< fei::MatrixGraph >
fei::Matrix_core::work_data2D_
std::vector< const double * > work_data2D_
Definition: fei_Matrix_core.hpp:208
fei::Matrix_core::setSlaveInfo
void setSlaveInfo(fei::SharedPtr< fei::MatrixGraph > matrixGraph)
fei_macros.hpp
fei_fwd.hpp
fei::Matrix_core::getRemotelyOwnedMatrices
std::map< int, FillableMat * > & getRemotelyOwnedMatrices()
Definition: fei_Matrix_core.cpp:87
fei::Matrix_core::numProcs_
int numProcs_
Definition: fei_Matrix_core.hpp:218
fei::Matrix_core::work_ints_
std::vector< int > work_ints_
Definition: fei_Matrix_core.hpp:205
fei_Vector.hpp
fei::Matrix_core::remotelyOwned_last_requested_
FillableMat * remotelyOwned_last_requested_
Definition: fei_Matrix_core.hpp:224
fei::Matrix_core::haveFEMatrix
bool haveFEMatrix() const
Definition: fei_Matrix_core.hpp:195
fei::Matrix_core::comm_
MPI_Comm comm_
Definition: fei_Matrix_core.hpp:216
fei::Matrix_core::copyTransposeToWorkArrays
static void copyTransposeToWorkArrays(int numRows, int numCols, const double *const *values, std::vector< double > &work_1D, std::vector< const double * > &work_2D)
Definition: fei_Matrix_core.cpp:320
fei::Matrix_core::work_data1D_
std::vector< double > work_data1D_
Definition: fei_Matrix_core.hpp:207
fei::Logger
Definition: fei_Logger.hpp:19
fei::Matrix_core::getOwnerProc
int getOwnerProc(int globalEqn) const
Definition: fei_Matrix_core.cpp:152
fei::ParameterSet
Definition: fei_ParameterSet.hpp:46
fei::Matrix_core::firstLocalOffset_
int firstLocalOffset_
Definition: fei_Matrix_core.hpp:236
fei::Matrix_core::matrixGraph_
fei::SharedPtr< fei::MatrixGraph > matrixGraph_
Definition: fei_Matrix_core.hpp:221
fei::Matrix_core::setMatrixGraph
void setMatrixGraph(fei::SharedPtr< fei::MatrixGraph > matrixGraph)
Definition: fei_Matrix_core.cpp:399
fei::Matrix_core::Matrix_core
Matrix_core(fei::SharedPtr< fei::MatrixGraph > matrixGraph, int numLocalEqns)
Definition: fei_Matrix_core.cpp:32
fei_MatrixGraph.hpp
fei::Matrix_core::proc_last_requested_
int proc_last_requested_
Definition: fei_Matrix_core.hpp:230
fei::Matrix_core::vecSpace
const fei::SharedPtr< fei::VectorSpace > vecSpace() const
Definition: fei_Matrix_core.hpp:180
fei::Matrix_core::recv_chars_
std::vector< std::vector< char > > recv_chars_
Definition: fei_Matrix_core.hpp:227
fei::Matrix_core::numProcs
int numProcs() const
Definition: fei_Matrix_core.hpp:189
fei::Matrix_core::~Matrix_core
virtual ~Matrix_core()
Definition: fei_Matrix_core.cpp:113
fei::Matrix_core::lastLocalOffset_
int lastLocalOffset_
Definition: fei_Matrix_core.hpp:236
fei::Matrix_core::remotelyOwned_
std::map< int, FillableMat * > remotelyOwned_
Definition: fei_Matrix_core.hpp:223
fei_mpi.h
fei::Matrix_core::getCommunicator
MPI_Comm getCommunicator() const
Definition: fei_Matrix_core.hpp:178
fei::Matrix_core::haveBlockMatrix
bool haveBlockMatrix() const
Definition: fei_Matrix_core.hpp:192
fei_Logger.hpp
fei_EqnComm.hpp
fei::Matrix_core::setCommSizes
void setCommSizes()
Definition: fei_Matrix_core.cpp:171
fei_CommUtils.hpp
fei::Matrix_core::setName
void setName(const char *name)
Definition: fei_Matrix_core.cpp:143
fei::Matrix_core::copyPointRowsToBlockRow
int copyPointRowsToBlockRow(int numPtRows, int numPtCols, const double *const *ptValues, int numBlkCols, const int *blkColDims, double **blkValues)
Definition: fei_Matrix_core.cpp:376
fei::Matrix_core::getMatrixGraph
fei::SharedPtr< fei::MatrixGraph > getMatrixGraph() const
Definition: fei_Matrix_core.hpp:81
fei::Matrix_core::work_indices2_
std::vector< int > work_indices2_
Definition: fei_Matrix_core.hpp:203
fei::Matrix_core::send_chars_
std::vector< std::vector< char > > send_chars_
Definition: fei_Matrix_core.hpp:228
fei
Definition: fei_ArrayUtils.hpp:16
fei::Matrix_core::setRHS
void setRHS(fei::SharedPtr< fei::Vector > rhsvector)
Definition: fei_Matrix_core.cpp:166
fei::Matrix_core::haveFEMatrix_
bool haveFEMatrix_
Definition: fei_Matrix_core.hpp:233
fei::Matrix_core::globalOffsets
const std::vector< int > & globalOffsets() const
Definition: fei_Matrix_core.hpp:184
fei::Matrix_core::setFEMatrix
void setFEMatrix(bool flag)
Definition: fei_Matrix_core.hpp:196
MPI_Comm
#define MPI_Comm
Definition: fei_mpi.h:56
fei::Matrix_core::firstLocalOffset
int firstLocalOffset() const
Definition: fei_Matrix_core.hpp:186
fei::Matrix_core::localProc_
int localProc_
Definition: fei_Matrix_core.hpp:218
fei::Matrix_core::rhsVector_
fei::SharedPtr< fei::Vector > rhsVector_
Definition: fei_Matrix_core.hpp:214
fei::Matrix_core::lastLocalOffset
int lastLocalOffset() const
Definition: fei_Matrix_core.hpp:187
fei::Matrix_core::globalOffsets_
std::vector< int > globalOffsets_
Definition: fei_Matrix_core.hpp:235
fei::Matrix_core::sendProcs_
std::vector< int > sendProcs_
Definition: fei_Matrix_core.hpp:225
fei::Matrix_core::giveToUnderlyingBlockMatrix
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
fei::Matrix_core::vecSpace_
fei::SharedPtr< fei::VectorSpace > vecSpace_
Definition: fei_Matrix_core.hpp:220
fei::Matrix_core::getRemotelyOwnedMatrix
const FillableMat * getRemotelyOwnedMatrix(int proc) const
Definition: fei_Matrix_core.hpp:83
fei::Matrix_core::parameters
void parameters(const fei::ParameterSet &paramset)
Definition: fei_Matrix_core.cpp:124
fei::Matrix_core
Definition: fei_Matrix_core.hpp:25
fei::Matrix_core::globalOffsets
std::vector< int > & globalOffsets()
Definition: fei_Matrix_core.hpp:183
fei_FillableMat.hpp
fei::Matrix_core::recvProcs_
std::vector< int > recvProcs_
Definition: fei_Matrix_core.hpp:226