xref: /petsc/src/ksp/pc/impls/tfs/tfs.h (revision 7cf18bfc0af3bd20f57ca1ab9dbfc3d774cdee5d)
1 
2 #if !defined(__TFS_H)
3 #define __TFS_H
4 
5 /**********************************const.h*************************************
6 
7 Author: Henry M. Tufo III
8 
9 e-mail: hmt@cs.brown.edu
10 
11 snail-mail:
12 Division of Applied Mathematics
13 Brown University
14 Providence, RI 02912
15 
16 Last Modification:
17 6.21.97
18 ***********************************const.h************************************/
19 
20 /**********************************const.h*************************************
21 File Description:
22 -----------------
23 
24 ***********************************const.h************************************/
25 #include <petscsys.h>
26 #include <petscblaslapack.h>
27 #if defined(PETSC_HAVE_STDLIB_H)
28 #include <stdlib.h>
29 #endif
30 
31 #define X          0
32 #define Y          1
33 #define Z          2
34 #define XY         3
35 #define XZ         4
36 #define YZ         5
37 
38 
39 #define THRESH          0.2
40 #define N_HALF          4096
41 #define PRIV_BUF_SZ     45
42 
43 /*4096 8192 32768 65536 1048576 */
44 #define MAX_MSG_BUF     32768
45 
46 #define FULL          2
47 #define PARTIAL       1
48 #define NONE          0
49 
50 #define BYTE		8
51 #define BIT_0		0x1
52 #define BIT_1		0x2
53 #define BIT_2		0x4
54 #define BIT_3		0x8
55 #define BIT_4		0x10
56 #define BIT_5		0x20
57 #define BIT_6		0x40
58 #define BIT_7		0x80
59 #define TOP_BIT         PETSC_MIN_INT
60 
61 #define C		0
62 
63 
64 #define MAX_VEC		1674
65 #define FORMAT		30
66 #define MAX_COL_LEN    	100
67 #define MAX_LINE	FORMAT*MAX_COL_LEN
68 #define   DELIM         " \n \t"
69 #define LINE		12
70 #define C_LINE		80
71 
72 #define   UT            5               /* dump upper 1/2 */
73 #define   LT            6               /* dump lower 1/2 */
74 #define   SYMM          8               /* we assume symm and dump upper 1/2 */
75 #define   NON_SYMM      9
76 
77 #define   ROW          10
78 #define   COL          11
79 
80 #define EPS   1.0e-14
81 #define EPS2  1.0e-07
82 
83 
84 #define MPI   1
85 #define NX    2
86 
87 #define LOG2(x)		(PetscScalar)log((double)x)/log(2)
88 #define SWAP(a,b)       temp=(a); (a)=(b); (b)=temp;
89 #define P_SWAP(a,b)     ptr=(a); (a)=(b); (b)=ptr;
90 
91 #define MAX_FABS(x,y)   (PetscAbsScalar(x)>PetscAbsScalar(y)) ? ((PetscScalar)x) : ((PetscScalar)y)
92 #define MIN_FABS(x,y)   (PetscAbsScalar(x)<PetscAbsScalar(y)) ? ((PetscScalar)x) : ((PetscScalar)y)
93 
94 /* specer's existence ... can be done w/MAX_ABS */
95 #define EXISTS(x,y)     ((x)==0.0) ? (y) : (x)
96 
97 #define MULT_NEG_ONE(a) (a) *= -1;
98 #define NEG(a)          (a) |= BIT_31;
99 #define POS(a)          (a) &= INT_MAX;
100 
101 
102 
103 
104 /**********************************types.h*************************************
105 
106 Author: Henry M. Tufo III
107 
108 e-mail: hmt@cs.brown.edu
109 
110 snail-mail:
111 Division of Applied Mathematics
112 Brown University
113 Providence, RI 02912
114 
115 Last Modification:
116 6.21.97
117 ***********************************types.h************************************/
118 
119 typedef PetscErrorCode (*vfp)(void*,void*,PetscInt,...);
120 typedef PetscErrorCode (*rbfp)(PetscScalar *, PetscScalar *, PetscInt len);
121 typedef PetscInt (*bfp)(void*, void *, PetscInt *len, MPI_Datatype *dt);
122 
123 /***********************************comm.h*************************************
124 
125 Author: Henry M. Tufo III
126 
127 e-mail: hmt@cs.brown.edu
128 
129 snail-mail:
130 Division of Applied Mathematics
131 Brown University
132 Providence, RI 02912
133 
134 Last Modification:
135 6.21.97
136 ***********************************comm.h*************************************/
137 extern PetscMPIInt my_id;
138 extern PetscMPIInt num_nodes;
139 extern PetscMPIInt floor_num_nodes;
140 extern PetscMPIInt i_log2_num_nodes;
141 
142 extern PetscErrorCode giop(PetscInt *vals, PetscInt *work, PetscInt n, PetscInt *oprs);
143 extern PetscErrorCode grop(PetscScalar *vals, PetscScalar *work, PetscInt n, PetscInt *oprs);
144 extern PetscErrorCode comm_init(void);
145 extern PetscErrorCode giop_hc(PetscInt *vals, PetscInt *work, PetscInt n, PetscInt *oprs, PetscInt dim);
146 extern PetscErrorCode grop_hc(PetscScalar *vals, PetscScalar *work, PetscInt n, PetscInt *oprs, PetscInt dim);
147 extern PetscErrorCode ssgl_radd(PetscScalar *vals, PetscScalar *work, PetscInt level, PetscInt *segs);
148 
149 #define MSGTAG0 101
150 #define MSGTAG1 1001
151 #define MSGTAG2 76207
152 #define MSGTAG3 100001
153 #define MSGTAG4 163841
154 #define MSGTAG5 249439
155 #define MSGTAG6 10000001
156 
157 #define NON_UNIFORM     0
158 #define GL_MAX          1
159 #define GL_MIN          2
160 #define GL_MULT         3
161 #define GL_ADD          4
162 #define GL_B_XOR        5
163 #define GL_B_OR         6
164 #define GL_B_AND        7
165 #define GL_L_XOR        8
166 #define GL_L_OR         9
167 #define GL_L_AND        10
168 #define GL_MAX_ABS      11
169 #define GL_MIN_ABS      12
170 #define GL_EXISTS       13
171 
172 extern PetscInt *ivec_copy(PetscInt *arg1, PetscInt *arg2, PetscInt n);
173 
174 extern PetscErrorCode ivec_zero(PetscInt *arg1, PetscInt n);
175 extern PetscErrorCode ivec_set(PetscInt *arg1, PetscInt arg2, PetscInt n);
176 
177 extern PetscInt ivec_lb(PetscInt *work, PetscInt n);
178 extern PetscInt ivec_ub(PetscInt *work, PetscInt n);
179 extern PetscInt ivec_sum(PetscInt *arg1, PetscInt n);
180 
181 extern vfp ivec_fct_addr(PetscInt type);
182 
183 extern PetscErrorCode ivec_non_uniform(PetscInt *arg1, PetscInt *arg2, PetscInt n, PetscInt *arg3);
184 extern PetscErrorCode ivec_max(PetscInt *arg1, PetscInt *arg2, PetscInt n);
185 extern PetscErrorCode ivec_min(PetscInt *arg1, PetscInt *arg2, PetscInt n);
186 extern PetscErrorCode ivec_mult(PetscInt *arg1, PetscInt *arg2, PetscInt n);
187 extern PetscErrorCode ivec_add(PetscInt *arg1, PetscInt *arg2, PetscInt n);
188 extern PetscErrorCode ivec_xor(PetscInt *arg1, PetscInt *arg2, PetscInt n);
189 extern PetscErrorCode ivec_or(PetscInt *arg1, PetscInt *arg2, PetscInt len);
190 extern PetscErrorCode ivec_and(PetscInt *arg1, PetscInt *arg2, PetscInt len);
191 extern PetscErrorCode ivec_lxor(PetscInt *arg1, PetscInt *arg2, PetscInt n);
192 extern PetscErrorCode ivec_lor(PetscInt *arg1, PetscInt *arg2, PetscInt len);
193 extern PetscErrorCode ivec_land(PetscInt *arg1, PetscInt *arg2, PetscInt len);
194 extern PetscErrorCode ivec_and3( PetscInt *arg1,  PetscInt *arg2,  PetscInt *arg3, PetscInt n);
195 
196 extern PetscErrorCode ivec_sort_companion(PetscInt *ar, PetscInt *ar2, PetscInt size);
197 extern PetscErrorCode ivec_sort(PetscInt *ar, PetscInt size);
198 extern PetscErrorCode SMI_sort(void *ar1, void *ar2, PetscInt size, PetscInt type);
199 extern PetscInt ivec_binary_search(PetscInt item, PetscInt *list, PetscInt n);
200 extern PetscInt ivec_linear_search(PetscInt item, PetscInt *list, PetscInt n);
201 
202 extern PetscErrorCode ivec_sort_companion_hack(PetscInt *ar, PetscInt **ar2, PetscInt size);
203 
204 #define SORT_INTEGER 1
205 #define SORT_INT_PTR 2
206 
207 extern PetscErrorCode rvec_zero(PetscScalar *arg1, PetscInt n);
208 extern PetscErrorCode rvec_one(PetscScalar *arg1, PetscInt n);
209 extern PetscErrorCode rvec_set(PetscScalar *arg1, PetscScalar arg2, PetscInt n);
210 extern PetscErrorCode rvec_copy(PetscScalar *arg1, PetscScalar *arg2, PetscInt n);
211 extern PetscErrorCode rvec_scale(PetscScalar *arg1, PetscScalar arg2, PetscInt n);
212 
213 extern vfp rvec_fct_addr(PetscInt type);
214 extern PetscErrorCode rvec_add(PetscScalar *arg1, PetscScalar *arg2, PetscInt n);
215 extern PetscErrorCode rvec_mult(PetscScalar *arg1, PetscScalar *arg2, PetscInt n);
216 extern PetscErrorCode rvec_max(PetscScalar *arg1, PetscScalar *arg2, PetscInt n);
217 extern PetscErrorCode rvec_max_abs(PetscScalar *arg1, PetscScalar *arg2, PetscInt n);
218 extern PetscErrorCode rvec_min(PetscScalar *arg1, PetscScalar *arg2, PetscInt n);
219 extern PetscErrorCode rvec_min_abs(PetscScalar *arg1, PetscScalar *arg2, PetscInt n);
220 extern PetscErrorCode vec_exists(PetscScalar *arg1, PetscScalar *arg2, PetscInt n);
221 
222 /***********************************gs.h***************************************
223 
224 Author: Henry M. Tufo III
225 
226 e-mail: hmt@cs.brown.edu
227 
228 snail-mail:
229 Division of Applied Mathematics
230 Brown University
231 Providence, RI 02912
232 
233 Last Modification:
234 6.21.97
235 ************************************gs.h**************************************/
236 
237 typedef struct gather_scatter_id *gs_ADT;
238 typedef PetscErrorCode (*Rbfp)(PetscScalar *, PetscScalar *, PetscInt len);
239 
240 extern gs_ADT gs_init(PetscInt *elms, PetscInt nel, PetscInt level);
241 extern PetscErrorCode   gs_gop_vec(gs_ADT gs_handle, PetscScalar *vals, const char *op, PetscInt step);
242 extern PetscErrorCode   gs_gop_binary(gs_ADT gs, PetscScalar *vals, Rbfp fct);
243 extern PetscErrorCode   gs_gop_hc(gs_ADT gs_handle, PetscScalar *vals, const char *op, PetscInt dim);
244 extern PetscErrorCode   gs_free(gs_ADT gs_handle);
245 extern PetscErrorCode   gs_init_msg_buf_sz(PetscInt buf_size);
246 extern PetscErrorCode   gs_init_vec_sz(PetscInt size);
247 
248 /*************************************xxt.h************************************
249 Module Name: xxt
250 Module Info: need xxt.{c,h} gs.{c,h} comm.{c,h} ivec.{c,h} error.{c,h}
251 
252 author:  Henry M. Tufo III
253 e-mail:  hmt@asci.uchicago.edu
254 contact:
255 +--------------------------------+--------------------------------+
256 |MCS Division - Building 221     |Department of Computer Science  |
257 |Argonne National Laboratory     |Ryerson 152                     |
258 |9700 S. Cass Avenue             |The University of Chicago       |
259 |Argonne, IL  60439              |Chicago, IL  60637              |
260 |(630) 252-5354/5986 ph/fx       |(773) 702-6019/8487 ph/fx       |
261 +--------------------------------+--------------------------------+
262 
263 Last Modification: 3.20.01
264 **************************************xxt.h***********************************/
265 
266 typedef struct xxt_CDT *xxt_ADT;
267 
268 
269 /*************************************xxt.h************************************
270 Function: XXT_new()
271 
272 Return: ADT ptr or NULL upon failure.
273 Description: This function allocates and returns an xxt handle
274 Usage: xxt_handle = xxt_new();
275 **************************************xxt.h***********************************/
276 extern xxt_ADT XXT_new(void);
277 
278 
279 /*************************************xxt.h************************************
280 Function: XXT_free()
281 
282 Input : pointer to ADT.
283 
284 Description: This function frees the storage associated with an xxt handle
285 Usage: XXT_free(xxt_handle);
286 **************************************xxt.h***********************************/
287 extern PetscInt XXT_free(xxt_ADT xxt_handle);
288 
289 
290 /*************************************xxt.h************************************
291 Function: XXT_factor
292 
293 Input : ADT ptr,  and pointer to object
294 Return: 0 on failure, 1 on success
295 Description: This function sets the xxt solver
296 
297 xxt assumptions: given n rows of global coarse matrix (E_loc) where
298    o global dofs N = sum_p(n), p=0,P-1
299    (i.e. row dist. with no dof replication)
300    (5.21.00 will handle dif replication case)
301    o m is the number of columns in E_loc (m>=n)
302    o local2global holds global number of column i (i=0,...,m-1)
303    o local2global holds global number of row    i (i=0,...,n-1)
304    o mylocmatvec performs E_loc . x_loc where x_loc is an vector of
305    length m in 1-1 correspondence with local2global
306    (note that gs package takes care of communication).
307    (note do not zero out upper m-n entries!)
308    o mylocmatvec(void *grid_data, double *in, double *out)
309 
310 ML beliefs/usage: move this to to ML_XXT_factor routine
311    o my_ml holds address of ML struct associated w/E_loc, grid_data, grid_tag
312    o grid_tag, grid_data, my_ml used in
313       ML_Set_CSolve(my_ml, grid_tag, grid_data, ML_Do_CoarseDirect);
314    o grid_data used in
315       A_matvec(grid_data,v,u);
316 
317 Usage:
318 **************************************xxt.h***********************************/
319 extern PetscInt XXT_factor(xxt_ADT xxt_handle,   /* prev. allocated xxt  handle */
320                       PetscInt *local2global,    /* global column mapping       */
321 		      PetscInt n,                /* local num rows              */
322 		      PetscInt m,                /* local num cols              */
323 		      void *mylocmatvec,    /* b_loc=A_local.x_loc         */
324 		      void *grid_data       /* grid data for matvec        */
325 		      );
326 
327 
328 /*************************************xxt.h************************************
329 Function: XXT_solve
330 
331 Input : ADT ptr, b (rhs)
332 Output: x (soln)
333 Return:
334 Description: This function performs x = E^-1.b
335 Usage:
336 XXT_solve(xxt_handle, double *x, double *b)
337 XXT_solve(xxt_handle, double *x, NULL)
338 assumes x has been initialized to be b
339 **************************************xxt.h***********************************/
340 extern PetscInt XXT_solve(xxt_ADT xxt_handle, PetscScalar *x, PetscScalar *b);
341 
342 /*************************************xxt.h************************************
343 Function: XXT_stats
344 
345 Input : handle
346 **************************************xxt.h***********************************/
347 extern PetscInt XXT_stats(xxt_ADT xxt_handle);
348 
349 
350 /*************************************xxt.h************************************
351 Function: XXT_sp_1()
352 
353 Input : pointer to ADT
354 Output:
355 Return:
356 Description: sets xxt parameter 1 in xxt_handle
357 Usage: implement later
358 
359 void XXT_sp_1(xxt_handle,parameter 1 value)
360 **************************************xxt.h***********************************/
361 
362 
363 /*************************************xyt.h************************************
364 Module Name: xyt
365 Module Info: need xyt.{c,h} gs.{c,h} comm.{c,h} ivec.{c,h} error.{c,h}
366 
367 author:  Henry M. Tufo III
368 e-mail:  hmt@asci.uchicago.edu
369 contact:
370 +--------------------------------+--------------------------------+
371 |MCS Division - Building 221     |Department of Computer Science  |
372 |Argonne National Laboratory     |Ryerson 152                     |
373 |9700 S. Cass Avenue             |The University of Chicago       |
374 |Argonne, IL  60439              |Chicago, IL  60637              |
375 |(630) 252-5354/5986 ph/fx       |(773) 702-6019/8487 ph/fx       |
376 +--------------------------------+--------------------------------+
377 
378 Last Modification: 3.20.01
379 **************************************xyt.h***********************************/
380 
381 typedef struct xyt_CDT *xyt_ADT;
382 
383 
384 /*************************************xyt.h************************************
385 Function: XYT_new()
386 
387 Return: ADT ptr or NULL upon failure.
388 Description: This function allocates and returns an xyt handle
389 Usage: xyt_handle = xyt_new();
390 **************************************xyt.h***********************************/
391 extern xyt_ADT XYT_new(void);
392 
393 
394 /*************************************xyt.h************************************
395 Function: XYT_free()
396 
397 Input : pointer to ADT.
398 Description: This function frees the storage associated with an xyt handle
399 Usage: XYT_free(xyt_handle);
400 **************************************xyt.h***********************************/
401 extern PetscInt XYT_free(xyt_ADT xyt_handle);
402 
403 
404 /*************************************xyt.h************************************
405 Function: XYT_factor
406 
407 Input : ADT ptr,  and pointer to object
408 Output:
409 Return: 0 on failure, 1 on success
410 Description: This function sets the xyt solver
411 
412 xyt assumptions: given n rows of global coarse matrix (E_loc) where
413    o global dofs N = sum_p(n), p=0,P-1
414    (i.e. row dist. with no dof replication)
415    (5.21.00 will handle dif replication case)
416    o m is the number of columns in E_loc (m>=n)
417    o local2global holds global number of column i (i=0,...,m-1)
418    o local2global holds global number of row    i (i=0,...,n-1)
419    o mylocmatvec performs E_loc . x_loc where x_loc is an vector of
420    length m in 1-1 correspondence with local2global
421    (note that gs package takes care of communication).
422    (note do not zero out upper m-n entries!)
423    o mylocmatvec(void *grid_data, double *in, double *out)
424 
425 ML beliefs/usage: move this to to ML_XYT_factor routine
426    o my_ml holds address of ML struct associated w/E_loc, grid_data, grid_tag
427    o grid_tag, grid_data, my_ml used in
428       ML_Set_CSolve(my_ml, grid_tag, grid_data, ML_Do_CoarseDirect);
429    o grid_data used in
430       A_matvec(grid_data,v,u);
431 
432 Usage:
433 **************************************xyt.h***********************************/
434 extern PetscInt XYT_factor(xyt_ADT xyt_handle,   /* prev. allocated xyt  handle */
435                       PetscInt *local2global,    /* global column mapping       */
436 		      PetscInt n,                /* local num rows              */
437 		      PetscInt m,                /* local num cols              */
438 		      void *mylocmatvec,    /* b_loc=A_local.x_loc         */
439 		      void *grid_data       /* grid data for matvec        */
440 		      );
441 
442 
443 /*************************************xyt.h************************************
444 Function: XYT_solve
445 
446 Input : ADT ptr, b (rhs)
447 Output: x (soln)
448 Return:
449 Description: This function performs x = E^-1.b
450 Usage: XYT_solve(xyt_handle, double *x, double *b)
451 **************************************xyt.h***********************************/
452 extern PetscInt XYT_solve(xyt_ADT xyt_handle, PetscScalar *x, PetscScalar *b);
453 
454 
455 /*************************************xyt.h************************************
456 Function: XYT_stats
457 
458 Input : handle
459 **************************************xyt.h***********************************/
460 extern PetscInt XYT_stats(xyt_ADT xyt_handle);
461 
462 
463 /********************************bit_mask.h************************************
464 
465 Author: Henry M. Tufo III
466 
467 e-mail: hmt@cs.brown.edu
468 
469 snail-mail:
470 Division of Applied Mathematics
471 Brown University
472 Providence, RI 02912
473 
474 Last Modification:
475 11.21.97
476 *********************************bit_mask.h***********************************/
477 extern PetscInt div_ceil(PetscInt numin, PetscInt denom);
478 extern PetscErrorCode set_bit_mask(PetscInt *bm, PetscInt len, PetscInt val);
479 extern PetscInt len_bit_mask(PetscInt num_items);
480 extern PetscInt ct_bits(char *ptr, PetscInt n);
481 extern PetscErrorCode bm_to_proc(char *ptr, PetscInt p_mask, PetscInt *msg_list);
482 extern PetscInt len_buf(PetscInt item_size, PetscInt num_items);
483 
484 #endif
485 
486