Main Page Class Hierarchy Compound List File List Compound Members Related Pages

# dist.h

    00001 //
    00002 // dist.h
    00003 //
    00004 // Copyright (C) 1996 Limit Point Systems, Inc.
    00005 //
    00006 // Author: Curtis Janssen <cljanss@limitpt.com>
    00007 // Maintainer: LPS
    00008 //
    00009 // This file is part of the SC Toolkit.
    00010 //
    00011 // The SC Toolkit is free software; you can redistribute it and/or modify
    00012 // it under the terms of the GNU Library General Public License as published by
    00013 // the Free Software Foundation; either version 2, or (at your option)
    00014 // any later version.
    00015 //
    00016 // The SC Toolkit is distributed in the hope that it will be useful,
    00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00019 // GNU Library General Public License for more details.
    00020 //
    00021 // You should have received a copy of the GNU Library General Public License
    00022 // along with the SC Toolkit; see the file COPYING.LIB.  If not, write to
    00023 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
    00024 //
    00025 // The U.S. Government is granted a limited license as per AL 91-7.
    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
    00042 namespace sc {
    00043
    00046 class DistSCMatrixKit: public SCMatrixKit {
    00047   public:
    00048     DistSCMatrixKit(const Ref<MessageGrp> &grp = 0);
    00049     DistSCMatrixKit(const Ref<KeyVal>&);
    00050     ~DistSCMatrixKit();
    00051     SCMatrix* matrix(const RefSCDimension&,const RefSCDimension&);
    00052     SymmSCMatrix* symmmatrix(const RefSCDimension&);
    00053     DiagSCMatrix* diagmatrix(const RefSCDimension&);
    00054     SCVector* vector(const RefSCDimension&);
    00055 };
    00056
    00057
    00058 class DistSCVector: public SCVector {
    00059     friend class DistSCMatrix;
    00060     friend class DistSymmSCMatrix;
    00061     friend class DistDiagSCMatrix;
    00062   protected:
    00063     Ref<SCMatrixBlockList> blocklist;
    00064
    00065     void init_blocklist();
    00066     double *find_element(int i) const;
    00067     int element_to_node(int i) const;
    00068     int block_to_node(int) const;
    00069     Ref<SCMatrixBlock> block_to_block(int) const;
    00070     void error(const char *);
    00071   public:
    00072     DistSCVector(const RefSCDimension&, DistSCMatrixKit*);
    00073     ~DistSCVector();
    00074     void assign_p(const double*);
    00075     void assign_v(SCVector*a);
    00076     void convert(double* v) const;
    00077     void convert(SCVector *);
    00078
    00079     void set_element(int,double);
    00080     void accumulate_element(int,double);
    00081     double get_element(int) const;
    00082     void accumulate(const SCVector*);
    00083     void accumulate(const SCMatrix*m);
    00084     double scalar_product(SCVector*);
    00085     void accumulate_product_rv(SCMatrix *, SCVector *);
    00086     void element_op(const Ref<SCElementOp>&);
    00087     void element_op(const Ref<SCElementOp2>&,
    00088                     SCVector*);
    00089     void element_op(const Ref<SCElementOp3>&,
    00090                     SCVector*,SCVector*);
    00091     void vprint(const char* title=0,
    00092                 std::ostream& out=ExEnv::out0(), int =10) const;
    00093
    00094     Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
    00095     Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
    00096
    00097     Ref<DistSCMatrixKit> skit();
    00098 };
    00099
    00100 class DistSCMatrix: public SCMatrix {
    00101     friend class DistSymmSCMatrix;
    00102     friend class DistDiagSCMatrix;
    00103     friend class DistSCVector;
    00104   protected:
    00105     Ref<SCMatrixBlockList> blocklist;
    00106
    00107     int vecoff;
    00108     int nvec;
    00109     double **vec;
    00110   protected:
    00111     // utility functions
    00112     void init_blocklist();
    00113     void error(const char *);
    00114     double *find_element(int i, int j) const;
    00115     int element_to_node(int i, int j) const;
    00116     int block_to_node(int,int) const;
    00117     Ref<SCMatrixBlock> block_to_block(int, int) const;
    00118     Ref<SCBlockInfo> rowblocks() const { return d1->blocks(); }
    00119     Ref<SCBlockInfo> colblocks() const { return d2->blocks(); }
    00120
    00121     enum VecOp {CopyFromVec, CopyToVec, AccumFromVec, AccumToVec};
    00122     enum Form { Row, Col } form;
    00123     void create_vecform(Form, int nvec = -1);
    00124     void delete_vecform();
    00125     void vecform_op(VecOp op, int *ivec = 0);
    00126     void vecform_zero();
    00127   public:
    00128     DistSCMatrix(const RefSCDimension&, const RefSCDimension&,
    00129                  DistSCMatrixKit*);
    00130     ~DistSCMatrix();
    00131
    00132     // implementations and overrides of virtual functions
    00133     double get_element(int,int) const;
    00134     void set_element(int,int,double);
    00135     void accumulate_element(int,int,double);
    00136     SCMatrix * get_subblock(int,int,int,int);
    00137     void assign_subblock(SCMatrix*, int,int,int,int,int=0,int=0);
    00138     void accumulate_subblock(SCMatrix*, int,int,int,int,int=0,int=0);
    00139     SCVector * get_row(int i);
    00140     SCVector * get_column(int i);
    00141     void assign_row(SCVector *v, int i);
    00142     void assign_column(SCVector *v, int i);
    00143     void accumulate_row(SCVector *v, int i);
    00144     void accumulate_column(SCVector *v, int i);
    00145
    00146     void accumulate_outer_product(SCVector*,SCVector*);
    00147     void accumulate_product_rr(SCMatrix*,SCMatrix*);
    00148     void accumulate(const SCMatrix*);
    00149     void accumulate(const SymmSCMatrix*);
    00150     void accumulate(const DiagSCMatrix*);
    00151     void accumulate(const SCVector*);
    00152     void transpose_this();
    00153     double invert_this();
    00154     double solve_this(SCVector*);
    00155     double determ_this();
    00156     double trace();
    00157     void gen_invert_this();
    00158     void schmidt_orthog(SymmSCMatrix*,int);
    00159     int schmidt_orthog_tol(SymmSCMatrix*, double tol, double *res=0);
    00160     void element_op(const Ref<SCElementOp>&);
    00161     void element_op(const Ref<SCElementOp2>&,
    00162                     SCMatrix*);
    00163     void element_op(const Ref<SCElementOp3>&,
    00164                     SCMatrix*,SCMatrix*);
    00165     void vprint(const char* title=0,
    00166                 std::ostream& out=ExEnv::out0(), int =10);
    00167     void vprint(const char* title=0,
    00168                 std::ostream& out=ExEnv::out0(), int =10) const;
    00169
    00170     Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
    00171     Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
    00172
    00173     Ref<DistSCMatrixKit> skit();
    00174 };
    00175
    00176 class DistSymmSCMatrix: public SymmSCMatrix {
    00177     friend class DistSCMatrix;
    00178     friend class DistDiagSCMatrix;
    00179     friend class DistSCVector;
    00180   protected:
    00181     Ref<SCMatrixBlockList> blocklist;
    00182   protected:
    00183     // utility functions
    00184     void init_blocklist();
    00185     double *find_element(int i, int j) const;
    00186     int element_to_node(int i, int j) const;
    00187     int block_to_node(int,int) const;
    00188     Ref<SCMatrixBlock> block_to_block(int, int) const;
    00189
    00190     void error(const char *msg);
    00191   public:
    00192     DistSymmSCMatrix(const RefSCDimension&, DistSCMatrixKit*);
    00193     ~DistSymmSCMatrix();
    00194
    00195     // implementations and overrides of virtual functions
    00196     double get_element(int,int) const;
    00197     void set_element(int,int,double);
    00198     void accumulate_element(int,int,double);
    00199
    00200     SCMatrix * get_subblock(int,int,int,int);
    00201     SymmSCMatrix * get_subblock(int,int);
    00202     void assign_subblock(SCMatrix*, int,int,int,int);
    00203     void assign_subblock(SymmSCMatrix*, int,int);
    00204     void accumulate_subblock(SCMatrix*, int,int,int,int);
    00205     void accumulate_subblock(SymmSCMatrix*, int,int);
    00206     SCVector * get_row(int i);
    00207     void assign_row(SCVector *v, int i);
    00208     void accumulate_row(SCVector *v, int i);
    00209
    00210     void accumulate_product_rr(SCMatrix*,SCMatrix*);
    00211     void accumulate(const SymmSCMatrix*);
    00212     double invert_this();
    00213     double solve_this(SCVector*);
    00214     double trace();
    00215     double determ_this();
    00216     void gen_invert_this();
    00217
    00218     void diagonalize(DiagSCMatrix*,SCMatrix*);
    00219     void accumulate_symmetric_sum(SCMatrix*);
    00220     void element_op(const Ref<SCElementOp>&);
    00221     void element_op(const Ref<SCElementOp2>&,
    00222                     SymmSCMatrix*);
    00223     void element_op(const Ref<SCElementOp3>&,
    00224                     SymmSCMatrix*,SymmSCMatrix*);
    00225
    00226     virtual void convert_accumulate(SymmSCMatrix*);
    00227
    00228     Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
    00229     Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
    00230
    00231     Ref<DistSCMatrixKit> skit();
    00232 };
    00233
    00234 class DistDiagSCMatrix: public DiagSCMatrix {
    00235     friend class DistSCMatrix;
    00236     friend class DistSymmSCMatrix;
    00237     friend class DistSCVector;
    00238   protected:
    00239     Ref<SCMatrixBlockList> blocklist;
    00240
    00241     void init_blocklist();
    00242     double *find_element(int i) const;
    00243     int element_to_node(int i) const;
    00244     int block_to_node(int) const;
    00245     Ref<SCMatrixBlock> block_to_block(int) const;
    00246     void error(const char *msg);
    00247   public:
    00248     DistDiagSCMatrix(const RefSCDimension&, DistSCMatrixKit*);
    00249     ~DistDiagSCMatrix();
    00250
    00251     // implementations and overrides of virtual functions
    00252     double get_element(int) const;
    00253     void set_element(int,double);
    00254     void accumulate_element(int,double);
    00255     void accumulate(const DiagSCMatrix*);
    00256     double invert_this();
    00257     double determ_this();
    00258     double trace();
    00259     void gen_invert_this();
    00260
    00261     void element_op(const Ref<SCElementOp>&);
    00262     void element_op(const Ref<SCElementOp2>&,
    00263                     DiagSCMatrix*);
    00264     void element_op(const Ref<SCElementOp3>&,
    00265                     DiagSCMatrix*,DiagSCMatrix*);
    00266
    00267     Ref<SCMatrixSubblockIter> local_blocks(SCMatrixSubblockIter::Access);
    00268     Ref<SCMatrixSubblockIter> all_blocks(SCMatrixSubblockIter::Access);
    00269
    00270     Ref<DistSCMatrixKit> skit();
    00271 };
    00272
    00273 class DistSCMatrixListSubblockIter: public SCMatrixListSubblockIter {
    00274   protected:
    00275     Ref<MessageGrp> grp_;
    00276     StateSend out_;
    00277     StateRecv in_;
    00278     int step_;
    00279     Ref<SCMatrixBlockList> locallist_;
    00280
    00281     void maybe_advance_list();
    00282     void advance_list();
    00283   public:
    00284     DistSCMatrixListSubblockIter(Access,
    00285                                  const Ref<SCMatrixBlockList> &locallist,
    00286                                  const Ref<MessageGrp> &grp);
    00287     void begin();
    00288     void next();
    00289     ~DistSCMatrixListSubblockIter();
    00290 };
    00291
    00292 }
    00293
    00294 #endif
    00295
    00296 // Local Variables:
    00297 // mode: c++
    00298 // c-file-style: "CLJ"
    00299 // End: