MPQC  3.0.0-alpha
dist.h
1 //
2 // dist.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_dist_h
29 #define _math_scmat_dist_h
30 
31 #include <util/group/message.h>
32 #include <util/group/mstate.h>
33 
34 #include <math/scmat/block.h>
35 #include <math/scmat/matrix.h>
36 #include <math/scmat/abstract.h>
37 
38 namespace sc {
39 
43  public:
44  DistSCMatrixKit(const Ref<MessageGrp> &grp = 0);
46  ~DistSCMatrixKit();
48  SymmSCMatrix* symmmatrix(const RefSCDimension&);
49  DiagSCMatrix* diagmatrix(const RefSCDimension&);
51 };
52 
53 
54 class DistSCVector: public SCVector {
55  friend class DistSCMatrix;
56  friend class DistSymmSCMatrix;
57  friend class DistDiagSCMatrix;
58  protected:
59  Ref<SCMatrixBlockList> blocklist;
60 
61  void init_blocklist();
62  double *find_element(int i) const;
63  int element_to_node(int i) const;
64  int block_to_node(int) const;
65  Ref<SCMatrixBlock> block_to_block(int) const;
66  void error(const char *);
67  public:
69  ~DistSCVector();
70  void assign_p(const double*);
71  void assign_v(SCVector*a);
72  void convert(double* v) const;
73  void convert(SCVector *);
74 
75  void set_element(int,double);
76  void accumulate_element(int,double);
77  double get_element(int) const;
78  void accumulate(const SCVector*);
79  void accumulate(const SCMatrix*m);
80  double scalar_product(SCVector*);
81  void accumulate_product_rv(SCMatrix *, SCVector *);
82  void element_op(const Ref<SCElementOp>&);
83  void element_op(const Ref<SCElementOp2>&,
84  SCVector*);
85  void element_op(const Ref<SCElementOp3>&,
86  SCVector*,SCVector*);
87  void vprint(const char* title=0,
88  std::ostream& out=ExEnv::out0(), int =10) const;
89 
90  Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
91  Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
92 
93  Ref<DistSCMatrixKit> skit();
94 };
95 
97 class DistSCMatrix: public SCMatrix {
98  friend class DistSymmSCMatrix;
99  friend class DistDiagSCMatrix;
100  friend class DistSCVector;
101  protected:
102  Ref<SCMatrixBlockList> blocklist;
103 
104  int vecoff;
105  int nvec;
106  double **vec;
107  protected:
108  // utility functions
109  void init_blocklist();
110  void error(const char *);
111  double *find_element(int i, int j) const;
112  int element_to_node(int i, int j) const;
113  int block_to_node(int,int) const;
114  Ref<SCMatrixBlock> block_to_block(int, int) const;
115  Ref<SCBlockInfo> rowblocks() const { return d1->blocks(); }
116  Ref<SCBlockInfo> colblocks() const { return d2->blocks(); }
117 
118  enum VecOp {CopyFromVec, CopyToVec, AccumFromVec, AccumToVec};
119  enum Form { Row, Col } form;
120  void create_vecform(Form, int nvec = -1);
121  void delete_vecform();
122  void vecform_op(VecOp op, int *ivec = 0);
123  void vecform_zero();
124  public:
126  DistSCMatrixKit*);
127  ~DistSCMatrix();
128 
129  // implementations and overrides of virtual functions
130  double get_element(int,int) const;
131  void set_element(int,int,double);
132  void accumulate_element(int,int,double);
133  SCMatrix * get_subblock(int,int,int,int);
134  void assign_subblock(SCMatrix*, int,int,int,int,int=0,int=0);
135  void accumulate_subblock(SCMatrix*, int,int,int,int,int=0,int=0);
136  SCVector * get_row(int i);
137  SCVector * get_column(int i);
138  void assign_row(SCVector *v, int i);
139  void assign_column(SCVector *v, int i);
140  void accumulate_row(SCVector *v, int i);
141  void accumulate_column(SCVector *v, int i);
142 
144  void accumulate_product_rr(SCMatrix*,SCMatrix*);
145  void accumulate(const SCMatrix*);
146  void accumulate(const SymmSCMatrix*);
147  void accumulate(const DiagSCMatrix*);
148  void accumulate(const SCVector*);
149  void transpose_this();
150  double invert_this();
151  double solve_this(SCVector*);
152  double determ_this();
153  double trace();
155  void gen_invert_this(double condition_number_threshold = 1e8);
156  void schmidt_orthog(SymmSCMatrix*,int);
157  int schmidt_orthog_tol(SymmSCMatrix*, double tol, double *res=0);
158  void element_op(const Ref<SCElementOp>&);
159  void element_op(const Ref<SCElementOp2>&,
160  SCMatrix*);
161  void element_op(const Ref<SCElementOp3>&,
162  SCMatrix*,SCMatrix*);
163  void vprint(const char* title=0,
164  std::ostream& out=ExEnv::out0(), int =10);
165  void vprint(const char* title=0,
166  std::ostream& out=ExEnv::out0(), int =10) const;
167 
168  Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
169  Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
170 
171  Ref<DistSCMatrixKit> skit();
172 };
173 
176  friend class DistSCMatrix;
177  friend class DistDiagSCMatrix;
178  friend class DistSCVector;
179  protected:
180  Ref<SCMatrixBlockList> blocklist;
181  protected:
182  // utility functions
183  void init_blocklist();
184  double *find_element(int i, int j) const;
185  int element_to_node(int i, int j) const;
186  int block_to_node(int,int) const;
187  Ref<SCMatrixBlock> block_to_block(int, int) const;
188 
189  void error(const char *msg);
190  public:
192  ~DistSymmSCMatrix();
193 
194  // implementations and overrides of virtual functions
195  double get_element(int,int) const;
196  void set_element(int,int,double);
197  void accumulate_element(int,int,double);
198 
199  SCMatrix * get_subblock(int,int,int,int);
200  SymmSCMatrix * get_subblock(int,int);
201  void assign_subblock(SCMatrix*, int,int,int,int);
202  void assign_subblock(SymmSCMatrix*, int,int);
203  void accumulate_subblock(SCMatrix*, int,int,int,int);
204  void accumulate_subblock(SymmSCMatrix*, int,int);
205  SCVector * get_row(int i);
206  void assign_row(SCVector *v, int i);
207  void accumulate_row(SCVector *v, int i);
208 
209  void accumulate_product_rr(SCMatrix*,SCMatrix*);
210  void accumulate(const SymmSCMatrix*);
211  double invert_this();
212  double solve_this(SCVector*);
213  double trace();
214  double determ_this();
216  void gen_invert_this(double condition_number_threshold = 1e8);
217 
221  void element_op(const Ref<SCElementOp>&);
222  void element_op(const Ref<SCElementOp2>&,
223  SymmSCMatrix*);
224  void element_op(const Ref<SCElementOp3>&,
226 
227  virtual void convert_accumulate(SymmSCMatrix*);
228 
229  Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
230  Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
231 
232  Ref<DistSCMatrixKit> skit();
233 };
234 
237  friend class DistSCMatrix;
238  friend class DistSymmSCMatrix;
239  friend class DistSCVector;
240  protected:
241  Ref<SCMatrixBlockList> blocklist;
242 
243  void init_blocklist();
244  double *find_element(int i) const;
245  int element_to_node(int i) const;
246  int block_to_node(int) const;
247  Ref<SCMatrixBlock> block_to_block(int) const;
248  void error(const char *msg);
249  public:
251  ~DistDiagSCMatrix();
252 
253  // implementations and overrides of virtual functions
254  double get_element(int) const;
255  void set_element(int,double);
256  void accumulate_element(int,double);
257  void accumulate(const DiagSCMatrix*);
258  double invert_this();
259  double determ_this();
260  double trace();
262  void gen_invert_this(double condition_number_threshold = 1e8);
263 
264  void element_op(const Ref<SCElementOp>&);
265  void element_op(const Ref<SCElementOp2>&,
266  DiagSCMatrix*);
267  void element_op(const Ref<SCElementOp3>&,
269 
270  Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
271  Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
272 
273  Ref<DistSCMatrixKit> skit();
274 };
275 
277  protected:
278  Ref<MessageGrp> grp_;
279  StateSend out_;
280  StateRecv in_;
281  int step_;
282  Ref<SCMatrixBlockList> locallist_;
283 
284  void maybe_advance_list();
285  void advance_list();
286  public:
288  const Ref<SCMatrixBlockList> &locallist,
289  const Ref<MessageGrp> &grp);
290  void begin();
291  void next();
293 };
294 
295 }
296 
297 #endif
298 
299 // Local Variables:
300 // mode: c++
301 // c-file-style: "CLJ"
302 // End:
sc::DistSymmSCMatrix::accumulate_subblock
void accumulate_subblock(SCMatrix *, int, int, int, int)
Sum m into a subblock of this.
sc::DistSCMatrix::gen_invert_this
void gen_invert_this(double condition_number_threshold=1e8)
uses invert_this()
sc::DistDiagSCMatrix
Distributed DiagSCMatrix.
Definition: dist.h:236
sc::DistSymmSCMatrix::assign_subblock
void assign_subblock(SCMatrix *, int, int, int, int)
Assign m to a subblock of this.
sc::DistSymmSCMatrix
Distributed SymmSCMatrix.
Definition: dist.h:175
sc::DistDiagSCMatrix::element_op
void element_op(const Ref< SCElementOp > &)
Perform the element operation op on each element of this.
sc::DistDiagSCMatrix::get_element
double get_element(int) const
Return or modify an element.
sc::SCVector
The SCVector class is the abstract base class for double valued vectors.
Definition: abstract.h:97
sc::DistSCMatrixKit::matrix
SCMatrix * matrix(const RefSCDimension &, const RefSCDimension &)
Given the dimensions, create matrices or vectors.
sc::DistSCMatrixListSubblockIter
Definition: dist.h:276
sc::DistSymmSCMatrix::accumulate_symmetric_sum
void accumulate_symmetric_sum(SCMatrix *)
Sum into a + a.t()
sc::DistSCMatrix::schmidt_orthog_tol
int schmidt_orthog_tol(SymmSCMatrix *, double tol, double *res=0)
Schmidt orthogonalize this.
sc::DistSCMatrix::accumulate_row
void accumulate_row(SCVector *v, int i)
Sum v to a row or column of this.
sc::DistSCVector
Definition: dist.h:54
sc::DistSCMatrix
Distributed SCMatrix.
Definition: dist.h:97
sc::Ref
A template class that maintains references counts.
Definition: ref.h:361
sc::DistSCMatrix::get_element
double get_element(int, int) const
Return or modify an element.
sc::DistSCVector::local_blocks
Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the local (rapidly accessible) blocks used in this vector.
sc::DistSCMatrixListSubblockIter::begin
void begin()
Start at the beginning.
sc::SCMatrixKit
The SCMatrixKit abstract class acts as a factory for producing matrices.
Definition: abstract.h:57
sc::DistDiagSCMatrix::trace
double trace()
Return the trace.
sc::DistSCMatrix::accumulate_outer_product
void accumulate_outer_product(SCVector *, SCVector *)
Sum into this the products of various vectors or matrices.
sc::DistSymmSCMatrix::accumulate
void accumulate(const SymmSCMatrix *)
Sum m into this.
sc::DistSymmSCMatrix::all_blocks
Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the all blocks used in this matrix.
sc::DistSCMatrix::all_blocks
Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the all blocks used in this matrix.
sc::DistSymmSCMatrix::element_op
void element_op(const Ref< SCElementOp > &)
only applied to the unique elements of this.
sc::DistSCMatrix::assign_subblock
void assign_subblock(SCMatrix *, int, int, int, int, int=0, int=0)
Assign m to a subblock of this.
sc::DistSCMatrix::assign_row
void assign_row(SCVector *v, int i)
Assign v to a row or column of this.
sc::StateRecv
StateRecv is a concrete specialization of MsgStateRecv that does the receive part of point to point c...
Definition: mstate.h:193
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::DistSymmSCMatrix::get_row
SCVector * get_row(int i)
Return a row of this.
sc::convert
std::vector< double > convert(const RefDiagSCMatrix &A)
Converts RefDiagSCMatrix to std::vector<double>
sc::StateSend
StateSend is a concrete specialization of MsgStateSend that does the send part of point to point comm...
Definition: mstate.h:165
sc::DistSCMatrix::schmidt_orthog
void schmidt_orthog(SymmSCMatrix *, int)
Schmidt orthogonalize this.
sc::RefSCDimension
The RefSCDimension class is a smart pointer to an SCDimension specialization.
Definition: dim.h:152
sc::DistSymmSCMatrix::local_blocks
Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the local (rapidly accessible) blocks used in this matrix.
sc::DistDiagSCMatrix::local_blocks
Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the local (rapidly accessible) blocks used in this matrix.
sc::DistSymmSCMatrix::get_subblock
SCMatrix * get_subblock(int, int, int, int)
Return a subblock of this.
sc::DistSCVector::set_element
void set_element(int, double)
Set element i to val.
sc::DistSCMatrix::accumulate_subblock
void accumulate_subblock(SCMatrix *, int, int, int, int, int=0, int=0)
Sum m into a subblock of this.
sc::DistSymmSCMatrix::diagonalize
void diagonalize(DiagSCMatrix *, SCMatrix *)
Diagonalize this, placing the eigenvalues in d and the eigenvectors in m.
sc::DistSCMatrix::invert_this
double invert_this()
Invert this.
sc::DistSymmSCMatrix::eigensystem
void eigensystem(SymmSCMatrix *, DiagSCMatrix *, SCMatrix *)
Solve generalized eigensystem for this with metric s, placing the eigenvalues in d and the eigenvecto...
sc::DistSymmSCMatrix::trace
double trace()
Return the trace.
sc::DistSymmSCMatrix::gen_invert_this
void gen_invert_this(double condition_number_threshold=1e8)
uses invert_this()
sc::DistSCMatrix::trace
double trace()
Return the trace.
sc::DistSCMatrix::element_op
void element_op(const Ref< SCElementOp > &)
Perform the element operation op on each element of this.
sc::DistSCMatrix::determ_this
double determ_this()
Return the determinant of this. this is overwritten.
sc::DistSCVector::accumulate_element
void accumulate_element(int, double)
Add val to element i.
sc::DistSymmSCMatrix::assign_row
void assign_row(SCVector *v, int i)
Assign v to a row of this.
sc::DistSymmSCMatrix::accumulate_row
void accumulate_row(SCVector *v, int i)
Sum v to a row of this.
sc::DistDiagSCMatrix::determ_this
double determ_this()
Return the determinant of this. this is overwritten.
sc::DistSymmSCMatrix::invert_this
double invert_this()
Invert this.
sc::DistSymmSCMatrix::get_element
double get_element(int, int) const
Return or modify an element.
sc::DistSCVector::accumulate
void accumulate(const SCVector *)
Sum v into this.
sc::DistSCVector::element_op
void element_op(const Ref< SCElementOp > &)
Perform the element operation op on each element of this.
sc::DistSCVector::all_blocks
Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the all blocks used in this vector.
sc::SymmSCMatrix
The SymmSCMatrix class is the abstract base class for symmetric double valued matrices.
Definition: abstract.h:385
sc::DistDiagSCMatrix::all_blocks
Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the all blocks used in this matrix.
sc::DistDiagSCMatrix::gen_invert_this
void gen_invert_this(double condition_number_threshold=1e8)
generalized-invert this
sc::DistSCVector::get_element
double get_element(int) const
Return the value of element i.
sc::DistSCMatrix::get_subblock
SCMatrix * get_subblock(int, int, int, int)
Return a subblock of this.
sc::DistSCVector::scalar_product
double scalar_product(SCVector *)
Return the dot product.
sc::DistSCMatrix::local_blocks
Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the local (rapidly accessible) blocks used in this matrix.
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::DistDiagSCMatrix::accumulate
void accumulate(const DiagSCMatrix *)
Sum m into this.
mpqc::vector
Vector class derived from Eigen::Matrix with additional MPQC integration.
Definition: matrix.hpp:133
sc::DistSCMatrixListSubblockIter::next
void next()
Proceed to the next block.
sc::DistSCMatrix::transpose_this
void transpose_this()
Transpose this.
sc::DistSCMatrix::accumulate
void accumulate(const SCMatrix *)
Sum m into this.
sc
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14
sc::DistSymmSCMatrix::determ_this
double determ_this()
Return the determinant of this. this is overwritten.
sc::DistSCMatrix::get_row
SCVector * get_row(int i)
Return a row or column of this.
sc::DistSCMatrixKit
The DistSCMatrixKit produces matrices that work in a many processor environment.
Definition: dist.h:42
sc::DistDiagSCMatrix::invert_this
double invert_this()
Invert this.

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