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