Actual source code: tfs.h
1: #pragma once
2: #if defined(__GNUC__) || defined(__clang__)
3: #pragma GCC diagnostic ignored "-Wconversion"
4: #endif
6: /*
8: Author: Henry M. Tufo III
10: e-mail: hmt@cs.brown.edu
12: snail-mail:
13: Division of Applied Mathematics
14: Brown University
15: Providence, RI 02912
17: Last Modification:
18: 6.21.97
20: File Description:
21: */
22: #include <petscsys.h>
23: #include <petscblaslapack.h>
25: #define X 0
26: #define Y 1
27: #define Z 2
28: #define XY 3
29: #define XZ 4
30: #define YZ 5
32: #define THRESH 0.2
33: #define N_HALF 4096
34: #define PRIV_BUF_SZ 45
36: /*4096 8192 32768 65536 1048576 */
37: #define MAX_MSG_BUF 32768
39: #define FULL 2
40: #define PARTIAL 1
41: #define NONE 0
43: #define BYTE 8
44: #define BIT_0 0x1
45: #define BIT_1 0x2
46: #define BIT_2 0x4
47: #define BIT_3 0x8
48: #define BIT_4 0x10
49: #define BIT_5 0x20
50: #define BIT_6 0x40
51: #define BIT_7 0x80
52: #define TOP_BIT PETSC_INT_MIN
54: #define C 0
56: #define MAX_VEC 1674
57: #define FORMAT 30
58: #define MAX_COL_LEN 100
59: #define MAX_LINE FORMAT *MAX_COL_LEN
60: #define DELIM " \n \t"
61: #define LINE 12
62: #define C_LINE 80
64: #define UT 5 /* dump upper 1/2 */
65: #define LT 6 /* dump lower 1/2 */
66: #define SYMM 8 /* we assume symm and dump upper 1/2 */
67: #define NON_SYMM 9
69: #define ROW 10
70: #define COL 11
72: #define EPS 1.0e-14
73: #define EPS2 1.0e-07
75: #define MPI 1
76: #define NX 2
78: #define SWAP(a, b) \
79: do { \
80: temp = (a); \
81: (a) = (b); \
82: (b) = temp; \
83: } while (0)
84: #define P_SWAP(a, b) \
85: do { \
86: ptr = (a); \
87: (a) = (b); \
88: (b) = ptr; \
89: } while (0)
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)
94: /* specer's existence ... can be done w/MAX_ABS */
95: #define EXISTS(x, y) ((x) == 0.0) ? (y) : (x)
97: #define MULT_NEG_ONE(a) (a) *= -1;
98: #define NEG(a) (a) |= BIT_31;
99: #define POS(a) (a) &= INT_MAX;
101: /*
102: Author: Henry M. Tufo III
104: e-mail: hmt@cs.brown.edu
106: snail-mail:
107: Division of Applied Mathematics
108: Brown University
109: Providence, RI 02912
111: Last Modification:
112: 6.21.97
113: */
115: typedef PetscErrorCode (*vfp)(void *, void *, PetscInt, ...);
116: typedef PetscErrorCode (*rbfp)(PetscScalar *, PetscScalar *, PetscInt);
117: typedef PetscInt (*bfp)(void *, void *, PetscInt *, MPI_Datatype *);
119: /*
121: Author: Henry M. Tufo III
123: e-mail: hmt@cs.brown.edu
125: snail-mail:
126: Division of Applied Mathematics
127: Brown University
128: Providence, RI 02912
130: Last Modification:
131: 6.21.97
132: */
133: PETSC_INTERN PetscMPIInt PCTFS_my_id;
134: PETSC_INTERN PetscMPIInt PCTFS_num_nodes;
135: PETSC_INTERN PetscMPIInt PCTFS_floor_num_nodes;
136: PETSC_INTERN PetscMPIInt PCTFS_i_log2_num_nodes;
138: PETSC_INTERN PetscErrorCode PCTFS_giop(PetscInt *, PetscInt *, PetscInt, PetscInt *);
139: PETSC_INTERN PetscErrorCode PCTFS_grop(PetscScalar *, PetscScalar *, PetscInt, PetscInt *);
140: PETSC_INTERN PetscErrorCode PCTFS_comm_init(void);
141: PETSC_INTERN PetscErrorCode PCTFS_giop_hc(PetscInt *, PetscInt *, PetscInt, PetscInt *, PetscInt);
142: PETSC_INTERN PetscErrorCode PCTFS_grop_hc(PetscScalar *, PetscScalar *, PetscInt, PetscInt *, PetscInt);
143: PETSC_INTERN PetscErrorCode PCTFS_ssgl_radd(PetscScalar *, PetscScalar *, PetscInt, PetscInt *);
145: #define MSGTAG0 101
146: #define MSGTAG1 1001
147: #define MSGTAG2 76207
148: #define MSGTAG3 100001
149: #define MSGTAG4 163841
150: #define MSGTAG5 249439
151: #define MSGTAG6 10000001
153: #define NON_UNIFORM 0
154: #define GL_MAX 1
155: #define GL_MIN 2
156: #define GL_MULT 3
157: #define GL_ADD 4
158: #define GL_B_XOR 5
159: #define GL_B_OR 6
160: #define GL_B_AND 7
161: #define GL_L_XOR 8
162: #define GL_L_OR 9
163: #define GL_L_AND 10
164: #define GL_MAX_ABS 11
165: #define GL_MIN_ABS 12
166: #define GL_EXISTS 13
168: PETSC_INTERN PetscInt *PCTFS_ivec_copy(PetscInt *, PetscInt *, PetscInt);
169: PETSC_INTERN PetscErrorCode PCTFS_ivec_zero(PetscInt *, PetscInt);
170: PETSC_INTERN PetscErrorCode PCTFS_ivec_set(PetscInt *, PetscInt, PetscInt);
172: PETSC_INTERN PetscInt PCTFS_ivec_sum(PetscInt *, PetscInt);
173: PETSC_INTERN vfp PCTFS_ivec_fct_addr(PetscInt);
175: PETSC_INTERN PetscErrorCode PCTFS_ivec_non_uniform(PetscInt *, PetscInt *, PetscInt, ...);
176: PETSC_INTERN PetscErrorCode PCTFS_ivec_max(PetscInt *, PetscInt *, PetscInt);
177: PETSC_INTERN PetscErrorCode PCTFS_ivec_min(PetscInt *, PetscInt *, PetscInt);
178: PETSC_INTERN PetscErrorCode PCTFS_ivec_mult(PetscInt *, PetscInt *, PetscInt);
179: PETSC_INTERN PetscErrorCode PCTFS_ivec_add(PetscInt *, PetscInt *, PetscInt);
180: PETSC_INTERN PetscErrorCode PCTFS_ivec_xor(PetscInt *, PetscInt *, PetscInt);
181: PETSC_INTERN PetscErrorCode PCTFS_ivec_or(PetscInt *, PetscInt *, PetscInt);
182: PETSC_INTERN PetscErrorCode PCTFS_ivec_and(PetscInt *, PetscInt *, PetscInt);
183: PETSC_INTERN PetscErrorCode PCTFS_ivec_lxor(PetscInt *, PetscInt *, PetscInt);
184: PETSC_INTERN PetscErrorCode PCTFS_ivec_lor(PetscInt *, PetscInt *, PetscInt);
185: PETSC_INTERN PetscErrorCode PCTFS_ivec_land(PetscInt *, PetscInt *, PetscInt);
186: PETSC_INTERN PetscErrorCode PCTFS_ivec_and3(PetscInt *, PetscInt *, PetscInt *, PetscInt);
188: PETSC_INTERN PetscErrorCode PCTFS_ivec_sort_companion(PetscInt *, PetscInt *, PetscInt);
189: PETSC_INTERN PetscErrorCode PCTFS_ivec_sort(PetscInt *, PetscInt);
190: PETSC_INTERN PetscErrorCode PCTFS_SMI_sort(void *, void *, PetscInt, PetscInt);
191: PETSC_INTERN PetscInt PCTFS_ivec_binary_search(PetscInt, PetscInt *, PetscInt);
192: PETSC_INTERN PetscInt PCTFS_ivec_linear_search(PetscInt, PetscInt *, PetscInt);
194: PETSC_INTERN PetscErrorCode PCTFS_ivec_sort_companion_hack(PetscInt *, PetscInt **, PetscInt);
196: #define SORT_INTEGER 1
197: #define SORT_INT_PTR 2
199: PETSC_INTERN PetscErrorCode PCTFS_rvec_zero(PetscScalar *, PetscInt);
200: PETSC_INTERN PetscErrorCode PCTFS_rvec_one(PetscScalar *, PetscInt);
201: PETSC_INTERN PetscErrorCode PCTFS_rvec_set(PetscScalar *, PetscScalar, PetscInt);
202: PETSC_INTERN PetscErrorCode PCTFS_rvec_copy(PetscScalar *, PetscScalar *, PetscInt);
203: PETSC_INTERN PetscErrorCode PCTFS_rvec_scale(PetscScalar *, PetscScalar, PetscInt);
205: PETSC_INTERN vfp PCTFS_rvec_fct_addr(PetscInt);
206: PETSC_INTERN PetscErrorCode PCTFS_rvec_add(PetscScalar *, PetscScalar *, PetscInt);
207: PETSC_INTERN PetscErrorCode PCTFS_rvec_mult(PetscScalar *, PetscScalar *, PetscInt);
208: PETSC_INTERN PetscErrorCode PCTFS_rvec_max(PetscScalar *, PetscScalar *, PetscInt);
209: PETSC_INTERN PetscErrorCode PCTFS_rvec_max_abs(PetscScalar *, PetscScalar *, PetscInt);
210: PETSC_INTERN PetscErrorCode PCTFS_rvec_min(PetscScalar *, PetscScalar *, PetscInt);
211: PETSC_INTERN PetscErrorCode PCTFS_rvec_min_abs(PetscScalar *, PetscScalar *, PetscInt);
213: /*
214: Author: Henry M. Tufo III
216: e-mail: hmt@cs.brown.edu
218: snail-mail:
219: Division of Applied Mathematics
220: Brown University
221: Providence, RI 02912
223: Last Modification:
224: 6.21.97
225: */
227: typedef struct gather_scatter_id *PCTFS_gs_ADT;
229: PETSC_INTERN PCTFS_gs_ADT PCTFS_gs_init(PetscInt *, PetscInt, PetscInt);
230: PETSC_INTERN PetscErrorCode PCTFS_gs_gop_vec(PCTFS_gs_ADT, PetscScalar *, const char *, PetscInt);
231: PETSC_INTERN PetscErrorCode PCTFS_gs_gop_hc(PCTFS_gs_ADT, PetscScalar *, const char *, PetscInt);
232: PETSC_INTERN PetscErrorCode PCTFS_gs_free(PCTFS_gs_ADT);
233: PETSC_INTERN PetscErrorCode PCTFS_gs_init_msg_buf_sz(PetscInt);
234: PETSC_INTERN PetscErrorCode PCTFS_gs_init_vec_sz(PetscInt);
236: /*
237: Module Name: xxt
238: Module Info: need xxt.{c,h} gs.{c,h} comm.{c,h} ivec.{c,h} error.{c,h}
240: author: Henry M. Tufo III
241: e-mail: hmt@asci.uchicago.edu
242: contact:
243: +--------------------------------+--------------------------------+
244: |MCS Division - Building 221 |Department of Computer Science |
245: |Argonne National Laboratory |Ryerson 152 |
246: |9700 S. Cass Avenue |The University of Chicago |
247: |Argonne, IL 60439 |Chicago, IL 60637 |
248: |(630) 252-5354/5986 ph/fx |(773) 702-6019/8487 ph/fx |
249: +--------------------------------+--------------------------------+
251: Last Modification: 3.20.01
252: */
254: typedef struct xxt_CDT *xxt_ADT;
256: /*
257: Function: XXT_new()
259: Return: ADT ptr or NULL upon failure.
260: Description: This function allocates and returns an xxt handle
261: Usage: xxt_handle = xxt_new();
262: */
263: PETSC_INTERN xxt_ADT XXT_new(void);
265: /*
266: Function: XXT_free()
268: Input : pointer to ADT.
270: Description: This function frees the storage associated with an xxt handle
271: Usage: XXT_free(xxt_handle);
272: */
273: PETSC_INTERN PetscErrorCode XXT_free(xxt_ADT);
275: /*
276: Function: XXT_factor
278: Input : ADT ptr, and pointer to object
279: Return: 0 on failure, 1 on success
280: Description: This function sets the xxt solver
282: xxt assumptions: given n rows of global coarse matrix (E_loc) where
283: o global dofs N = sum_p(n), p=0,P-1
284: (i.e. row dist. with no dof replication)
285: (5.21.00 will handle dif replication case)
286: o m is the number of columns in E_loc (m>=n)
287: o local2global holds global number of column i (i=0,...,m-1)
288: o local2global holds global number of row i (i=0,...,n-1)
289: o mylocmatvec performs E_loc . x_loc where x_loc is an vector of
290: length m in 1-1 correspondence with local2global
291: (note that gs package takes care of communication).
292: (note do not zero out upper m-n entries!)
293: o mylocmatvec(void *grid_data, double *in, double *out)
295: ML beliefs/usage: move this to ML_XXT_factor routine
296: o my_ml holds address of ML struct associated w/E_loc, grid_data, grid_tag
297: o grid_tag, grid_data, my_ml used in
298: ML_Set_CSolve(my_ml, grid_tag, grid_data, ML_Do_CoarseDirect);
299: o grid_data used in
300: A_matvec(grid_data,v,u);
302: Usage:
303: */
304: PETSC_INTERN PetscErrorCode XXT_factor(xxt_ADT, /* prev. allocated xxt handle */
305: PetscInt *, /* global column mapping */
306: PetscInt, /* local num rows */
307: PetscInt, /* local num cols */
308: PetscErrorCode (*)(void *, PetscScalar *, PetscScalar *), /* b_loc=A_local.x_loc */
309: void *); /* grid data for matvec */
311: /*
312: Function: XXT_solve
314: Input : ADT ptr, b (rhs)
315: Output: x (soln)
316: Return:
317: Description: This function performs x = E^-1.b
318: Usage:
319: XXT_solve(xxt_handle, double *x, double *b)
320: XXT_solve(xxt_handle, double *x, NULL)
321: assumes x has been initialized to be b
322: */
323: PETSC_INTERN PetscErrorCode XXT_solve(xxt_ADT, PetscScalar *, PetscScalar *);
325: /*
326: Function: XXT_sp_1()
328: Input : pointer to ADT
329: Output:
330: Return:
331: Description: sets xxt parameter 1 in xxt_handle
332: Usage: implement later
334: void XXT_sp_1(xxt_handle,parameter 1 value)
335: */
337: /*
338: Module Name: xyt
339: Module Info: need xyt.{c,h} gs.{c,h} comm.{c,h} ivec.{c,h} error.{c,h}
341: author: Henry M. Tufo III
342: e-mail: hmt@asci.uchicago.edu
343: contact:
344: +--------------------------------+--------------------------------+
345: |MCS Division - Building 221 |Department of Computer Science |
346: |Argonne National Laboratory |Ryerson 152 |
347: |9700 S. Cass Avenue |The University of Chicago |
348: |Argonne, IL 60439 |Chicago, IL 60637 |
349: |(630) 252-5354/5986 ph/fx |(773) 702-6019/8487 ph/fx |
350: +--------------------------------+--------------------------------+
352: Last Modification: 3.20.01
353: */
355: typedef struct xyt_CDT *xyt_ADT;
357: /*
358: Function: XYT_new()
360: Return: ADT ptr or NULL upon failure.
361: Description: This function allocates and returns an xyt handle
362: Usage: xyt_handle = xyt_new();
363: */
364: PETSC_INTERN xyt_ADT XYT_new(void);
366: /*
367: Function: XYT_free()
369: Input : pointer to ADT.
370: Description: This function frees the storage associated with an xyt handle
371: Usage: XYT_free(xyt_handle);
372: */
373: PETSC_INTERN PetscErrorCode XYT_free(xyt_ADT);
375: /*
376: Function: XYT_factor
378: Input : ADT ptr, and pointer to object
379: Output:
380: Return: 0 on failure, 1 on success
381: Description: This function sets the xyt solver
383: xyt assumptions: given n rows of global coarse matrix (E_loc) where
384: o global dofs N = sum_p(n), p=0,P-1
385: (i.e. row dist. with no dof replication)
386: (5.21.00 will handle dif replication case)
387: o m is the number of columns in E_loc (m>=n)
388: o local2global holds global number of column i (i=0,...,m-1)
389: o local2global holds global number of row i (i=0,...,n-1)
390: o mylocmatvec performs E_loc . x_loc where x_loc is an vector of
391: length m in 1-1 correspondence with local2global
392: (note that gs package takes care of communication).
393: (note do not zero out upper m-n entries!)
394: o mylocmatvec(void *grid_data, double *in, double *out)
396: ML beliefs/usage: move this to ML_XYT_factor routine
397: o my_ml holds address of ML struct associated w/E_loc, grid_data, grid_tag
398: o grid_tag, grid_data, my_ml used in
399: ML_Set_CSolve(my_ml, grid_tag, grid_data, ML_Do_CoarseDirect);
400: o grid_data used in
401: A_matvec(grid_data,v,u);
403: Usage:
404: */
405: PETSC_INTERN PetscErrorCode XYT_factor(xyt_ADT, /* prev. allocated xyt handle */
406: PetscInt *, /* global column mapping */
407: PetscInt, /* local num rows */
408: PetscInt, /* local num cols */
409: PetscErrorCode (*)(void *, PetscScalar *, PetscScalar *), /* b_loc=A_local.x_loc */
410: void *); /* grid data for matvec */
412: /*
413: Function: XYT_solve
415: Input : ADT ptr, b (rhs)
416: Output: x (soln)
417: Return:
418: Description: This function performs x = E^-1.b
419: Usage: XYT_solve(xyt_handle, double *x, double *b)
420: */
421: PETSC_INTERN PetscErrorCode XYT_solve(xyt_ADT, PetscScalar *, PetscScalar *);
423: /*
424: Function: XYT_stats
426: Input : handle
427: */
428: PETSC_INTERN PetscErrorCode XYT_stats(xyt_ADT);
430: /*
432: Author: Henry M. Tufo III
434: e-mail: hmt@cs.brown.edu
436: snail-mail:
437: Division of Applied Mathematics
438: Brown University
439: Providence, RI 02912
441: Last Modification:
442: 11.21.97
443: */
444: PETSC_INTERN PetscInt PCTFS_div_ceil(PetscInt, PetscInt);
445: PETSC_INTERN PetscErrorCode PCTFS_set_bit_mask(PetscInt *, PetscInt, PetscInt);
446: PETSC_INTERN PetscInt PCTFS_len_bit_mask(PetscInt);
447: PETSC_INTERN PetscInt PCTFS_ct_bits(char *, PetscInt);
448: PETSC_INTERN PetscErrorCode PCTFS_bm_to_proc(char *, PetscInt, PetscInt *);
449: PETSC_INTERN PetscInt PCTFS_len_buf(PetscInt, PetscInt);