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
42namespace sc {
43
47 public:
48 DistSCMatrixKit(const Ref<MessageGrp> &grp = 0);
52 SymmSCMatrix* symmmatrix(const RefSCDimension&);
53 DiagSCMatrix* diagmatrix(const RefSCDimension&);
54 SCVector* vector(const RefSCDimension&);
55};
56
57
58class 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:
74 void assign_p(const double*);
75 void assign_v(SCVector*a);
76 void convert(double* v) const;
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);
85 void accumulate_product_rv(SCMatrix *, SCVector *);
87 void element_op(const Ref<SCElementOp2>&,
88 SCVector*);
89 void element_op(const Ref<SCElementOp3>&,
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
98};
99
100class 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:
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);
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*);
153 double invert_this();
154 double solve_this(SCVector*);
155 double determ_this();
156 double trace();
157 void gen_invert_this();
159 int schmidt_orthog_tol(SymmSCMatrix*, double tol, double *res=0);
161 void element_op(const Ref<SCElementOp2>&,
162 SCMatrix*);
163 void element_op(const Ref<SCElementOp3>&,
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
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:
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);
207 void assign_row(SCVector *v, int i);
208 void accumulate_row(SCVector *v, int i);
209
210 void accumulate_product_rr(SCMatrix*,SCMatrix*);
212 double invert_this();
213 double solve_this(SCVector*);
214 double trace();
215 double determ_this();
216 void gen_invert_this();
217
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
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:
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);
256 double invert_this();
257 double determ_this();
258 double trace();
260
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
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:
The SymmSCMatrix class is the abstract base class for diagonal double valued matrices.
Definition abstract.h:503
Definition dist.h:234
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.
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 gen_invert_this()
Do a generalized inversion of this.
void accumulate(const DiagSCMatrix *)
Sum m into this.
The DistSCMatrixKit produces matrices that work in a many processor environment.
Definition dist.h:46
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.
Definition dist.h:100
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 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:58
Ref< SCMatrixSubblockIter > all_blocks(SCMatrixSubblockIter::Access)
Returns iterators for the all blocks used in this vector.
void convert(SCVector *)
Convert an SCVector of a different specialization to this specialization and possibly accumulate the ...
void element_op(const Ref< SCElementOp > &)
Perform the element operation op on each element of this.
void convert(double *v) const
Assign v[i] to element i for all i.
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.
Definition dist.h:176
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.
SCMatrix * get_subblock(int, int, int, int)
Return a subblock of this.
void element_op(const Ref< SCElementOp > &)
Perform the element operation op on each element 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 this the products of various vectors or matrices.
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.
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:156
A template class that maintains references counts.
Definition ref.h:332
The SCMatrixKit abstract class acts as a factory for producing matrices.
Definition abstract.h:58
Definition block.h:418
The SCMatrix class is the abstract base class for general double valued n by m matrices.
Definition abstract.h:195
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:178
StateSend is a concrete specialization of MsgStateSend that does the send part of point to point comm...
Definition mstate.h:157
The SymmSCMatrix class is the abstract base class for symmetric double valued matrices.
Definition abstract.h:364

Generated at Fri May 31 2024 00:00:00 for MPQC 2.3.1 using the documentation package Doxygen 1.11.0.