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