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 PCTFS_my_id; 138 extern PetscMPIInt PCTFS_num_nodes; 139 extern PetscMPIInt PCTFS_floor_num_nodes; 140 extern PetscMPIInt PCTFS_i_log2_num_nodes; 141 142 extern PetscErrorCode PCTFS_giop(PetscInt *vals, PetscInt *work, PetscInt n, PetscInt *oprs); 143 extern PetscErrorCode PCTFS_grop(PetscScalar *vals, PetscScalar *work, PetscInt n, PetscInt *oprs); 144 extern PetscErrorCode PCTFS_comm_init(void); 145 extern PetscErrorCode PCTFS_giop_hc(PetscInt *vals, PetscInt *work, PetscInt n, PetscInt *oprs, PetscInt dim); 146 extern PetscErrorCode PCTFS_grop_hc(PetscScalar *vals, PetscScalar *work, PetscInt n, PetscInt *oprs, PetscInt dim); 147 extern PetscErrorCode PCTFS_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 *PCTFS_ivec_copy(PetscInt *arg1, PetscInt *arg2, PetscInt n); 173 174 extern PetscErrorCode PCTFS_ivec_zero(PetscInt *arg1, PetscInt n); 175 extern PetscErrorCode PCTFS_ivec_set(PetscInt *arg1, PetscInt arg2, PetscInt n); 176 177 extern PetscInt PCTFS_ivec_lb(PetscInt *work, PetscInt n); 178 extern PetscInt PCTFS_ivec_ub(PetscInt *work, PetscInt n); 179 extern PetscInt PCTFS_ivec_sum(PetscInt *arg1, PetscInt n); 180 181 extern vfp PCTFS_ivec_fct_addr(PetscInt type); 182 183 extern PetscErrorCode PCTFS_ivec_non_uniform(PetscInt *arg1, PetscInt *arg2, PetscInt n, PetscInt *arg3); 184 extern PetscErrorCode PCTFS_ivec_max(PetscInt *arg1, PetscInt *arg2, PetscInt n); 185 extern PetscErrorCode PCTFS_ivec_min(PetscInt *arg1, PetscInt *arg2, PetscInt n); 186 extern PetscErrorCode PCTFS_ivec_mult(PetscInt *arg1, PetscInt *arg2, PetscInt n); 187 extern PetscErrorCode PCTFS_ivec_add(PetscInt *arg1, PetscInt *arg2, PetscInt n); 188 extern PetscErrorCode PCTFS_ivec_xor(PetscInt *arg1, PetscInt *arg2, PetscInt n); 189 extern PetscErrorCode PCTFS_ivec_or(PetscInt *arg1, PetscInt *arg2, PetscInt len); 190 extern PetscErrorCode PCTFS_ivec_and(PetscInt *arg1, PetscInt *arg2, PetscInt len); 191 extern PetscErrorCode PCTFS_ivec_lxor(PetscInt *arg1, PetscInt *arg2, PetscInt n); 192 extern PetscErrorCode PCTFS_ivec_lor(PetscInt *arg1, PetscInt *arg2, PetscInt len); 193 extern PetscErrorCode PCTFS_ivec_land(PetscInt *arg1, PetscInt *arg2, PetscInt len); 194 extern PetscErrorCode PCTFS_ivec_and3(PetscInt *arg1, PetscInt *arg2, PetscInt *arg3, PetscInt n); 195 196 extern PetscErrorCode PCTFS_ivec_sort_companion(PetscInt *ar, PetscInt *ar2, PetscInt size); 197 extern PetscErrorCode PCTFS_ivec_sort(PetscInt *ar, PetscInt size); 198 extern PetscErrorCode PCTFS_SMI_sort(void *ar1, void *ar2, PetscInt size, PetscInt type); 199 extern PetscInt PCTFS_ivec_binary_search(PetscInt item, PetscInt *list, PetscInt n); 200 extern PetscInt PCTFS_ivec_linear_search(PetscInt item, PetscInt *list, PetscInt n); 201 202 extern PetscErrorCode PCTFS_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 PCTFS_rvec_zero(PetscScalar *arg1, PetscInt n); 208 extern PetscErrorCode PCTFS_rvec_one(PetscScalar *arg1, PetscInt n); 209 extern PetscErrorCode PCTFS_rvec_set(PetscScalar *arg1, PetscScalar arg2, PetscInt n); 210 extern PetscErrorCode PCTFS_rvec_copy(PetscScalar *arg1, PetscScalar *arg2, PetscInt n); 211 extern PetscErrorCode PCTFS_rvec_scale(PetscScalar *arg1, PetscScalar arg2, PetscInt n); 212 213 extern vfp PCTFS_rvec_fct_addr(PetscInt type); 214 extern PetscErrorCode PCTFS_rvec_add(PetscScalar *arg1, PetscScalar *arg2, PetscInt n); 215 extern PetscErrorCode PCTFS_rvec_mult(PetscScalar *arg1, PetscScalar *arg2, PetscInt n); 216 extern PetscErrorCode PCTFS_rvec_max(PetscScalar *arg1, PetscScalar *arg2, PetscInt n); 217 extern PetscErrorCode PCTFS_rvec_max_abs(PetscScalar *arg1, PetscScalar *arg2, PetscInt n); 218 extern PetscErrorCode PCTFS_rvec_min(PetscScalar *arg1, PetscScalar *arg2, PetscInt n); 219 extern PetscErrorCode PCTFS_rvec_min_abs(PetscScalar *arg1, PetscScalar *arg2, PetscInt n); 220 extern PetscErrorCode PCTFS_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 *PCTFS_gs_ADT; 238 /*typedef PetscErrorCode (*Rbfp)(PetscScalar *, PetscScalar *, PetscInt len);*/ 239 240 extern PCTFS_gs_ADT PCTFS_gs_init(PetscInt *elms, PetscInt nel, PetscInt level); 241 extern PetscErrorCode PCTFS_gs_gop_vec(PCTFS_gs_ADT PCTFS_gs_handle, PetscScalar *vals, const char *op, PetscInt step); 242 /*extern PetscErrorCode PCTFS_gs_gop_binary(PCTFS_gs_ADT gs, PetscScalar *vals, Rbfp fct);*/ 243 extern PetscErrorCode PCTFS_gs_gop_hc(PCTFS_gs_ADT PCTFS_gs_handle, PetscScalar *vals, const char *op, PetscInt dim); 244 extern PetscErrorCode PCTFS_gs_free(PCTFS_gs_ADT PCTFS_gs_handle); 245 extern PetscErrorCode PCTFS_gs_init_msg_buf_sz(PetscInt buf_size); 246 extern PetscErrorCode PCTFS_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 PetscErrorCode (*matvec)(void*,PetscScalar*,PetscScalar*), /* b_loc=A_local.x_loc */ 324 void *grid_data); /* grid data for matvec */ 325 326 327 /*************************************xxt.h************************************ 328 Function: XXT_solve 329 330 Input : ADT ptr, b (rhs) 331 Output: x (soln) 332 Return: 333 Description: This function performs x = E^-1.b 334 Usage: 335 XXT_solve(xxt_handle, double *x, double *b) 336 XXT_solve(xxt_handle, double *x, NULL) 337 assumes x has been initialized to be b 338 **************************************xxt.h***********************************/ 339 extern PetscInt XXT_solve(xxt_ADT xxt_handle, PetscScalar *x, PetscScalar *b); 340 341 /*************************************xxt.h************************************ 342 Function: XXT_stats 343 344 Input : handle 345 **************************************xxt.h***********************************/ 346 extern PetscInt XXT_stats(xxt_ADT xxt_handle); 347 348 349 /*************************************xxt.h************************************ 350 Function: XXT_sp_1() 351 352 Input : pointer to ADT 353 Output: 354 Return: 355 Description: sets xxt parameter 1 in xxt_handle 356 Usage: implement later 357 358 void XXT_sp_1(xxt_handle,parameter 1 value) 359 **************************************xxt.h***********************************/ 360 361 362 /*************************************xyt.h************************************ 363 Module Name: xyt 364 Module Info: need xyt.{c,h} gs.{c,h} comm.{c,h} ivec.{c,h} error.{c,h} 365 366 author: Henry M. Tufo III 367 e-mail: hmt@asci.uchicago.edu 368 contact: 369 +--------------------------------+--------------------------------+ 370 |MCS Division - Building 221 |Department of Computer Science | 371 |Argonne National Laboratory |Ryerson 152 | 372 |9700 S. Cass Avenue |The University of Chicago | 373 |Argonne, IL 60439 |Chicago, IL 60637 | 374 |(630) 252-5354/5986 ph/fx |(773) 702-6019/8487 ph/fx | 375 +--------------------------------+--------------------------------+ 376 377 Last Modification: 3.20.01 378 **************************************xyt.h***********************************/ 379 380 typedef struct xyt_CDT *xyt_ADT; 381 382 383 /*************************************xyt.h************************************ 384 Function: XYT_new() 385 386 Return: ADT ptr or NULL upon failure. 387 Description: This function allocates and returns an xyt handle 388 Usage: xyt_handle = xyt_new(); 389 **************************************xyt.h***********************************/ 390 extern xyt_ADT XYT_new(void); 391 392 393 /*************************************xyt.h************************************ 394 Function: XYT_free() 395 396 Input : pointer to ADT. 397 Description: This function frees the storage associated with an xyt handle 398 Usage: XYT_free(xyt_handle); 399 **************************************xyt.h***********************************/ 400 extern PetscInt XYT_free(xyt_ADT xyt_handle); 401 402 403 /*************************************xyt.h************************************ 404 Function: XYT_factor 405 406 Input : ADT ptr, and pointer to object 407 Output: 408 Return: 0 on failure, 1 on success 409 Description: This function sets the xyt solver 410 411 xyt assumptions: given n rows of global coarse matrix (E_loc) where 412 o global dofs N = sum_p(n), p=0,P-1 413 (i.e. row dist. with no dof replication) 414 (5.21.00 will handle dif replication case) 415 o m is the number of columns in E_loc (m>=n) 416 o local2global holds global number of column i (i=0,...,m-1) 417 o local2global holds global number of row i (i=0,...,n-1) 418 o mylocmatvec performs E_loc . x_loc where x_loc is an vector of 419 length m in 1-1 correspondence with local2global 420 (note that gs package takes care of communication). 421 (note do not zero out upper m-n entries!) 422 o mylocmatvec(void *grid_data, double *in, double *out) 423 424 ML beliefs/usage: move this to to ML_XYT_factor routine 425 o my_ml holds address of ML struct associated w/E_loc, grid_data, grid_tag 426 o grid_tag, grid_data, my_ml used in 427 ML_Set_CSolve(my_ml, grid_tag, grid_data, ML_Do_CoarseDirect); 428 o grid_data used in 429 A_matvec(grid_data,v,u); 430 431 Usage: 432 **************************************xyt.h***********************************/ 433 extern PetscInt XYT_factor(xyt_ADT xyt_handle, /* prev. allocated xyt handle */ 434 PetscInt *local2global, /* global column mapping */ 435 PetscInt n, /* local num rows */ 436 PetscInt m, /* local num cols */ 437 PetscErrorCode (*matvec)(void*,PetscScalar*,PetscScalar*), /* b_loc=A_local.x_loc */ 438 void *grid_data); /* grid data for matvec */ 439 440 441 /*************************************xyt.h************************************ 442 Function: XYT_solve 443 444 Input : ADT ptr, b (rhs) 445 Output: x (soln) 446 Return: 447 Description: This function performs x = E^-1.b 448 Usage: XYT_solve(xyt_handle, double *x, double *b) 449 **************************************xyt.h***********************************/ 450 extern PetscInt XYT_solve(xyt_ADT xyt_handle, PetscScalar *x, PetscScalar *b); 451 452 453 /*************************************xyt.h************************************ 454 Function: XYT_stats 455 456 Input : handle 457 **************************************xyt.h***********************************/ 458 extern PetscInt XYT_stats(xyt_ADT xyt_handle); 459 460 461 /********************************bit_mask.h************************************ 462 463 Author: Henry M. Tufo III 464 465 e-mail: hmt@cs.brown.edu 466 467 snail-mail: 468 Division of Applied Mathematics 469 Brown University 470 Providence, RI 02912 471 472 Last Modification: 473 11.21.97 474 *********************************bit_mask.h***********************************/ 475 extern PetscInt PCTFS_div_ceil(PetscInt numin, PetscInt denom); 476 extern PetscErrorCode PCTFS_set_bit_mask(PetscInt *bm, PetscInt len, PetscInt val); 477 extern PetscInt PCTFS_len_bit_mask(PetscInt num_items); 478 extern PetscInt PCTFS_ct_bits(char *ptr, PetscInt n); 479 extern PetscErrorCode PCTFS_bm_to_proc(char *ptr, PetscInt p_mask, PetscInt *msg_list); 480 extern PetscInt PCTFS_len_buf(PetscInt item_size, PetscInt num_items); 481 482 #endif 483 484