Ifpack Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Mat_dh.h
Go to the documentation of this file.
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 */
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];
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;
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);
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
int recvlen
Definition: Mat_dh.h:102
int * cval
Definition: Mat_dh.h:73
bool debug
Definition: Mat_dh.h:107
int len_private
Definition: Mat_dh.h:80
void Mat_dhReadBIN(Mat_dh *mat, char *filename)
Definition: Mat_dh.c:1397
void Mat_dhMatVecSetup(Mat_dh mat)
Definition: Mat_dh.c:249
int * diag
Definition: Mat_dh.h:75
void Mat_dhGetRow(Mat_dh B, int globalRow, int *len, int **ind, double **val)
Definition: Mat_dh.c:1596
void Mat_dhPermute(Mat_dh A, int *n2o, Mat_dh *Bout)
Definition: Mat_dh.c:807
void Mat_dhMatVec_uni(Mat_dh mat, double *x, double *b)
Definition: Mat_dh.c:686
void Mat_dhMatVec_uni_omp(Mat_dh mat, double *x, double *b)
Definition: Mat_dh.c:645
double * recvbuf
Definition: Mat_dh.h:99
void Mat_dhMatVec_omp(Mat_dh mat, double *x, double *b)
Definition: Mat_dh.c:564
void Mat_dhReadCSR(Mat_dh *mat, char *filename)
Definition: Mat_dh.c:1338
void Mat_dhPrintDiags(Mat_dh A, FILE *fp)
Definition: Mat_dh.c:1565
void Mat_dhReadTriples(Mat_dh *mat, int ignore, char *filename)
Definition: Mat_dh.c:1366
#define MAT_DH_BINS
Definition: Mat_dh.h:49
double * aval_private
Definition: Mat_dh.h:83
void Mat_dhFixDiags(Mat_dh A)
Definition: Mat_dh.c:1457
void Mat_dhPrintGraph(Mat_dh A, SubdomainGraph_dh sg, FILE *fp)
Definition: Mat_dh.c:868
int * len
Definition: Mat_dh.h:72
Numbering_dh numb
Definition: Mat_dh.h:104
int Mat_dhReadNz(Mat_dh mat)
Definition: Mat_dh.c:723
MPI_Request * send_req
Definition: Mat_dh.h:98
void Mat_dhPrintBIN(Mat_dh A, SubdomainGraph_dh sg, char *filename)
Definition: Mat_dh.c:1312
void Mat_dhRestoreRow(Mat_dh B, int row, int *len, int **ind, double **val)
Definition: Mat_dh.c:1616
void Mat_dhPrintCSR(Mat_dh A, SubdomainGraph_dh sg, char *filename)
Definition: Mat_dh.c:1276
void Mat_dhMatVec(Mat_dh mat, double *x, double *b)
Definition: Mat_dh.c:476
int * row_perm
Definition: Mat_dh.h:86
void Mat_dhRowPermute(Mat_dh mat)
Definition: Mat_dh.c:1623
int m
Definition: Mat_dh.h:64
double time_min[MAT_DH_BINS]
Definition: Mat_dh.h:91
void Mat_dhMatVecSetdown(Mat_dh mat)
Definition: Mat_dh.c:238
void Mat_dhCreate(Mat_dh *mat)
Definition: Mat_dh.c:73
int * rp
Definition: Mat_dh.h:71
double time[MAT_DH_BINS]
Definition: Mat_dh.h:89
void Mat_dhPrintTriples(Mat_dh A, SubdomainGraph_dh sg, char *filename)
Definition: Mat_dh.c:1071
int rowCheckedOut
Definition: Mat_dh.h:81
void dldperm(int job, int n, int nnz, int colptr[], int adjncy[], double nzval[], int *perm, double u[], double v[])
void Mat_dhReduceTiming(Mat_dh mat)
Definition: Mat_dh.c:791
int bs
Definition: Mat_dh.h:68
void Mat_dhPartition(Mat_dh mat, int blocks, int **beg_rowOUT, int **row_countOUT, int **n2oOUT, int **o2nOUT)
Definition: Mat_dh.c:1794
int num_send
Definition: Mat_dh.h:96
void Mat_dhTranspose(Mat_dh A, Mat_dh *Bout)
Definition: Mat_dh.c:1417
double time_max[MAT_DH_BINS]
Definition: Mat_dh.h:90
int num_recv
Definition: Mat_dh.h:95
void Mat_dhZeroTiming(Mat_dh mat)
Definition: Mat_dh.c:776
bool matvec_timing
Definition: Mat_dh.h:92
void Mat_dhPrintRows(Mat_dh A, SubdomainGraph_dh sg, FILE *fp)
Definition: Mat_dh.c:906
double * aval
Definition: Mat_dh.h:76
MPI_Request * recv_req
Definition: Mat_dh.h:97
int * cval_private
Definition: Mat_dh.h:82
int * sendind
Definition: Mat_dh.h:100
int sendlen
Definition: Mat_dh.h:101
void Mat_dhMakeStructurallySymmetric(Mat_dh A)
Definition: Mat_dh.c:1438
MPI_Status * status
Definition: Mat_dh.h:105
void Mat_dhDestroy(Mat_dh mat)
Definition: Mat_dh.c:131
int beg_row
Definition: Mat_dh.h:67
double * sendbuf
Definition: Mat_dh.h:99
int n
Definition: Mat_dh.h:64
bool owner
Definition: Mat_dh.h:77
int * fill
Definition: Mat_dh.h:74
bool matvecIsSetup
Definition: Mat_dh.h:103