IFPACK  Development
 All Classes Namespaces Files Functions Variables Enumerations Friends Pages
SubdomainGraph_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 SUBDOMAIN_GRAPH_DH
44 #define SUBDOMAIN_GRAPH_DH
45 
46 #if defined(Ifpack_SHOW_DEPRECATED_WARNINGS)
47 #ifdef __GNUC__
48 #warning "The Ifpack package is deprecated"
49 #endif
50 #endif
51 
52 #include "euclid_common.h"
53 
54 #ifdef __cplusplus
55 extern "C"
56 {
57 #endif
58 
59 #define MAX_SUBDOMAIN_COLOR 100
60  /* could be done better: if we can't color the subdomain graph
61  with this many colors, an error is thrown in SubdomainGraph_dhColor().
62  */
63 
64 /* for internal timing */
65 #define TIMING_BINS_SG 10
66  enum
67  { TOTAL_SGT, /* total Init (setup) time */
68  FIND_NABORS_SGT,
69  ORDER_BDRY_SGT,
70  FORM_GRAPH_SGT,
71  EXCHANGE_PERMS_SGT
72  };
73 
75  {
76  int blocks; /* number of subdomains */
77  int *ptrs, *adj; /* csr structure for representing subdomain graph */
78  int *o2n_sub; /* subdomain graph permutation; */
79  int *n2o_sub; /* inverse permutation; */
80  int colors; /* number of colors used for coloring the subdomain graph */
81  bool doNotColor; /* if true, subdomain graph is not colored and reordered */
82  int *colorVec; /* if colorVec[i] = x, then subdomain i was colored "x".
83  this array is probably only useful for debugging.
84  */
85 
86  int *beg_row; /* global ordering of first local row owned by P_i */
87  int *beg_rowP; /* global ordering of first local row owned by P_i after
88  subdomain reordering
89  */
90  int *row_count; /* P_i owns row_count[i] local rows */
91  int *bdry_count; /* bdry_count[i] of P_i's rows are boundary rows */
92 
93  /* Nearest neighbors in subdomain graph, before reordering;
94  "self" is not included. Not used for sequential case.
95  */
96  int *loNabors, loCount;
97  int *hiNabors, hiCount;
98  int *allNabors, allCount;
99 
100 
101  /* permutation information for global unknowns (matrix rows) */
102  int m; /* length of n2o_row and o2n_col */
103  int *n2o_row; /* permutation for locally owned matrix rows */
104  int *o2n_col; /* permutation for locally owned matrix columns */
105 
106  Hash_i_dh o2n_ext; /* permutation for external columns */
107  Hash_i_dh n2o_ext; /* inverse permutation for external columns */
108 
109  double timing[TIMING_BINS_SG];
110  bool debug;
111  };
112 
113  extern void SubdomainGraph_dhCreate (SubdomainGraph_dh * s);
114  extern void SubdomainGraph_dhDestroy (SubdomainGraph_dh s);
115 
116  extern void SubdomainGraph_dhInit (SubdomainGraph_dh s, int blocks, bool bj,
117  void *A);
118  /* Partitions matrix A into the specified number of blocks,
119  if there is a single MPI task; for mpi use, "blocks" must be the same
120  as the number of mpi tasks; for sequential, it may vary.
121  On completion, the subdomain graph will be fully formed,
122  (all fields valid); o2n_row[] and n2o_col[] will be permutations
123  for the locally owned portion of A such that A's interior nodes are
124  ordered first.
125  This function may call a partitioner, such as METIS (currently, only for sequential).
126  On completion, "o2n" contains a natural ordering, beg_row is identical to
127  beg_rowP, and_rowP is identical to end_rowP.
128 
129  if "bj" is true, the following setup steps are NOT performed:
130  form subdomain graph; find neighbors; order boundary nodes
131  */
132 
133  extern void SubdomainGraph_dhColor (SubdomainGraph_dh s);
134  /*
135  Colors and orders subdomain graph; on completion, o2n[], beg_rowP[], and
136  end_rowP[] may be altered.
137  */
138 
139  extern int SubdomainGraph_dhFindOwner (SubdomainGraph_dh s, int idx,
140  bool permuted);
141  /* Returns the subdomain block to which row idx belongs, or throws an error.
142  If "permuted" is true, it's assumed the graph has been permuted (i.e.,
143  'globally reordering phase' in PILU algorithm).
144  */
145 
146  extern void SubdomainGraph_dhExchangePerms (SubdomainGraph_dh s);
147  /*
148  exchange permutation information for external columns with nearest neighbors;
149  caller must ensure SubdomainGraph_dhInit() has completed before calling.
150  */
151 
152  extern void SubdomainGraph_dhPrintSubdomainGraph (SubdomainGraph_dh s,
153  FILE * fp);
154 
155  extern void SubdomainGraph_dhPrintStatsLong (SubdomainGraph_dh s,
156  FILE * fp);
157  /* similar to Short, but prints complete list of interior/bdry node ratios;
158  also prints subdomain permutation
159  */
160 
161  extern void SubdomainGraph_dhDump (SubdomainGraph_dh s, char *filename);
162  /* for testing */
163 
164  extern void SubdomainGraph_dhPrintRatios (SubdomainGraph_dh s, FILE * fp);
165  /* prints ratios of interior/boundary node for all subdomains */
166 
167 
168  extern void SubdomainGraph_dhPrintStats (SubdomainGraph_dh sg, FILE * fp);
169 
170 #ifdef __cplusplus
171 }
172 #endif
173 #endif