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