C++ mpi module for stochmagnet_main Package
SM_PackedBlockMatrix.h
1 #ifndef SM_PackedBlockMatrix_H
2 #define SM_PackedBlockMatrix_H
3 
4 //base classes
5 #include "CORE_Object.h"
6 
7 
17 template<typename T,tUCInt P>
19 
20 public:
23  static constexpr tUCInt BLOCK_SIZE=P*(P+1)/2;
24 
25 private :
26 
27  //type class
28  typedef CORE_Object SuperClass;
30 
31  //single attributes
32  //-----------------
33 
34 
35  tInteger mRowBlocksNumber;
36  tInteger mColumnBlocksNumber;
37 
38  //single associations
39  //-------------------
40 
41 
42  //multiple associations
43  //---------------------
44 
45 
46 
47 protected:
48  // CONSTRUCTORS
52  mRowBlocksNumber=0;
53  mColumnBlocksNumber=0;
54  }
55 
56  // DESTRUCTORS
59  virtual ~SM_PackedBlockMatrix(void) {
60  }
61 
62 
63 public :
64 
65  //Instance building
66  //=================
67 
68 
82  virtual tMemSize getMemorySize() const {
83  return sizeof(*this)+this->getContentsMemorySize();
84  }
85 
94  virtual tMemSize getContentsMemorySize() const {
95  tMemSize mem=SuperClass::getContentsMemorySize();
96  return mem;
97  }
98 
99 public:
100 
101  //SET & GET
102  //=========
103 
106  virtual void reset()=0;
107 
112  virtual void setSize(const tInteger& nRowBlocks,const tInteger& nColBlocks) {
113  mRowBlocksNumber=nRowBlocks;
114  mColumnBlocksNumber=nColBlocks;
115  }
116 
119  inline const tInteger& getRowBlocksNumber() const {
120  return mRowBlocksNumber;
121  }
124  inline const tInteger& getColumnBlocksNumber() const {
125  return mColumnBlocksNumber;
126  }
132  virtual void setValue(const tIndex& i,const tIndex& j,const T& v)=0;
133 
139  virtual const T& getValue(const tIndex& i,const tIndex& j) const=0;
140 
146  virtual T& getValue(const tIndex& i,const tIndex& j)=0;
147 
148 protected:
149 
150 
151 
152 
153 
154  //OPERATORS
155  //==========
156 
157 
158 
159 protected:
165  inline static tIndex GetPackedIndex(const tIndex& i ,const tIndex& j) {
166  ASSERT_IN(i<=j);
167  tIndex index=j;
168  index++;
169  index*=j;
170  index/=2;
171  index+=i;
172  return index;
173  }
174 
175 
176 
177 protected:
188  inline static void BlockVectorProduct(const T* B,
189  const T* X,
190  T* Y,const T *eY,
191  const T* Xi,const T* Xj,T* Yi,T* Yj) {
192 
193 
194  //X
195  Xj=X;
196  //Y
197  Yj=Y;
198  while (Yj!=eY) {//loop on j column
199  //X[i]
200  Xi=X;
201  //Y[i]
202  Yi=Y;
203  while (Yi!=Yj) {//loop on i < j
204  //Yi+=Bij.Xj
205  //Yj+=Bij.Xi
206  (*Yi)+=(*B)*(*Xj);
207  (*Yj)+=(*B)*(*Xi);
208  //next i
209  Xi++;
210  Yi++;
211  B++;
212  }
213 
214  //Yj+=Bjj.Xj
215  (*Yj)+=(*B)*(*Xj);
216 
217  //next j
218  B++;
219  Yj++;
220  Xj++;
221  }
222 
223  }
224 public:
225 
230  virtual void vectorProduct(const T* vX,T* vY) const=0;
231 
232 public:
233 
236  virtual tString toString() const override {
237  std::stringstream ret;
238  ret<<SuperClass::toString()<<"\n";
239  ret<<"block size:"<<P<<"\n";
240  ret<<"Rows number:"<<mRowBlocksNumber<<"\n";
241  ret<<"Columns number:"<<mColumnBlocksNumber<<"\n";
242  return ret.str();
243  }
244 
245 };
246 
247 
248 #endif
abstract base class for most classes.
Definition: CORE_Object.h:65
virtual tMemSize getContentsMemorySize() const
return nthe memory size of the included associations
Definition: CORE_Object.h:278
virtual tString toString() const
return the string representation of the object node
Definition: CORE_Object.h:333
This class described a matrix by packed block of size in a row storage.
Definition: SM_PackedBlockMatrix.h:18
virtual tString toString() const override
return string representaton of the operator
Definition: SM_PackedBlockMatrix.h:236
static void BlockVectorProduct(const T *B, const T *X, T *Y, const T *eY, const T *Xi, const T *Xj, T *Yi, T *Yj)
compute sthe vector product of the packed symmetric block B of dimension P by X to obtain Y=B....
Definition: SM_PackedBlockMatrix.h:188
virtual T & getValue(const tIndex &i, const tIndex &j)=0
get values at row i and column j for writing
virtual void reset()=0
reset the values
virtual ~SM_PackedBlockMatrix(void)
destroy
Definition: SM_PackedBlockMatrix.h:59
const tInteger & getColumnBlocksNumber() const
get the number of column blocks
Definition: SM_PackedBlockMatrix.h:124
virtual tMemSize getMemorySize() const
return the memory size of the class and the memory size of all its attributes/associations
Definition: SM_PackedBlockMatrix.h:82
virtual void setValue(const tIndex &i, const tIndex &j, const T &v)=0
set values at row i and column j
virtual void setSize(const tInteger &nRowBlocks, const tInteger &nColBlocks)
set the number or rows & columns of the blocks matrix
Definition: SM_PackedBlockMatrix.h:112
virtual const T & getValue(const tIndex &i, const tIndex &j) const =0
get values at row i and column j for reading
virtual tMemSize getContentsMemorySize() const
return the memory size of the included associations
Definition: SM_PackedBlockMatrix.h:94
SM_PackedBlockMatrix(void)
create a matrix of size 0
Definition: SM_PackedBlockMatrix.h:51
static tIndex GetPackedIndex(const tIndex &i, const tIndex &j)
return the pack index of size Q in a column storage
Definition: SM_PackedBlockMatrix.h:165
virtual void vectorProduct(const T *vX, T *vY) const =0
vector product
static constexpr tUCInt BLOCK_SIZE
size of the block in packed storage with diagonal
Definition: SM_PackedBlockMatrix.h:23
const tInteger & getRowBlocksNumber() const
get the number of row blowks
Definition: SM_PackedBlockMatrix.h:119