MPQC  3.0.0-alpha
repl.h
1 //
2 // repl.h
3 //
4 // Copyright (C) 1996 Limit Point Systems, Inc.
5 //
6 // Author: Curtis Janssen <cljanss@limitpt.com>
7 // Maintainer: LPS
8 //
9 // This file is part of the SC Toolkit.
10 //
11 // The SC Toolkit is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU Library General Public License as published by
13 // the Free Software Foundation; either version 2, or (at your option)
14 // any later version.
15 //
16 // The SC Toolkit is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU Library General Public License for more details.
20 //
21 // You should have received a copy of the GNU Library General Public License
22 // along with the SC Toolkit; see the file COPYING.LIB. If not, write to
23 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 //
25 // The U.S. Government is granted a limited license as per AL 91-7.
26 //
27 
28 #ifndef _math_scmat_repl_h
29 #define _math_scmat_repl_h
30 
31 #include <util/group/message.h>
32 
33 #include <math/scmat/block.h>
34 #include <math/scmat/matrix.h>
35 #include <math/scmat/abstract.h>
36 
37 namespace sc {
38 
43  public:
46  ~ReplSCMatrixKit();
48  SymmSCMatrix* symmmatrix(const RefSCDimension&);
49  DiagSCMatrix* diagmatrix(const RefSCDimension&);
51 };
52 
53 
55  protected:
56  Ref<MessageGrp> grp_;
57  double *data_;
58  int ndata_;
59  public:
61  const Ref<SCMatrixBlockList> &list,
62  const Ref<MessageGrp> &grp,
63  double *data, int ndata);
65 };
66 
67 class ReplSCVector: public SCVector {
68  friend class ReplSCMatrix;
69  friend class ReplSymmSCMatrix;
70  friend class ReplDiagSCMatrix;
71  protected:
72  Ref<SCMatrixBlockList> blocklist;
73  double* vector;
74  void init_blocklist();
75  void before_elemop();
76  void after_elemop();
77  public:
79  ~ReplSCVector();
80  void assign_val(double);
81  void assign_v(SCVector*);
82  void assign_p(const double*);
83 
84  void set_element(int,double);
85  void accumulate_element(int,double);
86  double get_element(int) const;
87  void accumulate_product_sv(SymmSCMatrix*,SCVector*);
88  void accumulate_product_rv(SCMatrix*,SCVector*);
89  void accumulate(const SCVector*);
90  void accumulate(const SCMatrix*);
91  double scalar_product(SCVector*);
92  void element_op(const Ref<SCElementOp>&);
93  void element_op(const Ref<SCElementOp2>&,
94  SCVector*);
95  void element_op(const Ref<SCElementOp3>&,
96  SCVector*,SCVector*);
97  void vprint(const char* title=0,
98  std::ostream& out=ExEnv::out0(), int =10) const;
99 
100  // return a pointer to the data for fast access
101  double *get_data() { return vector; }
102 
103  Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
104  Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
105 
106  Ref<ReplSCMatrixKit> skit();
107 };
108 
109 class ReplSCMatrix: public SCMatrix {
110  friend class ReplSymmSCMatrix;
111  friend class ReplDiagSCMatrix;
112  friend class ReplSCVector;
113  protected:
114  Ref<SCMatrixBlockList> blocklist;
115  double* matrix;
116  double** rows;
117  protected:
118  // utility functions
119  size_t compute_offset(int,int) const;
120  void init_blocklist();
121 
122  void before_elemop();
123  void after_elemop();
124  public:
126  ReplSCMatrixKit*);
127  ~ReplSCMatrix();
128 
129  // implementations and overrides of virtual functions
130  void assign_val(double);
131  double get_element(int,int) const;
132  void set_element(int,int,double);
133  void accumulate_element(int,int,double);
134  SCMatrix * get_subblock(int,int,int,int);
135  void assign_subblock(SCMatrix*, int,int,int,int,int=0,int=0);
136  void accumulate_subblock(SCMatrix*, int,int,int,int,int=0,int=0);
137  SCVector * get_row(int i);
138  SCVector * get_column(int i);
139  void assign_row(SCVector *v, int i);
140  void assign_column(SCVector *v, int i);
141  void accumulate_row(SCVector *v, int i);
142  void accumulate_column(SCVector *v, int i);
143  void assign_p(const double*);
144  void assign_pp(const double**);
145  void convert_p(double*) const;
146  void convert_pp(double**) const;
147 
149  void accumulate_product_rr(SCMatrix*,SCMatrix*);
150  void accumulate_product_rs(SCMatrix*,SymmSCMatrix*);
151  void accumulate_product_rd(SCMatrix*,DiagSCMatrix*);
152  void accumulate(const SCMatrix*);
153  void accumulate(const SymmSCMatrix*);
154  void accumulate(const DiagSCMatrix*);
155  void accumulate(const SCVector*);
156  void transpose_this();
157  double invert_this();
159  double solve_this(SCVector*);
160  double determ_this();
161  double trace();
162  void schmidt_orthog(SymmSCMatrix*,int);
163  int schmidt_orthog_tol(SymmSCMatrix*, double tol, double *res=0);
164  void element_op(const Ref<SCElementOp>&);
165  void element_op(const Ref<SCElementOp2>&,
166  SCMatrix*);
167  void element_op(const Ref<SCElementOp3>&,
168  SCMatrix*,SCMatrix*);
169  void vprint(const char* title=0,
170  std::ostream& out=ExEnv::out0(), int =10) const;
171 
172  // return a pointer to the data for fast access
173  double *get_data() { return matrix; }
174  double **get_rows() { return rows; }
175 
176  Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
177  Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
178 
179  Ref<ReplSCMatrixKit> skit();
180 };
181 
184  friend class ReplSCMatrix;
185  friend class ReplDiagSCMatrix;
186  friend class ReplSCVector;
187  protected:
188  Ref<SCMatrixBlockList> blocklist;
189  double* matrix;
190  double** rows;
191  protected:
192  // utility functions
193  size_t compute_offset(int,int) const;
194  void init_blocklist();
195 
196  void before_elemop();
197  void after_elemop();
198  public:
200  ~ReplSymmSCMatrix();
201 
202  // implementations and overrides of virtual functions
203  void assign_val(double);
204  void assign_s(SymmSCMatrix*);
205  void assign_p(const double*);
206  void assign_pp(const double**);
207  void convert_p(double*) const;
208  void convert_pp(double**) const;
209  double get_element(int,int) const;
210  void set_element(int,int,double);
211  void accumulate_element(int,int,double);
212  void scale(double);
213 
214  SCMatrix * get_subblock(int,int,int,int);
215  SymmSCMatrix * get_subblock(int,int);
216  void assign_subblock(SCMatrix*, int,int,int,int);
217  void assign_subblock(SymmSCMatrix*, int,int);
218  void accumulate_subblock(SCMatrix*, int,int,int,int);
219  void accumulate_subblock(SymmSCMatrix*, int,int);
220  SCVector * get_row(int i);
221  void assign_row(SCVector *v, int i);
222  void accumulate_row(SCVector *v, int i);
223 
224  void accumulate_product_rr(SCMatrix*,SCMatrix*);
225  void accumulate(const SymmSCMatrix*);
226  double invert_this();
227  double solve_this(SCVector*);
228  double trace();
229  double determ_this();
230  void gen_invert_this(double condition_number_threshold = 1e8);
231 
232  double scalar_product(SCVector*);
235  void accumulate_symmetric_outer_product(SCVector*);
238  void accumulate_transform(SCMatrix*,SymmSCMatrix*,
239  SCMatrix::Transform = SCMatrix::NormalTransform);
240  void accumulate_transform(SCMatrix*,DiagSCMatrix*,
241  SCMatrix::Transform = SCMatrix::NormalTransform);
242  void accumulate_transform(SymmSCMatrix*,SymmSCMatrix*);
243  void element_op(const Ref<SCElementOp>&);
244  void element_op(const Ref<SCElementOp2>&,
245  SymmSCMatrix*);
246  void element_op(const Ref<SCElementOp3>&,
248  void vprint(const char* title=0,
249  std::ostream& out=ExEnv::out0(), int =10) const;
250 
251  // return a pointer to the data for fast access
252  double *get_data() { return matrix; }
253  double **get_rows() { return rows; }
254 
255  Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
256  Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
257 
258  Ref<ReplSCMatrixKit> skit();
259 };
260 
263  friend class ReplSCMatrix;
264  friend class ReplSymmSCMatrix;
265  friend class ReplSCVector;
266  protected:
267  Ref<SCMatrixBlockList> blocklist;
268  void init_blocklist();
269  double* matrix;
270 
271  void before_elemop();
272  void after_elemop();
273  public:
275  ~ReplDiagSCMatrix();
276 
277  // implementations and overrides of virtual functions
278  void assign_val(double);
279  double get_element(int) const;
280  void set_element(int,double);
281  void accumulate_element(int,double);
282  void accumulate(const DiagSCMatrix*);
283  double invert_this();
284  double determ_this();
285  double trace();
286  void gen_invert_this(double condition_number_threshold = 1e8);
287 
288  void element_op(const Ref<SCElementOp>&);
289  void element_op(const Ref<SCElementOp2>&,
290  DiagSCMatrix*);
291  void element_op(const Ref<SCElementOp3>&,
293  void vprint(const char* title=0,
294  std::ostream& out=ExEnv::out0(), int =10) const;
295 
296  // return a pointer to the data for fast access
297  double *get_data() { return matrix; }
298 
299  Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
300  Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
301 
302  Ref<ReplSCMatrixKit> skit();
303 };
304 
305 }
306 
307 #endif
308 
309 // Local Variables:
310 // mode: c++
311 // c-file-style: "CLJ"
312 // End:
sc::ReplSymmSCMatrix::element_op
void element_op(const Ref< SCElementOp > &)
only applied to the unique elements of this.
sc::ReplSymmSCMatrix::accumulate_row
void accumulate_row(SCVector *v, int i)
Sum v to a row of this.
sc::ReplSCMatrix::assign_val
void assign_val(double)
Overridden to implement to assign members.
sc::ReplSCMatrix::get_element
double get_element(int, int) const
Return or modify an element.
sc::ReplSCVector::accumulate_element
void accumulate_element(int, double)
Add val to element i.
mpqc::ci::sigma
void sigma(const CI< Type, Index > &ci, const mpqc::Vector &h, const Matrix &V, ci::Vector &C, ci::Vector &S)
Computes sigma 1,2,3 contributions.
Definition: sigma.hpp:30
sc::ReplSymmSCMatrix
Replicated SymmSCMatrix.
Definition: repl.h:183
sc::SCVector
The SCVector class is the abstract base class for double valued vectors.
Definition: abstract.h:97
sc::ReplSCMatrix::trace
double trace()
Return the trace.
sc::ReplSCMatrix::element_op
void element_op(const Ref< SCElementOp > &)
Perform the element operation op on each element of this.
sc::ReplDiagSCMatrix::element_op
void element_op(const Ref< SCElementOp > &)
Perform the element operation op on each element of this.
sc::ReplSCVector::set_element
void set_element(int, double)
Set element i to val.
sc::ReplSymmSCMatrix::assign_subblock
void assign_subblock(SCMatrix *, int, int, int, int)
Assign m to a subblock of this.
sc::ReplSymmSCMatrix::gen_invert_this
void gen_invert_this(double condition_number_threshold=1e8)
Return the generalized inverse of this using SVD decomposition.
sc::ReplSymmSCMatrix::scale
void scale(double)
Multiply all elements by val.
sc::Ref
A template class that maintains references counts.
Definition: ref.h:361
mpqc::matrix
Matrix class derived from Eigen::Matrix with additional MPQC integration.
Definition: matrix.hpp:21
sc::ReplDiagSCMatrix::invert_this
double invert_this()
Invert this.
sc::ReplSymmSCMatrix::accumulate_symmetric_product
void accumulate_symmetric_product(SCMatrix *)
Sum into this a * a.t()
sc::ReplSCMatrixKit::matrix
SCMatrix * matrix(const RefSCDimension &, const RefSCDimension &)
Given the dimensions, create matrices or vectors.
sc::ReplSymmSCMatrix::get_element
double get_element(int, int) const
Return or modify an element.
sc::SCMatrixKit
The SCMatrixKit abstract class acts as a factory for producing matrices.
Definition: abstract.h:57
sc::ReplSCMatrix::determ_this
double determ_this()
Return the determinant of this. this is overwritten.
sc::ReplSCMatrixListSubblockIter
Definition: repl.h:54
sc::ReplSymmSCMatrix::diagonalize
void diagonalize(DiagSCMatrix *, SCMatrix *)
Diagonalize this, placing the eigenvalues in d and the eigenvectors in m.
sc::ReplSymmSCMatrix::scalar_product
double scalar_product(SCVector *)
Return the scalar obtained by multiplying this on the left and right by v.
sc::ReplDiagSCMatrix::trace
double trace()
Return the trace.
sc::ReplSCVector::assign_val
void assign_val(double)
Overridden to implement the assign functions.
sc::ReplSymmSCMatrix::all_blocks
Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the all blocks used in this matrix.
sc::ReplSCMatrix::local_blocks
Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the local (rapidly accessible) blocks used in this matrix.
sc::ReplSymmSCMatrix::get_subblock
SCMatrix * get_subblock(int, int, int, int)
Return a subblock of this.
sc::SCMatrixListSubblockIter
Definition: block.h:414
sc::DiagSCMatrix
The SymmSCMatrix class is the abstract base class for diagonal double valued matrices.
Definition: abstract.h:551
sc::ReplSCMatrix::all_blocks
Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the all blocks used in this matrix.
sc::ReplSCMatrix::assign_row
void assign_row(SCVector *v, int i)
Assign v to a row or column of this.
sc::RefSCDimension
The RefSCDimension class is a smart pointer to an SCDimension specialization.
Definition: dim.h:152
sc::ReplDiagSCMatrix::determ_this
double determ_this()
Return the determinant of this. this is overwritten.
sc::ReplDiagSCMatrix::get_element
double get_element(int) const
Return or modify an element.
sc::ReplSymmSCMatrix::eigensystem
void eigensystem(SymmSCMatrix *, DiagSCMatrix *, SCMatrix *)
Solve generalized eigensystem for this with metric s, placing the eigenvalues in d and the eigenvecto...
sc::ReplSCMatrix::accumulate_outer_product
void accumulate_outer_product(SCVector *, SCVector *)
Sum into this the products of various vectors or matrices.
sc::ReplDiagSCMatrix::all_blocks
Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the all blocks used in this matrix.
sc::ReplSymmSCMatrix::accumulate_subblock
void accumulate_subblock(SCMatrix *, int, int, int, int)
Sum m into a subblock of this.
sc::ReplSymmSCMatrix::determ_this
double determ_this()
Return the determinant of this. this is overwritten.
sc::ReplSymmSCMatrix::local_blocks
Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the local (rapidly accessible) blocks used in this matrix.
sc::ReplSCVector
Definition: repl.h:67
sc::ReplSCMatrix::transpose_this
void transpose_this()
Transpose this.
sc::ReplSCMatrix::accumulate
void accumulate(const SCMatrix *)
Sum m into this.
sc::ReplSymmSCMatrix::trace
double trace()
Return the trace.
sc::ReplSCMatrix::get_subblock
SCMatrix * get_subblock(int, int, int, int)
Return a subblock of this.
sc::ReplSCVector::local_blocks
Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the local (rapidly accessible) blocks used in this vector.
sc::ReplDiagSCMatrix::gen_invert_this
void gen_invert_this(double condition_number_threshold=1e8)
Return the generalized inverse of this using SVD decomposition.
sc::ReplSCMatrix::get_row
SCVector * get_row(int i)
Return a row or column of this.
sc::ReplSymmSCMatrix::accumulate_symmetric_sum
void accumulate_symmetric_sum(SCMatrix *)
Sum into a + a.t()
sc::SymmSCMatrix
The SymmSCMatrix class is the abstract base class for symmetric double valued matrices.
Definition: abstract.h:385
sc::ReplSCVector::all_blocks
Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the all blocks used in this vector.
sc::ReplSCMatrix::svd_this
void svd_this(SCMatrix *U, DiagSCMatrix *sigma, SCMatrix *V)
Compute the singular value decomposition for this, possibly destroying this.
sc::ReplSCMatrix::invert_this
double invert_this()
Invert this.
sc::ReplSCMatrix::accumulate_row
void accumulate_row(SCVector *v, int i)
Sum v to a row or column of this.
sc::SCMatrix::Transform
Transform
types of matrix transforms. Only real-valued matrices are assumed.
Definition: abstract.h:205
sc::ReplSCVector::accumulate
void accumulate(const SCVector *)
Sum v into this.
sc::ReplDiagSCMatrix::assign_val
void assign_val(double)
Overridden to implement the assign members.
sc::ReplSymmSCMatrix::accumulate
void accumulate(const SymmSCMatrix *)
Sum m into this.
sc::ReplSymmSCMatrix::get_row
SCVector * get_row(int i)
Return a row of this.
sc::ReplSCMatrix::accumulate_subblock
void accumulate_subblock(SCMatrix *, int, int, int, int, int=0, int=0)
Sum m into a subblock of this.
sc::ExEnv::out0
static std::ostream & out0()
Return an ostream that writes from node 0.
sc::SCMatrix
The SCMatrix class is the abstract base class for general double valued n by m matrices.
Definition: abstract.h:195
sc::ReplSCMatrix
Definition: repl.h:109
sc::ReplSCMatrix::schmidt_orthog_tol
int schmidt_orthog_tol(SymmSCMatrix *, double tol, double *res=0)
Schmidt orthogonalize this.
sc::ReplSymmSCMatrix::invert_this
double invert_this()
Invert this.
sc::ReplSCMatrix::schmidt_orthog
void schmidt_orthog(SymmSCMatrix *, int)
Schmidt orthogonalize this.
sc::ReplSCVector::scalar_product
double scalar_product(SCVector *)
Return the dot product.
mpqc::vector
Vector class derived from Eigen::Matrix with additional MPQC integration.
Definition: matrix.hpp:133
sc::ReplSymmSCMatrix::assign_row
void assign_row(SCVector *v, int i)
Assign v to a row of this.
sc::ReplSCMatrixKit
The ReplSCMatrixKit produces matrices that work in a many processor environment.
Definition: repl.h:42
sc::ReplSCVector::element_op
void element_op(const Ref< SCElementOp > &)
Perform the element operation op on each element of this.
sc::ReplDiagSCMatrix::local_blocks
Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the local (rapidly accessible) blocks used in this matrix.
sc::ReplSCVector::get_element
double get_element(int) const
Return the value of element i.
sc
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14
sc::ReplDiagSCMatrix::accumulate
void accumulate(const DiagSCMatrix *)
Sum m into this.
sc::ReplSymmSCMatrix::assign_val
void assign_val(double)
Overridden to implement the assign functions.
sc::ReplSCMatrix::assign_subblock
void assign_subblock(SCMatrix *, int, int, int, int, int=0, int=0)
Assign m to a subblock of this.
sc::ReplDiagSCMatrix
Replicated DiagSCMatrix.
Definition: repl.h:262

Generated at Sun Jan 26 2020 23:24:00 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.16.