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(gs_ADT gs_handle, PetscScalar *vals, const char *op); 257 extern PetscErrorCode gs_gop_vec(gs_ADT gs_handle, PetscScalar *vals, const char *op, PetscInt step); 258 extern PetscErrorCode gs_gop_binary(gs_ADT gs, PetscScalar *vals, Rbfp fct); 259 extern PetscErrorCode gs_gop_hc(gs_ADT gs_handle, PetscScalar *vals, const char *op, PetscInt dim); 260 extern PetscErrorCode gs_free(gs_ADT gs_handle); 261 extern PetscErrorCode gs_init_msg_buf_sz(PetscInt buf_size); 262 extern PetscErrorCode gs_init_vec_sz(PetscInt size); 263 264 /*************************************xxt.h************************************ 265 Module Name: xxt 266 Module Info: need xxt.{c,h} gs.{c,h} comm.{c,h} ivec.{c,h} error.{c,h} 267 268 author: Henry M. Tufo III 269 e-mail: hmt@asci.uchicago.edu 270 contact: 271 +--------------------------------+--------------------------------+ 272 |MCS Division - Building 221 |Department of Computer Science | 273 |Argonne National Laboratory |Ryerson 152 | 274 |9700 S. Cass Avenue |The University of Chicago | 275 |Argonne, IL 60439 |Chicago, IL 60637 | 276 |(630) 252-5354/5986 ph/fx |(773) 702-6019/8487 ph/fx | 277 +--------------------------------+--------------------------------+ 278 279 Last Modification: 3.20.01 280 **************************************xxt.h***********************************/ 281 282 typedef struct xxt_CDT *xxt_ADT; 283 284 285 /*************************************xxt.h************************************ 286 Function: XXT_new() 287 288 Return: ADT ptr or NULL upon failure. 289 Description: This function allocates and returns an xxt handle 290 Usage: xxt_handle = xxt_new(); 291 **************************************xxt.h***********************************/ 292 extern xxt_ADT XXT_new(void); 293 294 295 /*************************************xxt.h************************************ 296 Function: XXT_free() 297 298 Input : pointer to ADT. 299 300 Description: This function frees the storage associated with an xxt handle 301 Usage: XXT_free(xxt_handle); 302 **************************************xxt.h***********************************/ 303 EXTERN PetscInt XXT_free(xxt_ADT xxt_handle); 304 305 306 /*************************************xxt.h************************************ 307 Function: XXT_factor 308 309 Input : ADT ptr, and pointer to object 310 Return: 0 on failure, 1 on success 311 Description: This function sets the xxt solver 312 313 xxt assumptions: given n rows of global coarse matrix (E_loc) where 314 o global dofs N = sum_p(n), p=0,P-1 315 (i.e. row dist. with no dof replication) 316 (5.21.00 will handle dif replication case) 317 o m is the number of columns in E_loc (m>=n) 318 o local2global holds global number of column i (i=0,...,m-1) 319 o local2global holds global number of row i (i=0,...,n-1) 320 o mylocmatvec performs E_loc . x_loc where x_loc is an vector of 321 length m in 1-1 correspondence with local2global 322 (note that gs package takes care of communication). 323 (note do not zero out upper m-n entries!) 324 o mylocmatvec(void *grid_data, double *in, double *out) 325 326 ML beliefs/usage: move this to to ML_XXT_factor routine 327 o my_ml holds address of ML struct associated w/E_loc, grid_data, grid_tag 328 o grid_tag, grid_data, my_ml used in 329 ML_Set_CSolve(my_ml, grid_tag, grid_data, ML_Do_CoarseDirect); 330 o grid_data used in 331 A_matvec(grid_data,v,u); 332 333 Usage: 334 **************************************xxt.h***********************************/ 335 extern PetscInt XXT_factor(xxt_ADT xxt_handle, /* prev. allocated xxt handle */ 336 PetscInt *local2global, /* global column mapping */ 337 PetscInt n, /* local num rows */ 338 PetscInt m, /* local num cols */ 339 void *mylocmatvec, /* b_loc=A_local.x_loc */ 340 void *grid_data /* grid data for matvec */ 341 ); 342 343 344 /*************************************xxt.h************************************ 345 Function: XXT_solve 346 347 Input : ADT ptr, b (rhs) 348 Output: x (soln) 349 Return: 350 Description: This function performs x = E^-1.b 351 Usage: 352 XXT_solve(xxt_handle, double *x, double *b) 353 XXT_solve(xxt_handle, double *x, NULL) 354 assumes x has been initialized to be b 355 **************************************xxt.h***********************************/ 356 extern PetscInt XXT_solve(xxt_ADT xxt_handle, double *x, double *b); 357 358 /*************************************xxt.h************************************ 359 Function: XXT_stats 360 361 Input : handle 362 **************************************xxt.h***********************************/ 363 extern PetscInt XXT_stats(xxt_ADT xxt_handle); 364 365 366 /*************************************xxt.h************************************ 367 Function: XXT_sp_1() 368 369 Input : pointer to ADT 370 Output: 371 Return: 372 Description: sets xxt parameter 1 in xxt_handle 373 Usage: implement later 374 375 void XXT_sp_1(xxt_handle,parameter 1 value) 376 **************************************xxt.h***********************************/ 377 378 379 /*************************************xyt.h************************************ 380 Module Name: xyt 381 Module Info: need xyt.{c,h} gs.{c,h} comm.{c,h} ivec.{c,h} error.{c,h} 382 383 author: Henry M. Tufo III 384 e-mail: hmt@asci.uchicago.edu 385 contact: 386 +--------------------------------+--------------------------------+ 387 |MCS Division - Building 221 |Department of Computer Science | 388 |Argonne National Laboratory |Ryerson 152 | 389 |9700 S. Cass Avenue |The University of Chicago | 390 |Argonne, IL 60439 |Chicago, IL 60637 | 391 |(630) 252-5354/5986 ph/fx |(773) 702-6019/8487 ph/fx | 392 +--------------------------------+--------------------------------+ 393 394 Last Modification: 3.20.01 395 **************************************xyt.h***********************************/ 396 397 typedef struct xyt_CDT *xyt_ADT; 398 399 400 /*************************************xyt.h************************************ 401 Function: XYT_new() 402 403 Return: ADT ptr or NULL upon failure. 404 Description: This function allocates and returns an xyt handle 405 Usage: xyt_handle = xyt_new(); 406 **************************************xyt.h***********************************/ 407 extern xyt_ADT XYT_new(void); 408 409 410 /*************************************xyt.h************************************ 411 Function: XYT_free() 412 413 Input : pointer to ADT. 414 Description: This function frees the storage associated with an xyt handle 415 Usage: XYT_free(xyt_handle); 416 **************************************xyt.h***********************************/ 417 EXTERN PetscInt XYT_free(xyt_ADT xyt_handle); 418 419 420 /*************************************xyt.h************************************ 421 Function: XYT_factor 422 423 Input : ADT ptr, and pointer to object 424 Output: 425 Return: 0 on failure, 1 on success 426 Description: This function sets the xyt solver 427 428 xyt assumptions: given n rows of global coarse matrix (E_loc) where 429 o global dofs N = sum_p(n), p=0,P-1 430 (i.e. row dist. with no dof replication) 431 (5.21.00 will handle dif replication case) 432 o m is the number of columns in E_loc (m>=n) 433 o local2global holds global number of column i (i=0,...,m-1) 434 o local2global holds global number of row i (i=0,...,n-1) 435 o mylocmatvec performs E_loc . x_loc where x_loc is an vector of 436 length m in 1-1 correspondence with local2global 437 (note that gs package takes care of communication). 438 (note do not zero out upper m-n entries!) 439 o mylocmatvec(void *grid_data, double *in, double *out) 440 441 ML beliefs/usage: move this to to ML_XYT_factor routine 442 o my_ml holds address of ML struct associated w/E_loc, grid_data, grid_tag 443 o grid_tag, grid_data, my_ml used in 444 ML_Set_CSolve(my_ml, grid_tag, grid_data, ML_Do_CoarseDirect); 445 o grid_data used in 446 A_matvec(grid_data,v,u); 447 448 Usage: 449 **************************************xyt.h***********************************/ 450 extern PetscInt XYT_factor(xyt_ADT xyt_handle, /* prev. allocated xyt handle */ 451 PetscInt *local2global, /* global column mapping */ 452 PetscInt n, /* local num rows */ 453 PetscInt m, /* local num cols */ 454 void *mylocmatvec, /* b_loc=A_local.x_loc */ 455 void *grid_data /* grid data for matvec */ 456 ); 457 458 459 /*************************************xyt.h************************************ 460 Function: XYT_solve 461 462 Input : ADT ptr, b (rhs) 463 Output: x (soln) 464 Return: 465 Description: This function performs x = E^-1.b 466 Usage: XYT_solve(xyt_handle, double *x, double *b) 467 **************************************xyt.h***********************************/ 468 extern PetscInt XYT_solve(xyt_ADT xyt_handle, double *x, double *b); 469 470 471 /*************************************xyt.h************************************ 472 Function: XYT_stats 473 474 Input : handle 475 **************************************xyt.h***********************************/ 476 extern PetscInt XYT_stats(xyt_ADT xyt_handle); 477 478 479 /********************************bit_mask.h************************************ 480 481 Author: Henry M. Tufo III 482 483 e-mail: hmt@cs.brown.edu 484 485 snail-mail: 486 Division of Applied Mathematics 487 Brown University 488 Providence, RI 02912 489 490 Last Modification: 491 11.21.97 492 *********************************bit_mask.h***********************************/ 493 extern PetscInt div_ceil(PetscInt numin, PetscInt denom); 494 extern PetscErrorCode set_bit_mask(PetscInt *bm, PetscInt len, PetscInt val); 495 extern PetscInt len_bit_mask(PetscInt num_items); 496 extern PetscInt ct_bits(char *ptr, PetscInt n); 497 extern PetscErrorCode bm_to_proc(char *ptr, PetscInt p_mask, PetscInt *msg_list); 498 extern PetscInt len_buf(PetscInt item_size, PetscInt num_items); 499 500 #endif 501 502