MPQC  2.3.1
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 #ifdef __GNUC__
29 #pragma interface
30 #endif
31 
32 #ifndef _math_scmat_dist_h
33 #define _math_scmat_dist_h
34 
35 #include <util/group/message.h>
36 #include <util/group/mstate.h>
37 
38 #include <math/scmat/block.h>
39 #include <math/scmat/matrix.h>
40 #include <math/scmat/abstract.h>
41 
42 namespace sc {
43 
47  public:
48  DistSCMatrixKit(const Ref<MessageGrp> &grp = 0);
50  ~DistSCMatrixKit();
52  SymmSCMatrix* symmmatrix(const RefSCDimension&);
53  DiagSCMatrix* diagmatrix(const RefSCDimension&);
54  SCVector* vector(const RefSCDimension&);
55 };
56 
57 
58 class DistSCVector: public SCVector {
59  friend class DistSCMatrix;
60  friend class DistSymmSCMatrix;
61  friend class DistDiagSCMatrix;
62  protected:
63  Ref<SCMatrixBlockList> blocklist;
64 
65  void init_blocklist();
66  double *find_element(int i) const;
67  int element_to_node(int i) const;
68  int block_to_node(int) const;
69  Ref<SCMatrixBlock> block_to_block(int) const;
70  void error(const char *);
71  public:
73  ~DistSCVector();
74  void assign_p(const double*);
75  void assign_v(SCVector*a);
76  void convert(double* v) const;
77  void convert(SCVector *);
78 
79  void set_element(int,double);
80  void accumulate_element(int,double);
81  double get_element(int) const;
82  void accumulate(const SCVector*);
83  void accumulate(const SCMatrix*m);
84  double scalar_product(SCVector*);
85  void accumulate_product_rv(SCMatrix *, SCVector *);
86  void element_op(const Ref<SCElementOp>&);
87  void element_op(const Ref<SCElementOp2>&,
88  SCVector*);
89  void element_op(const Ref<SCElementOp3>&,
90  SCVector*,SCVector*);
91  void vprint(const char* title=0,
92  std::ostream& out=ExEnv::out0(), int =10) const;
93 
94  Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
95  Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
96 
97  Ref<DistSCMatrixKit> skit();
98 };
99 
100 class DistSCMatrix: public SCMatrix {
101  friend class DistSymmSCMatrix;
102  friend class DistDiagSCMatrix;
103  friend class DistSCVector;
104  protected:
105  Ref<SCMatrixBlockList> blocklist;
106 
107  int vecoff;
108  int nvec;
109  double **vec;
110  protected:
111  // utility functions
112  void init_blocklist();
113  void error(const char *);
114  double *find_element(int i, int j) const;
115  int element_to_node(int i, int j) const;
116  int block_to_node(int,int) const;
117  Ref<SCMatrixBlock> block_to_block(int, int) const;
118  Ref<SCBlockInfo> rowblocks() const { return d1->blocks(); }
119  Ref<SCBlockInfo> colblocks() const { return d2->blocks(); }
120 
121  enum VecOp {CopyFromVec, CopyToVec, AccumFromVec, AccumToVec};
122  enum Form { Row, Col } form;
123  void create_vecform(Form, int nvec = -1);
124  void delete_vecform();
125  void vecform_op(VecOp op, int *ivec = 0);
126  void vecform_zero();
127  public:
129  DistSCMatrixKit*);
130  ~DistSCMatrix();
131 
132  // implementations and overrides of virtual functions
133  double get_element(int,int) const;
134  void set_element(int,int,double);
135  void accumulate_element(int,int,double);
136  SCMatrix * get_subblock(int,int,int,int);
137  void assign_subblock(SCMatrix*, int,int,int,int,int=0,int=0);
138  void accumulate_subblock(SCMatrix*, int,int,int,int,int=0,int=0);
139  SCVector * get_row(int i);
140  SCVector * get_column(int i);
141  void assign_row(SCVector *v, int i);
142  void assign_column(SCVector *v, int i);
143  void accumulate_row(SCVector *v, int i);
144  void accumulate_column(SCVector *v, int i);
145 
147  void accumulate_product_rr(SCMatrix*,SCMatrix*);
148  void accumulate(const SCMatrix*);
149  void accumulate(const SymmSCMatrix*);
150  void accumulate(const DiagSCMatrix*);
151  void accumulate(const SCVector*);
152  void transpose_this();
153  double invert_this();
154  double solve_this(SCVector*);
155  double determ_this();
156  double trace();
157  void gen_invert_this();
158  void schmidt_orthog(SymmSCMatrix*,int);
159  int schmidt_orthog_tol(SymmSCMatrix*, double tol, double *res=0);
160  void element_op(const Ref<SCElementOp>&);
161  void element_op(const Ref<SCElementOp2>&,
162  SCMatrix*);
163  void element_op(const Ref<SCElementOp3>&,
164  SCMatrix*,SCMatrix*);
165  void vprint(const char* title=0,
166  std::ostream& out=ExEnv::out0(), int =10);
167  void vprint(const char* title=0,
168  std::ostream& out=ExEnv::out0(), int =10) const;
169 
170  Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
171  Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
172 
173  Ref<DistSCMatrixKit> skit();
174 };
175 
177  friend class DistSCMatrix;
178  friend class DistDiagSCMatrix;
179  friend class DistSCVector;
180  protected:
181  Ref<SCMatrixBlockList> blocklist;
182  protected:
183  // utility functions
184  void init_blocklist();
185  double *find_element(int i, int j) const;
186  int element_to_node(int i, int j) const;
187  int block_to_node(int,int) const;
188  Ref<SCMatrixBlock> block_to_block(int, int) const;
189 
190  void error(const char *msg);
191  public:
193  ~DistSymmSCMatrix();
194 
195  // implementations and overrides of virtual functions
196  double get_element(int,int) const;
197  void set_element(int,int,double);
198  void accumulate_element(int,int,double);
199 
200  SCMatrix * get_subblock(int,int,int,int);
201  SymmSCMatrix * get_subblock(int,int);
202  void assign_subblock(SCMatrix*, int,int,int,int);
203  void assign_subblock(SymmSCMatrix*, int,int);
204  void accumulate_subblock(SCMatrix*, int,int,int,int);
205  void accumulate_subblock(SymmSCMatrix*, int,int);
206  SCVector * get_row(int i);
207  void assign_row(SCVector *v, int i);
208  void accumulate_row(SCVector *v, int i);
209 
210  void accumulate_product_rr(SCMatrix*,SCMatrix*);
211  void accumulate(const SymmSCMatrix*);
212  double invert_this();
213  double solve_this(SCVector*);
214  double trace();
215  double determ_this();
216  void gen_invert_this();
217 
220  void element_op(const Ref<SCElementOp>&);
221  void element_op(const Ref<SCElementOp2>&,
222  SymmSCMatrix*);
223  void element_op(const Ref<SCElementOp3>&,
225 
226  virtual void convert_accumulate(SymmSCMatrix*);
227 
228  Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
229  Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
230 
231  Ref<DistSCMatrixKit> skit();
232 };
233 
235  friend class DistSCMatrix;
236  friend class DistSymmSCMatrix;
237  friend class DistSCVector;
238  protected:
239  Ref<SCMatrixBlockList> blocklist;
240 
241  void init_blocklist();
242  double *find_element(int i) const;
243  int element_to_node(int i) const;
244  int block_to_node(int) const;
245  Ref<SCMatrixBlock> block_to_block(int) const;
246  void error(const char *msg);
247  public:
249  ~DistDiagSCMatrix();
250 
251  // implementations and overrides of virtual functions
252  double get_element(int) const;
253  void set_element(int,double);
254  void accumulate_element(int,double);
255  void accumulate(const DiagSCMatrix*);
256  double invert_this();
257  double determ_this();
258  double trace();
259  void gen_invert_this();
260 
261  void element_op(const Ref<SCElementOp>&);
262  void element_op(const Ref<SCElementOp2>&,
263  DiagSCMatrix*);
264  void element_op(const Ref<SCElementOp3>&,
266 
267  Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
268  Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
269 
270  Ref<DistSCMatrixKit> skit();
271 };
272 
274  protected:
275  Ref<MessageGrp> grp_;
276  StateSend out_;
277  StateRecv in_;
278  int step_;
279  Ref<SCMatrixBlockList> locallist_;
280 
281  void maybe_advance_list();
282  void advance_list();
283  public:
285  const Ref<SCMatrixBlockList> &locallist,
286  const Ref<MessageGrp> &grp);
287  void begin();
288  void next();
290 };
291 
292 }
293 
294 #endif
295 
296 // Local Variables:
297 // mode: c++
298 // c-file-style: "CLJ"
299 // End:
sc::DistSymmSCMatrix::accumulate_subblock
void accumulate_subblock(SCMatrix *, int, int, int, int)
Sum m into a subblock of this.
sc::DistDiagSCMatrix
Definition: dist.h:234
sc::DistSymmSCMatrix::assign_subblock
void assign_subblock(SCMatrix *, int, int, int, int)
Assign m to a subblock of this.
sc::DistSymmSCMatrix
Definition: dist.h:176
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:273
sc::DistSymmSCMatrix::accumulate_symmetric_sum
void accumulate_symmetric_sum(SCMatrix *)
Sum into this the products of various vectors or matrices.
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:58
sc::DistSCMatrix
Definition: dist.h:100
sc::Ref
A template class that maintains references counts.
Definition: ref.h:332
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:58
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 > &)
Perform the element operation op on each element 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:178
sc::SCMatrixListSubblockIter
Definition: block.h:418
sc::DiagSCMatrix
The SymmSCMatrix class is the abstract base class for diagonal double valued matrices.
Definition: abstract.h:503
sc::DistSymmSCMatrix::get_row
SCVector * get_row(int i)
Return a row of this.
sc::StateSend
StateSend is a concrete specialization of MsgStateSend that does the send part of point to point comm...
Definition: mstate.h:157
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:156
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::trace
double trace()
Return the trace.
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:364
sc::DistDiagSCMatrix::all_blocks
Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the all blocks used in this matrix.
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.
sc::DistSCMatrixListSubblockIter::next
void next()
Proceed to the next block.
sc::DistSCVector::convert
void convert(double *v) const
Assign v[i] to element i for all i.
sc::DistSCMatrix::transpose_this
void transpose_this()
Transpose this.
sc::DistSCMatrix::accumulate
void accumulate(const SCMatrix *)
Sum m into this.
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::DistDiagSCMatrix::gen_invert_this
void gen_invert_this()
Do a generalized inversion of this.
sc::DistSCMatrixKit
The DistSCMatrixKit produces matrices that work in a many processor environment.
Definition: dist.h:46
sc::DistDiagSCMatrix::invert_this
double invert_this()
Invert this.

Generated at Sun Jan 26 2020 23:33:03 for MPQC 2.3.1 using the documentation package Doxygen 1.8.16.