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