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