1 /* 2 This is the main PETSc include file (for C and C++). It is included by all 3 other PETSc include files, so it almost never has to be specifically included. 4 */ 5 #if !defined(__PETSCSYS_H) 6 #define __PETSCSYS_H 7 /* ========================================================================== */ 8 /* 9 petscconf.h is contained in ${PETSC_ARCH}/include/petscconf.h it is 10 found automatically by the compiler due to the -I${PETSC_DIR}/${PETSC_ARCH}/include 11 in the conf/variables definition of PETSC_INCLUDE 12 */ 13 #include "petscconf.h" 14 #include "petscfix.h" 15 16 /* ========================================================================== */ 17 /* 18 This facilitates using C version of PETSc from C++ and 19 C++ version from C. Use --with-c-support --with-clanguage=c++ with ./configure for the latter) 20 */ 21 #if defined(PETSC_CLANGUAGE_CXX) && !defined(PETSC_USE_EXTERN_CXX) && !defined(__cplusplus) 22 #error "PETSc configured with --with-clanguage=c++ and NOT --with-c-support - it can be used only with a C++ compiler" 23 #endif 24 25 #if defined(__cplusplus) 26 # define PETSC_FUNCTION_NAME PETSC_FUNCTION_NAME_CXX 27 #else 28 # define PETSC_FUNCTION_NAME PETSC_FUNCTION_NAME_C 29 #endif 30 31 #if defined(PETSC_USE_EXTERN_CXX) && defined(__cplusplus) 32 #define PETSC_EXTERN_CXX_BEGIN extern "C" { 33 #define PETSC_EXTERN_CXX_END } 34 #else 35 #define PETSC_EXTERN_CXX_BEGIN 36 #define PETSC_EXTERN_CXX_END 37 #endif 38 /* ========================================================================== */ 39 /* 40 Current PETSc version number and release date. Also listed in 41 Web page 42 src/docs/tex/manual/intro.tex, 43 src/docs/tex/manual/manual.tex. 44 src/docs/website/index.html. 45 */ 46 #include "petscversion.h" 47 #define PETSC_AUTHOR_INFO " The PETSc Team\n petsc-maint@mcs.anl.gov\n http://www.mcs.anl.gov/petsc/\n" 48 #if (PETSC_VERSION_RELEASE == 1) 49 #define PetscGetVersion(version,len) PetscSNPrintf(version,len,"Petsc Release Version %d.%d.%d, Patch %d, %s ", \ 50 PETSC_VERSION_MAJOR,PETSC_VERSION_MINOR, PETSC_VERSION_SUBMINOR, \ 51 PETSC_VERSION_PATCH,PETSC_VERSION_PATCH_DATE) 52 #else 53 #define PetscGetVersion(version,len) PetscSNPrintf(version,len,"Petsc Development HG revision: %s HG Date: %s", \ 54 PETSC_VERSION_HG, PETSC_VERSION_DATE_HG) 55 #endif 56 57 /*MC 58 PetscGetVersion - Gets the PETSc version information in a string. 59 60 Input Parameter: 61 . len - length of the string 62 63 Output Parameter: 64 . version - version string 65 66 Level: developer 67 68 Usage: 69 char version[256]; 70 ierr = PetscGetVersion(version,256);CHKERRQ(ierr) 71 72 Fortran Note: 73 This routine is not supported in Fortran. 74 75 .seealso: PetscGetProgramName() 76 77 M*/ 78 79 /* ========================================================================== */ 80 81 /* 82 Currently cannot check formatting for PETSc print statements because we have our 83 own format %D and %G 84 */ 85 #undef PETSC_PRINTF_FORMAT_CHECK 86 #define PETSC_PRINTF_FORMAT_CHECK(a,b) 87 #undef PETSC_FPRINTF_FORMAT_CHECK 88 #define PETSC_FPRINTF_FORMAT_CHECK(a,b) 89 90 /* 91 Fixes for ./configure time choices which impact our interface. Currently only 92 calling conventions and extra compiler checking falls under this category. 93 */ 94 #if !defined(PETSC_STDCALL) 95 #define PETSC_STDCALL 96 #endif 97 #if !defined(PETSC_TEMPLATE) 98 #define PETSC_TEMPLATE 99 #endif 100 #if !defined(PETSC_HAVE_DLL_EXPORT) 101 #define PETSC_DLL_EXPORT 102 #define PETSC_DLL_IMPORT 103 #endif 104 #if !defined(PETSCSYS_DLLEXPORT) 105 #define PETSCSYS_DLLEXPORT 106 #endif 107 #if !defined(PETSCVEC_DLLEXPORT) 108 #define PETSCVEC_DLLEXPORT 109 #endif 110 #if !defined(PETSCMAT_DLLEXPORT) 111 #define PETSCMAT_DLLEXPORT 112 #endif 113 #if !defined(PETSCDM_DLLEXPORT) 114 #define PETSCDM_DLLEXPORT 115 #endif 116 #if !defined(PETSCKSP_DLLEXPORT) 117 #define PETSCKSP_DLLEXPORT 118 #endif 119 #if !defined(PETSCSNES_DLLEXPORT) 120 #define PETSCSNES_DLLEXPORT 121 #endif 122 #if !defined(PETSCTS_DLLEXPORT) 123 #define PETSCTS_DLLEXPORT 124 #endif 125 #if !defined(PETSCFORTRAN_DLLEXPORT) 126 #define PETSCFORTRAN_DLLEXPORT 127 #endif 128 /* ========================================================================== */ 129 130 /* 131 Defines the interface to MPI allowing the use of all MPI functions. 132 133 PETSc does not use the C++ binding of MPI at ALL. The following flag 134 makes sure the C++ bindings are not included. The C++ bindings REQUIRE 135 putting mpi.h before ANY C++ include files, we cannot control this 136 with all PETSc users. Users who want to use the MPI C++ bindings can include 137 mpicxx.h directly in their code 138 */ 139 #define MPICH_SKIP_MPICXX 1 140 #define OMPI_SKIP_MPICXX 1 141 #include "mpi.h" 142 143 /* 144 Yuck, we need to put stdio.h AFTER mpi.h for MPICH2 with C++ compiler 145 see the top of mpicxx.h in the MPICH2 distribution. 146 147 The MPI STANDARD HAS TO BE CHANGED to prevent this nonsense. 148 */ 149 #include <stdio.h> 150 151 /* MSMPI on 32bit windows requires this yukky hack - that breaks MPI standard compliance */ 152 #if !defined(MPIAPI) 153 #define MPIAPI 154 #endif 155 156 157 /*MC 158 PetscErrorCode - datatype used for return error code from all PETSc functions 159 160 Level: beginner 161 162 .seealso: CHKERRQ, SETERRQ 163 M*/ 164 typedef int PetscErrorCode; 165 166 /*MC 167 168 PetscClassId - A unique id used to identify each PETSc class. 169 (internal integer in the data structure used for error 170 checking). These are all defined by an offset from the lowest 171 one, PETSC_SMALLEST_CLASSID. 172 173 Level: advanced 174 175 .seealso: PetscClassIdRegister(), PetscLogEventRegister(), PetscHeaderCreate() 176 M*/ 177 typedef int PetscClassId; 178 179 180 /*MC 181 PetscBLASInt - datatype used to represent 'int' parameters to BLAS/LAPACK functions. 182 183 Level: intermediate 184 185 Notes: usually this is the same as PetscInt, but if PETSc was built with --with-64-bit-indices but 186 standard C/Fortran integers are 32 bit then this is NOT the same as PetscInt it remains 32 bit 187 (except on very rare BLAS/LAPACK implementations that support 64 bit integers). 188 189 PetscBLASIntCheck(a) checks if the given PetscInt a will fit in a PetscBLASInt, if not it generates a 190 PETSC_ERR_ARG_OUTOFRANGE. 191 192 PetscBLASInt b = PetscBLASIntCast(a) checks if the given PetscInt a will fit in a PetscBLASInt, if not it 193 generates a PETSC_ERR_ARG_OUTOFRANGE 194 195 .seealso: PetscMPIInt, PetscInt 196 197 M*/ 198 typedef int PetscBLASInt; 199 200 /*MC 201 PetscMPIInt - datatype used to represent 'int' parameters to MPI functions. 202 203 Level: intermediate 204 205 Notes: usually this is the same as PetscInt, but if PETSc was built with --with-64-bit-indices but 206 standard C/Fortran integers are 32 bit then this is NOT the same as PetscInt it remains 32 bit 207 208 PetscMPIIntCheck(a) checks if the given PetscInt a will fit in a PetscMPIInt, if not it generates a 209 PETSC_ERR_ARG_OUTOFRANGE. 210 211 PetscMPIInt b = PetscMPIIntCast(a) checks if the given PetscInt a will fit in a PetscMPIInt, if not it 212 generates a PETSC_ERR_ARG_OUTOFRANGE 213 214 .seealso: PetscBLASInt, PetscInt 215 216 M*/ 217 typedef int PetscMPIInt; 218 219 /*MC 220 PetscEnum - datatype used to pass enum types within PETSc functions. 221 222 Level: intermediate 223 224 PetscMPIIntCheck(a) checks if the given PetscInt a will fit in a PetscMPIInt, if not it generates a 225 PETSC_ERR_ARG_OUTOFRANGE. 226 227 PetscMPIInt b = PetscMPIIntCast(a) checks if the given PetscInt a will fit in a PetscMPIInt, if not it 228 generates a PETSC_ERR_ARG_OUTOFRANGE 229 230 .seealso: PetscOptionsGetEnum(), PetscOptionsEnum(), PetscBagRegisterEnum() 231 M*/ 232 typedef enum { ENUM_DUMMY } PetscEnum; 233 234 /*MC 235 PetscInt - PETSc type that represents integer - used primarily to 236 represent size of arrays and indexing into arrays. Its size can be configured with the option 237 --with-64-bit-indices - to be either 32bit or 64bit [default 32 bit ints] 238 239 Level: intermediate 240 241 .seealso: PetscScalar, PetscBLASInt, PetscMPIInt 242 M*/ 243 #if defined(PETSC_USE_64BIT_INDICES) 244 typedef long long PetscInt; 245 #define MPIU_INT MPI_LONG_LONG_INT 246 #else 247 typedef int PetscInt; 248 #define MPIU_INT MPI_INT 249 #endif 250 251 /* 252 For the rare cases when one needs to send a size_t object with MPI 253 */ 254 #if (PETSC_SIZEOF_SIZE_T) == (PETSC_SIZEOF_INT) 255 #define MPIU_SIZE_T MPI_INT 256 #elif (PETSC_SIZEOF_SIZE_T) == (PETSC_SIZEOF_LONG) 257 #define MPIU_SIZE_T MPI_LONG 258 #elif (PETSC_SIZEOF_SIZE_T) == (PETSC_SIZEOF_LONG_LONG) 259 #define MPIU_SIZE_T MPI_LONG_LONG_INT 260 #else 261 #error "Unknown size for size_t! Send us a bugreport at petsc-maint@mcs.anl.gov" 262 #endif 263 264 265 /* 266 You can use PETSC_STDOUT as a replacement of stdout. You can also change 267 the value of PETSC_STDOUT to redirect all standard output elsewhere 268 */ 269 270 extern FILE* PETSC_STDOUT; 271 272 /* 273 You can use PETSC_STDERR as a replacement of stderr. You can also change 274 the value of PETSC_STDERR to redirect all standard error elsewhere 275 */ 276 extern FILE* PETSC_STDERR; 277 278 /* 279 PETSC_ZOPEFD is used to send data to the PETSc webpage. It can be used 280 in conjunction with PETSC_STDOUT, or by itself. 281 */ 282 extern FILE* PETSC_ZOPEFD; 283 284 #if !defined(PETSC_USE_EXTERN_CXX) && defined(__cplusplus) 285 /*MC 286 PetscPolymorphicSubroutine - allows defining a C++ polymorphic version of 287 a PETSc function that remove certain optional arguments for a simplier user interface 288 289 Synopsis: 290 PetscPolymorphicSubroutine(Functionname,(arguments of C++ function),(arguments of C function)) 291 292 Not collective 293 294 Level: developer 295 296 Example: 297 PetscPolymorphicSubroutine(VecNorm,(Vec x,PetscReal *r),(x,NORM_2,r)) generates the new routine 298 PetscErrorCode VecNorm(Vec x,PetscReal *r) = VecNorm(x,NORM_2,r) 299 300 .seealso: PetscPolymorphicFunction() 301 302 M*/ 303 #define PetscPolymorphicSubroutine(A,B,C) PETSC_STATIC_INLINE PetscErrorCode A B {return A C;} 304 305 /*MC 306 PetscPolymorphicScalar - allows defining a C++ polymorphic version of 307 a PETSc function that replaces a PetscScalar * argument with a PetscScalar argument 308 309 Synopsis: 310 PetscPolymorphicScalar(Functionname,(arguments of C++ function),(arguments of C function)) 311 312 Not collective 313 314 Level: developer 315 316 Example: 317 PetscPolymorphicScalar(VecAXPY,(PetscScalar _val,Vec x,Vec y),(&_Val,x,y)) generates the new routine 318 PetscErrorCode VecAXPY(PetscScalar _val,Vec x,Vec y) = {PetscScalar _Val = _val; return VecAXPY(&_Val,x,y);} 319 320 .seealso: PetscPolymorphicFunction(),PetscPolymorphicSubroutine() 321 322 M*/ 323 #define PetscPolymorphicScalar(A,B,C) PETSC_STATIC_INLINE PetscErrorCode A B {PetscScalar _Val = _val; return A C;} 324 325 /*MC 326 PetscPolymorphicFunction - allows defining a C++ polymorphic version of 327 a PETSc function that remove certain optional arguments for a simplier user interface 328 and returns the computed value (istead of an error code) 329 330 Synopsis: 331 PetscPolymorphicFunction(Functionname,(arguments of C++ function),(arguments of C function),return type,return variable name) 332 333 Not collective 334 335 Level: developer 336 337 Example: 338 PetscPolymorphicFunction(VecNorm,(Vec x,NormType t),(x,t,&r),PetscReal,r) generates the new routine 339 PetscReal VecNorm(Vec x,NormType t) = {PetscReal r; VecNorm(x,t,&r); return r;} 340 341 .seealso: PetscPolymorphicSubroutine() 342 343 M*/ 344 #define PetscPolymorphicFunction(A,B,C,D,E) PETSC_STATIC_INLINE D A B {D E; A C;return E;} 345 346 #else 347 #define PetscPolymorphicSubroutine(A,B,C) 348 #define PetscPolymorphicScalar(A,B,C) 349 #define PetscPolymorphicFunction(A,B,C,D,E) 350 #endif 351 352 /*MC 353 PetscUnlikely - hints the compiler that the given condition is usually FALSE 354 355 Synopsis: 356 PetscBool PetscUnlikely(PetscBool cond) 357 358 Not Collective 359 360 Input Parameters: 361 . cond - condition or expression 362 363 Note: This returns the same truth value, it is only a hint to compilers that the resulting 364 branch is unlikely. 365 366 Level: advanced 367 368 .seealso: PetscLikely(), CHKERRQ 369 M*/ 370 371 /*MC 372 PetscLikely - hints the compiler that the given condition is usually TRUE 373 374 Synopsis: 375 PetscBool PetscUnlikely(PetscBool cond) 376 377 Not Collective 378 379 Input Parameters: 380 . cond - condition or expression 381 382 Note: This returns the same truth value, it is only a hint to compilers that the resulting 383 branch is likely. 384 385 Level: advanced 386 387 .seealso: PetscUnlikely() 388 M*/ 389 #if defined(PETSC_HAVE_BUILTIN_EXPECT) 390 # define PetscUnlikely(cond) __builtin_expect(!!(cond),0) 391 # define PetscLikely(cond) __builtin_expect(!!(cond),1) 392 #else 393 # define PetscUnlikely(cond) (cond) 394 # define PetscLikely(cond) (cond) 395 #endif 396 397 /* 398 Extern indicates a PETSc function defined elsewhere 399 */ 400 #if !defined(EXTERN) 401 #define EXTERN extern 402 #endif 403 404 /* 405 Defines some elementary mathematics functions and constants. 406 */ 407 #include "petscmath.h" 408 409 /* 410 Declare extern C stuff after including external header files 411 */ 412 413 PETSC_EXTERN_CXX_BEGIN 414 415 /* 416 Basic PETSc constants 417 */ 418 419 /*E 420 PetscBool - Logical variable. Actually an int in C and a logical in Fortran. 421 422 Level: beginner 423 424 Developer Note: Why have PetscBool , why not use bool in C? The problem is that K and R C, C99 and C++ all have different mechanisms for 425 boolean values. It is not easy to have a simple macro that that will work properly in all circumstances with all three mechanisms. 426 427 E*/ 428 typedef enum { PETSC_FALSE,PETSC_TRUE } PetscBool; 429 extern const char *PetscBools[]; 430 431 /*E 432 PetscCopyMode - Determines how an array passed to certain functions is copied or retained 433 434 Level: beginner 435 436 $ PETSC_COPY_VALUES - the array values are copied into new space, the user is free to reuse or delete the passed in array 437 $ PETSC_OWN_POINTER - the array values are NOT copied, the object takes ownership of the array and will free it later, the user cannot change or 438 $ delete the array. The array MUST have been obtained with PetscMalloc(). Hence this mode cannot be used in Fortran. 439 $ PETSC_USE_POINTER - the array values are NOT copied, the object uses the array but does NOT take ownership of the array. The user cannot use 440 the array but the user must delete the array after the object is destroyed. 441 442 E*/ 443 typedef enum { PETSC_COPY_VALUES, PETSC_OWN_POINTER, PETSC_USE_POINTER} PetscCopyMode; 444 extern const char *PetscCopyModes[]; 445 446 /*MC 447 PETSC_FALSE - False value of PetscBool 448 449 Level: beginner 450 451 Note: Zero integer 452 453 .seealso: PetscBool , PETSC_TRUE 454 M*/ 455 456 /*MC 457 PETSC_TRUE - True value of PetscBool 458 459 Level: beginner 460 461 Note: Nonzero integer 462 463 .seealso: PetscBool , PETSC_FALSE 464 M*/ 465 466 /*MC 467 PETSC_YES - Alias for PETSC_TRUE 468 469 Level: beginner 470 471 Note: Zero integer 472 473 .seealso: PetscBool , PETSC_TRUE, PETSC_FALSE, PETSC_NO 474 M*/ 475 #define PETSC_YES PETSC_TRUE 476 477 /*MC 478 PETSC_NO - Alias for PETSC_FALSE 479 480 Level: beginner 481 482 Note: Nonzero integer 483 484 .seealso: PetscBool , PETSC_TRUE, PETSC_FALSE, PETSC_YES 485 M*/ 486 #define PETSC_NO PETSC_FALSE 487 488 /*MC 489 PETSC_NULL - standard way of passing in a null or array or pointer 490 491 Level: beginner 492 493 Notes: accepted by many PETSc functions to not set a parameter and instead use 494 some default 495 496 This macro does not exist in Fortran; you must use PETSC_NULL_INTEGER, 497 PETSC_NULL_DOUBLE_PRECISION, PETSC_NULL_FUNCTION, PETSC_NULL_OBJECT etc 498 499 Developer Note: Why have PETSC_NULL, why not just use NULL? The problem is that NULL is defined in different include files under 500 different versions of Unix. It is tricky to insure the correct include file is always included. 501 502 .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_IGNORE, PETSC_DETERMINE 503 504 M*/ 505 #define PETSC_NULL 0 506 507 /*MC 508 PETSC_DECIDE - standard way of passing in integer or floating point parameter 509 where you wish PETSc to use the default. 510 511 Level: beginner 512 513 .seealso: PETSC_NULL, PETSC_DEFAULT, PETSC_IGNORE, PETSC_DETERMINE 514 515 M*/ 516 #define PETSC_DECIDE -1 517 518 /*MC 519 PETSC_DEFAULT - standard way of passing in integer or floating point parameter 520 where you wish PETSc to use the default. 521 522 Level: beginner 523 524 Fortran Notes: You need to use PETSC_DEFAULT_INTEGER or PETSC_DEFAULT_DOUBLE_PRECISION. 525 526 .seealso: PETSC_DECIDE, PETSC_NULL, PETSC_IGNORE, PETSC_DETERMINE 527 528 M*/ 529 #define PETSC_DEFAULT -2 530 531 532 /*MC 533 PETSC_IGNORE - same as PETSC_NULL, means PETSc will ignore this argument 534 535 Level: beginner 536 537 Note: accepted by many PETSc functions to not set a parameter and instead use 538 some default 539 540 Fortran Notes: This macro does not exist in Fortran; you must use PETSC_NULL_INTEGER, 541 PETSC_NULL_DOUBLE_PRECISION etc 542 543 .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_NULL, PETSC_DETERMINE 544 545 M*/ 546 #define PETSC_IGNORE PETSC_NULL 547 548 /*MC 549 PETSC_DETERMINE - standard way of passing in integer or floating point parameter 550 where you wish PETSc to compute the required value. 551 552 Level: beginner 553 554 .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_IGNORE, PETSC_NULL, VecSetSizes() 555 556 M*/ 557 #define PETSC_DETERMINE PETSC_DECIDE 558 559 /*MC 560 PETSC_COMM_WORLD - the equivalent of the MPI_COMM_WORLD communicator which represents 561 all the processs that PETSc knows about. 562 563 Level: beginner 564 565 Notes: By default PETSC_COMM_WORLD and MPI_COMM_WORLD are identical unless you wish to 566 run PETSc on ONLY a subset of MPI_COMM_WORLD. In that case create your new (smaller) 567 communicator, call it, say comm, and set PETSC_COMM_WORLD = comm BEFORE calling 568 PetscInitialize() 569 570 .seealso: PETSC_COMM_SELF 571 572 M*/ 573 extern MPI_Comm PETSC_COMM_WORLD; 574 575 /*MC 576 PETSC_COMM_SELF - This is always MPI_COMM_SELF 577 578 Level: beginner 579 580 .seealso: PETSC_COMM_WORLD 581 582 M*/ 583 #define PETSC_COMM_SELF MPI_COMM_SELF 584 585 extern PETSCSYS_DLLEXPORT PetscBool PetscInitializeCalled; 586 extern PETSCSYS_DLLEXPORT PetscBool PetscFinalizeCalled; 587 588 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscSetHelpVersionFunctions(PetscErrorCode (*)(MPI_Comm),PetscErrorCode (*)(MPI_Comm)); 589 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscCommDuplicate(MPI_Comm,MPI_Comm*,int*); 590 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscCommDestroy(MPI_Comm*); 591 592 /*MC 593 PetscMalloc - Allocates memory 594 595 Synopsis: 596 PetscErrorCode PetscMalloc(size_t m,void **result) 597 598 Not Collective 599 600 Input Parameter: 601 . m - number of bytes to allocate 602 603 Output Parameter: 604 . result - memory allocated 605 606 Level: beginner 607 608 Notes: Memory is always allocated at least double aligned 609 610 If you request memory of zero size it will allocate no space and assign the pointer to 0; PetscFree() will 611 properly handle not freeing the null pointer. 612 613 .seealso: PetscFree(), PetscNew() 614 615 Concepts: memory allocation 616 617 M*/ 618 #define PetscMalloc(a,b) ((a != 0) ? (*PetscTrMalloc)((a),__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__,(void**)(b)) : (*(b) = 0,0) ) 619 620 /*MC 621 PetscAddrAlign - Rounds up an address to PETSC_MEMALIGN alignment 622 623 Synopsis: 624 void *PetscAddrAlign(void *addr) 625 626 Not Collective 627 628 Input Parameters: 629 . addr - address to align (any pointer type) 630 631 Level: developer 632 633 .seealso: PetscMallocAlign() 634 635 Concepts: memory allocation 636 M*/ 637 #define PetscAddrAlign(a) (void*)((((PETSC_UINTPTR_T)(a))+(PETSC_MEMALIGN-1)) & ~(PETSC_MEMALIGN-1)) 638 639 /*MC 640 PetscMalloc2 - Allocates 2 chunks of memory both aligned to PETSC_MEMALIGN 641 642 Synopsis: 643 PetscErrorCode PetscMalloc2(size_t m1,type, t1,void **r1,size_t m2,type t2,void **r2) 644 645 Not Collective 646 647 Input Parameter: 648 + m1 - number of elements to allocate in 1st chunk (may be zero) 649 . t1 - type of first memory elements 650 . m2 - number of elements to allocate in 2nd chunk (may be zero) 651 - t2 - type of second memory elements 652 653 Output Parameter: 654 + r1 - memory allocated in first chunk 655 - r2 - memory allocated in second chunk 656 657 Level: developer 658 659 .seealso: PetscFree(), PetscNew(), PetscMalloc() 660 661 Concepts: memory allocation 662 663 M*/ 664 #if defined(PETSC_USE_DEBUG) 665 #define PetscMalloc2(m1,t1,r1,m2,t2,r2) (PetscMalloc((m1)*sizeof(t1),r1) || PetscMalloc((m2)*sizeof(t2),r2)) 666 #else 667 #define PetscMalloc2(m1,t1,r1,m2,t2,r2) ((*(r2) = 0,PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(PETSC_MEMALIGN-1),r1)) \ 668 || (*(r2) = (t2*)PetscAddrAlign(*(r1)+m1),0)) 669 #endif 670 671 /*MC 672 PetscMalloc3 - Allocates 3 chunks of memory all aligned to PETSC_MEMALIGN 673 674 Synopsis: 675 PetscErrorCode PetscMalloc3(size_t m1,type, t1,void **r1,size_t m2,type t2,void **r2,size_t m3,type t3,void **r3) 676 677 Not Collective 678 679 Input Parameter: 680 + m1 - number of elements to allocate in 1st chunk (may be zero) 681 . t1 - type of first memory elements 682 . m2 - number of elements to allocate in 2nd chunk (may be zero) 683 . t2 - type of second memory elements 684 . m3 - number of elements to allocate in 3rd chunk (may be zero) 685 - t3 - type of third memory elements 686 687 Output Parameter: 688 + r1 - memory allocated in first chunk 689 . r2 - memory allocated in second chunk 690 - r3 - memory allocated in third chunk 691 692 Level: developer 693 694 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3() 695 696 Concepts: memory allocation 697 698 M*/ 699 #if defined(PETSC_USE_DEBUG) 700 #define PetscMalloc3(m1,t1,r1,m2,t2,r2,m3,t3,r3) (PetscMalloc((m1)*sizeof(t1),r1) || PetscMalloc((m2)*sizeof(t2),r2) || PetscMalloc((m3)*sizeof(t3),r3)) 701 #else 702 #define PetscMalloc3(m1,t1,r1,m2,t2,r2,m3,t3,r3) ((*(r2) = 0,*(r3) = 0,PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3)+2*(PETSC_MEMALIGN-1),r1)) \ 703 || (*(r2) = (t2*)PetscAddrAlign(*(r1)+m1),*(r3) = (t3*)PetscAddrAlign(*(r2)+m2),0)) 704 #endif 705 706 /*MC 707 PetscMalloc4 - Allocates 4 chunks of memory all aligned to PETSC_MEMALIGN 708 709 Synopsis: 710 PetscErrorCode PetscMalloc4(size_t m1,type, t1,void **r1,size_t m2,type t2,void **r2,size_t m3,type t3,void **r3,size_t m4,type t4,void **r4) 711 712 Not Collective 713 714 Input Parameter: 715 + m1 - number of elements to allocate in 1st chunk (may be zero) 716 . t1 - type of first memory elements 717 . m2 - number of elements to allocate in 2nd chunk (may be zero) 718 . t2 - type of second memory elements 719 . m3 - number of elements to allocate in 3rd chunk (may be zero) 720 . t3 - type of third memory elements 721 . m4 - number of elements to allocate in 4th chunk (may be zero) 722 - t4 - type of fourth memory elements 723 724 Output Parameter: 725 + r1 - memory allocated in first chunk 726 . r2 - memory allocated in second chunk 727 . r3 - memory allocated in third chunk 728 - r4 - memory allocated in fourth chunk 729 730 Level: developer 731 732 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4() 733 734 Concepts: memory allocation 735 736 M*/ 737 #if defined(PETSC_USE_DEBUG) 738 #define PetscMalloc4(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4) (PetscMalloc((m1)*sizeof(t1),r1) || PetscMalloc((m2)*sizeof(t2),r2) || PetscMalloc((m3)*sizeof(t3),r3) || PetscMalloc((m4)*sizeof(t4),r4)) 739 #else 740 #define PetscMalloc4(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4) \ 741 ((*(r2) = 0, *(r3) = 0, *(r4) = 0,PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3)+(m4)*sizeof(t4)+3*(PETSC_MEMALIGN-1),r1)) \ 742 || (*(r2) = (t2*)PetscAddrAlign(*(r1)+m1),*(r3) = (t3*)PetscAddrAlign(*(r2)+m2),*(r4) = (t4*)PetscAddrAlign(*(r3)+m3),0)) 743 #endif 744 745 /*MC 746 PetscMalloc5 - Allocates 5 chunks of memory all aligned to PETSC_MEMALIGN 747 748 Synopsis: 749 PetscErrorCode PetscMalloc5(size_t m1,type, t1,void **r1,size_t m2,type t2,void **r2,size_t m3,type t3,void **r3,size_t m4,type t4,void **r4,size_t m5,type t5,void **r5) 750 751 Not Collective 752 753 Input Parameter: 754 + m1 - number of elements to allocate in 1st chunk (may be zero) 755 . t1 - type of first memory elements 756 . m2 - number of elements to allocate in 2nd chunk (may be zero) 757 . t2 - type of second memory elements 758 . m3 - number of elements to allocate in 3rd chunk (may be zero) 759 . t3 - type of third memory elements 760 . m4 - number of elements to allocate in 4th chunk (may be zero) 761 . t4 - type of fourth memory elements 762 . m5 - number of elements to allocate in 5th chunk (may be zero) 763 - t5 - type of fifth memory elements 764 765 Output Parameter: 766 + r1 - memory allocated in first chunk 767 . r2 - memory allocated in second chunk 768 . r3 - memory allocated in third chunk 769 . r4 - memory allocated in fourth chunk 770 - r5 - memory allocated in fifth chunk 771 772 Level: developer 773 774 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4(), PetscFree5() 775 776 Concepts: memory allocation 777 778 M*/ 779 #if defined(PETSC_USE_DEBUG) 780 #define PetscMalloc5(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4,m5,t5,r5) (PetscMalloc((m1)*sizeof(t1),r1) || PetscMalloc((m2)*sizeof(t2),r2) || PetscMalloc((m3)*sizeof(t3),r3) || PetscMalloc((m4)*sizeof(t4),r4) || PetscMalloc((m5)*sizeof(t5),r5)) 781 #else 782 #define PetscMalloc5(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4,m5,t5,r5) \ 783 ((*(r2) = 0, *(r3) = 0, *(r4) = 0,*(r5) = 0,PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3)+(m4)*sizeof(t4)+(m5)*sizeof(t5)+4*(PETSC_MEMALIGN-1),r1)) \ 784 || (*(r2) = (t2*)PetscAddrAlign(*(r1)+m1),*(r3) = (t3*)PetscAddrAlign(*(r2)+m2),*(r4) = (t4*)PetscAddrAlign(*(r3)+m3),*(r5) = (t5*)PetscAddrAlign(*(r4)+m4),0)) 785 #endif 786 787 788 /*MC 789 PetscMalloc6 - Allocates 6 chunks of memory all aligned to PETSC_MEMALIGN 790 791 Synopsis: 792 PetscErrorCode PetscMalloc6(size_t m1,type, t1,void **r1,size_t m2,type t2,void **r2,size_t m3,type t3,void **r3,size_t m4,type t4,void **r4,size_t m5,type t5,void **r5,size_t m6,type t6,void **r6) 793 794 Not Collective 795 796 Input Parameter: 797 + m1 - number of elements to allocate in 1st chunk (may be zero) 798 . t1 - type of first memory elements 799 . m2 - number of elements to allocate in 2nd chunk (may be zero) 800 . t2 - type of second memory elements 801 . m3 - number of elements to allocate in 3rd chunk (may be zero) 802 . t3 - type of third memory elements 803 . m4 - number of elements to allocate in 4th chunk (may be zero) 804 . t4 - type of fourth memory elements 805 . m5 - number of elements to allocate in 5th chunk (may be zero) 806 . t5 - type of fifth memory elements 807 . m6 - number of elements to allocate in 6th chunk (may be zero) 808 - t6 - type of sixth memory elements 809 810 Output Parameter: 811 + r1 - memory allocated in first chunk 812 . r2 - memory allocated in second chunk 813 . r3 - memory allocated in third chunk 814 . r4 - memory allocated in fourth chunk 815 . r5 - memory allocated in fifth chunk 816 - r6 - memory allocated in sixth chunk 817 818 Level: developer 819 820 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4(), PetscFree5(), PetscFree6() 821 822 Concepts: memory allocation 823 824 M*/ 825 #if defined(PETSC_USE_DEBUG) 826 #define PetscMalloc6(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4,m5,t5,r5,m6,t6,r6) (PetscMalloc((m1)*sizeof(t1),r1) || PetscMalloc((m2)*sizeof(t2),r2) || PetscMalloc((m3)*sizeof(t3),r3) || PetscMalloc((m4)*sizeof(t4),r4) || PetscMalloc((m5)*sizeof(t5),r5) || PetscMalloc((m6)*sizeof(t6),r6)) 827 #else 828 #define PetscMalloc6(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4,m5,t5,r5,m6,t6,r6) \ 829 ((*(r2) = 0, *(r3) = 0, *(r4) = 0,*(r5) = 0,*(r6) = 0,PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3)+(m4)*sizeof(t4)+(m5)*sizeof(t5)+(m6)*sizeof(t6)+5*(PETSC_MEMALIGN-1),r1)) \ 830 || (*(r2) = (t2*)PetscAddrAlign(*(r1)+m1),*(r3) = (t3*)PetscAddrAlign(*(r2)+m2),*(r4) = (t4*)PetscAddrAlign(*(r3)+m3),*(r5) = (t5*)PetscAddrAlign(*(r4)+m4),*(r6) = (t6*)PetscAddrAlign(*(r5)+m5),0)) 831 #endif 832 833 /*MC 834 PetscMalloc7 - Allocates 7 chunks of memory all aligned to PETSC_MEMALIGN 835 836 Synopsis: 837 PetscErrorCode PetscMalloc7(size_t m1,type, t1,void **r1,size_t m2,type t2,void **r2,size_t m3,type t3,void **r3,size_t m4,type t4,void **r4,size_t m5,type t5,void **r5,size_t m6,type t6,void **r6,size_t m7,type t7,void **r7) 838 839 Not Collective 840 841 Input Parameter: 842 + m1 - number of elements to allocate in 1st chunk (may be zero) 843 . t1 - type of first memory elements 844 . m2 - number of elements to allocate in 2nd chunk (may be zero) 845 . t2 - type of second memory elements 846 . m3 - number of elements to allocate in 3rd chunk (may be zero) 847 . t3 - type of third memory elements 848 . m4 - number of elements to allocate in 4th chunk (may be zero) 849 . t4 - type of fourth memory elements 850 . m5 - number of elements to allocate in 5th chunk (may be zero) 851 . t5 - type of fifth memory elements 852 . m6 - number of elements to allocate in 6th chunk (may be zero) 853 . t6 - type of sixth memory elements 854 . m7 - number of elements to allocate in 7th chunk (may be zero) 855 - t7 - type of sixth memory elements 856 857 Output Parameter: 858 + r1 - memory allocated in first chunk 859 . r2 - memory allocated in second chunk 860 . r3 - memory allocated in third chunk 861 . r4 - memory allocated in fourth chunk 862 . r5 - memory allocated in fifth chunk 863 . r6 - memory allocated in sixth chunk 864 - r7 - memory allocated in seventh chunk 865 866 Level: developer 867 868 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4(), PetscFree5(), PetscFree6(), PetscFree7() 869 870 Concepts: memory allocation 871 872 M*/ 873 #if defined(PETSC_USE_DEBUG) 874 #define PetscMalloc7(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4,m5,t5,r5,m6,t6,r6,m7,t7,r7) (PetscMalloc((m1)*sizeof(t1),r1) || PetscMalloc((m2)*sizeof(t2),r2) || PetscMalloc((m3)*sizeof(t3),r3) || PetscMalloc((m4)*sizeof(t4),r4) || PetscMalloc((m5)*sizeof(t5),r5) || PetscMalloc((m6)*sizeof(t6),r6) || PetscMalloc((m7)*sizeof(t7),r7)) 875 #else 876 #define PetscMalloc7(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4,m5,t5,r5,m6,t6,r6,m7,t7,r7) \ 877 ((*(r2) = 0, *(r3) = 0, *(r4) = 0,*(r5) = 0,*(r6) = 0,*(r7) = 0,PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3)+(m4)*sizeof(t4)+(m5)*sizeof(t5)+(m6)*sizeof(t6)+(m7)*sizeof(t7)+6*(PETSC_MEMALIGN-1),r1)) \ 878 || (*(r2) = (t2*)PetscAddrAlign(*(r1)+m1),*(r3) = (t3*)PetscAddrAlign(*(r2)+m2),*(r4) = (t4*)PetscAddrAlign(*(r3)+m3),*(r5) = (t5*)PetscAddrAlign(*(r4)+m4),*(r6) = (t6*)PetscAddrAlign(*(r5)+m5),*(r7) = (t7*)PetscAddrAlign(*(r6)+m6),0)) 879 #endif 880 881 /*MC 882 PetscNew - Allocates memory of a particular type, zeros the memory! Aligned to PETSC_MEMALIGN 883 884 Synopsis: 885 PetscErrorCode PetscNew(struct type,((type *))result) 886 887 Not Collective 888 889 Input Parameter: 890 . type - structure name of space to be allocated. Memory of size sizeof(type) is allocated 891 892 Output Parameter: 893 . result - memory allocated 894 895 Level: beginner 896 897 .seealso: PetscFree(), PetscMalloc(), PetscNewLog() 898 899 Concepts: memory allocation 900 901 M*/ 902 #define PetscNew(A,b) (PetscMalloc(sizeof(A),(b)) || PetscMemzero(*(b),sizeof(A))) 903 904 /*MC 905 PetscNewLog - Allocates memory of a particular type, zeros the memory! Aligned to PETSC_MEMALIGN. Associates the memory allocated 906 with the given object using PetscLogObjectMemory(). 907 908 Synopsis: 909 PetscErrorCode PetscNewLog(PetscObject obj,struct type,((type *))result) 910 911 Not Collective 912 913 Input Parameter: 914 + obj - object memory is logged to 915 - type - structure name of space to be allocated. Memory of size sizeof(type) is allocated 916 917 Output Parameter: 918 . result - memory allocated 919 920 Level: developer 921 922 .seealso: PetscFree(), PetscMalloc(), PetscNew(), PetscLogObjectMemory() 923 924 Concepts: memory allocation 925 926 M*/ 927 #define PetscNewLog(o,A,b) (PetscNew(A,b) || ((o) ? PetscLogObjectMemory(o,sizeof(A)) : 0)) 928 929 /*MC 930 PetscFree - Frees memory 931 932 Synopsis: 933 PetscErrorCode PetscFree(void *memory) 934 935 Not Collective 936 937 Input Parameter: 938 . memory - memory to free (the pointer is ALWAYS set to 0 upon sucess) 939 940 Level: beginner 941 942 Notes: Memory must have been obtained with PetscNew() or PetscMalloc() 943 944 .seealso: PetscNew(), PetscMalloc(), PetscFreeVoid() 945 946 Concepts: memory allocation 947 948 M*/ 949 #define PetscFree(a) ((a) ? ((*PetscTrFree)((void*)(a),__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__) || (((a) = 0),0)) : 0) 950 951 /*MC 952 PetscFreeVoid - Frees memory 953 954 Synopsis: 955 void PetscFreeVoid(void *memory) 956 957 Not Collective 958 959 Input Parameter: 960 . memory - memory to free 961 962 Level: beginner 963 964 Notes: This is different from PetscFree() in that no error code is returned 965 966 .seealso: PetscFree(), PetscNew(), PetscMalloc() 967 968 Concepts: memory allocation 969 970 M*/ 971 #define PetscFreeVoid(a) ((*PetscTrFree)((a),__LINE__,PETSC_FUNCTION_NAME,__FILE__,__SDIR__),(a) = 0) 972 973 974 /*MC 975 PetscFree2 - Frees 2 chunks of memory obtained with PetscMalloc2() 976 977 Synopsis: 978 PetscErrorCode PetscFree2(void *memory1,void *memory2) 979 980 Not Collective 981 982 Input Parameter: 983 + memory1 - memory to free 984 - memory2 - 2nd memory to free 985 986 Level: developer 987 988 Notes: Memory must have been obtained with PetscMalloc2() 989 990 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree() 991 992 Concepts: memory allocation 993 994 M*/ 995 #if defined(PETSC_USE_DEBUG) 996 #define PetscFree2(m1,m2) (PetscFree(m2) || PetscFree(m1)) 997 #else 998 #define PetscFree2(m1,m2) ((m2)=0, PetscFree(m1)) 999 #endif 1000 1001 /*MC 1002 PetscFree3 - Frees 3 chunks of memory obtained with PetscMalloc3() 1003 1004 Synopsis: 1005 PetscErrorCode PetscFree3(void *memory1,void *memory2,void *memory3) 1006 1007 Not Collective 1008 1009 Input Parameter: 1010 + memory1 - memory to free 1011 . memory2 - 2nd memory to free 1012 - memory3 - 3rd memory to free 1013 1014 Level: developer 1015 1016 Notes: Memory must have been obtained with PetscMalloc3() 1017 1018 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3() 1019 1020 Concepts: memory allocation 1021 1022 M*/ 1023 #if defined(PETSC_USE_DEBUG) 1024 #define PetscFree3(m1,m2,m3) (PetscFree(m3) || PetscFree(m2) || PetscFree(m1)) 1025 #else 1026 #define PetscFree3(m1,m2,m3) ((m3)=0,(m2)=0,PetscFree(m1)) 1027 #endif 1028 1029 /*MC 1030 PetscFree4 - Frees 4 chunks of memory obtained with PetscMalloc4() 1031 1032 Synopsis: 1033 PetscErrorCode PetscFree4(void *m1,void *m2,void *m3,void *m4) 1034 1035 Not Collective 1036 1037 Input Parameter: 1038 + m1 - memory to free 1039 . m2 - 2nd memory to free 1040 . m3 - 3rd memory to free 1041 - m4 - 4th memory to free 1042 1043 Level: developer 1044 1045 Notes: Memory must have been obtained with PetscMalloc4() 1046 1047 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4() 1048 1049 Concepts: memory allocation 1050 1051 M*/ 1052 #if defined(PETSC_USE_DEBUG) 1053 #define PetscFree4(m1,m2,m3,m4) (PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1)) 1054 #else 1055 #define PetscFree4(m1,m2,m3,m4) ((m4)=0,(m3)=0,(m2)=0,PetscFree(m1)) 1056 #endif 1057 1058 /*MC 1059 PetscFree5 - Frees 5 chunks of memory obtained with PetscMalloc5() 1060 1061 Synopsis: 1062 PetscErrorCode PetscFree5(void *m1,void *m2,void *m3,void *m4,void *m5) 1063 1064 Not Collective 1065 1066 Input Parameter: 1067 + m1 - memory to free 1068 . m2 - 2nd memory to free 1069 . m3 - 3rd memory to free 1070 . m4 - 4th memory to free 1071 - m5 - 5th memory to free 1072 1073 Level: developer 1074 1075 Notes: Memory must have been obtained with PetscMalloc5() 1076 1077 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5() 1078 1079 Concepts: memory allocation 1080 1081 M*/ 1082 #if defined(PETSC_USE_DEBUG) 1083 #define PetscFree5(m1,m2,m3,m4,m5) (PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1)) 1084 #else 1085 #define PetscFree5(m1,m2,m3,m4,m5) ((m5)=0,(m4)=0,(m3)=0,(m2)=0,PetscFree(m1)) 1086 #endif 1087 1088 1089 /*MC 1090 PetscFree6 - Frees 6 chunks of memory obtained with PetscMalloc6() 1091 1092 Synopsis: 1093 PetscErrorCode PetscFree6(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6) 1094 1095 Not Collective 1096 1097 Input Parameter: 1098 + m1 - memory to free 1099 . m2 - 2nd memory to free 1100 . m3 - 3rd memory to free 1101 . m4 - 4th memory to free 1102 . m5 - 5th memory to free 1103 - m6 - 6th memory to free 1104 1105 1106 Level: developer 1107 1108 Notes: Memory must have been obtained with PetscMalloc6() 1109 1110 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5(), PetscMalloc6() 1111 1112 Concepts: memory allocation 1113 1114 M*/ 1115 #if defined(PETSC_USE_DEBUG) 1116 #define PetscFree6(m1,m2,m3,m4,m5,m6) (PetscFree(m6) || PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1)) 1117 #else 1118 #define PetscFree6(m1,m2,m3,m4,m5,m6) ((m6)=0,(m5)=0,(m4)=0,(m3)=0,(m2)=0,PetscFree(m1)) 1119 #endif 1120 1121 /*MC 1122 PetscFree7 - Frees 7 chunks of memory obtained with PetscMalloc7() 1123 1124 Synopsis: 1125 PetscErrorCode PetscFree7(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6,void *m7) 1126 1127 Not Collective 1128 1129 Input Parameter: 1130 + m1 - memory to free 1131 . m2 - 2nd memory to free 1132 . m3 - 3rd memory to free 1133 . m4 - 4th memory to free 1134 . m5 - 5th memory to free 1135 . m6 - 6th memory to free 1136 - m7 - 7th memory to free 1137 1138 1139 Level: developer 1140 1141 Notes: Memory must have been obtained with PetscMalloc7() 1142 1143 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5(), PetscMalloc6(), 1144 PetscMalloc7() 1145 1146 Concepts: memory allocation 1147 1148 M*/ 1149 #if defined(PETSC_USE_DEBUG) 1150 #define PetscFree7(m1,m2,m3,m4,m5,m6,m7) (PetscFree(m7) || PetscFree(m6) || PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1)) 1151 #else 1152 #define PetscFree7(m1,m2,m3,m4,m5,m6,m7) ((m7)=0,(m6)=0,(m5)=0,(m4)=0,(m3)=0,(m2)=0,PetscFree(m1)) 1153 #endif 1154 1155 EXTERN PETSCSYS_DLLEXPORT PetscErrorCode (*PetscTrMalloc)(size_t,int,const char[],const char[],const char[],void**); 1156 EXTERN PETSCSYS_DLLEXPORT PetscErrorCode (*PetscTrFree)(void*,int,const char[],const char[],const char[]); 1157 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscMallocSet(PetscErrorCode (*)(size_t,int,const char[],const char[],const char[],void**),PetscErrorCode (*)(void*,int,const char[],const char[],const char[])); 1158 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscMallocClear(void); 1159 1160 /* 1161 Routines for tracing memory corruption/bleeding with default PETSc 1162 memory allocation 1163 */ 1164 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscMallocDump(FILE *); 1165 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscMallocDumpLog(FILE *); 1166 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscMallocGetCurrentUsage(PetscLogDouble *); 1167 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscMallocGetMaximumUsage(PetscLogDouble *); 1168 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscMallocDebug(PetscBool); 1169 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscMallocValidate(int,const char[],const char[],const char[]); 1170 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscMallocSetDumpLog(void); 1171 1172 1173 /* 1174 Variable type where we stash PETSc object pointers in Fortran. 1175 On most machines size(pointer) == sizeof(long) - except windows 1176 where its sizeof(long long) 1177 */ 1178 1179 #if (PETSC_SIZEOF_VOID_P) == (PETSC_SIZEOF_LONG) 1180 #define PetscFortranAddr long 1181 #elif (PETSC_SIZEOF_VOID_P) == (PETSC_SIZEOF_LONG_LONG) 1182 #define PetscFortranAddr long long 1183 #else 1184 #error "Unknown size for PetscFortranAddr! Send us a bugreport at petsc-maint@mcs.anl.gov" 1185 #endif 1186 1187 /*E 1188 PetscDataType - Used for handling different basic data types. 1189 1190 Level: beginner 1191 1192 Developer comment: It would be nice if we could always just use MPI Datatypes, why can we not? 1193 1194 .seealso: PetscBinaryRead(), PetscBinaryWrite(), PetscDataTypeToMPIDataType(), 1195 PetscDataTypeGetSize() 1196 1197 E*/ 1198 typedef enum {PETSC_INT = 0,PETSC_DOUBLE = 1,PETSC_COMPLEX = 2, PETSC_LONG = 3 ,PETSC_SHORT = 4,PETSC_FLOAT = 5, 1199 PETSC_CHAR = 6,PETSC_BIT_LOGICAL = 7,PETSC_ENUM = 8,PETSC_BOOL=9, PETSC_LONG_DOUBLE = 10, PETSC_QD_DD = 11} PetscDataType; 1200 extern const char *PetscDataTypes[]; 1201 1202 #if defined(PETSC_USE_COMPLEX) 1203 #define PETSC_SCALAR PETSC_COMPLEX 1204 #else 1205 #if defined(PETSC_USE_SCALAR_SINGLE) 1206 #define PETSC_SCALAR PETSC_FLOAT 1207 #elif defined(PETSC_USE_SCALAR_LONG_DOUBLE) 1208 #define PETSC_SCALAR PETSC_LONG_DOUBLE 1209 #elif defined(PETSC_USE_SCALAR_INT) 1210 #define PETSC_SCALAR PETSC_INT 1211 #elif defined(PETSC_USE_SCALAR_QD_DD) 1212 #define PETSC_SCALAR PETSC_QD_DD 1213 #else 1214 #define PETSC_SCALAR PETSC_DOUBLE 1215 #endif 1216 #endif 1217 #if defined(PETSC_USE_SCALAR_SINGLE) 1218 #define PETSC_REAL PETSC_FLOAT 1219 #elif defined(PETSC_USE_SCALAR_LONG_DOUBLE) 1220 #define PETSC_REAL PETSC_LONG_DOUBLE 1221 #elif defined(PETSC_USE_SCALAR_INT) 1222 #define PETSC_REAL PETSC_INT 1223 #elif defined(PETSC_USE_SCALAR_QD_DD) 1224 #define PETSC_REAL PETSC_QD_DD 1225 #else 1226 #define PETSC_REAL PETSC_DOUBLE 1227 #endif 1228 #define PETSC_FORTRANADDR PETSC_LONG 1229 1230 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscDataTypeToMPIDataType(PetscDataType,MPI_Datatype*); 1231 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscMPIDataTypeToPetscDataType(MPI_Datatype,PetscDataType*); 1232 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscDataTypeGetSize(PetscDataType,size_t*); 1233 1234 /* 1235 Basic memory and string operations. These are usually simple wrappers 1236 around the basic Unix system calls, but a few of them have additional 1237 functionality and/or error checking. 1238 */ 1239 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscBitMemcpy(void*,PetscInt,const void*,PetscInt,PetscInt,PetscDataType); 1240 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscMemmove(void*,void *,size_t); 1241 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscMemcmp(const void*,const void*,size_t,PetscBool *); 1242 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscStrlen(const char[],size_t*); 1243 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscStrToArray(const char[],int*,char ***); 1244 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscStrToArrayDestroy(int,char **); 1245 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscStrcmp(const char[],const char[],PetscBool *); 1246 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscStrgrt(const char[],const char[],PetscBool *); 1247 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscStrcasecmp(const char[],const char[],PetscBool *); 1248 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscStrncmp(const char[],const char[],size_t,PetscBool *); 1249 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscStrcpy(char[],const char[]); 1250 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscStrcat(char[],const char[]); 1251 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscStrncat(char[],const char[],size_t); 1252 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscStrncpy(char[],const char[],size_t); 1253 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscStrchr(const char[],char,char *[]); 1254 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscStrtolower(char[]); 1255 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscStrrchr(const char[],char,char *[]); 1256 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscStrstr(const char[],const char[],char *[]); 1257 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscStrrstr(const char[],const char[],char *[]); 1258 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscStrallocpy(const char[],char *[]); 1259 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscStrreplace(MPI_Comm,const char[],char[],size_t); 1260 1261 /*S 1262 PetscToken - 'Token' used for managing tokenizing strings 1263 1264 Level: intermediate 1265 1266 .seealso: PetscTokenCreate(), PetscTokenFind(), PetscTokenDestroy() 1267 S*/ 1268 typedef struct _p_PetscToken* PetscToken; 1269 1270 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscTokenCreate(const char[],const char,PetscToken*); 1271 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscTokenFind(PetscToken,char *[]); 1272 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscTokenDestroy(PetscToken); 1273 1274 /* 1275 These are MPI operations for MPI_Allreduce() etc 1276 */ 1277 EXTERN PETSCSYS_DLLEXPORT MPI_Op PetscMaxSum_Op; 1278 #if defined(PETSC_USE_COMPLEX) && !defined(PETSC_HAVE_MPI_C_DOUBLE_COMPLEX) 1279 EXTERN PETSCSYS_DLLEXPORT MPI_Op MPIU_SUM; 1280 #else 1281 #define MPIU_SUM MPI_SUM 1282 #endif 1283 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscMaxSum(MPI_Comm,const PetscInt[],PetscInt*,PetscInt*); 1284 1285 /*S 1286 PetscObject - any PETSc object, PetscViewer, Mat, Vec, KSP etc 1287 1288 Level: beginner 1289 1290 Note: This is the base class from which all objects appear. 1291 1292 .seealso: PetscObjectDestroy(), PetscObjectView(), PetscObjectGetName(), PetscObjectSetName(), PetscObjectReference(), PetscObjectDereferenc() 1293 S*/ 1294 typedef struct _p_PetscObject* PetscObject; 1295 1296 /*S 1297 PetscFList - Linked list of functions, possibly stored in dynamic libraries, accessed 1298 by string name 1299 1300 Level: advanced 1301 1302 .seealso: PetscFListAdd(), PetscFListDestroy() 1303 S*/ 1304 typedef struct _n_PetscFList *PetscFList; 1305 1306 /*E 1307 PetscFileMode - Access mode for a file. 1308 1309 Level: beginner 1310 1311 FILE_MODE_READ - open a file at its beginning for reading 1312 1313 FILE_MODE_WRITE - open a file at its beginning for writing (will create if the file does not exist) 1314 1315 FILE_MODE_APPEND - open a file at end for writing 1316 1317 FILE_MODE_UPDATE - open a file for updating, meaning for reading and writing 1318 1319 FILE_MODE_APPEND_UPDATE - open a file for updating, meaning for reading and writing, at the end 1320 1321 .seealso: PetscViewerFileSetMode() 1322 E*/ 1323 typedef enum {FILE_MODE_READ, FILE_MODE_WRITE, FILE_MODE_APPEND, FILE_MODE_UPDATE, FILE_MODE_APPEND_UPDATE} PetscFileMode; 1324 1325 #include "petscviewer.h" 1326 #include "petscoptions.h" 1327 1328 #define PETSC_SMALLEST_CLASSID 1211211 1329 extern PETSCSYS_DLLEXPORT PetscClassId PETSC_LARGEST_CLASSID; 1330 extern PETSCSYS_DLLEXPORT PetscClassId PETSC_OBJECT_CLASSID; 1331 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscClassIdRegister(const char[],PetscClassId *); 1332 1333 /* 1334 Routines that get memory usage information from the OS 1335 */ 1336 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscMemoryGetCurrentUsage(PetscLogDouble *); 1337 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscMemoryGetMaximumUsage(PetscLogDouble *); 1338 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscMemorySetGetMaximumUsage(void); 1339 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscMemoryShowUsage(PetscViewer,const char[]); 1340 1341 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscInfoAllow(PetscBool ,const char []); 1342 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscGetTime(PetscLogDouble*); 1343 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscGetCPUTime(PetscLogDouble*); 1344 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscSleep(PetscReal); 1345 1346 /* 1347 Initialization of PETSc 1348 */ 1349 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscInitialize(int*,char***,const char[],const char[]); 1350 PetscPolymorphicSubroutine(PetscInitialize,(int *argc,char ***args),(argc,args,PETSC_NULL,PETSC_NULL)) 1351 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscInitializeNoArguments(void); 1352 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscInitialized(PetscBool *); 1353 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscFinalized(PetscBool *); 1354 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscFinalize(void); 1355 EXTERN PetscErrorCode PetscInitializeFortran(void); 1356 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscGetArgs(int*,char ***); 1357 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscGetArguments(char ***); 1358 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscFreeArguments(char **); 1359 1360 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscEnd(void); 1361 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscSysInitializePackage(const char[]); 1362 1363 extern MPI_Comm PETSC_COMM_LOCAL_WORLD; 1364 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscOpenMPMerge(PetscMPIInt,PetscErrorCode (*)(void*),void*); 1365 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscOpenMPSpawn(PetscMPIInt); 1366 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscOpenMPFinalize(void); 1367 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscOpenMPRun(MPI_Comm,PetscErrorCode (*)(MPI_Comm,void *),void*); 1368 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscOpenMPRunCtx(MPI_Comm,PetscErrorCode (*)(MPI_Comm,void*,void *),void*); 1369 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscOpenMPFree(MPI_Comm,void*); 1370 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscOpenMPMalloc(MPI_Comm,size_t,void**); 1371 1372 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscPythonInitialize(const char[],const char[]); 1373 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscPythonFinalize(void); 1374 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscPythonPrintError(void); 1375 1376 /* 1377 These are so that in extern C code we can caste function pointers to non-extern C 1378 function pointers. Since the regular C++ code expects its function pointers to be 1379 C++. 1380 */ 1381 typedef void (**PetscVoidStarFunction)(void); 1382 typedef void (*PetscVoidFunction)(void); 1383 typedef PetscErrorCode (*PetscErrorCodeFunction)(void); 1384 1385 /* 1386 PetscTryMethod - Queries an object for a method, if it exists then calls it. 1387 These are intended to be used only inside PETSc functions. 1388 1389 Level: developer 1390 1391 .seealso: PetscUseMethod() 1392 */ 1393 #define PetscTryMethod(obj,A,B,C) \ 1394 0;{ PetscErrorCode (*f)B, __ierr; \ 1395 __ierr = PetscObjectQueryFunction((PetscObject)obj,A,(PetscVoidStarFunction)&f);CHKERRQ(__ierr); \ 1396 if (f) {__ierr = (*f)C;CHKERRQ(__ierr);}\ 1397 } 1398 1399 /* 1400 PetscUseMethod - Queries an object for a method, if it exists then calls it, otherwise generates an error. 1401 These are intended to be used only inside PETSc functions. 1402 1403 Level: developer 1404 1405 .seealso: PetscTryMethod() 1406 */ 1407 #define PetscUseMethod(obj,A,B,C) \ 1408 0;{ PetscErrorCode (*f)B, __ierr; \ 1409 __ierr = PetscObjectQueryFunction((PetscObject)obj,A,(PetscVoidStarFunction)&f);CHKERRQ(__ierr); \ 1410 if (f) {__ierr = (*f)C;CHKERRQ(__ierr);}\ 1411 else SETERRQ1(((PetscObject)A)->comm,PETSC_ERR_SUP,"Cannot locate function %s in object",A); \ 1412 } 1413 1414 /* 1415 Functions that can act on any PETSc object. 1416 */ 1417 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectCreate(MPI_Comm,PetscObject*); 1418 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectCreateGeneric(MPI_Comm, PetscClassId, const char [], PetscObject *); 1419 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectDestroy(PetscObject); 1420 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectGetComm(PetscObject,MPI_Comm *); 1421 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectGetClassId(PetscObject,PetscClassId *); 1422 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectSetType(PetscObject,const char []); 1423 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectGetType(PetscObject,const char *[]); 1424 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectSetName(PetscObject,const char[]); 1425 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectGetName(PetscObject,const char*[]); 1426 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectPrintClassNamePrefixType(PetscObject,PetscViewer,const char[]); 1427 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectSetTabLevel(PetscObject,PetscInt); 1428 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectGetTabLevel(PetscObject,PetscInt*); 1429 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectIncrementTabLevel(PetscObject,PetscObject,PetscInt); 1430 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectReference(PetscObject); 1431 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectGetReference(PetscObject,PetscInt*); 1432 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectDereference(PetscObject); 1433 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectGetNewTag(PetscObject,PetscMPIInt *); 1434 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectView(PetscObject,PetscViewer); 1435 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectCompose(PetscObject,const char[],PetscObject); 1436 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectQuery(PetscObject,const char[],PetscObject *); 1437 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectComposeFunction(PetscObject,const char[],const char[],void (*)(void)); 1438 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectSetFromOptions(PetscObject); 1439 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectSetUp(PetscObject); 1440 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscCommGetNewTag(MPI_Comm,PetscMPIInt *); 1441 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectAddOptionsHandler(PetscObject,PetscErrorCode (*)(PetscObject,void*),PetscErrorCode (*)(PetscObject,void*),void*); 1442 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectProcessOptionsHandlers(PetscObject); 1443 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectDestroyOptionsHandlers(PetscObject); 1444 1445 /*MC 1446 PetscObjectComposeFunctionDynamic - Associates a function with a given PETSc object. 1447 1448 Synopsis: 1449 PetscErrorCode PetscObjectComposeFunctionDynamic(PetscObject obj,const char name[],const char fname[],void *ptr) 1450 1451 Logically Collective on PetscObject 1452 1453 Input Parameters: 1454 + obj - the PETSc object; this must be cast with a (PetscObject), for example, 1455 PetscObjectCompose((PetscObject)mat,...); 1456 . name - name associated with the child function 1457 . fname - name of the function 1458 - ptr - function pointer (or PETSC_NULL if using dynamic libraries) 1459 1460 Level: advanced 1461 1462 1463 Notes: 1464 To remove a registered routine, pass in a PETSC_NULL rname and fnc(). 1465 1466 PetscObjectComposeFunctionDynamic() can be used with any PETSc object (such as 1467 Mat, Vec, KSP, SNES, etc.) or any user-provided object. 1468 1469 The composed function must be wrapped in a EXTERN_C_BEGIN/END for this to 1470 work in C++/complex with dynamic link libraries (./configure options --with-shared-libraries --with-dynamic-loading) 1471 enabled. 1472 1473 Concepts: objects^composing functions 1474 Concepts: composing functions 1475 Concepts: functions^querying 1476 Concepts: objects^querying 1477 Concepts: querying objects 1478 1479 .seealso: PetscObjectQueryFunction() 1480 M*/ 1481 #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 1482 #define PetscObjectComposeFunctionDynamic(a,b,c,d) PetscObjectComposeFunction(a,b,c,0) 1483 #else 1484 #define PetscObjectComposeFunctionDynamic(a,b,c,d) PetscObjectComposeFunction(a,b,c,(PetscVoidFunction)(d)) 1485 #endif 1486 1487 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectQueryFunction(PetscObject,const char[],void (**)(void)); 1488 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectSetOptionsPrefix(PetscObject,const char[]); 1489 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectAppendOptionsPrefix(PetscObject,const char[]); 1490 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectPrependOptionsPrefix(PetscObject,const char[]); 1491 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectGetOptionsPrefix(PetscObject,const char*[]); 1492 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectAMSPublish(PetscObject); 1493 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectUnPublish(PetscObject); 1494 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectChangeTypeName(PetscObject,const char[]); 1495 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectRegisterDestroy(PetscObject); 1496 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectRegisterDestroyAll(void); 1497 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscObjectName(PetscObject); 1498 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscTypeCompare(PetscObject,const char[],PetscBool *); 1499 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscRegisterFinalize(PetscErrorCode (*)(void)); 1500 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscRegisterFinalizeAll(void); 1501 1502 /* 1503 Defines PETSc error handling. 1504 */ 1505 #include "petscerror.h" 1506 1507 /*S 1508 PetscOList - Linked list of PETSc objects, each accessable by string name 1509 1510 Level: developer 1511 1512 Notes: Used by PetscObjectCompose() and PetscObjectQuery() 1513 1514 .seealso: PetscOListAdd(), PetscOListDestroy(), PetscOListFind(), PetscObjectCompose(), PetscObjectQuery() 1515 S*/ 1516 typedef struct _n_PetscOList *PetscOList; 1517 1518 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscOListDestroy(PetscOList); 1519 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscOListFind(PetscOList,const char[],PetscObject*); 1520 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscOListReverseFind(PetscOList,PetscObject,char**); 1521 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscOListAdd(PetscOList *,const char[],PetscObject); 1522 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscOListDuplicate(PetscOList,PetscOList *); 1523 1524 /* 1525 Dynamic library lists. Lists of names of routines in objects or in dynamic 1526 link libraries that will be loaded as needed. 1527 */ 1528 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscFListAdd(PetscFList*,const char[],const char[],void (*)(void)); 1529 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscFListDestroy(PetscFList*); 1530 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscFListFind(PetscFList,MPI_Comm,const char[],void (**)(void)); 1531 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscFListPrintTypes(MPI_Comm,FILE*,const char[],const char[],const char[],const char[],PetscFList,const char[]); 1532 #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 1533 #define PetscFListAddDynamic(a,b,p,c) PetscFListAdd(a,b,p,0) 1534 #else 1535 #define PetscFListAddDynamic(a,b,p,c) PetscFListAdd(a,b,p,(void (*)(void))c) 1536 #endif 1537 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscFListDuplicate(PetscFList,PetscFList *); 1538 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscFListView(PetscFList,PetscViewer); 1539 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscFListConcat(const char [],const char [],char []); 1540 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscFListGet(PetscFList,char ***,int*); 1541 1542 /*S 1543 PetscDLLibrary - Linked list of dynamics libraries to search for functions 1544 1545 Level: advanced 1546 1547 --with-shared-libraries --with-dynamic-loading must be used with ./configure to use dynamic libraries 1548 1549 .seealso: PetscDLLibraryOpen() 1550 S*/ 1551 typedef struct _n_PetscDLLibrary *PetscDLLibrary; 1552 extern PETSCSYS_DLLEXPORT PetscDLLibrary DLLibrariesLoaded; 1553 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscDLLibraryAppend(MPI_Comm,PetscDLLibrary *,const char[]); 1554 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscDLLibraryPrepend(MPI_Comm,PetscDLLibrary *,const char[]); 1555 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscDLLibrarySym(MPI_Comm,PetscDLLibrary *,const char[],const char[],void **); 1556 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscDLLibraryPrintPath(PetscDLLibrary); 1557 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscDLLibraryRetrieve(MPI_Comm,const char[],char *,size_t,PetscBool *); 1558 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscDLLibraryOpen(MPI_Comm,const char[],PetscDLLibrary *); 1559 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscDLLibraryClose(PetscDLLibrary); 1560 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscDLLibraryCCAAppend(MPI_Comm,PetscDLLibrary *,const char[]); 1561 1562 /* 1563 PetscFwk support. Needs to be documented. 1564 Logically it is an extension of PetscDLLXXX, PetscObjectCompose, etc. 1565 */ 1566 #include "petscfwk.h" 1567 1568 /* 1569 Useful utility routines 1570 */ 1571 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscSplitOwnership(MPI_Comm,PetscInt*,PetscInt*); 1572 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscSplitOwnershipBlock(MPI_Comm,PetscInt,PetscInt*,PetscInt*); 1573 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscSequentialPhaseBegin(MPI_Comm,PetscMPIInt); 1574 PetscPolymorphicSubroutine(PetscSequentialPhaseBegin,(MPI_Comm comm),(comm,1)) 1575 PetscPolymorphicSubroutine(PetscSequentialPhaseBegin,(void),(PETSC_COMM_WORLD,1)) 1576 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscSequentialPhaseEnd(MPI_Comm,PetscMPIInt); 1577 PetscPolymorphicSubroutine(PetscSequentialPhaseEnd,(MPI_Comm comm),(comm,1)) 1578 PetscPolymorphicSubroutine(PetscSequentialPhaseEnd,(void),(PETSC_COMM_WORLD,1)) 1579 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscBarrier(PetscObject); 1580 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscMPIDump(FILE*); 1581 1582 /* 1583 PetscNot - negates a logical type value and returns result as a PetscBool 1584 1585 Notes: This is useful in cases like 1586 $ int *a; 1587 $ PetscBool flag = PetscNot(a) 1588 where !a does not return a PetscBool because we cannot provide a cast from int to PetscBool in C. 1589 */ 1590 #define PetscNot(a) ((a) ? PETSC_FALSE : PETSC_TRUE) 1591 1592 /* 1593 Defines basic graphics available from PETSc. 1594 */ 1595 #include "petscdraw.h" 1596 1597 /* 1598 Defines the base data structures for all PETSc objects 1599 */ 1600 #include "private/petscimpl.h" 1601 1602 /* 1603 Defines PETSc profiling. 1604 */ 1605 #include "petsclog.h" 1606 1607 /* 1608 For locking, unlocking and destroying AMS memories associated with PETSc objects. ams.h is included in petscviewer.h 1609 */ 1610 #if defined(PETSC_HAVE_AMS) 1611 extern PetscBool PetscAMSPublishAll; 1612 #define PetscObjectTakeAccess(obj) ((((PetscObject)(obj))->amem == -1) ? 0 : AMS_Memory_take_access(((PetscObject)(obj))->amem)) 1613 #define PetscObjectGrantAccess(obj) ((((PetscObject)(obj))->amem == -1) ? 0 : AMS_Memory_grant_access(((PetscObject)(obj))->amem)) 1614 #define PetscObjectDepublish(obj) ((((PetscObject)(obj))->amem == -1) ? 0 : AMS_Memory_destroy(((PetscObject)(obj))->amem));((PetscObject)(obj))->amem = -1; 1615 #else 1616 #define PetscObjectTakeAccess(obj) 0 1617 #define PetscObjectGrantAccess(obj) 0 1618 #define PetscObjectDepublish(obj) 0 1619 #endif 1620 1621 /* 1622 Simple PETSc parallel IO for ASCII printing 1623 */ 1624 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscFixFilename(const char[],char[]); 1625 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscFOpen(MPI_Comm,const char[],const char[],FILE**); 1626 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscFClose(MPI_Comm,FILE*); 1627 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4); 1628 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscPrintf(MPI_Comm,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3); 1629 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscSNPrintf(char*,size_t,const char [],...); 1630 1631 /* These are used internally by PETSc ASCII IO routines*/ 1632 #include <stdarg.h> 1633 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscVSNPrintf(char*,size_t,const char[],size_t*,va_list); 1634 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT (*PetscVFPrintf)(FILE*,const char[],va_list); 1635 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscVFPrintfDefault(FILE*,const char[],va_list); 1636 1637 /*MC 1638 PetscErrorPrintf - Prints error messages. 1639 1640 Synopsis: 1641 PetscErrorCode (*PetscErrorPrintf)(const char format[],...); 1642 1643 Not Collective 1644 1645 Input Parameters: 1646 . format - the usual printf() format string 1647 1648 Options Database Keys: 1649 + -error_output_stdout - cause error messages to be printed to stdout instead of the 1650 (default) stderr 1651 - -error_output_none to turn off all printing of error messages (does not change the way the 1652 error is handled.) 1653 1654 Notes: Use 1655 $ PetscErrorPrintf = PetscErrorPrintfNone; to turn off all printing of error messages (does not change the way the 1656 $ error is handled.) and 1657 $ PetscErrorPrintf = PetscErrorPrintfDefault; to turn it back on 1658 $ of you can use your own function 1659 1660 Use 1661 PETSC_STDERR = FILE* obtained from a file open etc. to have stderr printed to the file. 1662 PETSC_STDOUT = FILE* obtained from a file open etc. to have stdout printed to the file. 1663 1664 Use 1665 PetscPushErrorHandler() to provide your own error handler that determines what kind of messages to print 1666 1667 Level: developer 1668 1669 Fortran Note: 1670 This routine is not supported in Fortran. 1671 1672 Concepts: error messages^printing 1673 Concepts: printing^error messages 1674 1675 .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf(), PetscPrintf(), PetscErrorHandlerPush(), PetscVFPrintf(), PetscHelpPrintf() 1676 M*/ 1677 EXTERN PETSCSYS_DLLEXPORT PetscErrorCode (*PetscErrorPrintf)(const char[],...); 1678 1679 /*MC 1680 PetscHelpPrintf - Prints help messages. 1681 1682 Synopsis: 1683 PetscErrorCode (*PetscHelpPrintf)(const char format[],...); 1684 1685 Not Collective 1686 1687 Input Parameters: 1688 . format - the usual printf() format string 1689 1690 Level: developer 1691 1692 Fortran Note: 1693 This routine is not supported in Fortran. 1694 1695 Concepts: help messages^printing 1696 Concepts: printing^help messages 1697 1698 .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscErrorPrintf() 1699 M*/ 1700 EXTERN PETSCSYS_DLLEXPORT PetscErrorCode (*PetscHelpPrintf)(MPI_Comm,const char[],...); 1701 1702 EXTERN PetscErrorCode PetscErrorPrintfDefault(const char [],...); 1703 EXTERN PetscErrorCode PetscErrorPrintfNone(const char [],...); 1704 EXTERN PetscErrorCode PetscHelpPrintfDefault(MPI_Comm,const char [],...); 1705 1706 #if defined(PETSC_HAVE_POPEN) 1707 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscPOpen(MPI_Comm,const char[],const char[],const char[],FILE **); 1708 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscPClose(MPI_Comm,FILE*); 1709 #endif 1710 1711 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscSynchronizedPrintf(MPI_Comm,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3); 1712 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscSynchronizedFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4); 1713 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscSynchronizedFlush(MPI_Comm); 1714 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscSynchronizedFGets(MPI_Comm,FILE*,size_t,char[]); 1715 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscStartMatlab(MPI_Comm,const char[],const char[],FILE**); 1716 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscStartJava(MPI_Comm,const char[],const char[],FILE**); 1717 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscGetPetscDir(const char*[]); 1718 1719 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscPopUpSelect(MPI_Comm,const char*,const char*,int,const char**,int*); 1720 1721 /*S 1722 PetscContainer - Simple PETSc object that contains a pointer to any required data 1723 1724 Level: advanced 1725 1726 .seealso: PetscObject, PetscContainerCreate() 1727 S*/ 1728 extern PetscClassId PETSCSYS_DLLEXPORT PETSC_CONTAINER_CLASSID; 1729 typedef struct _p_PetscContainer* PetscContainer; 1730 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscContainerGetPointer(PetscContainer,void **); 1731 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscContainerSetPointer(PetscContainer,void *); 1732 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscContainerDestroy(PetscContainer); 1733 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscContainerCreate(MPI_Comm,PetscContainer *); 1734 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscContainerSetUserDestroy(PetscContainer, PetscErrorCode (*)(void*)); 1735 1736 /* 1737 For use in debuggers 1738 */ 1739 extern PETSCSYS_DLLEXPORT PetscMPIInt PetscGlobalRank; 1740 extern PETSCSYS_DLLEXPORT PetscMPIInt PetscGlobalSize; 1741 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscIntView(PetscInt,const PetscInt[],PetscViewer); 1742 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscRealView(PetscInt,const PetscReal[],PetscViewer); 1743 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscScalarView(PetscInt,const PetscScalar[],PetscViewer); 1744 1745 #if defined(PETSC_HAVE_MEMORY_H) 1746 #include <memory.h> 1747 #endif 1748 #if defined(PETSC_HAVE_STDLIB_H) 1749 #include <stdlib.h> 1750 #endif 1751 #if defined(PETSC_HAVE_STRINGS_H) 1752 #include <strings.h> 1753 #endif 1754 #if defined(PETSC_HAVE_STRING_H) 1755 #include <string.h> 1756 #endif 1757 1758 1759 #if defined(PETSC_HAVE_XMMINTRIN_H) 1760 #include <xmmintrin.h> 1761 #endif 1762 #if defined(PETSC_HAVE_STDINT_H) 1763 #include <stdint.h> 1764 #endif 1765 1766 /*@C 1767 PetscMemcpy - Copies n bytes, beginning at location b, to the space 1768 beginning at location a. The two memory regions CANNOT overlap, use 1769 PetscMemmove() in that case. 1770 1771 Not Collective 1772 1773 Input Parameters: 1774 + b - pointer to initial memory space 1775 - n - length (in bytes) of space to copy 1776 1777 Output Parameter: 1778 . a - pointer to copy space 1779 1780 Level: intermediate 1781 1782 Compile Option: 1783 PETSC_PREFER_DCOPY_FOR_MEMCPY will cause the BLAS dcopy() routine to be used 1784 for memory copies on double precision values. 1785 PETSC_PREFER_COPY_FOR_MEMCPY will cause C code to be used 1786 for memory copies on double precision values. 1787 PETSC_PREFER_FORTRAN_FORMEMCPY will cause Fortran code to be used 1788 for memory copies on double precision values. 1789 1790 Note: 1791 This routine is analogous to memcpy(). 1792 1793 Developer Note: this is inlined for fastest performance 1794 1795 Concepts: memory^copying 1796 Concepts: copying^memory 1797 1798 .seealso: PetscMemmove() 1799 1800 @*/ 1801 PETSC_STATIC_INLINE PetscErrorCode PETSCSYS_DLLEXPORT PetscMemcpy(void *a,const void *b,size_t n) 1802 { 1803 #if defined(PETSC_USE_DEBUG) 1804 unsigned long al = (unsigned long) a,bl = (unsigned long) b; 1805 unsigned long nl = (unsigned long) n; 1806 if (n > 0 && !b) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Trying to copy from a null pointer"); 1807 if (n > 0 && !a) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Trying to copy to a null pointer"); 1808 #endif 1809 PetscFunctionBegin; 1810 if (a != b) { 1811 #if defined(PETSC_USE_DEBUG) 1812 if ((al > bl && (al - bl) < nl) || (bl - al) < nl) { 1813 SETERRQ3(PETSC_COMM_SELF,PETSC_ERR_ARG_INCOMP,"Memory regions overlap: either use PetscMemmov()\n\ 1814 or make sure your copy regions and lengths are correct. \n\ 1815 Length (bytes) %ld first address %ld second address %ld",nl,al,bl); 1816 } 1817 #endif 1818 #if (defined(PETSC_PREFER_DCOPY_FOR_MEMCPY) || defined(PETSC_PREFER_COPY_FOR_MEMCPY) || defined(PETSC_PREFER_FORTRAN_FORMEMCPY)) 1819 if (!(((long) a) % sizeof(PetscScalar)) && !(n % sizeof(PetscScalar))) { 1820 size_t len = n/sizeof(PetscScalar); 1821 #if defined(PETSC_PREFER_DCOPY_FOR_MEMCPY) 1822 PetscBLASInt one = 1,blen = PetscBLASIntCast(len); 1823 BLAScopy_(&blen,(PetscScalar *)b,&one,(PetscScalar *)a,&one); 1824 #elif defined(PETSC_PREFER_FORTRAN_FORMEMCPY) 1825 fortrancopy_(&len,(PetscScalar*)b,(PetscScalar*)a); 1826 #else 1827 size_t i; 1828 PetscScalar *x = (PetscScalar*)b, *y = (PetscScalar*)a; 1829 for (i=0; i<len; i++) y[i] = x[i]; 1830 #endif 1831 } else { 1832 memcpy((char*)(a),(char*)(b),n); 1833 } 1834 #elif defined(PETSC_HAVE__INTEL_FAST_MEMCPY) 1835 _intel_fast_memcpy((char*)(a),(char*)(b),n); 1836 #else 1837 memcpy((char*)(a),(char*)(b),n); 1838 #endif 1839 } 1840 PetscFunctionReturn(0); 1841 } 1842 1843 /*@C 1844 PetscMemzero - Zeros the specified memory. 1845 1846 Not Collective 1847 1848 Input Parameters: 1849 + a - pointer to beginning memory location 1850 - n - length (in bytes) of memory to initialize 1851 1852 Level: intermediate 1853 1854 Compile Option: 1855 PETSC_PREFER_BZERO - on certain machines (the IBM RS6000) the bzero() routine happens 1856 to be faster than the memset() routine. This flag causes the bzero() routine to be used. 1857 1858 Developer Note: this is inlined for fastest performance 1859 1860 Concepts: memory^zeroing 1861 Concepts: zeroing^memory 1862 1863 .seealso: PetscMemcpy() 1864 @*/ 1865 PETSC_STATIC_INLINE PetscErrorCode PETSCSYS_DLLEXPORT PetscMemzero(void *a,size_t n) 1866 { 1867 if (n > 0) { 1868 #if defined(PETSC_USE_DEBUG) 1869 if (!a) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Trying to zero at a null pointer"); 1870 #endif 1871 #if defined(PETSC_PREFER_ZERO_FOR_MEMZERO) 1872 if (!(((long) a) % sizeof(PetscScalar)) && !(n % sizeof(PetscScalar))) { 1873 size_t i,len = n/sizeof(PetscScalar); 1874 PetscScalar *x = (PetscScalar*)a; 1875 for (i=0; i<len; i++) x[i] = 0.0; 1876 } else { 1877 #elif defined(PETSC_PREFER_FORTRAN_FOR_MEMZERO) 1878 if (!(((long) a) % sizeof(PetscScalar)) && !(n % sizeof(PetscScalar))) { 1879 PetscInt len = n/sizeof(PetscScalar); 1880 fortranzero_(&len,(PetscScalar*)a); 1881 } else { 1882 #endif 1883 #if defined(PETSC_PREFER_BZERO) 1884 bzero((char *)a,n); 1885 #elif defined (PETSC_HAVE__INTEL_FAST_MEMSET) 1886 _intel_fast_memset((char*)a,0,n); 1887 #else 1888 memset((char*)a,0,n); 1889 #endif 1890 #if defined(PETSC_PREFER_ZERO_FOR_MEMZERO) || defined(PETSC_PREFER_FORTRAN_FOR_MEMZERO) 1891 } 1892 #endif 1893 } 1894 return 0; 1895 } 1896 1897 /*MC 1898 PetscPrefetchBlock - Prefetches a block of memory 1899 1900 Synopsis: 1901 void PetscPrefetchBlock(const anytype *a,size_t n,int rw,int t) 1902 1903 Not Collective 1904 1905 Input Parameters: 1906 + a - pointer to first element to fetch (any type but usually PetscInt or PetscScalar) 1907 . n - number of elements to fetch 1908 . rw - 1 if the memory will be written to, otherwise 0 (ignored by many processors) 1909 - t - temporal locality (PETSC_PREFETCH_HINT_{NTA,T0,T1,T2}), see note 1910 1911 Level: developer 1912 1913 Notes: 1914 The last two arguments (rw and t) must be compile-time constants. 1915 1916 Adopting Intel's x86/x86-64 conventions, there are four levels of temporal locality. Not all architectures offer 1917 equivalent locality hints, but the following macros are always defined to their closest analogue. 1918 + PETSC_PREFETCH_HINT_NTA - Non-temporal. Prefetches directly to L1, evicts to memory (skips higher level cache unless it was already there when prefetched). 1919 . PETSC_PREFETCH_HINT_T0 - Fetch to all levels of cache and evict to the closest level. Use this when the memory will be reused regularly despite necessary eviction from L1. 1920 . PETSC_PREFETCH_HINT_T1 - Fetch to level 2 and higher (not L1). 1921 - PETSC_PREFETCH_HINT_T2 - Fetch to high-level cache only. (On many systems, T0 and T1 are equivalent.) 1922 1923 This function does nothing on architectures that do not support prefetch and never errors (even if passed an invalid 1924 address). 1925 1926 Concepts: memory 1927 M*/ 1928 #define PetscPrefetchBlock(a,n,rw,t) do { \ 1929 const char *_p = (const char*)(a),*_end = (const char*)((a)+(n)); \ 1930 for ( ; _p < _end; _p += PETSC_LEVEL1_DCACHE_LINESIZE) PETSC_Prefetch(_p,(rw),(t)); \ 1931 } while (0) 1932 1933 /* 1934 Allows accessing Matlab Engine 1935 */ 1936 #include "petscmatlab.h" 1937 1938 /* 1939 Determine if some of the kernel computation routines use 1940 Fortran (rather than C) for the numerical calculations. On some machines 1941 and compilers (like complex numbers) the Fortran version of the routines 1942 is faster than the C/C++ versions. The flag --with-fortran-kernels 1943 should be used with ./configure to turn these on. 1944 */ 1945 #if defined(PETSC_USE_FORTRAN_KERNELS) 1946 1947 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTCRL) 1948 #define PETSC_USE_FORTRAN_KERNEL_MULTCRL 1949 #endif 1950 1951 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJPERM) 1952 #define PETSC_USE_FORTRAN_KERNEL_MULTAIJPERM 1953 #endif 1954 1955 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ) 1956 #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ 1957 #endif 1958 1959 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ) 1960 #define PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ 1961 #endif 1962 1963 #if !defined(PETSC_USE_FORTRAN_KERNEL_NORM) 1964 #define PETSC_USE_FORTRAN_KERNEL_NORM 1965 #endif 1966 1967 #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY) 1968 #define PETSC_USE_FORTRAN_KERNEL_MAXPY 1969 #endif 1970 1971 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ) 1972 #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ 1973 #endif 1974 1975 #if !defined(PETSC_USE_FORTRAN_KERNEL_RELAXAIJ) 1976 #define PETSC_USE_FORTRAN_KERNEL_RELAXAIJ 1977 #endif 1978 1979 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ) 1980 #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ 1981 #endif 1982 1983 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ) 1984 #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ 1985 #endif 1986 1987 #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT) 1988 #define PETSC_USE_FORTRAN_KERNEL_MDOT 1989 #endif 1990 1991 #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY) 1992 #define PETSC_USE_FORTRAN_KERNEL_XTIMESY 1993 #endif 1994 1995 #if !defined(PETSC_USE_FORTRAN_KERNEL_AYPX) 1996 #define PETSC_USE_FORTRAN_KERNEL_AYPX 1997 #endif 1998 1999 #if !defined(PETSC_USE_FORTRAN_KERNEL_WAXPY) 2000 #define PETSC_USE_FORTRAN_KERNEL_WAXPY 2001 #endif 2002 2003 #endif 2004 2005 /* 2006 Macros for indicating code that should be compiled with a C interface, 2007 rather than a C++ interface. Any routines that are dynamically loaded 2008 (such as the PCCreate_XXX() routines) must be wrapped so that the name 2009 mangler does not change the functions symbol name. This just hides the 2010 ugly extern "C" {} wrappers. 2011 */ 2012 #if defined(__cplusplus) 2013 #define EXTERN_C_BEGIN extern "C" { 2014 #define EXTERN_C_END } 2015 #else 2016 #define EXTERN_C_BEGIN 2017 #define EXTERN_C_END 2018 #endif 2019 2020 /* --------------------------------------------------------------------*/ 2021 2022 /*MC 2023 MPI_Comm - the basic object used by MPI to determine which processes are involved in a 2024 communication 2025 2026 Level: beginner 2027 2028 Note: This manual page is a place-holder because MPICH does not have a manual page for MPI_Comm 2029 2030 .seealso: PETSC_COMM_WORLD, PETSC_COMM_SELF 2031 M*/ 2032 2033 /*MC 2034 PetscScalar - PETSc type that represents either a double precision real number, a double precision 2035 complex number, a single precision real number, a long double or an int - if the code is configured 2036 with --with-scalar-type=real,complex --with-precision=single,double,longdouble,int,matsingle 2037 2038 2039 Level: beginner 2040 2041 .seealso: PetscReal, PassiveReal, PassiveScalar, MPIU_SCALAR, PetscInt 2042 M*/ 2043 2044 /*MC 2045 PetscReal - PETSc type that represents a real number version of PetscScalar 2046 2047 Level: beginner 2048 2049 .seealso: PetscScalar, PassiveReal, PassiveScalar 2050 M*/ 2051 2052 /*MC 2053 PassiveScalar - PETSc type that represents a PetscScalar 2054 Level: beginner 2055 2056 This is the same as a PetscScalar except in code that is automatically differentiated it is 2057 treated as a constant (not an indendent or dependent variable) 2058 2059 .seealso: PetscReal, PassiveReal, PetscScalar 2060 M*/ 2061 2062 /*MC 2063 PassiveReal - PETSc type that represents a PetscReal 2064 2065 Level: beginner 2066 2067 This is the same as a PetscReal except in code that is automatically differentiated it is 2068 treated as a constant (not an indendent or dependent variable) 2069 2070 .seealso: PetscScalar, PetscReal, PassiveScalar 2071 M*/ 2072 2073 /*MC 2074 MPIU_SCALAR - MPI datatype corresponding to PetscScalar 2075 2076 Level: beginner 2077 2078 Note: In MPI calls that require an MPI datatype that matches a PetscScalar or array of PetscScalars 2079 pass this value 2080 2081 .seealso: PetscReal, PassiveReal, PassiveScalar, PetscScalar, MPIU_INT 2082 M*/ 2083 2084 #if defined(PETSC_HAVE_MPIIO) 2085 #if !defined(PETSC_WORDS_BIGENDIAN) 2086 extern PetscErrorCode MPIU_File_write_all(MPI_File,void*,PetscMPIInt,MPI_Datatype,MPI_Status*); 2087 extern PetscErrorCode MPIU_File_read_all(MPI_File,void*,PetscMPIInt,MPI_Datatype,MPI_Status*); 2088 #else 2089 #define MPIU_File_write_all(a,b,c,d,e) MPI_File_write_all(a,b,c,d,e) 2090 #define MPIU_File_read_all(a,b,c,d,e) MPI_File_read_all(a,b,c,d,e) 2091 #endif 2092 #endif 2093 2094 /* the following petsc_static_inline require petscerror.h */ 2095 2096 /* Limit MPI to 32-bits */ 2097 #define PETSC_MPI_INT_MAX 2147483647 2098 #define PETSC_MPI_INT_MIN -2147483647 2099 /* Limit BLAS to 32-bits */ 2100 #define PETSC_BLAS_INT_MAX 2147483647 2101 #define PETSC_BLAS_INT_MIN -2147483647 2102 /* On 32 bit systems HDF5 is limited by size of integer, because hsize_t is defined as size_t */ 2103 #define PETSC_HDF5_INT_MAX 2147483647 2104 #define PETSC_HDF5_INT_MIN -2147483647 2105 2106 #if defined(PETSC_USE_64BIT_INDICES) 2107 #define PetscMPIIntCheck(a) if ((a) > PETSC_MPI_INT_MAX) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Message too long for MPI") 2108 #define PetscBLASIntCheck(a) if ((a) > PETSC_BLAS_INT_MAX) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Array too long for BLAS/LAPACK") 2109 #define PetscMPIIntCast(a) (a);PetscMPIIntCheck(a) 2110 #define PetscBLASIntCast(a) (a);PetscBLASIntCheck(a) 2111 2112 #if (PETSC_SIZEOF_SIZE_T == 4) 2113 #define PetscHDF5IntCheck(a) if ((a) > PETSC_HDF5_INT_MAX) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Array too long for HDF5") 2114 #define PetscHDF5IntCast(a) (a);PetscHDF5IntCheck(a) 2115 #else 2116 #define PetscHDF5IntCheck(a) 2117 #define PetscHDF5IntCast(a) a 2118 #endif 2119 2120 #else 2121 #define PetscMPIIntCheck(a) 2122 #define PetscBLASIntCheck(a) 2123 #define PetscHDF5IntCheck(a) 2124 #define PetscMPIIntCast(a) a 2125 #define PetscBLASIntCast(a) a 2126 #define PetscHDF5IntCast(a) a 2127 #endif 2128 2129 2130 /* 2131 The IBM include files define hz, here we hide it so that it may be used 2132 as a regular user variable. 2133 */ 2134 #if defined(hz) 2135 #undef hz 2136 #endif 2137 2138 /* For arrays that contain filenames or paths */ 2139 2140 2141 #if defined(PETSC_HAVE_LIMITS_H) 2142 #include <limits.h> 2143 #endif 2144 #if defined(PETSC_HAVE_SYS_PARAM_H) 2145 #include <sys/param.h> 2146 #endif 2147 #if defined(PETSC_HAVE_SYS_TYPES_H) 2148 #include <sys/types.h> 2149 #endif 2150 #if defined(MAXPATHLEN) 2151 # define PETSC_MAX_PATH_LEN MAXPATHLEN 2152 #elif defined(MAX_PATH) 2153 # define PETSC_MAX_PATH_LEN MAX_PATH 2154 #elif defined(_MAX_PATH) 2155 # define PETSC_MAX_PATH_LEN _MAX_PATH 2156 #else 2157 # define PETSC_MAX_PATH_LEN 4096 2158 #endif 2159 2160 /* Special support for C++ */ 2161 #include "petscsys.hh" 2162 2163 2164 /*MC 2165 2166 UsingFortran - Fortran can be used with PETSc in four distinct approaches 2167 2168 $ 1) classic Fortran 77 style 2169 $#include "finclude/petscXXX.h" to work with material from the XXX component of PETSc 2170 $ XXX variablename 2171 $ You cannot use this approach if you wish to use the Fortran 90 specific PETSc routines 2172 $ which end in F90; such as VecGetArrayF90() 2173 $ 2174 $ 2) classic Fortran 90 style 2175 $#include "finclude/petscXXX.h" 2176 $#include "finclude/petscXXX.h90" to work with material from the XXX component of PETSc 2177 $ XXX variablename 2178 $ 2179 $ 3) Using Fortran modules 2180 $#include "finclude/petscXXXdef.h" 2181 $ use petscXXXX 2182 $ XXX variablename 2183 $ 2184 $ 4) Use Fortran modules and Fortran data types for PETSc types 2185 $#include "finclude/petscXXXdef.h" 2186 $ use petscXXXX 2187 $ type(XXX) variablename 2188 $ To use this approach you must ./configure PETSc with the additional 2189 $ option --with-fortran-datatypes You cannot use the type(XXX) declaration approach without using Fortran modules 2190 2191 Finally if you absolutely do not want to use any #include you can use either 2192 2193 $ 3a) skip the #include BUT you cannot use any PETSc data type names like Vec, Mat, PetscInt, PetscErrorCode etc 2194 $ and you must declare the variables as integer, for example 2195 $ integer variablename 2196 $ 2197 $ 4a) skip the #include, you use the object types like type(Vec) type(Mat) but cannot use the data type 2198 $ names like PetscErrorCode, PetscInt etc. again for those you must use integer 2199 2200 We recommend either 2 or 3. Approaches 2 and 3 provide type checking for most PETSc function calls; 4 has type checking 2201 for only a few PETSc functions. 2202 2203 Fortran type checking with interfaces is strick, this means you cannot pass a scalar value when an array value 2204 is expected (even though it is legal Fortran). For example when setting a single value in a matrix with MatSetValues() 2205 you cannot have something like 2206 $ PetscInt row,col 2207 $ PetscScalar val 2208 $ ... 2209 $ call MatSetValues(mat,1,row,1,col,val,INSERT_VALUES,ierr) 2210 You must instead have 2211 $ PetscInt row(1),col(1) 2212 $ PetscScalar val(1) 2213 $ ... 2214 $ call MatSetValues(mat,1,row,1,col,val,INSERT_VALUES,ierr) 2215 2216 2217 See the example src/vec/vec/examples/tutorials/ex20f90.F90 for an example that can use all four approaches 2218 2219 Developer Notes: The finclude/petscXXXdef.h contain all the #defines (would be typedefs in C code) these 2220 automatically include their predecessors; for example finclude/petscvecdef.h includes finclude/petscisdef.h 2221 2222 The finclude/petscXXXX.h contain all the parameter statements for that package. These automatically include 2223 their finclude/petscXXXdef.h file but DO NOT automatically include their predecessors; for example 2224 finclude/petscvec.h does NOT automatically include finclude/petscis.h 2225 2226 The finclude/ftn-custom/petscXXXdef.h90 are not intended to be used directly in code, they define the 2227 Fortran data type type(XXX) (for example type(Vec)) when PETSc is ./configure with the --with-fortran-datatypes option. 2228 2229 The finclude/ftn-custom/petscXXX.h90 (not included directly by code) contain interface definitions for 2230 the PETSc Fortran stubs that have different bindings then their C version (for example VecGetArrayF90). 2231 2232 The finclude/ftn-auto/petscXXX.h90 (not included directly by code) contain interface definitions generated 2233 automatically by "make allfortranstubs". 2234 2235 The finclude/petscXXX.h90 includes the custom finclude/ftn-custom/petscXXX.h90 and if ./configure 2236 was run with --with-fortran-interfaces it also includes the finclude/ftn-auto/petscXXX.h90 These DO NOT automatically 2237 include their predecessors 2238 2239 Level: beginner 2240 2241 M*/ 2242 2243 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscGetArchType(char[],size_t); 2244 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscGetHostName(char[],size_t); 2245 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscGetUserName(char[],size_t); 2246 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscGetProgramName(char[],size_t); 2247 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscSetProgramName(const char[]); 2248 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscGetDate(char[],size_t); 2249 2250 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscSortInt(PetscInt,PetscInt[]); 2251 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscSortRemoveDupsInt(PetscInt*,PetscInt[]); 2252 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscSortIntWithPermutation(PetscInt,const PetscInt[],PetscInt[]); 2253 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscSortStrWithPermutation(PetscInt,const char*[],PetscInt[]); 2254 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscSortIntWithArray(PetscInt,PetscInt[],PetscInt[]); 2255 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscSortMPIIntWithArray(PetscMPIInt,PetscMPIInt[],PetscMPIInt[]); 2256 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscSortIntWithScalarArray(PetscInt,PetscInt[],PetscScalar[]); 2257 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscSortReal(PetscInt,PetscReal[]); 2258 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscSortRealWithPermutation(PetscInt,const PetscReal[],PetscInt[]); 2259 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscSortSplit(PetscInt,PetscInt,PetscScalar[],PetscInt[]); 2260 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscSortSplitReal(PetscInt,PetscInt,PetscReal[],PetscInt[]); 2261 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscProcessTree(PetscInt,const PetscBool [],const PetscInt[],PetscInt*,PetscInt**,PetscInt**,PetscInt**,PetscInt**); 2262 2263 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscSetDisplay(void); 2264 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscGetDisplay(char[],size_t); 2265 2266 /*E 2267 PetscRandomType - String with the name of a PETSc randomizer 2268 with an optional dynamic library name, for example 2269 http://www.mcs.anl.gov/petsc/lib.a:myrandcreate() 2270 2271 Level: beginner 2272 2273 Notes: to use the SPRNG you must have ./configure PETSc 2274 with the option --download-sprng 2275 2276 .seealso: PetscRandomSetType(), PetscRandom 2277 E*/ 2278 #define PetscRandomType char* 2279 #define PETSCRAND "rand" 2280 #define PETSCRAND48 "rand48" 2281 #define PETSCSPRNG "sprng" 2282 2283 /* Logging support */ 2284 extern PETSCSYS_DLLEXPORT PetscClassId PETSC_RANDOM_CLASSID; 2285 2286 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscRandomInitializePackage(const char[]); 2287 2288 /*S 2289 PetscRandom - Abstract PETSc object that manages generating random numbers 2290 2291 Level: intermediate 2292 2293 Concepts: random numbers 2294 2295 .seealso: PetscRandomCreate(), PetscRandomGetValue(), PetscRandomType 2296 S*/ 2297 typedef struct _p_PetscRandom* PetscRandom; 2298 2299 /* Dynamic creation and loading functions */ 2300 extern PetscFList PetscRandomList; 2301 extern PetscBool PetscRandomRegisterAllCalled; 2302 2303 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscRandomRegisterAll(const char []); 2304 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscRandomRegister(const char[],const char[],const char[],PetscErrorCode (*)(PetscRandom)); 2305 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscRandomRegisterDestroy(void); 2306 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscRandomSetType(PetscRandom, const PetscRandomType); 2307 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscRandomSetFromOptions(PetscRandom); 2308 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscRandomGetType(PetscRandom, const PetscRandomType*); 2309 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscRandomViewFromOptions(PetscRandom,char*); 2310 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscRandomView(PetscRandom,PetscViewer); 2311 2312 /*MC 2313 PetscRandomRegisterDynamic - Adds a new PetscRandom component implementation 2314 2315 Synopsis: 2316 PetscErrorCode PetscRandomRegisterDynamic(const char *name, const char *path, const char *func_name, PetscErrorCode (*create_func)(PetscRandom)) 2317 2318 Not Collective 2319 2320 Input Parameters: 2321 + name - The name of a new user-defined creation routine 2322 . path - The path (either absolute or relative) of the library containing this routine 2323 . func_name - The name of routine to create method context 2324 - create_func - The creation routine itself 2325 2326 Notes: 2327 PetscRandomRegisterDynamic() may be called multiple times to add several user-defined randome number generators 2328 2329 If dynamic libraries are used, then the fourth input argument (routine_create) is ignored. 2330 2331 Sample usage: 2332 .vb 2333 PetscRandomRegisterDynamic("my_rand","/home/username/my_lib/lib/libO/solaris/libmy.a", "MyPetscRandomtorCreate", MyPetscRandomtorCreate); 2334 .ve 2335 2336 Then, your random type can be chosen with the procedural interface via 2337 .vb 2338 PetscRandomCreate(MPI_Comm, PetscRandom *); 2339 PetscRandomSetType(PetscRandom,"my_random_name"); 2340 .ve 2341 or at runtime via the option 2342 .vb 2343 -random_type my_random_name 2344 .ve 2345 2346 Notes: $PETSC_ARCH occuring in pathname will be replaced with appropriate values. 2347 2348 For an example of the code needed to interface your own random number generator see 2349 src/sys/random/impls/rand/rand.c 2350 2351 Level: advanced 2352 2353 .keywords: PetscRandom, register 2354 .seealso: PetscRandomRegisterAll(), PetscRandomRegisterDestroy(), PetscRandomRegister() 2355 M*/ 2356 #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 2357 #define PetscRandomRegisterDynamic(a,b,c,d) PetscRandomRegister(a,b,c,0) 2358 #else 2359 #define PetscRandomRegisterDynamic(a,b,c,d) PetscRandomRegister(a,b,c,d) 2360 #endif 2361 2362 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscRandomCreate(MPI_Comm,PetscRandom*); 2363 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscRandomGetValue(PetscRandom,PetscScalar*); 2364 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscRandomGetValueReal(PetscRandom,PetscReal*); 2365 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscRandomGetInterval(PetscRandom,PetscScalar*,PetscScalar*); 2366 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscRandomSetInterval(PetscRandom,PetscScalar,PetscScalar); 2367 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscRandomSetSeed(PetscRandom,unsigned long); 2368 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscRandomGetSeed(PetscRandom,unsigned long *); 2369 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscRandomSeed(PetscRandom); 2370 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscRandomDestroy(PetscRandom); 2371 2372 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscGetFullPath(const char[],char[],size_t); 2373 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscGetRelativePath(const char[],char[],size_t); 2374 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscGetWorkingDirectory(char[],size_t); 2375 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscGetRealPath(const char[],char[]); 2376 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscGetHomeDirectory(char[],size_t); 2377 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscTestFile(const char[],char,PetscBool *); 2378 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscTestDirectory(const char[],char,PetscBool *); 2379 2380 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscBinaryRead(int,void*,PetscInt,PetscDataType); 2381 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscBinarySynchronizedRead(MPI_Comm,int,void*,PetscInt,PetscDataType); 2382 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscBinarySynchronizedWrite(MPI_Comm,int,void*,PetscInt,PetscDataType,PetscBool ); 2383 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscBinaryWrite(int,void*,PetscInt,PetscDataType,PetscBool ); 2384 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscBinaryOpen(const char[],PetscFileMode,int *); 2385 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscBinaryClose(int); 2386 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscSharedTmp(MPI_Comm,PetscBool *); 2387 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscSharedWorkingDirectory(MPI_Comm,PetscBool *); 2388 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscGetTmp(MPI_Comm,char[],size_t); 2389 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscFileRetrieve(MPI_Comm,const char[],char[],size_t,PetscBool *); 2390 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscLs(MPI_Comm,const char[],char[],size_t,PetscBool *); 2391 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscOpenSocket(char*,int,int*); 2392 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscWebServe(MPI_Comm,int); 2393 2394 /* 2395 In binary files variables are stored using the following lengths, 2396 regardless of how they are stored in memory on any one particular 2397 machine. Use these rather then sizeof() in computing sizes for 2398 PetscBinarySeek(). 2399 */ 2400 #define PETSC_BINARY_INT_SIZE (32/8) 2401 #define PETSC_BINARY_FLOAT_SIZE (32/8) 2402 #define PETSC_BINARY_CHAR_SIZE (8/8) 2403 #define PETSC_BINARY_SHORT_SIZE (16/8) 2404 #define PETSC_BINARY_DOUBLE_SIZE (64/8) 2405 #define PETSC_BINARY_SCALAR_SIZE sizeof(PetscScalar) 2406 2407 /*E 2408 PetscBinarySeekType - argument to PetscBinarySeek() 2409 2410 Level: advanced 2411 2412 .seealso: PetscBinarySeek(), PetscBinarySynchronizedSeek() 2413 E*/ 2414 typedef enum {PETSC_BINARY_SEEK_SET = 0,PETSC_BINARY_SEEK_CUR = 1,PETSC_BINARY_SEEK_END = 2} PetscBinarySeekType; 2415 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscBinarySeek(int,off_t,PetscBinarySeekType,off_t*); 2416 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscBinarySynchronizedSeek(MPI_Comm,int,off_t,PetscBinarySeekType,off_t*); 2417 2418 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscSetDebugTerminal(const char[]); 2419 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscSetDebugger(const char[],PetscBool ); 2420 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscSetDefaultDebugger(void); 2421 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscSetDebuggerFromString(char*); 2422 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscAttachDebugger(void); 2423 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscStopForDebugger(void); 2424 2425 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscGatherNumberOfMessages(MPI_Comm,const PetscMPIInt[],const PetscMPIInt[],PetscMPIInt*); 2426 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscGatherMessageLengths(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],PetscMPIInt**,PetscMPIInt**); 2427 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscGatherMessageLengths2(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],const PetscMPIInt[],PetscMPIInt**,PetscMPIInt**,PetscMPIInt**); 2428 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscPostIrecvInt(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],const PetscMPIInt[],PetscInt***,MPI_Request**); 2429 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscPostIrecvScalar(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],const PetscMPIInt[],PetscScalar***,MPI_Request**); 2430 2431 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscSSEIsEnabled(MPI_Comm,PetscBool *,PetscBool *); 2432 2433 /*E 2434 InsertMode - Whether entries are inserted or added into vectors or matrices 2435 2436 Level: beginner 2437 2438 .seealso: VecSetValues(), MatSetValues(), VecSetValue(), VecSetValuesBlocked(), 2439 VecSetValuesLocal(), VecSetValuesBlockedLocal(), MatSetValuesBlocked(), 2440 MatSetValuesBlockedLocal(), MatSetValuesLocal(), VecScatterBegin(), VecScatterEnd() 2441 E*/ 2442 typedef enum {NOT_SET_VALUES, INSERT_VALUES, ADD_VALUES, MAX_VALUES} InsertMode; 2443 2444 /*MC 2445 INSERT_VALUES - Put a value into a vector or matrix, overwrites any previous value 2446 2447 Level: beginner 2448 2449 .seealso: InsertMode, VecSetValues(), MatSetValues(), VecSetValue(), VecSetValuesBlocked(), 2450 VecSetValuesLocal(), VecSetValuesBlockedLocal(), MatSetValuesBlocked(), ADD_VALUES, 2451 MatSetValuesBlockedLocal(), MatSetValuesLocal(), VecScatterBegin(), VecScatterEnd(), MAX_VALUES 2452 2453 M*/ 2454 2455 /*MC 2456 ADD_VALUES - Adds a value into a vector or matrix, if there previously was no value, just puts the 2457 value into that location 2458 2459 Level: beginner 2460 2461 .seealso: InsertMode, VecSetValues(), MatSetValues(), VecSetValue(), VecSetValuesBlocked(), 2462 VecSetValuesLocal(), VecSetValuesBlockedLocal(), MatSetValuesBlocked(), INSERT_VALUES, 2463 MatSetValuesBlockedLocal(), MatSetValuesLocal(), VecScatterBegin(), VecScatterEnd(), MAX_VALUES 2464 2465 M*/ 2466 2467 /*MC 2468 MAX_VALUES - Puts the maximum of the scattered/gathered value and the current value into each location 2469 2470 Level: beginner 2471 2472 .seealso: InsertMode, VecScatterBegin(), VecScatterEnd(), ADD_VALUES, INSERT_VALUES 2473 2474 M*/ 2475 2476 /*S 2477 PetscSubcomm - Context of MPI subcommunicators, used by PCREDUNDANT 2478 2479 Level: advanced 2480 2481 Concepts: communicator, create 2482 S*/ 2483 typedef struct _n_PetscSubcomm* PetscSubcomm; 2484 2485 struct _n_PetscSubcomm { 2486 MPI_Comm parent; /* parent communicator */ 2487 MPI_Comm dupparent; /* duplicate parent communicator, under which the processors of this subcomm have contiguous rank */ 2488 MPI_Comm comm; /* this communicator */ 2489 PetscInt n; /* num of subcommunicators under the parent communicator */ 2490 PetscInt color; /* color of processors belong to this communicator */ 2491 }; 2492 2493 typedef enum {PETSC_SUBCOMM_GENERAL=0,PETSC_SUBCOMM_CONTIGUOUS=1,PETSC_SUBCOMM_INTERLACED=2} PetscSubcommType; 2494 extern const char *PetscSubcommTypes[]; 2495 2496 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscSubcommCreate(MPI_Comm,PetscSubcomm*); 2497 EXTERN PetscErrorCode PETSCSYS_DLLEXPORT PetscSubcommDestroy(PetscSubcomm); 2498 EXTERN PetscErrorCode PETSCMAT_DLLEXPORT PetscSubcommSetNumber(PetscSubcomm,PetscInt); 2499 EXTERN PetscErrorCode PETSCMAT_DLLEXPORT PetscSubcommSetType(PetscSubcomm,const PetscSubcommType); 2500 EXTERN PetscErrorCode PETSCMAT_DLLEXPORT PetscSubcommSetTypeGeneral(PetscSubcomm,PetscMPIInt,PetscMPIInt,PetscMPIInt); 2501 2502 PETSC_EXTERN_CXX_END 2503 2504 #endif 2505