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(__PETSC_H) 6 #define __PETSC_H 7 /* ========================================================================== */ 8 /* 9 This facilitates using C version of PETSc from C++ 10 */ 11 12 #if defined(PETSC_USE_EXTERN_CXX) && defined(__cplusplus) 13 #define PETSC_EXTERN_CXX_BEGIN extern "C" { 14 #define PETSC_EXTERN_CXX_END } 15 #else 16 #define PETSC_EXTERN_CXX_BEGIN 17 #define PETSC_EXTERN_CXX_END 18 #endif 19 /* ========================================================================== */ 20 /* 21 Current PETSc version number and release date 22 */ 23 #include "petscversion.h" 24 25 /* ========================================================================== */ 26 /* 27 petscconf.h is contained in bmake/${PETSC_ARCH}/petscconf.h it is 28 found automatically by the compiler due to the -I${PETSC_DIR}/bmake/${PETSC_ARCH} 29 in the bmake/common_variables definition of PETSC_INCLUDE 30 */ 31 #include "petscconf.h" 32 33 /* 34 Currently cannot check formatting for PETSc print statements because we have our 35 own format %D 36 */ 37 #undef PETSC_PRINTF_FORMAT_CHECK 38 #define PETSC_PRINTF_FORMAT_CHECK(a,b) 39 #undef PETSC_FPRINTF_FORMAT_CHECK 40 #define PETSC_FPRINTF_FORMAT_CHECK(a,b) 41 42 /* 43 Fixes for configure time choices which impact our interface. Currently only 44 calling conventions and extra compiler checking falls under this category. 45 */ 46 #if !defined(PETSC_STDCALL) 47 #define PETSC_STDCALL 48 #endif 49 #if !defined(PETSC_TEMPLATE) 50 #define PETSC_TEMPLATE 51 #endif 52 #if !defined(PETSC_HAVE_DLL_EXPORT) 53 #define PETSC_DLL_EXPORT 54 #define PETSC_DLL_IMPORT 55 #endif 56 #if !defined(PETSC_DLLEXPORT) 57 #define PETSC_DLLEXPORT 58 #endif 59 #if !defined(PETSCVEC_DLLEXPORT) 60 #define PETSCVEC_DLLEXPORT 61 #endif 62 #if !defined(PETSCMAT_DLLEXPORT) 63 #define PETSCMAT_DLLEXPORT 64 #endif 65 #if !defined(PETSCDM_DLLEXPORT) 66 #define PETSCDM_DLLEXPORT 67 #endif 68 #if !defined(PETSCKSP_DLLEXPORT) 69 #define PETSCKSP_DLLEXPORT 70 #endif 71 #if !defined(PETSCSNES_DLLEXPORT) 72 #define PETSCSNES_DLLEXPORT 73 #endif 74 #if !defined(PETSCTS_DLLEXPORT) 75 #define PETSCTS_DLLEXPORT 76 #endif 77 #if !defined(PETSCFORTRAN_DLLEXPORT) 78 #define PETSCFORTRAN_DLLEXPORT 79 #endif 80 /* ========================================================================== */ 81 82 /* 83 Defines the interface to MPI allowing the use of all MPI functions. 84 */ 85 #include "mpi.h" 86 /* 87 Yuck, we need to put stdio.h AFTER mpi.h for MPICH2 with C++ compiler 88 see the top of mpicxx.h 89 90 The MPI STANDARD HAS TO BE CHANGED to prevent this nonsense. 91 */ 92 #include <stdio.h> 93 94 /* 95 All PETSc C functions return this error code, it is the final argument of 96 all Fortran subroutines 97 */ 98 typedef int PetscErrorCode; 99 typedef int PetscCookie; 100 typedef int PetscEvent; 101 typedef int PetscBLASInt; 102 typedef int PetscMPIInt; 103 104 #if defined(PETSC_USE_64BIT_INT) 105 typedef long long PetscInt; 106 #define MPIU_INT MPI_LONG_LONG_INT 107 #else 108 typedef int PetscInt; 109 #define MPIU_INT MPI_INT 110 #endif 111 112 /* 113 Allows defining simple C++ polymorphic functions that remove certain 114 optional arguments for a simplier user interface. Also allows returning 115 an out argument instead of returning the error code. Eventually we should 116 check the error code and generate an exception. 117 */ 118 #if defined(__cplusplus) 119 #define PetscPolymorphicSubroutine(A,B,C) PETSC_STATIC_INLINE PetscErrorCode A B {return A C;} 120 #define PetscPolymorphicFunction(A,B,C,D,E) PETSC_STATIC_INLINE D A B {D E; A C;return E;} 121 #else 122 #define PetscPolymorphicSubroutine(A,B,C) 123 #define PetscPolymorphicFunction(A,B,C,D,E) 124 #endif 125 126 /* 127 Declare extern C stuff after incuding external header files 128 */ 129 130 PETSC_EXTERN_CXX_BEGIN 131 132 /* 133 EXTERN indicates a PETSc function defined elsewhere 134 */ 135 #if !defined(EXTERN) 136 #define EXTERN extern 137 #endif 138 139 /* 140 Defines some elementary mathematics functions and constants. 141 */ 142 #include "petscmath.h" 143 144 /* 145 Basic PETSc constants 146 */ 147 148 /*E 149 PetscTruth - Logical variable. Actually an integer 150 151 Level: beginner 152 153 E*/ 154 typedef enum { PETSC_FALSE,PETSC_TRUE } PetscTruth; 155 156 /*M 157 PETSC_FALSE - False value of PetscTruth 158 159 Level: beginner 160 161 Note: Zero integer 162 163 .seealso: PetscTruth 164 M*/ 165 166 /*M 167 PETSC_TRUE - True value of PetscTruth 168 169 Level: beginner 170 171 Note: Nonzero integer 172 173 .seealso: PetscTruth 174 M*/ 175 176 /*M 177 PETSC_YES - Alias for PETSC_TRUE 178 179 Level: beginner 180 181 Note: Zero integer 182 183 .seealso: PetscTruth 184 M*/ 185 186 /*M 187 PETSC_NO - Alias for PETSC_FALSE 188 189 Level: beginner 190 191 Note: Nonzero integer 192 193 .seealso: PetscTruth 194 M*/ 195 196 /*M 197 PETSC_NULL - standard way of passing in a null or array or pointer 198 199 Level: beginner 200 201 Notes: accepted by many PETSc functions to not set a parameter and instead use 202 some default 203 204 This macro does not exist in Fortran; you must use PETSC_NULL_INTEGER, 205 PETSC_NULL_DOUBLE_PRECISION etc 206 207 .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_IGNORE, PETSC_DETERMINE 208 209 M*/ 210 #define PETSC_NULL 0 211 212 /*M 213 PETSC_DECIDE - standard way of passing in integer or floating point parameter 214 where you wish PETSc to use the default. 215 216 Level: beginner 217 218 .seealso: PETSC_NULL, PETSC_DEFAULT, PETSC_IGNORE, PETSC_DETERMINE 219 220 M*/ 221 #define PETSC_DECIDE -1 222 223 /*M 224 PETSC_DEFAULT - standard way of passing in integer or floating point parameter 225 where you wish PETSc to use the default. 226 227 Level: beginner 228 229 .seealso: PETSC_DECIDE, PETSC_NULL, PETSC_IGNORE, PETSC_DETERMINE 230 231 M*/ 232 #define PETSC_DEFAULT -2 233 234 #define PETSC_YES PETSC_TRUE 235 #define PETSC_NO PETSC_FALSE 236 237 /*M 238 PETSC_IGNORE - same as PETSC_NULL, means PETSc will ignore this argument 239 240 Level: beginner 241 242 Notes: accepted by many PETSc functions to not set a parameter and instead use 243 some default 244 245 This macro does not exist in Fortran; you must use PETSC_NULL_INTEGER, 246 PETSC_NULL_DOUBLE_PRECISION etc 247 248 .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_NULL, PETSC_DETERMINE 249 250 M*/ 251 #define PETSC_IGNORE PETSC_NULL 252 253 /*M 254 PETSC_DETERMINE - standard way of passing in integer or floating point parameter 255 where you wish PETSc to compute the required value. 256 257 Level: beginner 258 259 .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_IGNORE, PETSC_NULL, VecSetSizes() 260 261 M*/ 262 #define PETSC_DETERMINE PETSC_DECIDE 263 264 /*M 265 PETSC_COMM_WORLD - the equivalent of the MPI_COMM_WORLD communicator which represents 266 all the processs that PETSc knows about. 267 268 Level: beginner 269 270 Notes: By default PETSC_COMM_WORLD and MPI_COMM_WORLD are identical unless you wish to 271 run PETSc on ONLY a subset of MPI_COMM_WORLD. In that case create your new (smaller) 272 communicator, call it, say comm, and set PETSC_COMM_WORLD = comm BEFORE calling 273 PetscInitialize() 274 275 .seealso: PETSC_COMM_SELF 276 277 M*/ 278 extern MPI_Comm PETSC_COMM_WORLD; 279 280 /*M 281 PETSC_COMM_SELF - a duplicate of the MPI_COMM_SELF communicator which represents 282 the current process 283 284 Level: beginner 285 286 Notes: PETSC_COMM_SELF and MPI_COMM_SELF are equivalent. 287 288 .seealso: PETSC_COMM_WORLD 289 290 M*/ 291 #define PETSC_COMM_SELF MPI_COMM_SELF 292 293 extern PETSC_DLLEXPORT PetscTruth PetscInitializeCalled; 294 extern PETSC_DLLEXPORT PetscTruth PetscFinalizeCalled; 295 296 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSetHelpVersionFunctions(PetscErrorCode (*)(MPI_Comm),PetscErrorCode (*)(MPI_Comm)); 297 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscCommDuplicate(MPI_Comm,MPI_Comm*,int*); 298 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscCommDestroy(MPI_Comm*); 299 300 /*MC 301 PetscMalloc - Allocates memory 302 303 Input Parameter: 304 . m - number of bytes to allocate 305 306 Output Parameter: 307 . result - memory allocated 308 309 Synopsis: 310 PetscErrorCode PetscMalloc(size_t m,void **result) 311 312 Level: beginner 313 314 Notes: Memory is always allocated at least double aligned 315 316 If you request memory of zero size it will allocate no space and assign the pointer to 0; PetscFree() will 317 properly handle not freeing the null pointer. 318 319 .seealso: PetscFree(), PetscNew() 320 321 Concepts: memory allocation 322 323 M*/ 324 #define PetscMalloc(a,b) ((a != 0) ? (*PetscTrMalloc)((a),__LINE__,__FUNCT__,__FILE__,__SDIR__,(void**)(b)) : (*(b) = 0,0) ) 325 326 /*MC 327 PetscMalloc2 - Allocates 2 chunks of memory 328 329 Input Parameter: 330 + m1 - number of elements to allocate in 1st chunk (may be zero) 331 . t1 - type of first memory elements 332 . m2 - number of elements to allocate in 2nd chunk (may be zero) 333 - t2 - type of second memory elements 334 335 Output Parameter: 336 + r1 - memory allocated in first chunk 337 - r2 - memory allocated in second chunk 338 339 Synopsis: 340 PetscErrorCode PetscMalloc2(size_t m1,type, t1,void **r1,size_t m2,type t2,void **r2) 341 342 Level: developer 343 344 Notes: Memory of first chunk is always allocated at least double aligned 345 346 .seealso: PetscFree(), PetscNew(), PetscMalloc() 347 348 Concepts: memory allocation 349 350 M*/ 351 #if defined(PETSC_USE_DEBUG) 352 #define PetscMalloc2(m1,t1,r1,m2,t2,r2) (PetscMalloc((m1)*sizeof(t1),r1) || PetscMalloc((m2)*sizeof(t2),r2)) 353 #else 354 #define PetscMalloc2(m1,t1,r1,m2,t2,r2) (PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2),r1) || (*(r2) = (t2*)(*(r1)+m1),0)) 355 #endif 356 357 /*MC 358 PetscMalloc3 - Allocates 3 chunks of memory 359 360 Input Parameter: 361 + m1 - number of elements to allocate in 1st chunk (may be zero) 362 . t1 - type of first memory elements 363 . m2 - number of elements to allocate in 2nd chunk (may be zero) 364 . t2 - type of second memory elements 365 . m3 - number of elements to allocate in 3rd chunk (may be zero) 366 - t3 - type of third memory elements 367 368 Output Parameter: 369 + r1 - memory allocated in first chunk 370 . r2 - memory allocated in second chunk 371 - r3 - memory allocated in third chunk 372 373 Synopsis: 374 PetscErrorCode PetscMalloc3(size_t m1,type, t1,void **r1,size_t m2,type t2,void **r2,size_t m3,type t3,void **r3) 375 376 Level: developer 377 378 Notes: Memory of first chunk is always allocated at least double aligned 379 380 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3() 381 382 Concepts: memory allocation 383 384 M*/ 385 #if defined(PETSC_USE_DEBUG) 386 #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)) 387 #else 388 #define PetscMalloc3(m1,t1,r1,m2,t2,r2,m3,t3,r3) (PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3),r1) || (*(r2) = (t2*)(*(r1)+m1),*(r3) = (t3*)(*(r2)+m2),0)) 389 #endif 390 391 /*MC 392 PetscMalloc4 - Allocates 4 chunks of memory 393 394 Input Parameter: 395 + m1 - number of elements to allocate in 1st chunk (may be zero) 396 . t1 - type of first memory elements 397 . m2 - number of elements to allocate in 2nd chunk (may be zero) 398 . t2 - type of second memory elements 399 . m3 - number of elements to allocate in 3rd chunk (may be zero) 400 . t3 - type of third memory elements 401 . m4 - number of elements to allocate in 4th chunk (may be zero) 402 - t4 - type of fourth memory elements 403 404 Output Parameter: 405 + r1 - memory allocated in first chunk 406 . r2 - memory allocated in second chunk 407 . r3 - memory allocated in third chunk 408 - r4 - memory allocated in fourth chunk 409 410 Synopsis: 411 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) 412 413 Level: developer 414 415 Notes: Memory of first chunk is always allocated at least double aligned 416 417 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4() 418 419 Concepts: memory allocation 420 421 M*/ 422 #if defined(PETSC_USE_DEBUG) 423 #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)) 424 #else 425 #define PetscMalloc4(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4) (PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3)+(m4)*sizeof(t4),r1) || (*(r2) = (t2*)(*(r1)+m1),*(r3) = (t3*)(*(r2)+m2),*(r4) = (t4*)(*(r3)+m3),0)) 426 #endif 427 428 /*MC 429 PetscMalloc5 - Allocates 5 chunks of memory 430 431 Input Parameter: 432 + m1 - number of elements to allocate in 1st chunk (may be zero) 433 . t1 - type of first memory elements 434 . m2 - number of elements to allocate in 2nd chunk (may be zero) 435 . t2 - type of second memory elements 436 . m3 - number of elements to allocate in 3rd chunk (may be zero) 437 . t3 - type of third memory elements 438 . m4 - number of elements to allocate in 4th chunk (may be zero) 439 . t4 - type of fourth memory elements 440 . m5 - number of elements to allocate in 5th chunk (may be zero) 441 - t5 - type of fifth memory elements 442 443 Output Parameter: 444 + r1 - memory allocated in first chunk 445 . r2 - memory allocated in second chunk 446 . r3 - memory allocated in third chunk 447 . r4 - memory allocated in fourth chunk 448 - r5 - memory allocated in fifth chunk 449 450 Synopsis: 451 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) 452 453 Level: developer 454 455 Notes: Memory of first chunk is always allocated at least double aligned 456 457 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4(), PetscFree5() 458 459 Concepts: memory allocation 460 461 M*/ 462 #if defined(PETSC_USE_DEBUG) 463 #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)) 464 #else 465 #define PetscMalloc5(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4,m5,t5,r5) (PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3)+(m4)*sizeof(t4)+(m5)*sizeof(t5),r1) || (*(r2) = (t2*)(*(r1)+m1),*(r3) = (t3*)(*(r2)+m2),*(r4) = (t4*)(*(r3)+m3),*(r5) = (t5*)(*(r4)+m4),0)) 466 #endif 467 468 469 /*MC 470 PetscMalloc6 - Allocates 6 chunks of memory 471 472 Input Parameter: 473 + m1 - number of elements to allocate in 1st chunk (may be zero) 474 . t1 - type of first memory elements 475 . m2 - number of elements to allocate in 2nd chunk (may be zero) 476 . t2 - type of second memory elements 477 . m3 - number of elements to allocate in 3rd chunk (may be zero) 478 . t3 - type of third memory elements 479 . m4 - number of elements to allocate in 4th chunk (may be zero) 480 . t4 - type of fourth memory elements 481 . m5 - number of elements to allocate in 5th chunk (may be zero) 482 . t5 - type of fifth memory elements 483 . m6 - number of elements to allocate in 6th chunk (may be zero) 484 - t6 - type of sixth memory elements 485 486 Output Parameter: 487 + r1 - memory allocated in first chunk 488 . r2 - memory allocated in second chunk 489 . r3 - memory allocated in third chunk 490 . r4 - memory allocated in fourth chunk 491 . r5 - memory allocated in fifth chunk 492 - r6 - memory allocated in sixth chunk 493 494 Synopsis: 495 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) 496 497 Level: developer 498 499 Notes: Memory of first chunk is always allocated at least double aligned 500 501 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4(), PetscFree5(), PetscFree6() 502 503 Concepts: memory allocation 504 505 M*/ 506 #if defined(PETSC_USE_DEBUG) 507 #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)) 508 #else 509 #define PetscMalloc6(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4,m5,t5,r5,m6,t6,r6) (PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3)+(m4)*sizeof(t4)+(m5)*sizeof(t5)+(m6)*sizeof(t6),r1) || (*(r2) = (t2*)(*(r1)+m1),*(r3) = (t3*)(*(r2)+m2),*(r4) = (t4*)(*(r3)+m3),*(r5) = (t5*)(*(r4)+m4),*(r6) = (t6*)(*(r5)+m5),0)) 510 #endif 511 512 /*MC 513 PetscMalloc7 - Allocates 7 chunks of memory 514 515 Input Parameter: 516 + m1 - number of elements to allocate in 1st chunk (may be zero) 517 . t1 - type of first memory elements 518 . m2 - number of elements to allocate in 2nd chunk (may be zero) 519 . t2 - type of second memory elements 520 . m3 - number of elements to allocate in 3rd chunk (may be zero) 521 . t3 - type of third memory elements 522 . m4 - number of elements to allocate in 4th chunk (may be zero) 523 . t4 - type of fourth memory elements 524 . m5 - number of elements to allocate in 5th chunk (may be zero) 525 . t5 - type of fifth memory elements 526 . m6 - number of elements to allocate in 6th chunk (may be zero) 527 . t6 - type of sixth memory elements 528 . m7 - number of elements to allocate in 7th chunk (may be zero) 529 - t7 - type of sixth memory elements 530 531 Output Parameter: 532 + r1 - memory allocated in first chunk 533 . r2 - memory allocated in second chunk 534 . r3 - memory allocated in third chunk 535 . r4 - memory allocated in fourth chunk 536 . r5 - memory allocated in fifth chunk 537 . r6 - memory allocated in sixth chunk 538 - r7 - memory allocated in sixth chunk 539 540 Synopsis: 541 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) 542 543 Level: developer 544 545 Notes: Memory of first chunk is always allocated at least double aligned 546 547 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4(), PetscFree5(), PetscFree6(), PetscFree7() 548 549 Concepts: memory allocation 550 551 M*/ 552 #if defined(PETSC_USE_DEBUG) 553 #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)) 554 #else 555 #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)+(m2)*sizeof(t2)+(m3)*sizeof(t3)+(m4)*sizeof(t4)+(m5)*sizeof(t5)+(m6)*sizeof(t6)+(m7)*sizeof(t7),r1) || (*(r2) = (t2*)(*(r1)+m1),*(r3) = (t3*)(*(r2)+m2),*(r4) = (t4*)(*(r3)+m3),*(r5) = (t5*)(*(r4)+m4),*(r6) = (t6*)(*(r5)+m5),*(r7) = (t7*)(*(r6)+m6),0)) 556 #endif 557 558 /*MC 559 PetscNew - Allocates memory of a particular type, Zeros the memory! 560 561 Input Parameter: 562 . type - structure name of space to be allocated. Memory of size sizeof(type) is allocated 563 564 Output Parameter: 565 . result - memory allocated 566 567 Synopsis: 568 PetscErrorCode PetscNew(struct type,((type *))result) 569 570 Level: beginner 571 572 .seealso: PetscFree(), PetscMalloc() 573 574 Concepts: memory allocation 575 576 M*/ 577 #define PetscNew(A,b) (PetscMalloc(sizeof(A),(b)) || PetscMemzero(*(b),sizeof(A))) 578 579 /*MC 580 PetscFree - Frees memory 581 582 Input Parameter: 583 . memory - memory to free 584 585 Synopsis: 586 PetscErrorCode PetscFree(void *memory) 587 588 Level: beginner 589 590 Notes: Memory must have been obtained with PetscNew() or PetscMalloc() 591 592 .seealso: PetscNew(), PetscMalloc() 593 594 Concepts: memory allocation 595 596 M*/ 597 #define PetscFree(a) ((a) ? ((*PetscTrFree)((a),__LINE__,__FUNCT__,__FILE__,__SDIR__) || ((a = 0),0)) : 0) 598 599 /*MC 600 PetscFree2 - Frees 2 chunks of memory obtained with PetscMalloc2() 601 602 Input Parameter: 603 + memory1 - memory to free 604 - memory2 - 2nd memory to free 605 606 607 Synopsis: 608 PetscErrorCode PetscFree2(void *memory1,void *memory2) 609 610 Level: developer 611 612 Notes: Memory must have been obtained with PetscMalloc2() 613 614 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree() 615 616 Concepts: memory allocation 617 618 M*/ 619 #if defined(PETSC_USE_DEBUG) 620 #define PetscFree2(m1,m2) (PetscFree(m2) || PetscFree(m1)) 621 #else 622 #define PetscFree2(m1,m2) (PetscFree(m1)) 623 #endif 624 625 /*MC 626 PetscFree3 - Frees 3 chunks of memory obtained with PetscMalloc3() 627 628 Input Parameter: 629 + memory1 - memory to free 630 . memory2 - 2nd memory to free 631 - memory3 - 3rd memory to free 632 633 634 Synopsis: 635 PetscErrorCode PetscFree3(void *memory1,void *memory2,void *memory3) 636 637 Level: developer 638 639 Notes: Memory must have been obtained with PetscMalloc3() 640 641 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3() 642 643 Concepts: memory allocation 644 645 M*/ 646 #if defined(PETSC_USE_DEBUG) 647 #define PetscFree3(m1,m2,m3) (PetscFree(m3) || PetscFree(m2) || PetscFree(m1)) 648 #else 649 #define PetscFree3(m1,m2,m3) (PetscFree(m1)) 650 #endif 651 652 /*MC 653 PetscFree4 - Frees 4 chunks of memory obtained with PetscMalloc4() 654 655 Input Parameter: 656 + m1 - memory to free 657 . m2 - 2nd memory to free 658 . m3 - 3rd memory to free 659 - m4 - 4th memory to free 660 661 662 Synopsis: 663 PetscErrorCode PetscFree4(void *m1,void *m2,void *m3,void *m4) 664 665 Level: developer 666 667 Notes: Memory must have been obtained with PetscMalloc4() 668 669 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4() 670 671 Concepts: memory allocation 672 673 M*/ 674 #if defined(PETSC_USE_DEBUG) 675 #define PetscFree4(m1,m2,m3,m4) (PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1)) 676 #else 677 #define PetscFree4(m1,m2,m3,m4) (PetscFree(m1)) 678 #endif 679 680 /*MC 681 PetscFree5 - Frees 5 chunks of memory obtained with PetscMalloc5() 682 683 Input Parameter: 684 + m1 - memory to free 685 . m2 - 2nd memory to free 686 . m3 - 3rd memory to free 687 . m4 - 4th memory to free 688 - m5 - 5th memory to free 689 690 691 Synopsis: 692 PetscErrorCode PetscFree5(void *m1,void *m2,void *m3,void *m4,void *m5) 693 694 Level: developer 695 696 Notes: Memory must have been obtained with PetscMalloc5() 697 698 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5() 699 700 Concepts: memory allocation 701 702 M*/ 703 #if defined(PETSC_USE_DEBUG) 704 #define PetscFree5(m1,m2,m3,m4,m5) (PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1)) 705 #else 706 #define PetscFree5(m1,m2,m3,m4,m5) (PetscFree(m1)) 707 #endif 708 709 710 /*MC 711 PetscFree6 - Frees 6 chunks of memory obtained with PetscMalloc6() 712 713 Input Parameter: 714 + m1 - memory to free 715 . m2 - 2nd memory to free 716 . m3 - 3rd memory to free 717 . m4 - 4th memory to free 718 . m5 - 5th memory to free 719 - m6 - 6th memory to free 720 721 722 Synopsis: 723 PetscErrorCode PetscFree6(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6) 724 725 Level: developer 726 727 Notes: Memory must have been obtained with PetscMalloc6() 728 729 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5(), PetscMalloc6() 730 731 Concepts: memory allocation 732 733 M*/ 734 #if defined(PETSC_USE_DEBUG) 735 #define PetscFree6(m1,m2,m3,m4,m5,m6) (PetscFree(m6) || PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1)) 736 #else 737 #define PetscFree6(m1,m2,m3,m4,m5,m6) (PetscFree(m1)) 738 #endif 739 740 /*MC 741 PetscFree7 - Frees 7 chunks of memory obtained with PetscMalloc7() 742 743 Input Parameter: 744 + m1 - memory to free 745 . m2 - 2nd memory to free 746 . m3 - 3rd memory to free 747 . m4 - 4th memory to free 748 . m5 - 5th memory to free 749 . m6 - 6th memory to free 750 - m7 - 7th memory to free 751 752 753 Synopsis: 754 PetscErrorCode PetscFree7(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6,void *m7) 755 756 Level: developer 757 758 Notes: Memory must have been obtained with PetscMalloc6() 759 760 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5(), PetscMalloc6(), 761 PetscMalloc7() 762 763 Concepts: memory allocation 764 765 M*/ 766 #if defined(PETSC_USE_DEBUG) 767 #define PetscFree7(m1,m2,m3,m4,m5,m6,m7) (PetscFree(m7) || PetscFree(m6) || PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1)) 768 #else 769 #define PetscFree7(m1,m2,m3,m4,m5,m6,m7) (PetscFree(m1)) 770 #endif 771 772 EXTERN PETSC_DLLEXPORT PetscErrorCode (*PetscTrMalloc)(size_t,int,const char[],const char[],const char[],void**); 773 EXTERN PETSC_DLLEXPORT PetscErrorCode (*PetscTrFree)(void*,int,const char[],const char[],const char[]); 774 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSetMalloc(PetscErrorCode (*)(size_t,int,const char[],const char[],const char[],void**),PetscErrorCode (*)(void*,int,const char[],const char[],const char[])); 775 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscClearMalloc(void); 776 777 /* 778 Routines for tracing memory corruption/bleeding with default PETSc 779 memory allocation 780 */ 781 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMallocDump(FILE *); 782 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMallocDumpLog(FILE *); 783 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMallocGetCurrentUsage(PetscLogDouble *); 784 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMallocGetMaximumUsage(PetscLogDouble *); 785 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMallocDebug(PetscTruth); 786 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMallocValidate(int,const char[],const char[],const char[]); 787 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMallocSetDumpLog(void); 788 789 790 /* 791 Variable type where we stash PETSc object pointers in Fortran. 792 Assumes that sizeof(long) == sizeof(void*)which is true on 793 all machines that we know. 794 */ 795 #define PetscFortranAddr long 796 797 /*E 798 PetscDataType - Used for handling different basic data types. 799 800 Level: beginner 801 802 .seealso: PetscBinaryRead(), PetscBinaryWrite(), PetscDataTypeToMPIDataType(), 803 PetscDataTypeGetSize(), PetscDataTypeGetName() 804 805 E*/ 806 typedef enum {PETSC_INT = 0,PETSC_DOUBLE = 1,PETSC_COMPLEX = 2, 807 PETSC_LONG = 3 ,PETSC_SHORT = 4,PETSC_FLOAT = 5, 808 PETSC_CHAR = 6,PETSC_LOGICAL = 7} PetscDataType; 809 #if defined(PETSC_USE_COMPLEX) 810 #define PETSC_SCALAR PETSC_COMPLEX 811 #else 812 #if defined(PETSC_USE_SINGLE) 813 #define PETSC_SCALAR PETSC_FLOAT 814 #else 815 #define PETSC_SCALAR PETSC_DOUBLE 816 #endif 817 #endif 818 #if defined(PETSC_USE_SINGLE) 819 #define PETSC_REAL PETSC_FLOAT 820 #else 821 #define PETSC_REAL PETSC_DOUBLE 822 #endif 823 #define PETSC_FORTRANADDR PETSC_LONG 824 825 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDataTypeToMPIDataType(PetscDataType,MPI_Datatype*); 826 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDataTypeGetSize(PetscDataType,PetscInt*); 827 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDataTypeGetName(PetscDataType,const char*[]); 828 829 /* 830 Basic memory and string operations. These are usually simple wrappers 831 around the basic Unix system calls, but a few of them have additional 832 functionality and/or error checking. 833 */ 834 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemcpy(void*,const void *,size_t); 835 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscBitMemcpy(void*,PetscInt,const void*,PetscInt,PetscInt,PetscDataType); 836 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemmove(void*,void *,size_t); 837 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemzero(void*,size_t); 838 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemcmp(const void*,const void*,size_t,PetscTruth *); 839 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrlen(const char[],size_t*); 840 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrcmp(const char[],const char[],PetscTruth *); 841 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrgrt(const char[],const char[],PetscTruth *); 842 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrcasecmp(const char[],const char[],PetscTruth*); 843 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrncmp(const char[],const char[],size_t,PetscTruth*); 844 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrcpy(char[],const char[]); 845 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrcat(char[],const char[]); 846 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrncat(char[],const char[],size_t); 847 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrncpy(char[],const char[],size_t); 848 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrchr(const char[],char,char *[]); 849 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrtolower(char[]); 850 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrrchr(const char[],char,char *[]); 851 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrstr(const char[],const char[],char *[]); 852 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrallocpy(const char[],char *[]); 853 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStrreplace(MPI_Comm,const char[],char[],size_t); 854 #define PetscStrfree(a) ((a) ? PetscFree(a) : 0) 855 /*S 856 PetscToken - 'Token' used for managing tokenizing strings 857 858 Level: intermediate 859 860 .seealso: PetscTokenCreate(), PetscTokenFind(), PetscTokenDestroy() 861 S*/ 862 typedef struct {char token;char *array;char *current;} PetscToken; 863 864 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscTokenCreate(const char[],const char,PetscToken**); 865 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscTokenFind(PetscToken*,char *[]); 866 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscTokenDestroy(PetscToken*); 867 868 /* 869 These are MPI operations for MPI_Allreduce() etc 870 */ 871 EXTERN PETSC_DLLEXPORT MPI_Op PetscMaxSum_Op; 872 #if defined(PETSC_USE_COMPLEX) 873 EXTERN PETSC_DLLEXPORT MPI_Op PetscSum_Op; 874 #else 875 #define PetscSum_Op MPI_SUM 876 #endif 877 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMaxSum(MPI_Comm,const PetscInt[],PetscInt*,PetscInt*); 878 879 /*S 880 PetscObject - any PETSc object, PetscViewer, Mat, Vec, KSP etc 881 882 Level: beginner 883 884 Note: This is the base class from which all objects appear. 885 886 .seealso: PetscObjectDestroy(), PetscObjectView(), PetscObjectGetName(), PetscObjectSetName() 887 S*/ 888 typedef struct _p_PetscObject* PetscObject; 889 890 /*S 891 PetscFList - Linked list of functions, possibly stored in dynamic libraries, accessed 892 by string name 893 894 Level: advanced 895 896 .seealso: PetscFListAdd(), PetscFListDestroy() 897 S*/ 898 typedef struct _PetscFList *PetscFList; 899 900 #include "petscviewer.h" 901 #include "petscoptions.h" 902 903 /* 904 Routines that get memory usage information from the OS 905 */ 906 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemoryGetCurrentUsage(PetscLogDouble *); 907 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemoryGetMaximumUsage(PetscLogDouble *); 908 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemorySetGetMaximumUsage(void); 909 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemoryShowUsage(PetscViewer,const char[]); 910 911 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscLogInfoAllow(PetscTruth,const char []); 912 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetTime(PetscLogDouble*); 913 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetCPUTime(PetscLogDouble*); 914 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSleep(int); 915 916 /* 917 Initialization of PETSc 918 */ 919 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscInitialize(int*,char***,const char[],const char[]); 920 PetscPolymorphicSubroutine(PetscInitialize,(int *argc,char ***args),(argc,args,PETSC_NULL,PETSC_NULL)) 921 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscInitializeNoArguments(void); 922 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscInitialized(PetscTruth *); 923 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFinalized(PetscTruth *); 924 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFinalize(void); 925 EXTERN PetscErrorCode PetscInitializeFortran(void); 926 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetArgs(int*,char ***); 927 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscEnd(void); 928 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscInitializePackage(char *); 929 typedef void (**PetscVoidFunction)(void); 930 931 /* 932 PetscTryMethod - Queries an object for a method, if it exists then calls it. 933 These are intended to be used only inside PETSc functions. 934 */ 935 #define PetscTryMethod(obj,A,B,C) \ 936 0;{ PetscErrorCode (*f)B, __ierr; \ 937 __ierr = PetscObjectQueryFunction((PetscObject)obj,#A,(PetscVoidFunction)&f);CHKERRQ(__ierr); \ 938 if (f) {__ierr = (*f)C;CHKERRQ(__ierr);}\ 939 } 940 #define PetscUseMethod(obj,A,B,C) \ 941 0;{ PetscErrorCode (*f)B, __ierr; \ 942 __ierr = PetscObjectQueryFunction((PetscObject)obj,A,(PetscVoidFunction)&f);CHKERRQ(__ierr); \ 943 if (f) {__ierr = (*f)C;CHKERRQ(__ierr);}\ 944 else {SETERRQ1(PETSC_ERR_SUP,"Cannot locate function %s in object",A);} \ 945 } 946 /* 947 Functions that can act on any PETSc object. 948 */ 949 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectDestroy(PetscObject); 950 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectExists(PetscObject,PetscTruth*); 951 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetComm(PetscObject,MPI_Comm *); 952 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetCookie(PetscObject,int *); 953 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetType(PetscObject,int *); 954 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectSetName(PetscObject,const char[]); 955 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetName(PetscObject,char*[]); 956 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectReference(PetscObject); 957 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetReference(PetscObject,PetscInt*); 958 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectDereference(PetscObject); 959 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetNewTag(PetscObject,PetscMPIInt *); 960 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscCommGetNewTag(MPI_Comm,PetscMPIInt *); 961 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectView(PetscObject,PetscViewer); 962 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectCompose(PetscObject,const char[],PetscObject); 963 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectQuery(PetscObject,const char[],PetscObject *); 964 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectComposeFunction(PetscObject,const char[],const char[],void (*)(void)); 965 966 typedef void (*FCNVOID)(void); /* cast in next macro should never be extern C */ 967 typedef PetscErrorCode (*FCNINTVOID)(void); /* used in casts to make sure they are not extern C */ 968 /*MC 969 PetscObjectComposeFunctionDynamic - Associates a function with a given PETSc object. 970 971 Collective on PetscObject 972 973 Input Parameters: 974 + obj - the PETSc object; this must be cast with a (PetscObject), for example, 975 PetscObjectCompose((PetscObject)mat,...); 976 . name - name associated with the child function 977 . fname - name of the function 978 - ptr - function pointer (or PETSC_NULL if using dynamic libraries) 979 980 Level: advanced 981 982 Synopsis: 983 PetscErrorCode PetscObjectComposeFunctionDynamic(PetscObject obj,const char name[],const char fname[],void *ptr) 984 985 Notes: 986 To remove a registered routine, pass in a PETSC_NULL rname and fnc(). 987 988 PetscObjectComposeFunctionDynamic() can be used with any PETSc object (such as 989 Mat, Vec, KSP, SNES, etc.) or any user-provided object. 990 991 The composed function must be wrapped in a EXTERN_C_BEGIN/END for this to 992 work in C++/complex with dynamic link libraries (PETSC_USE_DYNAMIC_LIBRARIES) 993 enabled. 994 995 Concepts: objects^composing functions 996 Concepts: composing functions 997 Concepts: functions^querying 998 Concepts: objects^querying 999 Concepts: querying objects 1000 1001 .seealso: PetscObjectQueryFunction() 1002 M*/ 1003 #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 1004 #define PetscObjectComposeFunctionDynamic(a,b,c,d) PetscObjectComposeFunction(a,b,c,0) 1005 #else 1006 #define PetscObjectComposeFunctionDynamic(a,b,c,d) PetscObjectComposeFunction(a,b,c,(FCNVOID)(d)) 1007 #endif 1008 1009 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectQueryFunction(PetscObject,const char[],void (**)(void)); 1010 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectSetOptionsPrefix(PetscObject,const char[]); 1011 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectAppendOptionsPrefix(PetscObject,const char[]); 1012 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectPrependOptionsPrefix(PetscObject,const char[]); 1013 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetOptionsPrefix(PetscObject,char*[]); 1014 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectPublish(PetscObject); 1015 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectChangeTypeName(PetscObject,const char[]); 1016 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectRegisterDestroy(PetscObject); 1017 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectRegisterDestroyAll(void); 1018 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectName(PetscObject); 1019 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscTypeCompare(PetscObject,const char[],PetscTruth*); 1020 1021 /* 1022 Defines PETSc error handling. 1023 */ 1024 #include "petscerror.h" 1025 1026 /*S 1027 PetscOList - Linked list of PETSc objects, accessable by string name 1028 1029 Level: advanced 1030 1031 .seealso: PetscOListAdd(), PetscOListDestroy(), PetscOListFind() 1032 S*/ 1033 typedef struct _PetscOList *PetscOList; 1034 1035 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOListDestroy(PetscOList *); 1036 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOListFind(PetscOList,const char[],PetscObject*); 1037 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOListReverseFind(PetscOList,PetscObject,char**); 1038 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOListAdd(PetscOList *,const char[],PetscObject); 1039 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOListDuplicate(PetscOList,PetscOList *); 1040 1041 /* 1042 Dynamic library lists. Lists of names of routines in dynamic 1043 link libraries that will be loaded as needed. 1044 */ 1045 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListAdd(PetscFList*,const char[],const char[],void (*)(void)); 1046 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListDestroy(PetscFList*); 1047 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListFind(MPI_Comm,PetscFList,const char[],void (**)(void)); 1048 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListPrintTypes(MPI_Comm,FILE*,const char[],const char[],const char[],const char[],PetscFList); 1049 #if defined(PETSC_USE_DYNAMIC_LIBRARIES) 1050 #define PetscFListAddDynamic(a,b,p,c) PetscFListAdd(a,b,p,0) 1051 #else 1052 #define PetscFListAddDynamic(a,b,p,c) PetscFListAdd(a,b,p,(void (*)(void))c) 1053 #endif 1054 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListDuplicate(PetscFList,PetscFList *); 1055 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListView(PetscFList,PetscViewer); 1056 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListConcat(const char [],const char [],char []); 1057 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListGet(PetscFList,char ***,int*); 1058 1059 /*S 1060 PetscDLLibraryList - Linked list of dynamics libraries to search for functions 1061 1062 Level: advanced 1063 1064 PETSC_USE_DYNAMIC_LIBRARIES must be defined in petscconf.h to use dynamic libraries 1065 1066 .seealso: PetscDLLibraryOpen() 1067 S*/ 1068 typedef struct _PetscDLLibraryList *PetscDLLibraryList; 1069 extern PetscDLLibraryList DLLibrariesLoaded; 1070 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryRetrieve(MPI_Comm,const char[],char *,int,PetscTruth *); 1071 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryOpen(MPI_Comm,const char[],void **); 1072 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibrarySym(MPI_Comm,PetscDLLibraryList *,const char[],const char[],void **); 1073 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryAppend(MPI_Comm,PetscDLLibraryList *,const char[]); 1074 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryPrepend(MPI_Comm,PetscDLLibraryList *,const char[]); 1075 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryClose(PetscDLLibraryList); 1076 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryPrintPath(void); 1077 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryGetInfo(void*,const char[],const char *[]); 1078 1079 /* 1080 Mechanism for translating PETSc object representations between languages 1081 Not currently used. 1082 */ 1083 typedef enum {PETSC_LANGUAGE_C,PETSC_LANGUAGE_CXX} PetscLanguage; 1084 #define PETSC_LANGUAGE_F77 PETSC_LANGUAGE_C 1085 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectComposeLanguage(PetscObject,PetscLanguage,void *); 1086 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectQueryLanguage(PetscObject,PetscLanguage,void **); 1087 1088 /* 1089 Useful utility routines 1090 */ 1091 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSplitOwnership(MPI_Comm,PetscInt*,PetscInt*); 1092 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSplitOwnershipBlock(MPI_Comm,PetscInt,PetscInt*,PetscInt*); 1093 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSequentialPhaseBegin(MPI_Comm,PetscMPIInt); 1094 PetscPolymorphicSubroutine(PetscSequentialPhaseBegin,(MPI_Comm comm),(comm,1)) 1095 PetscPolymorphicSubroutine(PetscSequentialPhaseBegin,(void),(PETSC_COMM_WORLD,1)) 1096 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSequentialPhaseEnd(MPI_Comm,PetscMPIInt); 1097 PetscPolymorphicSubroutine(PetscSequentialPhaseEnd,(MPI_Comm comm),(comm,1)) 1098 PetscPolymorphicSubroutine(PetscSequentialPhaseEnd,(void),(PETSC_COMM_WORLD,1)) 1099 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscBarrier(PetscObject); 1100 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMPIDump(FILE*); 1101 1102 #define PetscNot(a) ((a) ? PETSC_FALSE : PETSC_TRUE) 1103 /* 1104 Defines basic graphics available from PETSc. 1105 */ 1106 #include "petscdraw.h" 1107 1108 /* 1109 Defines the base data structures for all PETSc objects 1110 */ 1111 #include "petschead.h" 1112 1113 /* 1114 Defines PETSc profiling. 1115 */ 1116 #include "petsclog.h" 1117 1118 /* 1119 For locking, unlocking and destroying AMS memories associated with 1120 PETSc objects. Not currently used. 1121 */ 1122 #define PetscPublishAll(v) 0 1123 #define PetscObjectTakeAccess(obj) 0 1124 #define PetscObjectGrantAccess(obj) 0 1125 #define PetscObjectDepublish(obj) 0 1126 1127 1128 1129 /* 1130 This code allows one to pass a MPI communicator between 1131 C and Fortran. MPI 2.0 defines a standard API for doing this. 1132 The code here is provided to allow PETSc to work with MPI 1.1 1133 standard MPI libraries. 1134 */ 1135 EXTERN PetscErrorCode MPICCommToFortranComm(MPI_Comm,int *); 1136 EXTERN PetscErrorCode MPIFortranCommToCComm(int,MPI_Comm*); 1137 1138 /* 1139 Simple PETSc parallel IO for ASCII printing 1140 */ 1141 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFixFilename(const char[],char[]); 1142 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFOpen(MPI_Comm,const char[],const char[],FILE**); 1143 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFClose(MPI_Comm,FILE*); 1144 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4); 1145 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscPrintf(MPI_Comm,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3); 1146 1147 /* These are used internally by PETSc ASCII IO routines*/ 1148 #include <stdarg.h> 1149 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscVSNPrintf(char*,size_t,const char*,va_list); 1150 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscVFPrintf(FILE*,const char*,va_list); 1151 1152 /*MC 1153 PetscErrorPrintf - Prints error messages. 1154 1155 Not Collective 1156 1157 Synopsis: 1158 PetscErrorCode (*PetscErrorPrintf)(const char format[],...); 1159 1160 Input Parameters: 1161 . format - the usual printf() format string 1162 1163 Options Database Keys: 1164 . -error_output_stderr - cause error messages to be printed to stderr instead of the 1165 (default) stdout 1166 1167 1168 Level: developer 1169 1170 Fortran Note: 1171 This routine is not supported in Fortran. 1172 1173 Concepts: error messages^printing 1174 Concepts: printing^error messages 1175 1176 .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf() 1177 M*/ 1178 EXTERN PETSC_DLLEXPORT PetscErrorCode (*PetscErrorPrintf)(const char[],...); 1179 1180 /*MC 1181 PetscHelpPrintf - Prints help messages. 1182 1183 Not Collective 1184 1185 Synopsis: 1186 PetscErrorCode (*PetscHelpPrintf)(const char format[],...); 1187 1188 Input Parameters: 1189 . format - the usual printf() format string 1190 1191 Level: developer 1192 1193 Fortran Note: 1194 This routine is not supported in Fortran. 1195 1196 Concepts: help messages^printing 1197 Concepts: printing^help messages 1198 1199 .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscErrorPrintf() 1200 M*/ 1201 EXTERN PETSC_DLLEXPORT PetscErrorCode (*PetscHelpPrintf)(MPI_Comm,const char[],...); 1202 1203 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscPOpen(MPI_Comm,const char[],const char[],const char[],FILE **); 1204 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscPClose(MPI_Comm,FILE*); 1205 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSynchronizedPrintf(MPI_Comm,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3); 1206 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSynchronizedFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4); 1207 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSynchronizedFlush(MPI_Comm); 1208 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSynchronizedFGets(MPI_Comm,FILE*,size_t,char[]); 1209 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStartMatlab(MPI_Comm,const char[],const char[],FILE**); 1210 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscStartJava(MPI_Comm,const char[],const char[],FILE**); 1211 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetPetscDir(const char*[]); 1212 1213 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscPopUpSelect(MPI_Comm,char*,char*,int,char**,int*); 1214 /*S 1215 PetscObjectContainer - Simple PETSc object that contains a pointer to any required data 1216 1217 Level: advanced 1218 1219 .seealso: PetscObject, PetscObjectContainerCreate() 1220 S*/ 1221 typedef struct _p_PetscObjectContainer* PetscObjectContainer; 1222 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectContainerGetPointer(PetscObjectContainer,void **); 1223 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectContainerSetPointer(PetscObjectContainer,void *); 1224 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectContainerDestroy(PetscObjectContainer); 1225 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectContainerCreate(MPI_Comm comm,PetscObjectContainer *); 1226 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectContainerSetUserDestroy(PetscObjectContainer, PetscErrorCode (*)(void*)); 1227 1228 /* 1229 For use in debuggers 1230 */ 1231 extern PETSC_DLLEXPORT PetscMPIInt PetscGlobalRank; 1232 extern PETSC_DLLEXPORT PetscMPIInt PetscGlobalSize; 1233 1234 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscIntView(PetscInt,PetscInt[],PetscViewer); 1235 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRealView(PetscInt,PetscReal[],PetscViewer); 1236 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscScalarView(PetscInt,PetscScalar[],PetscViewer); 1237 1238 /* 1239 Allows accessing Matlab Engine 1240 */ 1241 #include "petscmatlab.h" 1242 1243 /* 1244 C code optimization is often enhanced by telling the compiler 1245 that certain pointer arguments to functions are not aliased to 1246 to other arguments. This is not yet ANSI C standard so we define 1247 the macro "restrict" to indicate that the variable is not aliased 1248 to any other argument. 1249 */ 1250 #if defined(PETSC_HAVE_RESTRICT) && !defined(__cplusplus) 1251 #define restrict _Restrict 1252 #else 1253 #if defined(restrict) 1254 #undef restrict 1255 #endif 1256 #define restrict 1257 #endif 1258 1259 /* 1260 Determine if some of the kernel computation routines use 1261 Fortran (rather than C) for the numerical calculations. On some machines 1262 and compilers (like complex numbers) the Fortran version of the routines 1263 is faster than the C/C++ versions. The flag PETSC_USE_FORTRAN_KERNELS 1264 would be set in the petscconf.h file 1265 */ 1266 #if defined(PETSC_USE_FORTRAN_KERNELS) 1267 1268 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ) 1269 #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ 1270 #endif 1271 1272 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ) 1273 #define PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ 1274 #endif 1275 1276 #if !defined(PETSC_USE_FORTRAN_KERNEL_NORM) 1277 #define PETSC_USE_FORTRAN_KERNEL_NORM 1278 #endif 1279 1280 #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY) 1281 #define PETSC_USE_FORTRAN_KERNEL_MAXPY 1282 #endif 1283 1284 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ) 1285 #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ 1286 #endif 1287 1288 #if !defined(PETSC_USE_FORTRAN_KERNEL_RELAXAIJ) 1289 #define PETSC_USE_FORTRAN_KERNEL_RELAXAIJ 1290 #endif 1291 1292 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ) 1293 #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ 1294 #endif 1295 1296 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ) 1297 #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ 1298 #endif 1299 1300 #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT) 1301 #define PETSC_USE_FORTRAN_KERNEL_MDOT 1302 #endif 1303 1304 #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY) 1305 #define PETSC_USE_FORTRAN_KERNEL_XTIMESY 1306 #endif 1307 1308 #if !defined(PETSC_USE_FORTRAN_KERNEL_AYPX) 1309 #define PETSC_USE_FORTRAN_KERNEL_AYPX 1310 #endif 1311 1312 #if !defined(PETSC_USE_FORTRAN_KERNEL_WAXPY) 1313 #define PETSC_USE_FORTRAN_KERNEL_WAXPY 1314 #endif 1315 1316 #endif 1317 1318 /* 1319 Macros for indicating code that should be compiled with a C interface, 1320 rather than a C++ interface. Any routines that are dynamically loaded 1321 (such as the PCCreate_XXX() routines) must be wrapped so that the name 1322 mangler does not change the functions symbol name. This just hides the 1323 ugly extern "C" {} wrappers. 1324 */ 1325 #if defined(__cplusplus) 1326 #define EXTERN_C_BEGIN extern "C" { 1327 #define EXTERN_C_END } 1328 #else 1329 #define EXTERN_C_BEGIN 1330 #define EXTERN_C_END 1331 #endif 1332 1333 /* --------------------------------------------------------------------*/ 1334 1335 /*M 1336 size - integer variable used to contain the number of processors in 1337 the relevent MPI_Comm 1338 1339 Level: beginner 1340 1341 .seealso: rank, comm 1342 M*/ 1343 1344 /*M 1345 rank - integer variable used to contain the number of this processor relative 1346 to all in the relevent MPI_Comm 1347 1348 Level: beginner 1349 1350 .seealso: size, comm 1351 M*/ 1352 1353 /*M 1354 comm - MPI_Comm used in the current routine or object 1355 1356 Level: beginner 1357 1358 .seealso: size, rank 1359 M*/ 1360 1361 /*M 1362 MPI_Comm - the basic object used by MPI to determine which processes are involved in a 1363 communication 1364 1365 Level: beginner 1366 1367 Note: This manual page is a place-holder because MPICH does not have a manual page for MPI_Comm 1368 1369 .seealso: size, rank, comm, PETSC_COMM_WORLD, PETSC_COMM_SELF 1370 M*/ 1371 1372 /*M 1373 PetscScalar - PETSc type that represents either a double precision real number or 1374 a double precision complex number if the code is configured with --with-scalar-type=complex 1375 1376 Level: beginner 1377 1378 .seealso: PetscReal, PassiveReal, PassiveScalar 1379 M*/ 1380 1381 /*M 1382 PetscReal - PETSc type that represents a double precision real number 1383 1384 Level: beginner 1385 1386 .seealso: PetscScalar, PassiveReal, PassiveScalar 1387 M*/ 1388 1389 /*M 1390 PassiveScalar - PETSc type that represents either a double precision real number or 1391 a double precision complex number if the code is code is configured with --with-scalar-type=complex 1392 1393 Level: beginner 1394 1395 This is the same as a PetscScalar except in code that is automatically differentiated it is 1396 treated as a constant (not an indendent or dependent variable) 1397 1398 .seealso: PetscReal, PassiveReal, PetscScalar 1399 M*/ 1400 1401 /*M 1402 PassiveReal - PETSc type that represents a double precision real number 1403 1404 Level: beginner 1405 1406 This is the same as a PetscReal except in code that is automatically differentiated it is 1407 treated as a constant (not an indendent or dependent variable) 1408 1409 .seealso: PetscScalar, PetscReal, PassiveScalar 1410 M*/ 1411 1412 /*M 1413 MPIU_SCALAR - MPI datatype corresponding to PetscScalar 1414 1415 Level: beginner 1416 1417 Note: In MPI calls that require an MPI datatype that matches a PetscScalar or array of PetscScalars 1418 pass this value 1419 1420 .seealso: PetscReal, PassiveReal, PassiveScalar, PetscScalar 1421 M*/ 1422 1423 /* 1424 The IBM include files define hz, here we hide it so that it may be used 1425 as a regular user variable. 1426 */ 1427 #if defined(hz) 1428 #undef hz 1429 #endif 1430 1431 /* For arrays that contain filenames or paths */ 1432 1433 1434 #if defined(PETSC_HAVE_LIMITS_H) 1435 #include <limits.h> 1436 #endif 1437 #if defined(PETSC_HAVE_SYS_PARAM_H) 1438 #include <sys/param.h> 1439 #endif 1440 #if defined(PETSC_HAVE_SYS_TYPES_H) 1441 #include <sys/types.h> 1442 #endif 1443 #if defined(MAXPATHLEN) 1444 # define PETSC_MAX_PATH_LEN MAXPATHLEN 1445 #elif defined(MAX_PATH) 1446 # define PETSC_MAX_PATH_LEN MAX_PATH 1447 #elif defined(_MAX_PATH) 1448 # define PETSC_MAX_PATH_LEN _MAX_PATH 1449 #else 1450 # define PETSC_MAX_PATH_LEN 4096 1451 #endif 1452 1453 PETSC_EXTERN_CXX_END 1454 #endif 1455 1456 1457