MPQC 2.3.1

- Main Page
- Related Pages
- Classes
- Files

- File List

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
46 class DistSCMatrixKit: public SCMatrixKit {
47 public:
48 DistSCMatrixKit(const Ref<MessageGrp> &grp = 0);
49 DistSCMatrixKit(const Ref<KeyVal>&);
50 ~DistSCMatrixKit();
51 SCMatrix* matrix(const RefSCDimension&,const RefSCDimension&);
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:
72 DistSCVector(const RefSCDimension&, DistSCMatrixKit*);
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:
128 DistSCMatrix(const RefSCDimension&, const RefSCDimension&,
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
146 void accumulate_outer_product(SCVector*,SCVector*);
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
176 class DistSymmSCMatrix: public SymmSCMatrix {
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:
192 DistSymmSCMatrix(const RefSCDimension&, DistSCMatrixKit*);
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
218 void diagonalize(DiagSCMatrix*,SCMatrix*);
219 void accumulate_symmetric_sum(SCMatrix*);
220 void element_op(const Ref<SCElementOp>&);
221 void element_op(const Ref<SCElementOp2>&,
222 SymmSCMatrix*);
223 void element_op(const Ref<SCElementOp3>&,
224 SymmSCMatrix*,SymmSCMatrix*);
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
234 class DistDiagSCMatrix: public DiagSCMatrix {
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:
248 DistDiagSCMatrix(const RefSCDimension&, DistSCMatrixKit*);
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>&,
265 DiagSCMatrix*,DiagSCMatrix*);
266
267 Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
268 Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
269
270 Ref<DistSCMatrixKit> skit();
271 };
272
273 class DistSCMatrixListSubblockIter: public SCMatrixListSubblockIter {
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:
284 DistSCMatrixListSubblockIter(Access,
285 const Ref<SCMatrixBlockList> &locallist,
286 const Ref<MessageGrp> &grp);
287 void begin();
288 void next();
289 ~DistSCMatrixListSubblockIter();
290 };
291
292 }
293
294 #endif
295
296 // Local Variables:
297 // mode: c++
298 // c-file-style: "CLJ"
299 // End: