[0b990d] | 1 | //
|
---|
| 2 | // repl.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_repl_h
|
---|
| 33 | #define _math_scmat_repl_h
|
---|
| 34 |
|
---|
| 35 | #include <util/group/message.h>
|
---|
| 36 |
|
---|
| 37 | #include <math/scmat/block.h>
|
---|
| 38 | #include <math/scmat/matrix.h>
|
---|
| 39 | #include <math/scmat/abstract.h>
|
---|
| 40 |
|
---|
| 41 | namespace sc {
|
---|
| 42 |
|
---|
| 43 | /** The ReplSCMatrixKit produces matrices that work in a many processor
|
---|
| 44 | environment. A copy of the entire matrix is stored on each node.
|
---|
| 45 | */
|
---|
| 46 | class ReplSCMatrixKit: public SCMatrixKit {
|
---|
| 47 | public:
|
---|
| 48 | ReplSCMatrixKit();
|
---|
| 49 | ReplSCMatrixKit(const Ref<KeyVal>&);
|
---|
| 50 | ~ReplSCMatrixKit();
|
---|
| 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 ReplSCMatrixListSubblockIter: public SCMatrixListSubblockIter {
|
---|
| 59 | protected:
|
---|
| 60 | Ref<MessageGrp> grp_;
|
---|
| 61 | double *data_;
|
---|
| 62 | int ndata_;
|
---|
| 63 | public:
|
---|
| 64 | ReplSCMatrixListSubblockIter(Access,
|
---|
| 65 | const Ref<SCMatrixBlockList> &list,
|
---|
| 66 | const Ref<MessageGrp> &grp,
|
---|
| 67 | double *data, int ndata);
|
---|
| 68 | ~ReplSCMatrixListSubblockIter();
|
---|
| 69 | };
|
---|
| 70 |
|
---|
| 71 | class ReplSCVector: public SCVector {
|
---|
| 72 | friend class ReplSCMatrix;
|
---|
| 73 | friend class ReplSymmSCMatrix;
|
---|
| 74 | friend class ReplDiagSCMatrix;
|
---|
| 75 | protected:
|
---|
| 76 | Ref<SCMatrixBlockList> blocklist;
|
---|
| 77 | double* vector;
|
---|
| 78 | void init_blocklist();
|
---|
| 79 | void before_elemop();
|
---|
| 80 | void after_elemop();
|
---|
| 81 | public:
|
---|
| 82 | ReplSCVector(const RefSCDimension&,ReplSCMatrixKit*);
|
---|
| 83 | ~ReplSCVector();
|
---|
| 84 | void assign_val(double);
|
---|
| 85 | void assign_v(SCVector*);
|
---|
| 86 | void assign_p(const double*);
|
---|
| 87 |
|
---|
| 88 | void set_element(int,double);
|
---|
| 89 | void accumulate_element(int,double);
|
---|
| 90 | double get_element(int) const;
|
---|
| 91 | void accumulate_product_sv(SymmSCMatrix*,SCVector*);
|
---|
| 92 | void accumulate_product_rv(SCMatrix*,SCVector*);
|
---|
| 93 | void accumulate(const SCVector*);
|
---|
| 94 | void accumulate(const SCMatrix*);
|
---|
| 95 | double scalar_product(SCVector*);
|
---|
| 96 | void element_op(const Ref<SCElementOp>&);
|
---|
| 97 | void element_op(const Ref<SCElementOp2>&,
|
---|
| 98 | SCVector*);
|
---|
| 99 | void element_op(const Ref<SCElementOp3>&,
|
---|
| 100 | SCVector*,SCVector*);
|
---|
| 101 | void vprint(const char* title=0,
|
---|
| 102 | std::ostream& out=ExEnv::out0(), int =10) const;
|
---|
| 103 |
|
---|
| 104 | // return a pointer to the data for fast access
|
---|
| 105 | double *get_data() { return vector; }
|
---|
| 106 |
|
---|
| 107 | Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
|
---|
| 108 | Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
|
---|
| 109 |
|
---|
| 110 | Ref<ReplSCMatrixKit> skit();
|
---|
| 111 | };
|
---|
| 112 |
|
---|
| 113 | class ReplSCMatrix: public SCMatrix {
|
---|
| 114 | friend class ReplSymmSCMatrix;
|
---|
| 115 | friend class ReplDiagSCMatrix;
|
---|
| 116 | friend class ReplSCVector;
|
---|
| 117 | protected:
|
---|
| 118 | Ref<SCMatrixBlockList> blocklist;
|
---|
| 119 | double* matrix;
|
---|
| 120 | double** rows;
|
---|
| 121 | protected:
|
---|
| 122 | // utility functions
|
---|
| 123 | int compute_offset(int,int) const;
|
---|
| 124 | void init_blocklist();
|
---|
| 125 |
|
---|
| 126 | void before_elemop();
|
---|
| 127 | void after_elemop();
|
---|
| 128 | public:
|
---|
| 129 | ReplSCMatrix(const RefSCDimension&,const RefSCDimension&,
|
---|
| 130 | ReplSCMatrixKit*);
|
---|
| 131 | ~ReplSCMatrix();
|
---|
| 132 |
|
---|
| 133 | // implementations and overrides of virtual functions
|
---|
| 134 | void assign_val(double);
|
---|
| 135 | double get_element(int,int) const;
|
---|
| 136 | void set_element(int,int,double);
|
---|
| 137 | void accumulate_element(int,int,double);
|
---|
| 138 | SCMatrix * get_subblock(int,int,int,int);
|
---|
| 139 | void assign_subblock(SCMatrix*, int,int,int,int,int=0,int=0);
|
---|
| 140 | void accumulate_subblock(SCMatrix*, int,int,int,int,int=0,int=0);
|
---|
| 141 | SCVector * get_row(int i);
|
---|
| 142 | SCVector * get_column(int i);
|
---|
| 143 | void assign_row(SCVector *v, int i);
|
---|
| 144 | void assign_column(SCVector *v, int i);
|
---|
| 145 | void accumulate_row(SCVector *v, int i);
|
---|
| 146 | void accumulate_column(SCVector *v, int i);
|
---|
| 147 |
|
---|
| 148 | void accumulate_outer_product(SCVector*,SCVector*);
|
---|
| 149 | void accumulate_product_rr(SCMatrix*,SCMatrix*);
|
---|
| 150 | void accumulate_product_rs(SCMatrix*,SymmSCMatrix*);
|
---|
| 151 | void accumulate_product_rd(SCMatrix*,DiagSCMatrix*);
|
---|
| 152 | void accumulate(const SCMatrix*);
|
---|
| 153 | void accumulate(const SymmSCMatrix*);
|
---|
| 154 | void accumulate(const DiagSCMatrix*);
|
---|
| 155 | void accumulate(const SCVector*);
|
---|
| 156 | void transpose_this();
|
---|
| 157 | double invert_this();
|
---|
| 158 | void svd_this(SCMatrix *U, DiagSCMatrix *sigma, SCMatrix *V);
|
---|
| 159 | double solve_this(SCVector*);
|
---|
| 160 | double determ_this();
|
---|
| 161 | double trace();
|
---|
| 162 | void schmidt_orthog(SymmSCMatrix*,int);
|
---|
| 163 | int schmidt_orthog_tol(SymmSCMatrix*, double tol, double *res=0);
|
---|
| 164 | void element_op(const Ref<SCElementOp>&);
|
---|
| 165 | void element_op(const Ref<SCElementOp2>&,
|
---|
| 166 | SCMatrix*);
|
---|
| 167 | void element_op(const Ref<SCElementOp3>&,
|
---|
| 168 | SCMatrix*,SCMatrix*);
|
---|
| 169 | void vprint(const char* title=0,
|
---|
| 170 | std::ostream& out=ExEnv::out0(), int =10) const;
|
---|
| 171 |
|
---|
| 172 | // return a pointer to the data for fast access
|
---|
| 173 | double *get_data() { return matrix; }
|
---|
| 174 | double **get_rows() { return rows; }
|
---|
| 175 |
|
---|
| 176 | Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
|
---|
| 177 | Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
|
---|
| 178 |
|
---|
| 179 | Ref<ReplSCMatrixKit> skit();
|
---|
| 180 | };
|
---|
| 181 |
|
---|
| 182 | class ReplSymmSCMatrix: public SymmSCMatrix {
|
---|
| 183 | friend class ReplSCMatrix;
|
---|
| 184 | friend class ReplDiagSCMatrix;
|
---|
| 185 | friend class ReplSCVector;
|
---|
| 186 | protected:
|
---|
| 187 | Ref<SCMatrixBlockList> blocklist;
|
---|
| 188 | double* matrix;
|
---|
| 189 | double** rows;
|
---|
| 190 | protected:
|
---|
| 191 | // utility functions
|
---|
| 192 | int compute_offset(int,int) const;
|
---|
| 193 | void init_blocklist();
|
---|
| 194 |
|
---|
| 195 | void before_elemop();
|
---|
| 196 | void after_elemop();
|
---|
| 197 | public:
|
---|
| 198 | ReplSymmSCMatrix(const RefSCDimension&, ReplSCMatrixKit*);
|
---|
| 199 | ~ReplSymmSCMatrix();
|
---|
| 200 |
|
---|
| 201 | // implementations and overrides of virtual functions
|
---|
| 202 | void assign_val(double);
|
---|
| 203 | void assign_s(SymmSCMatrix*);
|
---|
| 204 | void assign_p(const double*);
|
---|
| 205 | void assign_pp(const double**);
|
---|
| 206 | double get_element(int,int) const;
|
---|
| 207 | void set_element(int,int,double);
|
---|
| 208 | void accumulate_element(int,int,double);
|
---|
| 209 | void scale(double);
|
---|
| 210 |
|
---|
| 211 | SCMatrix * get_subblock(int,int,int,int);
|
---|
| 212 | SymmSCMatrix * get_subblock(int,int);
|
---|
| 213 | void assign_subblock(SCMatrix*, int,int,int,int);
|
---|
| 214 | void assign_subblock(SymmSCMatrix*, int,int);
|
---|
| 215 | void accumulate_subblock(SCMatrix*, int,int,int,int);
|
---|
| 216 | void accumulate_subblock(SymmSCMatrix*, int,int);
|
---|
| 217 | SCVector * get_row(int i);
|
---|
| 218 | void assign_row(SCVector *v, int i);
|
---|
| 219 | void accumulate_row(SCVector *v, int i);
|
---|
| 220 |
|
---|
| 221 | void accumulate_product_rr(SCMatrix*,SCMatrix*);
|
---|
| 222 | void accumulate(const SymmSCMatrix*);
|
---|
| 223 | double invert_this();
|
---|
| 224 | double solve_this(SCVector*);
|
---|
| 225 | double trace();
|
---|
| 226 | double determ_this();
|
---|
| 227 | void gen_invert_this();
|
---|
| 228 |
|
---|
| 229 | double scalar_product(SCVector*);
|
---|
| 230 | void diagonalize(DiagSCMatrix*,SCMatrix*);
|
---|
| 231 | void accumulate_symmetric_outer_product(SCVector*);
|
---|
| 232 | void accumulate_symmetric_product(SCMatrix*);
|
---|
| 233 | void accumulate_symmetric_sum(SCMatrix*);
|
---|
| 234 | void accumulate_transform(SCMatrix*,SymmSCMatrix*,
|
---|
| 235 | SCMatrix::Transform = SCMatrix::NormalTransform);
|
---|
| 236 | void accumulate_transform(SCMatrix*,DiagSCMatrix*,
|
---|
| 237 | SCMatrix::Transform = SCMatrix::NormalTransform);
|
---|
| 238 | void accumulate_transform(SymmSCMatrix*,SymmSCMatrix*);
|
---|
| 239 | void element_op(const Ref<SCElementOp>&);
|
---|
| 240 | void element_op(const Ref<SCElementOp2>&,
|
---|
| 241 | SymmSCMatrix*);
|
---|
| 242 | void element_op(const Ref<SCElementOp3>&,
|
---|
| 243 | SymmSCMatrix*,SymmSCMatrix*);
|
---|
| 244 | void vprint(const char* title=0,
|
---|
| 245 | std::ostream& out=ExEnv::out0(), int =10) const;
|
---|
| 246 |
|
---|
| 247 | // return a pointer to the data for fast access
|
---|
| 248 | double *get_data() { return matrix; }
|
---|
| 249 | double **get_rows() { return rows; }
|
---|
| 250 |
|
---|
| 251 | Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
|
---|
| 252 | Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
|
---|
| 253 |
|
---|
| 254 | Ref<ReplSCMatrixKit> skit();
|
---|
| 255 | };
|
---|
| 256 |
|
---|
| 257 | class ReplDiagSCMatrix: public DiagSCMatrix {
|
---|
| 258 | friend class ReplSCMatrix;
|
---|
| 259 | friend class ReplSymmSCMatrix;
|
---|
| 260 | friend class ReplSCVector;
|
---|
| 261 | protected:
|
---|
| 262 | Ref<SCMatrixBlockList> blocklist;
|
---|
| 263 | void init_blocklist();
|
---|
| 264 | double* matrix;
|
---|
| 265 |
|
---|
| 266 | void before_elemop();
|
---|
| 267 | void after_elemop();
|
---|
| 268 | public:
|
---|
| 269 | ReplDiagSCMatrix(const RefSCDimension&, ReplSCMatrixKit*);
|
---|
| 270 | ~ReplDiagSCMatrix();
|
---|
| 271 |
|
---|
| 272 | // implementations and overrides of virtual functions
|
---|
| 273 | void assign_val(double);
|
---|
| 274 | double get_element(int) const;
|
---|
| 275 | void set_element(int,double);
|
---|
| 276 | void accumulate_element(int,double);
|
---|
| 277 | void accumulate(const DiagSCMatrix*);
|
---|
| 278 | double invert_this();
|
---|
| 279 | double determ_this();
|
---|
| 280 | double trace();
|
---|
| 281 | void gen_invert_this();
|
---|
| 282 |
|
---|
| 283 | void element_op(const Ref<SCElementOp>&);
|
---|
| 284 | void element_op(const Ref<SCElementOp2>&,
|
---|
| 285 | DiagSCMatrix*);
|
---|
| 286 | void element_op(const Ref<SCElementOp3>&,
|
---|
| 287 | DiagSCMatrix*,DiagSCMatrix*);
|
---|
| 288 | void vprint(const char* title=0,
|
---|
| 289 | std::ostream& out=ExEnv::out0(), int =10) const;
|
---|
| 290 |
|
---|
| 291 | // return a pointer to the data for fast access
|
---|
| 292 | double *get_data() { return matrix; }
|
---|
| 293 |
|
---|
| 294 | Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
|
---|
| 295 | Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
|
---|
| 296 |
|
---|
| 297 | Ref<ReplSCMatrixKit> skit();
|
---|
| 298 | };
|
---|
| 299 |
|
---|
| 300 | }
|
---|
| 301 |
|
---|
| 302 | #endif
|
---|
| 303 |
|
---|
| 304 | // Local Variables:
|
---|
| 305 | // mode: c++
|
---|
| 306 | // c-file-style: "CLJ"
|
---|
| 307 | // End:
|
---|