MPQC 3.0.0-alpha
Loading...
Searching...
No Matches
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
38namespace sc {
39
43 public:
44 DistSCMatrixKit(const Ref<MessageGrp> &grp = 0);
48 SymmSCMatrix* symmmatrix(const RefSCDimension&);
49 DiagSCMatrix* diagmatrix(const RefSCDimension&);
50 SCVector* vector(const RefSCDimension&);
51};
52
53
54class 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:
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);
81 void accumulate_product_rv(SCMatrix *, SCVector *);
83 void element_op(const Ref<SCElementOp2>&,
84 SCVector*);
85 void element_op(const Ref<SCElementOp3>&,
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
94};
95
97class 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:
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);
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*);
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);
157 int schmidt_orthog_tol(SymmSCMatrix*, double tol, double *res=0);
159 void element_op(const Ref<SCElementOp2>&,
160 SCMatrix*);
161 void element_op(const Ref<SCElementOp3>&,
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
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:
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);
206 void assign_row(SCVector *v, int i);
207 void accumulate_row(SCVector *v, int i);
208
209 void accumulate_product_rr(SCMatrix*,SCMatrix*);
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
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
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:
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);
258 double invert_this();
259 double determ_this();
260 double trace();
262 void gen_invert_this(double condition_number_threshold = 1e8);
263
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
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:
The SymmSCMatrix class is the abstract base class for diagonal double valued matrices.
Definition abstract.h:555
Distributed DiagSCMatrix.
Definition dist.h:236
double trace()
Return the trace.
Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the local (rapidly accessible) blocks used in this matrix.
double invert_this()
Invert this.
double get_element(int) const
Return or modify an element.
void gen_invert_this(double condition_number_threshold=1e8)
generalized-invert this
Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the all blocks used in this matrix.
void element_op(const Ref< SCElementOp > &)
Perform the element operation op on each element of this.
double determ_this()
Return the determinant of this. this is overwritten.
void accumulate(const DiagSCMatrix *)
Sum m into this.
The DistSCMatrixKit produces matrices that work in a many processor environment.
Definition dist.h:42
SCMatrix * matrix(const RefSCDimension &, const RefSCDimension &)
Given the dimensions, create matrices or vectors.
void begin()
Start at the beginning.
void next()
Proceed to the next block.
Distributed SCMatrix.
Definition dist.h:97
SCMatrix * get_subblock(int, int, int, int)
Return a subblock of this.
void transpose_this()
Transpose this.
double get_element(int, int) const
Return or modify an element.
void assign_row(SCVector *v, int i)
Assign v to a row or column of this.
void schmidt_orthog(SymmSCMatrix *, int)
Schmidt orthogonalize this.
int schmidt_orthog_tol(SymmSCMatrix *, double tol, double *res=0)
Schmidt orthogonalize this.
void element_op(const Ref< SCElementOp > &)
Perform the element operation op on each element of this.
void gen_invert_this(double condition_number_threshold=1e8)
uses invert_this()
void assign_subblock(SCMatrix *, int, int, int, int, int=0, int=0)
Assign m to a subblock of this.
void accumulate(const SCMatrix *)
Sum m into this.
SCVector * get_row(int i)
Return a row or column of this.
void accumulate_subblock(SCMatrix *, int, int, int, int, int=0, int=0)
Sum m into a subblock of this.
double determ_this()
Return the determinant of this. this is overwritten.
Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the all blocks used in this matrix.
void accumulate_row(SCVector *v, int i)
Sum v to a row or column of this.
Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the local (rapidly accessible) blocks used in this matrix.
double invert_this()
Invert this.
void accumulate_outer_product(SCVector *, SCVector *)
Sum into this the products of various vectors or matrices.
double trace()
Return the trace.
Definition dist.h:54
Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the all blocks used in this vector.
void element_op(const Ref< SCElementOp > &)
Perform the element operation op on each element of this.
void accumulate(const SCMatrix *m)
Sum m into this. One of m's dimensions must be 1.
void set_element(int, double)
Set element i to val.
Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the local (rapidly accessible) blocks used in this vector.
double scalar_product(SCVector *)
Return the dot product.
void accumulate(const SCVector *)
Sum v into this.
void accumulate_element(int, double)
Add val to element i.
double get_element(int) const
Return the value of element i.
Distributed SymmSCMatrix.
Definition dist.h:175
double get_element(int, int) const
Return or modify an element.
double invert_this()
Invert this.
void accumulate_subblock(SCMatrix *, int, int, int, int)
Sum m into a subblock of this.
void diagonalize(DiagSCMatrix *, SCMatrix *)
Diagonalize this, placing the eigenvalues in d and the eigenvectors in m.
void eigensystem(SymmSCMatrix *, DiagSCMatrix *, SCMatrix *)
Solve generalized eigensystem for this with metric s, placing the eigenvalues in d and the eigenvecto...
SCMatrix * get_subblock(int, int, int, int)
Return a subblock of this.
void element_op(const Ref< SCElementOp > &)
only applied to the unique elements of this.
void accumulate(const SymmSCMatrix *)
Sum m into this.
void assign_subblock(SCMatrix *, int, int, int, int)
Assign m to a subblock of this.
void accumulate_row(SCVector *v, int i)
Sum v to a row of this.
double trace()
Return the trace.
SCVector * get_row(int i)
Return a row of this.
void assign_row(SCVector *v, int i)
Assign v to a row of this.
void accumulate_symmetric_sum(SCMatrix *)
Sum into a + a.t()
Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the all blocks used in this matrix.
Ref< SCMatrixSubblockIter > local_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the local (rapidly accessible) blocks used in this matrix.
void gen_invert_this(double condition_number_threshold=1e8)
uses invert_this()
double determ_this()
Return the determinant of this. this is overwritten.
static std::ostream & out0()
Return an ostream that writes from node 0.
The RefSCDimension class is a smart pointer to an SCDimension specialization.
Definition dim.h:152
A template class that maintains references counts.
Definition ref.h:361
The SCMatrixKit abstract class acts as a factory for producing matrices.
Definition abstract.h:57
Definition block.h:414
The SCMatrix class is the abstract base class for general double valued n by m matrices.
Definition abstract.h:199
The SCVector class is the abstract base class for double valued vectors.
Definition abstract.h:97
StateRecv is a concrete specialization of MsgStateRecv that does the receive part of point to point c...
Definition mstate.h:193
StateSend is a concrete specialization of MsgStateSend that does the send part of point to point comm...
Definition mstate.h:165
The SymmSCMatrix class is the abstract base class for symmetric double valued matrices.
Definition abstract.h:389
Contains all MPQC code up to version 3.
Definition mpqcin.h:14
std::vector< double > convert(const RefDiagSCMatrix &A)
Converts RefDiagSCMatrix to std::vector<double>

Generated at Wed Sep 25 2024 02:45:30 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.12.0.