IFPACK  Development
 All Classes Files Functions Variables Enumerations Friends
Mat_dh.h
00001 /*@HEADER
00002 // ***********************************************************************
00003 //
00004 //       Ifpack: Object-Oriented Algebraic Preconditioner Package
00005 //                 Copyright (2002) Sandia Corporation
00006 //
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ***********************************************************************
00040 //@HEADER
00041 */
00042 
00043 #ifndef MAT_DH_DH
00044 #define MAT_DH_DH
00045 
00046 #include "euclid_common.h"
00047 
00048   /* this stuff for experimental internal timing */
00049 #define MAT_DH_BINS      10
00050 #define MATVEC_TIME       0 /* time to actually perform matvec */
00051 #define MATVEC_MPI_TIME   1 /* time for comms + vector copying needed */
00052 #define MATVEC_MPI_TIME2  5 /* time for comms, + vector copying needed */
00053 #define MATVEC_TOTAL_TIME 2 /* MATVEC_TIME+MATVEC_MPI_TIME */
00054 #define MATVEC_RATIO      3 /* computation/communication ratio */
00055 #define MATVEC_WORDS      4 /* total words sent to other procs. */
00056 
00057 #ifdef __cplusplus
00058 extern "C"
00059 {
00060 #endif
00061 
00062   struct _mat_dh
00063   {
00064     int m, n;           /* dimensions of local rectangular submatrix;
00065                  * the global matrix is n by n.
00066                  */
00067     int beg_row;        /* global number of 1st locally owned row */
00068     int bs;         /* block size */
00069 
00070     /* sparse row-oriented storage for locally owned submatrix */
00071     int *rp;
00072     int *len;           /* length of each row; only used for MPI triangular solves */
00073     int *cval;
00074     int *fill;
00075     int *diag;
00076     double *aval;
00077     bool owner;         /* for MPI triangular solves */
00078 
00079     /* working space for getRow */
00080     int len_private;
00081     int rowCheckedOut;
00082     int *cval_private;
00083     double *aval_private;
00084 
00085     /* row permutations to increase positive definiteness */
00086     int *row_perm;
00087 
00088     /* for timing matvecs in experimental studies */
00089     double time[MAT_DH_BINS];
00090     double time_max[MAT_DH_BINS];
00091     double time_min[MAT_DH_BINS];
00092     bool matvec_timing;
00093 
00094     /* used for MatVecs */
00095     int num_recv;
00096     int num_send;       /* used in destructor */
00097     MPI_Request *recv_req;
00098     MPI_Request *send_req;
00099     double *recvbuf, *sendbuf;
00100     int *sendind;
00101     int sendlen;
00102     int recvlen;
00103     bool matvecIsSetup;
00104     Numbering_dh numb;
00105     MPI_Status *status;
00106 
00107     bool debug;
00108   };
00109 
00110   extern void Mat_dhCreate (Mat_dh * mat);
00111   extern void Mat_dhDestroy (Mat_dh mat);
00112 
00113   extern void Mat_dhTranspose (Mat_dh matIN, Mat_dh * matOUT);
00114   extern void Mat_dhMakeStructurallySymmetric (Mat_dh A);
00115 
00116   /* adopted from ParaSails, by Edmond Chow */
00117   extern void Mat_dhMatVecSetup (Mat_dh mat);
00118   extern void Mat_dhMatVecSetdown (Mat_dh mat);
00119 
00120 /*========================================================================*/
00121 /* notes: if not compiled with OpenMP, Mat_dhMatVec() and Mat_dhMatVec_omp()
00122           perform identically; similarly for Mat_dhMatVec_uni()
00123           and Mat_dhMatVec_uni_omp()
00124 */
00125 
00126   extern void Mat_dhMatVec (Mat_dh mat, double *lhs, double *rhs);
00127   /* unthreaded MPI version */
00128 
00129   extern void Mat_dhMatVec_omp (Mat_dh mat, double *lhs, double *rhs);
00130   /* OpenMP/MPI version */
00131 
00132   extern void Mat_dhMatVec_uni (Mat_dh mat, double *lhs, double *rhs);
00133   /* unthreaded, single-task version */
00134 
00135   extern void Mat_dhMatVec_uni_omp (Mat_dh mat, double *lhs, double *rhs);
00136   /* OpenMP/single primary task version */
00137 
00138 
00139   extern int Mat_dhReadNz (Mat_dh mat);
00140 
00141   /* for next five, SubdomainGraph_dh() may be NULL; if not null,
00142      caller must ensure it has been properly initialized;
00143      if not null, matrix is permuted before printing.
00144 
00145      note: use "-matlab" when calling Mat_dhPrintTriples, to
00146      insert small value in place of 0.
00147 
00148      Mat_dhPrintCSR only implemented for single cpu, no reordering.
00149    */
00150   extern void Mat_dhPrintGraph (Mat_dh mat, SubdomainGraph_dh sg, FILE * fp);
00151   extern void Mat_dhPrintRows (Mat_dh mat, SubdomainGraph_dh sg, FILE * fp);
00152 
00153   extern void Mat_dhPrintCSR (Mat_dh mat, SubdomainGraph_dh sg,
00154                   char *filename);
00155   extern void Mat_dhPrintTriples (Mat_dh mat, SubdomainGraph_dh sg,
00156                   char *filename);
00157   extern void Mat_dhPrintBIN (Mat_dh mat, SubdomainGraph_dh sg,
00158                   char *filename);
00159 
00160   extern void Mat_dhReadCSR (Mat_dh * mat, char *filename);
00161   extern void Mat_dhReadTriples (Mat_dh * mat, int ignore, char *filename);
00162   extern void Mat_dhReadBIN (Mat_dh * mat, char *filename);
00163 
00164 
00165   extern void Mat_dhPermute (Mat_dh Ain, int *pIN, Mat_dh * Bout);
00166   /* for single cpu only! */
00167 
00168   extern void Mat_dhFixDiags (Mat_dh A);
00169   /* inserts diagonal if not explicitly present;
00170      sets diagonal value in row i to sum of absolute
00171      values of all elts in row i.
00172    */
00173 
00174   extern void Mat_dhPrintDiags (Mat_dh A, FILE * fp);
00175 
00176   extern void Mat_dhGetRow (Mat_dh B, int globalRow, int *len, int **ind,
00177                 double **val);
00178   extern void Mat_dhRestoreRow (Mat_dh B, int row, int *len, int **ind,
00179                 double **val);
00180 
00181   /* partition matrix into "k" blocks.  User must free storage. */
00182   extern void Mat_dhPartition (Mat_dh mat, int k, int **beg_rowOUT,
00183                    int **row_countOUT, int **n2oOUT,
00184                    int **o2nOUT);
00185 
00186 
00187 
00188 
00189   extern void Mat_dhZeroTiming (Mat_dh mat);
00190   extern void Mat_dhReduceTiming (Mat_dh mat);
00191 
00192 
00193   extern void Mat_dhRowPermute (Mat_dh);
00194 
00195   extern void dldperm (int job, int n, int nnz, int colptr[], int adjncy[],
00196                double nzval[], int *perm, double u[], double v[]);
00197 
00198 
00199 #ifdef __cplusplus
00200 }
00201 #endif
00202 #endif
 All Classes Files Functions Variables Enumerations Friends