00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifdef __GNUC__
00029 #pragma interface
00030 #endif
00031
00032 #ifndef _math_scmat_dist_h
00033 #define _math_scmat_dist_h
00034
00035 #include <util/group/message.h>
00036 #include <util/group/mstate.h>
00037
00038 #include <math/scmat/block.h>
00039 #include <math/scmat/matrix.h>
00040 #include <math/scmat/abstract.h>
00041
00044 class DistSCMatrixKit: public SCMatrixKit {
00045 public:
00046 DistSCMatrixKit(const Ref<MessageGrp> &grp = 0);
00047 DistSCMatrixKit(const Ref<KeyVal>&);
00048 ~DistSCMatrixKit();
00049 SCMatrix* matrix(const RefSCDimension&,const RefSCDimension&);
00050 SymmSCMatrix* symmmatrix(const RefSCDimension&);
00051 DiagSCMatrix* diagmatrix(const RefSCDimension&);
00052 SCVector* vector(const RefSCDimension&);
00053 };
00054
00055
00056 class DistSCVector: public SCVector {
00057 friend class DistSCMatrix;
00058 friend class DistSymmSCMatrix;
00059 friend class DistDiagSCMatrix;
00060 protected:
00061 Ref<SCMatrixBlockList> blocklist;
00062
00063 void init_blocklist();
00064 double *find_element(int i) const;
00065 int element_to_node(int i) const;
00066 int block_to_node(int) const;
00067 Ref<SCMatrixBlock> block_to_block(int) const;
00068 void error(const char *);
00069 public:
00070 DistSCVector(const RefSCDimension&, DistSCMatrixKit*);
00071 ~DistSCVector();
00072 void assign_p(const double*);
00073 void assign_v(SCVector*a);
00074 void convert(double* v) const;
00075 void convert(SCVector *);
00076
00077 void set_element(int,double);
00078 void accumulate_element(int,double);
00079 double get_element(int) const;
00080 void accumulate(const SCVector*);
00081 void accumulate(const SCMatrix*m);
00082 double scalar_product(SCVector*);
00083 void accumulate_product_rv(SCMatrix *, SCVector *);
00084 void element_op(const Ref<SCElementOp>&);
00085 void element_op(const Ref<SCElementOp2>&,
00086 SCVector*);
00087 void element_op(const Ref<SCElementOp3>&,
00088 SCVector*,SCVector*);
00089 void vprint(const char* title=0,
00090 std::ostream& out=ExEnv::out(), int =10) const;
00091
00092 Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
00093 Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
00094
00095 Ref<DistSCMatrixKit> skit();
00096 };
00097
00098 class DistSCMatrix: public SCMatrix {
00099 friend class DistSymmSCMatrix;
00100 friend class DistDiagSCMatrix;
00101 friend class DistSCVector;
00102 protected:
00103 Ref<SCMatrixBlockList> blocklist;
00104
00105 int vecoff;
00106 int nvec;
00107 double **vec;
00108 protected:
00109
00110 void init_blocklist();
00111 void error(const char *);
00112 double *find_element(int i, int j) const;
00113 int element_to_node(int i, int j) const;
00114 int block_to_node(int,int) const;
00115 Ref<SCMatrixBlock> block_to_block(int, int) const;
00116 Ref<SCBlockInfo> rowblocks() const { return d1->blocks(); }
00117 Ref<SCBlockInfo> colblocks() const { return d2->blocks(); }
00118
00119 enum VecOp {CopyFromVec, CopyToVec, AccumFromVec, AccumToVec};
00120 enum Form { Row, Col } form;
00121 void create_vecform(Form, int nvec = -1);
00122 void delete_vecform();
00123 void vecform_op(VecOp op, int *ivec = 0);
00124 void vecform_zero();
00125 public:
00126 DistSCMatrix(const RefSCDimension&, const RefSCDimension&,
00127 DistSCMatrixKit*);
00128 ~DistSCMatrix();
00129
00130
00131 double get_element(int,int) const;
00132 void set_element(int,int,double);
00133 void accumulate_element(int,int,double);
00134 SCMatrix * get_subblock(int,int,int,int);
00135 void assign_subblock(SCMatrix*, int,int,int,int,int=0,int=0);
00136 void accumulate_subblock(SCMatrix*, int,int,int,int,int=0,int=0);
00137 SCVector * get_row(int i);
00138 SCVector * get_column(int i);
00139 void assign_row(SCVector *v, int i);
00140 void assign_column(SCVector *v, int i);
00141 void accumulate_row(SCVector *v, int i);
00142 void accumulate_column(SCVector *v, int i);
00143
00144 void accumulate_outer_product(SCVector*,SCVector*);
00145 void accumulate_product_rr(SCMatrix*,SCMatrix*);
00146 void accumulate(const SCMatrix*);
00147 void accumulate(const SymmSCMatrix*);
00148 void accumulate(const DiagSCMatrix*);
00149 void accumulate(const SCVector*);
00150 void transpose_this();
00151 double invert_this();
00152 double solve_this(SCVector*);
00153 double determ_this();
00154 double trace();
00155 void gen_invert_this();
00156 void schmidt_orthog(SymmSCMatrix*,int);
00157 int schmidt_orthog_tol(SymmSCMatrix*, double tol, double *res=0);
00158 void element_op(const Ref<SCElementOp>&);
00159 void element_op(const Ref<SCElementOp2>&,
00160 SCMatrix*);
00161 void element_op(const Ref<SCElementOp3>&,
00162 SCMatrix*,SCMatrix*);
00163 void vprint(const char* title=0,
00164 std::ostream& out=ExEnv::out(), int =10);
00165 void vprint(const char* title=0,
00166 std::ostream& out=ExEnv::out(), int =10) const;
00167
00168 Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
00169 Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
00170
00171 Ref<DistSCMatrixKit> skit();
00172 };
00173
00174 class DistSymmSCMatrix: public SymmSCMatrix {
00175 friend class DistSCMatrix;
00176 friend class DistDiagSCMatrix;
00177 friend class DistSCVector;
00178 protected:
00179 Ref<SCMatrixBlockList> blocklist;
00180 protected:
00181
00182 void init_blocklist();
00183 double *find_element(int i, int j) const;
00184 int element_to_node(int i, int j) const;
00185 int block_to_node(int,int) const;
00186 Ref<SCMatrixBlock> block_to_block(int, int) const;
00187
00188 void error(const char *msg);
00189 public:
00190 DistSymmSCMatrix(const RefSCDimension&, DistSCMatrixKit*);
00191 ~DistSymmSCMatrix();
00192
00193
00194 double get_element(int,int) const;
00195 void set_element(int,int,double);
00196 void accumulate_element(int,int,double);
00197
00198 SCMatrix * get_subblock(int,int,int,int);
00199 SymmSCMatrix * get_subblock(int,int);
00200 void assign_subblock(SCMatrix*, int,int,int,int);
00201 void assign_subblock(SymmSCMatrix*, int,int);
00202 void accumulate_subblock(SCMatrix*, int,int,int,int);
00203 void accumulate_subblock(SymmSCMatrix*, int,int);
00204 SCVector * get_row(int i);
00205 void assign_row(SCVector *v, int i);
00206 void accumulate_row(SCVector *v, int i);
00207
00208 void accumulate_product_rr(SCMatrix*,SCMatrix*);
00209 void accumulate(const SymmSCMatrix*);
00210 double invert_this();
00211 double solve_this(SCVector*);
00212 double trace();
00213 double determ_this();
00214 void gen_invert_this();
00215
00216 void diagonalize(DiagSCMatrix*,SCMatrix*);
00217 void accumulate_symmetric_sum(SCMatrix*);
00218 void element_op(const Ref<SCElementOp>&);
00219 void element_op(const Ref<SCElementOp2>&,
00220 SymmSCMatrix*);
00221 void element_op(const Ref<SCElementOp3>&,
00222 SymmSCMatrix*,SymmSCMatrix*);
00223
00224 virtual void convert_accumulate(SymmSCMatrix*);
00225
00226 Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
00227 Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
00228
00229 Ref<DistSCMatrixKit> skit();
00230 };
00231
00232 class DistDiagSCMatrix: public DiagSCMatrix {
00233 friend class DistSCMatrix;
00234 friend class DistSymmSCMatrix;
00235 friend class DistSCVector;
00236 protected:
00237 Ref<SCMatrixBlockList> blocklist;
00238
00239 void init_blocklist();
00240 double *find_element(int i) const;
00241 int element_to_node(int i) const;
00242 int block_to_node(int) const;
00243 Ref<SCMatrixBlock> block_to_block(int) const;
00244 void error(const char *msg);
00245 public:
00246 DistDiagSCMatrix(const RefSCDimension&, DistSCMatrixKit*);
00247 ~DistDiagSCMatrix();
00248
00249
00250 double get_element(int) const;
00251 void set_element(int,double);
00252 void accumulate_element(int,double);
00253 void accumulate(const DiagSCMatrix*);
00254 double invert_this();
00255 double determ_this();
00256 double trace();
00257 void gen_invert_this();
00258
00259 void element_op(const Ref<SCElementOp>&);
00260 void element_op(const Ref<SCElementOp2>&,
00261 DiagSCMatrix*);
00262 void element_op(const Ref<SCElementOp3>&,
00263 DiagSCMatrix*,DiagSCMatrix*);
00264
00265 Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
00266 Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
00267
00268 Ref<DistSCMatrixKit> skit();
00269 };
00270
00271 class DistSCMatrixListSubblockIter: public SCMatrixListSubblockIter {
00272 protected:
00273 Ref<MessageGrp> grp_;
00274 StateSend out_;
00275 StateRecv in_;
00276 int step_;
00277 Ref<SCMatrixBlockList> locallist_;
00278
00279 void maybe_advance_list();
00280 void advance_list();
00281 public:
00282 DistSCMatrixListSubblockIter(Access,
00283 const Ref<SCMatrixBlockList> &locallist,
00284 const Ref<MessageGrp> &grp);
00285 void begin();
00286 void next();
00287 ~DistSCMatrixListSubblockIter();
00288 };
00289
00290 #endif
00291
00292
00293
00294
00295