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