IFPACK  Development
 All Classes Namespaces Files Functions Variables Enumerations Friends Pages
Mat_dh.h
1 /*@HEADER
2 // ***********************************************************************
3 //
4 // Ifpack: Object-Oriented Algebraic Preconditioner Package
5 // Copyright (2002) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 //@HEADER
41 */
42 
43 #ifndef MAT_DH_DH
44 #define MAT_DH_DH
45 
46 #include "euclid_common.h"
47 
48  /* this stuff for experimental internal timing */
49 #define MAT_DH_BINS 10
50 #define MATVEC_TIME 0 /* time to actually perform matvec */
51 #define MATVEC_MPI_TIME 1 /* time for comms + vector copying needed */
52 #define MATVEC_MPI_TIME2 5 /* time for comms, + vector copying needed */
53 #define MATVEC_TOTAL_TIME 2 /* MATVEC_TIME+MATVEC_MPI_TIME */
54 #define MATVEC_RATIO 3 /* computation/communication ratio */
55 #define MATVEC_WORDS 4 /* total words sent to other procs. */
56 
57 #ifdef __cplusplus
58 extern "C"
59 {
60 #endif
61 
62  struct _mat_dh
63  {
64  int m, n; /* dimensions of local rectangular submatrix;
65  * the global matrix is n by n.
66  */
67  int beg_row; /* global number of 1st locally owned row */
68  int bs; /* block size */
69 
70  /* sparse row-oriented storage for locally owned submatrix */
71  int *rp;
72  int *len; /* length of each row; only used for MPI triangular solves */
73  int *cval;
74  int *fill;
75  int *diag;
76  double *aval;
77  bool owner; /* for MPI triangular solves */
78 
79  /* working space for getRow */
80  int len_private;
81  int rowCheckedOut;
82  int *cval_private;
83  double *aval_private;
84 
85  /* row permutations to increase positive definiteness */
86  int *row_perm;
87 
88  /* for timing matvecs in experimental studies */
89  double time[MAT_DH_BINS];
90  double time_max[MAT_DH_BINS];
91  double time_min[MAT_DH_BINS];
92  bool matvec_timing;
93 
94  /* used for MatVecs */
95  int num_recv;
96  int num_send; /* used in destructor */
97  MPI_Request *recv_req;
98  MPI_Request *send_req;
99  double *recvbuf, *sendbuf;
100  int *sendind;
101  int sendlen;
102  int recvlen;
103  bool matvecIsSetup;
104  Numbering_dh numb;
105  MPI_Status *status;
106 
107  bool debug;
108  };
109 
110  extern void Mat_dhCreate (Mat_dh * mat);
111  extern void Mat_dhDestroy (Mat_dh mat);
112 
113  extern void Mat_dhTranspose (Mat_dh matIN, Mat_dh * matOUT);
114  extern void Mat_dhMakeStructurallySymmetric (Mat_dh A);
115 
116  /* adopted from ParaSails, by Edmond Chow */
117  extern void Mat_dhMatVecSetup (Mat_dh mat);
118  extern void Mat_dhMatVecSetdown (Mat_dh mat);
119 
120 /*========================================================================*/
121 /* notes: if not compiled with OpenMP, Mat_dhMatVec() and Mat_dhMatVec_omp()
122  perform identically; similarly for Mat_dhMatVec_uni()
123  and Mat_dhMatVec_uni_omp()
124 */
125 
126  extern void Mat_dhMatVec (Mat_dh mat, double *lhs, double *rhs);
127  /* unthreaded MPI version */
128 
129  extern void Mat_dhMatVec_omp (Mat_dh mat, double *lhs, double *rhs);
130  /* OpenMP/MPI version */
131 
132  extern void Mat_dhMatVec_uni (Mat_dh mat, double *lhs, double *rhs);
133  /* unthreaded, single-task version */
134 
135  extern void Mat_dhMatVec_uni_omp (Mat_dh mat, double *lhs, double *rhs);
136  /* OpenMP/single primary task version */
137 
138 
139  extern int Mat_dhReadNz (Mat_dh mat);
140 
141  /* for next five, SubdomainGraph_dh() may be NULL; if not null,
142  caller must ensure it has been properly initialized;
143  if not null, matrix is permuted before printing.
144 
145  note: use "-matlab" when calling Mat_dhPrintTriples, to
146  insert small value in place of 0.
147 
148  Mat_dhPrintCSR only implemented for single cpu, no reordering.
149  */
150  extern void Mat_dhPrintGraph (Mat_dh mat, SubdomainGraph_dh sg, FILE * fp);
151  extern void Mat_dhPrintRows (Mat_dh mat, SubdomainGraph_dh sg, FILE * fp);
152 
153  extern void Mat_dhPrintCSR (Mat_dh mat, SubdomainGraph_dh sg,
154  char *filename);
155  extern void Mat_dhPrintTriples (Mat_dh mat, SubdomainGraph_dh sg,
156  char *filename);
157  extern void Mat_dhPrintBIN (Mat_dh mat, SubdomainGraph_dh sg,
158  char *filename);
159 
160  extern void Mat_dhReadCSR (Mat_dh * mat, char *filename);
161  extern void Mat_dhReadTriples (Mat_dh * mat, int ignore, char *filename);
162  extern void Mat_dhReadBIN (Mat_dh * mat, char *filename);
163 
164 
165  extern void Mat_dhPermute (Mat_dh Ain, int *pIN, Mat_dh * Bout);
166  /* for single cpu only! */
167 
168  extern void Mat_dhFixDiags (Mat_dh A);
169  /* inserts diagonal if not explicitly present;
170  sets diagonal value in row i to sum of absolute
171  values of all elts in row i.
172  */
173 
174  extern void Mat_dhPrintDiags (Mat_dh A, FILE * fp);
175 
176  extern void Mat_dhGetRow (Mat_dh B, int globalRow, int *len, int **ind,
177  double **val);
178  extern void Mat_dhRestoreRow (Mat_dh B, int row, int *len, int **ind,
179  double **val);
180 
181  /* partition matrix into "k" blocks. User must free storage. */
182  extern void Mat_dhPartition (Mat_dh mat, int k, int **beg_rowOUT,
183  int **row_countOUT, int **n2oOUT,
184  int **o2nOUT);
185 
186 
187 
188 
189  extern void Mat_dhZeroTiming (Mat_dh mat);
190  extern void Mat_dhReduceTiming (Mat_dh mat);
191 
192 
193  extern void Mat_dhRowPermute (Mat_dh);
194 
195  extern void dldperm (int job, int n, int nnz, int colptr[], int adjncy[],
196  double nzval[], int *perm, double u[], double v[]);
197 
198 
199 #ifdef __cplusplus
200 }
201 #endif
202 #endif
Definition: Mat_dh.h:62