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