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 typedef PetscErrorCode (*vfp)(void*,void*,PetscInt,...); 133 typedef PetscErrorCode (*rbfp)(PetscScalar *, PetscScalar *, PetscInt len); 134 typedef PetscInt (*bfp)(void*, void *, PetscInt *len, MPI_Datatype *dt); 135 136 /***********************************comm.h************************************* 137 138 Author: Henry M. Tufo III 139 140 e-mail: hmt@cs.brown.edu 141 142 snail-mail: 143 Division of Applied Mathematics 144 Brown University 145 Providence, RI 02912 146 147 Last Modification: 148 6.21.97 149 ***********************************comm.h*************************************/ 150 extern PetscMPIInt my_id; 151 extern PetscMPIInt num_nodes; 152 extern PetscMPIInt floor_num_nodes; 153 extern PetscMPIInt i_log2_num_nodes; 154 155 extern PetscErrorCode giop(PetscInt *vals, PetscInt *work, PetscInt n, PetscInt *oprs); 156 extern PetscErrorCode grop(PetscScalar *vals, PetscScalar *work, PetscInt n, PetscInt *oprs); 157 extern PetscErrorCode comm_init(void); 158 extern PetscErrorCode giop_hc(PetscInt *vals, PetscInt *work, PetscInt n, PetscInt *oprs, PetscInt dim); 159 extern PetscErrorCode grop_hc(PetscScalar *vals, PetscScalar *work, PetscInt n, PetscInt *oprs, PetscInt dim); 160 extern PetscErrorCode ssgl_radd(PetscScalar *vals, PetscScalar *work, PetscInt level, PetscInt *segs); 161 162 #define MSGTAG0 101 163 #define MSGTAG1 1001 164 #define MSGTAG2 76207 165 #define MSGTAG3 100001 166 #define MSGTAG4 163841 167 #define MSGTAG5 249439 168 #define MSGTAG6 10000001 169 170 #define NON_UNIFORM 0 171 #define GL_MAX 1 172 #define GL_MIN 2 173 #define GL_MULT 3 174 #define GL_ADD 4 175 #define GL_B_XOR 5 176 #define GL_B_OR 6 177 #define GL_B_AND 7 178 #define GL_L_XOR 8 179 #define GL_L_OR 9 180 #define GL_L_AND 10 181 #define GL_MAX_ABS 11 182 #define GL_MIN_ABS 12 183 #define GL_EXISTS 13 184 185 extern PetscInt *ivec_copy(PetscInt *arg1, PetscInt *arg2, PetscInt n); 186 187 extern PetscErrorCode ivec_zero(PetscInt *arg1, PetscInt n); 188 extern PetscErrorCode ivec_set(PetscInt *arg1, PetscInt arg2, PetscInt n); 189 190 extern PetscInt ivec_lb(PetscInt *work, PetscInt n); 191 extern PetscInt ivec_ub(PetscInt *work, PetscInt n); 192 extern PetscInt ivec_sum(PetscInt *arg1, PetscInt n); 193 194 extern vfp ivec_fct_addr(PetscInt type); 195 196 extern PetscErrorCode ivec_non_uniform(PetscInt *arg1, PetscInt *arg2, PetscInt n, PetscInt *arg3); 197 extern PetscErrorCode ivec_max(PetscInt *arg1, PetscInt *arg2, PetscInt n); 198 extern PetscErrorCode ivec_min(PetscInt *arg1, PetscInt *arg2, PetscInt n); 199 extern PetscErrorCode ivec_mult(PetscInt *arg1, PetscInt *arg2, PetscInt n); 200 extern PetscErrorCode ivec_add(PetscInt *arg1, PetscInt *arg2, PetscInt n); 201 extern PetscErrorCode ivec_xor(PetscInt *arg1, PetscInt *arg2, PetscInt n); 202 extern PetscErrorCode ivec_or(PetscInt *arg1, PetscInt *arg2, PetscInt len); 203 extern PetscErrorCode ivec_and(PetscInt *arg1, PetscInt *arg2, PetscInt len); 204 extern PetscErrorCode ivec_lxor(PetscInt *arg1, PetscInt *arg2, PetscInt n); 205 extern PetscErrorCode ivec_lor(PetscInt *arg1, PetscInt *arg2, PetscInt len); 206 extern PetscErrorCode ivec_land(PetscInt *arg1, PetscInt *arg2, PetscInt len); 207 extern PetscErrorCode ivec_and3( PetscInt *arg1, PetscInt *arg2, PetscInt *arg3, PetscInt n); 208 209 extern PetscErrorCode ivec_sort_companion(PetscInt *ar, PetscInt *ar2, PetscInt size); 210 extern PetscErrorCode ivec_sort(PetscInt *ar, PetscInt size); 211 extern PetscErrorCode SMI_sort(void *ar1, void *ar2, PetscInt size, PetscInt type); 212 extern PetscInt ivec_binary_search(PetscInt item, PetscInt *list, PetscInt n); 213 extern PetscInt ivec_linear_search(PetscInt item, PetscInt *list, PetscInt n); 214 215 extern PetscErrorCode ivec_sort_companion_hack(PetscInt *ar, PetscInt **ar2, PetscInt size); 216 217 #define SORT_INTEGER 1 218 #define SORT_INT_PTR 2 219 220 extern PetscErrorCode rvec_zero(PetscScalar *arg1, PetscInt n); 221 extern PetscErrorCode rvec_one(PetscScalar *arg1, PetscInt n); 222 extern PetscErrorCode rvec_set(PetscScalar *arg1, PetscScalar arg2, PetscInt n); 223 extern PetscErrorCode rvec_copy(PetscScalar *arg1, PetscScalar *arg2, PetscInt n); 224 extern PetscErrorCode rvec_scale(PetscScalar *arg1, PetscScalar arg2, PetscInt n); 225 226 extern vfp rvec_fct_addr(PetscInt type); 227 extern PetscErrorCode rvec_add(PetscScalar *arg1, PetscScalar *arg2, PetscInt n); 228 extern PetscErrorCode rvec_mult(PetscScalar *arg1, PetscScalar *arg2, PetscInt n); 229 extern PetscErrorCode rvec_max(PetscScalar *arg1, PetscScalar *arg2, PetscInt n); 230 extern PetscErrorCode rvec_max_abs(PetscScalar *arg1, PetscScalar *arg2, PetscInt n); 231 extern PetscErrorCode rvec_min(PetscScalar *arg1, PetscScalar *arg2, PetscInt n); 232 extern PetscErrorCode rvec_min_abs(PetscScalar *arg1, PetscScalar *arg2, PetscInt n); 233 extern PetscErrorCode vec_exists(PetscScalar *arg1, PetscScalar *arg2, PetscInt n); 234 235 /***********************************gs.h*************************************** 236 237 Author: Henry M. Tufo III 238 239 e-mail: hmt@cs.brown.edu 240 241 snail-mail: 242 Division of Applied Mathematics 243 Brown University 244 Providence, RI 02912 245 246 Last Modification: 247 6.21.97 248 ************************************gs.h**************************************/ 249 250 typedef struct gather_scatter_id *gs_ADT; 251 typedef PetscErrorCode (*Rbfp)(PetscScalar *, PetscScalar *, PetscInt len); 252 253 extern gs_ADT gs_init(PetscInt *elms, PetscInt nel, PetscInt level); 254 extern PetscErrorCode gs_gop_vec(gs_ADT gs_handle, PetscScalar *vals, const char *op, PetscInt step); 255 extern PetscErrorCode gs_gop_binary(gs_ADT gs, PetscScalar *vals, Rbfp fct); 256 extern PetscErrorCode gs_gop_hc(gs_ADT gs_handle, PetscScalar *vals, const char *op, PetscInt dim); 257 extern PetscErrorCode gs_free(gs_ADT gs_handle); 258 extern PetscErrorCode gs_init_msg_buf_sz(PetscInt buf_size); 259 extern PetscErrorCode gs_init_vec_sz(PetscInt size); 260 261 /*************************************xxt.h************************************ 262 Module Name: xxt 263 Module Info: need xxt.{c,h} gs.{c,h} comm.{c,h} ivec.{c,h} error.{c,h} 264 265 author: Henry M. Tufo III 266 e-mail: hmt@asci.uchicago.edu 267 contact: 268 +--------------------------------+--------------------------------+ 269 |MCS Division - Building 221 |Department of Computer Science | 270 |Argonne National Laboratory |Ryerson 152 | 271 |9700 S. Cass Avenue |The University of Chicago | 272 |Argonne, IL 60439 |Chicago, IL 60637 | 273 |(630) 252-5354/5986 ph/fx |(773) 702-6019/8487 ph/fx | 274 +--------------------------------+--------------------------------+ 275 276 Last Modification: 3.20.01 277 **************************************xxt.h***********************************/ 278 279 typedef struct xxt_CDT *xxt_ADT; 280 281 282 /*************************************xxt.h************************************ 283 Function: XXT_new() 284 285 Return: ADT ptr or NULL upon failure. 286 Description: This function allocates and returns an xxt handle 287 Usage: xxt_handle = xxt_new(); 288 **************************************xxt.h***********************************/ 289 extern xxt_ADT XXT_new(void); 290 291 292 /*************************************xxt.h************************************ 293 Function: XXT_free() 294 295 Input : pointer to ADT. 296 297 Description: This function frees the storage associated with an xxt handle 298 Usage: XXT_free(xxt_handle); 299 **************************************xxt.h***********************************/ 300 EXTERN PetscInt XXT_free(xxt_ADT xxt_handle); 301 302 303 /*************************************xxt.h************************************ 304 Function: XXT_factor 305 306 Input : ADT ptr, and pointer to object 307 Return: 0 on failure, 1 on success 308 Description: This function sets the xxt solver 309 310 xxt assumptions: given n rows of global coarse matrix (E_loc) where 311 o global dofs N = sum_p(n), p=0,P-1 312 (i.e. row dist. with no dof replication) 313 (5.21.00 will handle dif replication case) 314 o m is the number of columns in E_loc (m>=n) 315 o local2global holds global number of column i (i=0,...,m-1) 316 o local2global holds global number of row i (i=0,...,n-1) 317 o mylocmatvec performs E_loc . x_loc where x_loc is an vector of 318 length m in 1-1 correspondence with local2global 319 (note that gs package takes care of communication). 320 (note do not zero out upper m-n entries!) 321 o mylocmatvec(void *grid_data, double *in, double *out) 322 323 ML beliefs/usage: move this to to ML_XXT_factor routine 324 o my_ml holds address of ML struct associated w/E_loc, grid_data, grid_tag 325 o grid_tag, grid_data, my_ml used in 326 ML_Set_CSolve(my_ml, grid_tag, grid_data, ML_Do_CoarseDirect); 327 o grid_data used in 328 A_matvec(grid_data,v,u); 329 330 Usage: 331 **************************************xxt.h***********************************/ 332 extern PetscInt XXT_factor(xxt_ADT xxt_handle, /* prev. allocated xxt handle */ 333 PetscInt *local2global, /* global column mapping */ 334 PetscInt n, /* local num rows */ 335 PetscInt m, /* local num cols */ 336 void *mylocmatvec, /* b_loc=A_local.x_loc */ 337 void *grid_data /* grid data for matvec */ 338 ); 339 340 341 /*************************************xxt.h************************************ 342 Function: XXT_solve 343 344 Input : ADT ptr, b (rhs) 345 Output: x (soln) 346 Return: 347 Description: This function performs x = E^-1.b 348 Usage: 349 XXT_solve(xxt_handle, double *x, double *b) 350 XXT_solve(xxt_handle, double *x, NULL) 351 assumes x has been initialized to be b 352 **************************************xxt.h***********************************/ 353 extern PetscInt XXT_solve(xxt_ADT xxt_handle, double *x, double *b); 354 355 /*************************************xxt.h************************************ 356 Function: XXT_stats 357 358 Input : handle 359 **************************************xxt.h***********************************/ 360 extern PetscInt XXT_stats(xxt_ADT xxt_handle); 361 362 363 /*************************************xxt.h************************************ 364 Function: XXT_sp_1() 365 366 Input : pointer to ADT 367 Output: 368 Return: 369 Description: sets xxt parameter 1 in xxt_handle 370 Usage: implement later 371 372 void XXT_sp_1(xxt_handle,parameter 1 value) 373 **************************************xxt.h***********************************/ 374 375 376 /*************************************xyt.h************************************ 377 Module Name: xyt 378 Module Info: need xyt.{c,h} gs.{c,h} comm.{c,h} ivec.{c,h} error.{c,h} 379 380 author: Henry M. Tufo III 381 e-mail: hmt@asci.uchicago.edu 382 contact: 383 +--------------------------------+--------------------------------+ 384 |MCS Division - Building 221 |Department of Computer Science | 385 |Argonne National Laboratory |Ryerson 152 | 386 |9700 S. Cass Avenue |The University of Chicago | 387 |Argonne, IL 60439 |Chicago, IL 60637 | 388 |(630) 252-5354/5986 ph/fx |(773) 702-6019/8487 ph/fx | 389 +--------------------------------+--------------------------------+ 390 391 Last Modification: 3.20.01 392 **************************************xyt.h***********************************/ 393 394 typedef struct xyt_CDT *xyt_ADT; 395 396 397 /*************************************xyt.h************************************ 398 Function: XYT_new() 399 400 Return: ADT ptr or NULL upon failure. 401 Description: This function allocates and returns an xyt handle 402 Usage: xyt_handle = xyt_new(); 403 **************************************xyt.h***********************************/ 404 extern xyt_ADT XYT_new(void); 405 406 407 /*************************************xyt.h************************************ 408 Function: XYT_free() 409 410 Input : pointer to ADT. 411 Description: This function frees the storage associated with an xyt handle 412 Usage: XYT_free(xyt_handle); 413 **************************************xyt.h***********************************/ 414 EXTERN PetscInt XYT_free(xyt_ADT xyt_handle); 415 416 417 /*************************************xyt.h************************************ 418 Function: XYT_factor 419 420 Input : ADT ptr, and pointer to object 421 Output: 422 Return: 0 on failure, 1 on success 423 Description: This function sets the xyt solver 424 425 xyt assumptions: given n rows of global coarse matrix (E_loc) where 426 o global dofs N = sum_p(n), p=0,P-1 427 (i.e. row dist. with no dof replication) 428 (5.21.00 will handle dif replication case) 429 o m is the number of columns in E_loc (m>=n) 430 o local2global holds global number of column i (i=0,...,m-1) 431 o local2global holds global number of row i (i=0,...,n-1) 432 o mylocmatvec performs E_loc . x_loc where x_loc is an vector of 433 length m in 1-1 correspondence with local2global 434 (note that gs package takes care of communication). 435 (note do not zero out upper m-n entries!) 436 o mylocmatvec(void *grid_data, double *in, double *out) 437 438 ML beliefs/usage: move this to to ML_XYT_factor routine 439 o my_ml holds address of ML struct associated w/E_loc, grid_data, grid_tag 440 o grid_tag, grid_data, my_ml used in 441 ML_Set_CSolve(my_ml, grid_tag, grid_data, ML_Do_CoarseDirect); 442 o grid_data used in 443 A_matvec(grid_data,v,u); 444 445 Usage: 446 **************************************xyt.h***********************************/ 447 extern PetscInt XYT_factor(xyt_ADT xyt_handle, /* prev. allocated xyt handle */ 448 PetscInt *local2global, /* global column mapping */ 449 PetscInt n, /* local num rows */ 450 PetscInt m, /* local num cols */ 451 void *mylocmatvec, /* b_loc=A_local.x_loc */ 452 void *grid_data /* grid data for matvec */ 453 ); 454 455 456 /*************************************xyt.h************************************ 457 Function: XYT_solve 458 459 Input : ADT ptr, b (rhs) 460 Output: x (soln) 461 Return: 462 Description: This function performs x = E^-1.b 463 Usage: XYT_solve(xyt_handle, double *x, double *b) 464 **************************************xyt.h***********************************/ 465 extern PetscInt XYT_solve(xyt_ADT xyt_handle, double *x, double *b); 466 467 468 /*************************************xyt.h************************************ 469 Function: XYT_stats 470 471 Input : handle 472 **************************************xyt.h***********************************/ 473 extern PetscInt XYT_stats(xyt_ADT xyt_handle); 474 475 476 /********************************bit_mask.h************************************ 477 478 Author: Henry M. Tufo III 479 480 e-mail: hmt@cs.brown.edu 481 482 snail-mail: 483 Division of Applied Mathematics 484 Brown University 485 Providence, RI 02912 486 487 Last Modification: 488 11.21.97 489 *********************************bit_mask.h***********************************/ 490 extern PetscInt div_ceil(PetscInt numin, PetscInt denom); 491 extern PetscErrorCode set_bit_mask(PetscInt *bm, PetscInt len, PetscInt val); 492 extern PetscInt len_bit_mask(PetscInt num_items); 493 extern PetscInt ct_bits(char *ptr, PetscInt n); 494 extern PetscErrorCode bm_to_proc(char *ptr, PetscInt p_mask, PetscInt *msg_list); 495 extern PetscInt len_buf(PetscInt item_size, PetscInt num_items); 496 497 #endif 498 499