Actual source code: petsc.h

  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: */
  7: /* ========================================================================== */
  8: /* 
  9:    petscconf.h is contained in bmake/${PETSC_ARCH}/petscconf.h it is 
 10:    found automatically by the compiler due to the -I${PETSC_DIR}/bmake/${PETSC_ARCH}
 11:    in the bmake/common/variables definition of PETSC_INCLUDE
 12: */
 13: #include "petscconf.h"

 15: /* ========================================================================== */
 16: /* 
 17:    This facilitates using C version of PETSc from C++ and 
 18:    C++ version from C. Use --with-c-support --with-clanguage=c++ with config/configure.py for the latter)
 19: */
 21: #error "PETSc configured with --with-clanguage=c++ and NOT --with-c-support - it can be used only with a C++ compiler"
 22: #endif      

 27: #else
 30: #endif
 31: /* ========================================================================== */
 32: /* 
 33:    Current PETSc version number and release date
 34: */
 35:  #include petscversion.h

 37: /*
 38:    Currently cannot check formatting for PETSc print statements because we have our
 39:    own format %D and %G
 40: */
 41: #undef  PETSC_PRINTF_FORMAT_CHECK
 42: #define PETSC_PRINTF_FORMAT_CHECK(a,b)
 43: #undef  PETSC_FPRINTF_FORMAT_CHECK
 44: #define PETSC_FPRINTF_FORMAT_CHECK(a,b)

 46: /*
 47:    Fixes for configure time choices which impact our interface. Currently only
 48:    calling conventions and extra compiler checking falls under this category.
 49: */
 50: #if !defined(PETSC_STDCALL)
 51: #define PETSC_STDCALL
 52: #endif
 53: #if !defined(PETSC_TEMPLATE)
 54: #define PETSC_TEMPLATE
 55: #endif
 56: #if !defined(PETSC_HAVE_DLL_EXPORT)
 57: #define PETSC_DLL_EXPORT
 58: #define PETSC_DLL_IMPORT
 59: #endif
 60: #if !defined()
 61: #define 
 62: #endif
 63: #if !defined()
 64: #define 
 65: #endif
 66: #if !defined()
 67: #define 
 68: #endif
 69: #if !defined()
 70: #define 
 71: #endif
 72: #if !defined()
 73: #define 
 74: #endif
 75: #if !defined()
 76: #define 
 77: #endif
 78: #if !defined()
 79: #define 
 80: #endif
 81: #if !defined()
 82: #define 
 83: #endif
 84: /* ========================================================================== */

 86: /*
 87:     Defines the interface to MPI allowing the use of all MPI functions.

 89:     PETSc does not use the C++ binding of MPI at ALL. The following flag
 90:     makes sure the C++ bindings are not included. The C++ bindings REQUIRE
 91:     putting mpi.h before ANY C++ include files, we cannot control this
 92:     with all PETSc users.
 93: */
 94: #define MPICH_SKIP_MPICXX 1
 95: #include "mpi.h"
 96: /*
 97:     Yuck, we need to put stdio.h AFTER mpi.h for MPICH2 with C++ compiler 
 98:     see the top of mpicxx.h

100:     The MPI STANDARD HAS TO BE CHANGED to prevent this nonsense.
101: */
102: #include <stdio.h>

104: /*MC
105:     PetscErrorCode - datatype used for return error code from all PETSc functions

107:     Level: beginner

109: .seealso: CHKERRQ, SETERRQ
110: M*/
111: typedef int PetscErrorCode;

113: /*MC

115:     PetscCookie - A unique id used to identify each PETSc object.
116:          (internal integer in the data structure used for error
117:          checking). These are all defined by an offset from the lowest
118:          one, PETSC_SMALLEST_COOKIE.

120:     Level: advanced
121: M*/
122: typedef int PetscCookie;

124: /*MC
125:     PetscEvent - id used to identify PETSc or user events - primarily for logging

127:     Level: intermediate

130: M*/
131: typedef int PetscEvent;

133: /*MC
134:     PetscBLASInt - datatype used to represent 'int' parameters to blas functions.

136:     Level: intermediate
137: M*/
138: typedef int PetscBLASInt;

140: /*MC
141:     PetscMPIInt - datatype used to represent 'int' parameters to MPI functions.

143:     Level: intermediate
144: M*/
145: typedef int PetscMPIInt;

147: /*MC
148:     PetscEnum - datatype used to pass enum types within PETSc functions.

150:     Level: intermediate

152: .seealso: PetscOptionsGetEnum, PetscOptionsEnum, PetscBagRegisterEnum
153: M*/
154: typedef enum { ENUM_DUMMY } PetscEnum;

156: /*MC
157:     PetscInt - PETSc type that represents integer - used primarily to
158:       represent size of objects. Its size can be configured with the option
159:       --with-64-bit-indices - to be either 32bit or 64bit [default 32 bit ints]

161:    Level: intermediate

163: .seealso: PetscScalar, VecSetSizes
164: M*/
165: #if defined(PETSC_USE_64BIT_INDICES)
166: typedef long long PetscInt;
167: #define MPIU_INT MPI_LONG_LONG_INT
168: #else
169: typedef int PetscInt;
170: #define MPIU_INT MPI_INT
171: #endif  

173: /*
174:       You can use PETSC_STDOUT as a replacement of stdout. You can also change
175:     the value of PETSC_STDOUT to redirect all standard output elsewhere
176: */

180: /*MC
181:       PetscPolymorphicSubroutine - allows defining a C++ polymorphic version of 
182:             a PETSc function that remove certain optional arguments for a simplier user interface

184:      Not collective

186:    Synopsis:
187:    PetscPolymorphicSubroutine(Functionname,(arguments of C++ function),(arguments of C function))
188:  
189:    Level: developer

191:     Example:
192:       PetscPolymorphicSubroutine(VecNorm,(Vec x,PetscReal *r),(x,NORM_2,r)) generates the new routine
193:            PetscErrorCode VecNorm(Vec x,PetscReal *r) = VecNorm(x,NORM_2,r)

195: .seealso: PetscPolymorphicFunction()

197: M*/
198: #define PetscPolymorphicSubroutine(A,B,C) PETSC_STATIC_INLINE PetscErrorCode A B {return A C;}

200: /*MC
201:       PetscPolymorphicScalar - allows defining a C++ polymorphic version of 
202:             a PETSc function that replaces a PetscScalar * argument with a PetscScalar argument

204:      Not collective

206:    Synopsis:
207:    PetscPolymorphicScalar(Functionname,(arguments of C++ function),(arguments of C function))
208:  
209:    Level: developer

211:     Example:
212:       PetscPolymorphicScalar(VecAXPY,(PetscScalar _val,Vec x,Vec y),(&_Val,x,y)) generates the new routine
213:            PetscErrorCode VecAXPY(PetscScalar _val,Vec x,Vec y) = {PetscScalar _Val = _val; return VecAXPY(&_Val,x,y);}

215: .seealso: PetscPolymorphicFunction(),PetscPolymorphicSubroutine()

217: M*/
218: #define PetscPolymorphicScalar(A,B,C) PETSC_STATIC_INLINE PetscErrorCode A B {PetscScalar _Val = _val; return A C;}

220: /*MC
221:       PetscPolymorphicFunction - allows defining a C++ polymorphic version of 
222:             a PETSc function that remove certain optional arguments for a simplier user interface
223:             and returns the computed value (istead of an error code)

225:      Not collective

227:    Synopsis:
228:    PetscPolymorphicFunction(Functionname,(arguments of C++ function),(arguments of C function),return type,return variable name)
229:  
230:    Level: developer

232:     Example:
233:       PetscPolymorphicFunction(VecNorm,(Vec x,NormType t),(x,t,&r),PetscReal,r) generates the new routine
234:          PetscReal VecNorm(Vec x,NormType t) = {PetscReal r; VecNorm(x,t,&r); return r;}

236: .seealso: PetscPolymorphicSubroutine()

238: M*/
239: #define PetscPolymorphicFunction(A,B,C,D,E) PETSC_STATIC_INLINE D A B {D E; A C;return E;}

241: #else
242: #define PetscPolymorphicSubroutine(A,B,C)
243: #define PetscPolymorphicScalar(A,B,C)
244: #define PetscPolymorphicFunction(A,B,C,D,E)
245: #endif

247: /*
248:     Extern indicates a PETSc function defined elsewhere
249: */
250: #if !defined(EXTERN)
251: #define EXTERN extern
252: #endif

254: /*
255:     Defines some elementary mathematics functions and constants.
256: */
257:  #include petscmath.h

259: /*
261: */


265: /*
266:        Basic PETSc constants
267: */

269: /*E
270:     PetscTruth - Logical variable. Actually an integer

272:    Level: beginner

274: E*/
275: typedef enum { PETSC_FALSE,PETSC_TRUE } PetscTruth;

278: /*MC
279:     PETSC_FALSE - False value of PetscTruth

281:     Level: beginner

283:     Note: Zero integer

285: .seealso: PetscTruth
286: M*/

288: /*MC
289:     PETSC_TRUE - True value of PetscTruth

291:     Level: beginner

293:     Note: Nonzero integer

295: .seealso: PetscTruth
296: M*/

298: /*MC
299:     PETSC_YES - Alias for PETSC_TRUE

301:     Level: beginner

303:     Note: Zero integer

305: .seealso: PetscTruth
306: M*/
307: #define PETSC_YES            PETSC_TRUE

309: /*MC
310:     PETSC_NO - Alias for PETSC_FALSE

312:     Level: beginner

314:     Note: Nonzero integer

316: .seealso: PetscTruth
317: M*/
318: #define PETSC_NO             PETSC_FALSE

320: /*MC
321:     PETSC_NULL - standard way of passing in a null or array or pointer

323:    Level: beginner

325:    Notes: accepted by many PETSc functions to not set a parameter and instead use
326:           some default

328:           This macro does not exist in Fortran; you must use PETSC_NULL_INTEGER, 
329:           PETSC_NULL_DOUBLE_PRECISION etc

331: .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_IGNORE, PETSC_DETERMINE

333: M*/
334: #define PETSC_NULL           0

336: /*MC
337:     PETSC_DECIDE - standard way of passing in integer or floating point parameter
338:        where you wish PETSc to use the default.

340:    Level: beginner

342: .seealso: PETSC_NULL, PETSC_DEFAULT, PETSC_IGNORE, PETSC_DETERMINE

344: M*/
345: #define PETSC_DECIDE         -1

347: /*MC
348:     PETSC_DEFAULT - standard way of passing in integer or floating point parameter
349:        where you wish PETSc to use the default.

351:    Level: beginner

353: .seealso: PETSC_DECIDE, PETSC_NULL, PETSC_IGNORE, PETSC_DETERMINE

355: M*/
356: #define PETSC_DEFAULT        -2


359: /*MC
360:     PETSC_IGNORE - same as PETSC_NULL, means PETSc will ignore this argument

362:    Level: beginner

364:    Notes: accepted by many PETSc functions to not set a parameter and instead use
365:           some default

367:           This macro does not exist in Fortran; you must use PETSC_NULL_INTEGER, 
368:           PETSC_NULL_DOUBLE_PRECISION etc

370: .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_NULL, PETSC_DETERMINE

372: M*/
373: #define PETSC_IGNORE         PETSC_NULL

375: /*MC
376:     PETSC_DETERMINE - standard way of passing in integer or floating point parameter
377:        where you wish PETSc to compute the required value.

379:    Level: beginner

381: .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_IGNORE, PETSC_NULL, VecSetSizes()

383: M*/
384: #define PETSC_DETERMINE      PETSC_DECIDE

386: /*MC
387:     PETSC_COMM_WORLD - the equivalent of the MPI_COMM_WORLD communicator which represents
388:            all the processs that PETSc knows about. 

390:    Level: beginner

392:    Notes: By default PETSC_COMM_WORLD and MPI_COMM_WORLD are identical unless you wish to 
393:           run PETSc on ONLY a subset of MPI_COMM_WORLD. In that case create your new (smaller)
394:           communicator, call it, say comm, and set PETSC_COMM_WORLD = comm BEFORE calling
395:           PetscInitialize()

397: .seealso: PETSC_COMM_SELF

399: M*/

402: /*MC
403:     PETSC_COMM_SELF - a duplicate of the MPI_COMM_SELF communicator which represents
404:            the current process

406:    Level: beginner

408:    Notes: PETSC_COMM_SELF and MPI_COMM_SELF are equivalent.

410: .seealso: PETSC_COMM_WORLD

412: M*/
413: #define PETSC_COMM_SELF MPI_COMM_SELF


418: EXTERN PetscErrorCode  PetscSetHelpVersionFunctions(PetscErrorCode (*)(MPI_Comm),PetscErrorCode (*)(MPI_Comm));
419: EXTERN PetscErrorCode  PetscCommDuplicate(MPI_Comm,MPI_Comm*,int*);
420: EXTERN PetscErrorCode  PetscCommDestroy(MPI_Comm*);

422: /*MC
423:    PetscMalloc - Allocates memory

425:    Input Parameter:
426: .  m - number of bytes to allocate

428:    Output Parameter:
429: .  result - memory allocated

431:    Synopsis:
432:    PetscErrorCode PetscMalloc(size_t m,void **result)

434:    Level: beginner

436:    Notes: Memory is always allocated at least double aligned

438:           If you request memory of zero size it will allocate no space and assign the pointer to 0; PetscFree() will 
439:           properly handle not freeing the null pointer.

441: .seealso: PetscFree(), PetscNew()

443:   Concepts: memory allocation

445: M*/
446: #define PetscMalloc(a,b)  ((a != 0) ? (*PetscTrMalloc)((a),__LINE__,__FUNCT__,__FILE__,__SDIR__,(void**)(b)) : (*(b) = 0,0) )

448: /*MC
449:    PetscMalloc2 - Allocates 2 chunks of  memory

451:    Input Parameter:
452: +  m1 - number of elements to allocate in 1st chunk  (may be zero)
453: .  t1 - type of first memory elements 
454: .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
455: -  t2 - type of second memory elements

457:    Output Parameter:
458: +  r1 - memory allocated in first chunk
459: -  r2 - memory allocated in second chunk

461:    Synopsis:
462:    PetscErrorCode PetscMalloc2(size_t m1,type, t1,void **r1,size_t m2,type t2,void **r2)

464:    Level: developer

466:    Notes: Memory of first chunk is always allocated at least double aligned

468: .seealso: PetscFree(), PetscNew(), PetscMalloc()

470:   Concepts: memory allocation

472: M*/
473: #if defined(PETSC_USE_DEBUG)
474: #define PetscMalloc2(m1,t1,r1,m2,t2,r2) (PetscMalloc((m1)*sizeof(t1),r1) || PetscMalloc((m2)*sizeof(t2),r2))
475: #else
476: #define PetscMalloc2(m1,t1,r1,m2,t2,r2) (PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2),r1) || (*(r2) = (t2*)(*(r1)+m1),0))
477: #endif

479: /*MC
480:    PetscMalloc3 - Allocates 3 chunks of  memory

482:    Input Parameter:
483: +  m1 - number of elements to allocate in 1st chunk  (may be zero)
484: .  t1 - type of first memory elements 
485: .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
486: .  t2 - type of second memory elements
487: .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
488: -  t3 - type of third memory elements

490:    Output Parameter:
491: +  r1 - memory allocated in first chunk
492: .  r2 - memory allocated in second chunk
493: -  r3 - memory allocated in third chunk

495:    Synopsis:
496:    PetscErrorCode PetscMalloc3(size_t m1,type, t1,void **r1,size_t m2,type t2,void **r2,size_t m3,type t3,void **r3)

498:    Level: developer

500:    Notes: Memory of first chunk is always allocated at least double aligned

502: .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3()

504:   Concepts: memory allocation

506: M*/
507: #if defined(PETSC_USE_DEBUG)
508: #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))
509: #else
510: #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))
511: #endif

513: /*MC
514:    PetscMalloc4 - Allocates 4 chunks of  memory

516:    Input Parameter:
517: +  m1 - number of elements to allocate in 1st chunk  (may be zero)
518: .  t1 - type of first memory elements 
519: .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
520: .  t2 - type of second memory elements
521: .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
522: .  t3 - type of third memory elements
523: .  m4 - number of elements to allocate in 4th chunk  (may be zero)
524: -  t4 - type of fourth memory elements

526:    Output Parameter:
527: +  r1 - memory allocated in first chunk
528: .  r2 - memory allocated in second chunk
529: .  r3 - memory allocated in third chunk
530: -  r4 - memory allocated in fourth chunk

532:    Synopsis:
533:    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)

535:    Level: developer

537:    Notes: Memory of first chunk is always allocated at least double aligned

539: .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4()

541:   Concepts: memory allocation

543: M*/
544: #if defined(PETSC_USE_DEBUG)
545: #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))
546: #else
547: #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))
548: #endif

550: /*MC
551:    PetscMalloc5 - Allocates 5 chunks of  memory

553:    Input Parameter:
554: +  m1 - number of elements to allocate in 1st chunk  (may be zero)
555: .  t1 - type of first memory elements 
556: .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
557: .  t2 - type of second memory elements
558: .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
559: .  t3 - type of third memory elements
560: .  m4 - number of elements to allocate in 4th chunk  (may be zero)
561: .  t4 - type of fourth memory elements
562: .  m5 - number of elements to allocate in 5th chunk  (may be zero)
563: -  t5 - type of fifth memory elements

565:    Output Parameter:
566: +  r1 - memory allocated in first chunk
567: .  r2 - memory allocated in second chunk
568: .  r3 - memory allocated in third chunk
569: .  r4 - memory allocated in fourth chunk
570: -  r5 - memory allocated in fifth chunk

572:    Synopsis:
573:    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)

575:    Level: developer

577:    Notes: Memory of first chunk is always allocated at least double aligned

579: .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4(), PetscFree5()

581:   Concepts: memory allocation

583: M*/
584: #if defined(PETSC_USE_DEBUG)
585: #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))
586: #else
587: #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))
588: #endif


591: /*MC
592:    PetscMalloc6 - Allocates 6 chunks of  memory

594:    Input Parameter:
595: +  m1 - number of elements to allocate in 1st chunk  (may be zero)
596: .  t1 - type of first memory elements 
597: .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
598: .  t2 - type of second memory elements
599: .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
600: .  t3 - type of third memory elements
601: .  m4 - number of elements to allocate in 4th chunk  (may be zero)
602: .  t4 - type of fourth memory elements
603: .  m5 - number of elements to allocate in 5th chunk  (may be zero)
604: .  t5 - type of fifth memory elements
605: .  m6 - number of elements to allocate in 6th chunk  (may be zero)
606: -  t6 - type of sixth memory elements

608:    Output Parameter:
609: +  r1 - memory allocated in first chunk
610: .  r2 - memory allocated in second chunk
611: .  r3 - memory allocated in third chunk
612: .  r4 - memory allocated in fourth chunk
613: .  r5 - memory allocated in fifth chunk
614: -  r6 - memory allocated in sixth chunk

616:    Synopsis:
617:    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)

619:    Level: developer

621:    Notes: Memory of first chunk is always allocated at least double aligned

623: .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4(), PetscFree5(), PetscFree6()

625:   Concepts: memory allocation

627: M*/
628: #if defined(PETSC_USE_DEBUG)
629: #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))
630: #else
631: #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))
632: #endif

634: /*MC
635:    PetscMalloc7 - Allocates 7 chunks of  memory

637:    Input Parameter:
638: +  m1 - number of elements to allocate in 1st chunk  (may be zero)
639: .  t1 - type of first memory elements 
640: .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
641: .  t2 - type of second memory elements
642: .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
643: .  t3 - type of third memory elements
644: .  m4 - number of elements to allocate in 4th chunk  (may be zero)
645: .  t4 - type of fourth memory elements
646: .  m5 - number of elements to allocate in 5th chunk  (may be zero)
647: .  t5 - type of fifth memory elements
648: .  m6 - number of elements to allocate in 6th chunk  (may be zero)
649: .  t6 - type of sixth memory elements
650: .  m7 - number of elements to allocate in 7th chunk  (may be zero)
651: -  t7 - type of sixth memory elements

653:    Output Parameter:
654: +  r1 - memory allocated in first chunk
655: .  r2 - memory allocated in second chunk
656: .  r3 - memory allocated in third chunk
657: .  r4 - memory allocated in fourth chunk
658: .  r5 - memory allocated in fifth chunk
659: .  r6 - memory allocated in sixth chunk
660: -  r7 - memory allocated in sixth chunk

662:    Synopsis:
663:    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)

665:    Level: developer

667:    Notes: Memory of first chunk is always allocated at least double aligned

669: .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4(), PetscFree5(), PetscFree6(), PetscFree7()

671:   Concepts: memory allocation

673: M*/
674: #if defined(PETSC_USE_DEBUG)
675: #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))
676: #else
677: #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))
678: #endif

680: /*MC
681:    PetscNew - Allocates memory of a particular type, zeros the memory!

683:    Input Parameter:
684: .  type - structure name of space to be allocated. Memory of size sizeof(type) is allocated

686:    Output Parameter:
687: .  result - memory allocated

689:    Synopsis:
690:    PetscErrorCode PetscNew(struct type,((type *))result)

692:    Level: beginner

694: .seealso: PetscFree(), PetscMalloc()

696:   Concepts: memory allocation

698: M*/
699: #define PetscNew(A,b)        (PetscMalloc(sizeof(A),(b)) || PetscMemzero(*(b),sizeof(A)))

701: /*MC
702:    PetscFree - Frees memory

704:    Input Parameter:
705: .   memory - memory to free (the pointer is ALWAYS set to 0 upon sucess)

707:    Synopsis:
708:    PetscErrorCode PetscFree(void *memory)

710:    Level: beginner

712:    Notes: Memory must have been obtained with PetscNew() or PetscMalloc()

714: .seealso: PetscNew(), PetscMalloc(), PetscFreeVoid()

716:   Concepts: memory allocation

718: M*/
719: #define PetscFree(a)   ((a) ? ((*PetscTrFree)((a),__LINE__,__FUNCT__,__FILE__,__SDIR__) || ((a = 0),0)) : 0)

721: /*MC
722:    PetscFreeVoid - Frees memory

724:    Input Parameter:
725: .   memory - memory to free

727:    Synopsis:
728:    void PetscFreeVoid(void *memory)

730:    Level: beginner

732:    Notes: This is different from PetscFree() in that no error code is returned

734: .seealso: PetscFree(), PetscNew(), PetscMalloc()

736:   Concepts: memory allocation

738: M*/
739: #define PetscFreeVoid(a) ((*PetscTrFree)((a),__LINE__,__FUNCT__,__FILE__,__SDIR__),(a) = 0)


742: /*MC
743:    PetscFree2 - Frees 2 chunks of memory obtained with PetscMalloc2()

745:    Input Parameter:
746: +   memory1 - memory to free
747: -   memory2 - 2nd memory to free


750:    Synopsis:
751:    PetscErrorCode PetscFree2(void *memory1,void *memory2)

753:    Level: developer

755:    Notes: Memory must have been obtained with PetscMalloc2()

757: .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree()

759:   Concepts: memory allocation

761: M*/
762: #if defined(PETSC_USE_DEBUG)
763: #define PetscFree2(m1,m2)   (PetscFree(m2) || PetscFree(m1))
764: #else
765: #define PetscFree2(m1,m2)   (PetscFree(m1))
766: #endif

768: /*MC
769:    PetscFree3 - Frees 3 chunks of memory obtained with PetscMalloc3()

771:    Input Parameter:
772: +   memory1 - memory to free
773: .   memory2 - 2nd memory to free
774: -   memory3 - 3rd memory to free


777:    Synopsis:
778:    PetscErrorCode PetscFree3(void *memory1,void *memory2,void *memory3)

780:    Level: developer

782:    Notes: Memory must have been obtained with PetscMalloc3()

784: .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3()

786:   Concepts: memory allocation

788: M*/
789: #if defined(PETSC_USE_DEBUG)
790: #define PetscFree3(m1,m2,m3)   (PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
791: #else
792: #define PetscFree3(m1,m2,m3)   (PetscFree(m1))
793: #endif

795: /*MC
796:    PetscFree4 - Frees 4 chunks of memory obtained with PetscMalloc4()

798:    Input Parameter:
799: +   m1 - memory to free
800: .   m2 - 2nd memory to free
801: .   m3 - 3rd memory to free
802: -   m4 - 4th memory to free


805:    Synopsis:
806:    PetscErrorCode PetscFree4(void *m1,void *m2,void *m3,void *m4)

808:    Level: developer

810:    Notes: Memory must have been obtained with PetscMalloc4()

812: .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4()

814:   Concepts: memory allocation

816: M*/
817: #if defined(PETSC_USE_DEBUG)
818: #define PetscFree4(m1,m2,m3,m4)   (PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
819: #else
820: #define PetscFree4(m1,m2,m3,m4)   (PetscFree(m1))
821: #endif

823: /*MC
824:    PetscFree5 - Frees 5 chunks of memory obtained with PetscMalloc5()

826:    Input Parameter:
827: +   m1 - memory to free
828: .   m2 - 2nd memory to free
829: .   m3 - 3rd memory to free
830: .   m4 - 4th memory to free
831: -   m5 - 5th memory to free


834:    Synopsis:
835:    PetscErrorCode PetscFree5(void *m1,void *m2,void *m3,void *m4,void *m5)

837:    Level: developer

839:    Notes: Memory must have been obtained with PetscMalloc5()

841: .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5()

843:   Concepts: memory allocation

845: M*/
846: #if defined(PETSC_USE_DEBUG)
847: #define PetscFree5(m1,m2,m3,m4,m5)   (PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
848: #else
849: #define PetscFree5(m1,m2,m3,m4,m5)   (PetscFree(m1))
850: #endif


853: /*MC
854:    PetscFree6 - Frees 6 chunks of memory obtained with PetscMalloc6()

856:    Input Parameter:
857: +   m1 - memory to free
858: .   m2 - 2nd memory to free
859: .   m3 - 3rd memory to free
860: .   m4 - 4th memory to free
861: .   m5 - 5th memory to free
862: -   m6 - 6th memory to free


865:    Synopsis:
866:    PetscErrorCode PetscFree6(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6)

868:    Level: developer

870:    Notes: Memory must have been obtained with PetscMalloc6()

872: .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5(), PetscMalloc6()

874:   Concepts: memory allocation

876: M*/
877: #if defined(PETSC_USE_DEBUG)
878: #define PetscFree6(m1,m2,m3,m4,m5,m6)   (PetscFree(m6) || PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
879: #else
880: #define PetscFree6(m1,m2,m3,m4,m5,m6)   (PetscFree(m1))
881: #endif

883: /*MC
884:    PetscFree7 - Frees 7 chunks of memory obtained with PetscMalloc7()

886:    Input Parameter:
887: +   m1 - memory to free
888: .   m2 - 2nd memory to free
889: .   m3 - 3rd memory to free
890: .   m4 - 4th memory to free
891: .   m5 - 5th memory to free
892: .   m6 - 6th memory to free
893: -   m7 - 7th memory to free


896:    Synopsis:
897:    PetscErrorCode PetscFree7(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6,void *m7)

899:    Level: developer

901:    Notes: Memory must have been obtained with PetscMalloc7()

903: .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5(), PetscMalloc6(),
904:           PetscMalloc7()

906:   Concepts: memory allocation

908: M*/
909: #if defined(PETSC_USE_DEBUG)
910: #define PetscFree7(m1,m2,m3,m4,m5,m6,m7)   (PetscFree(m7) || PetscFree(m6) || PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
911: #else
912: #define PetscFree7(m1,m2,m3,m4,m5,m6,m7)   (PetscFree(m1))
913: #endif

915: EXTERN  PetscErrorCode (*PetscTrMalloc)(size_t,int,const char[],const char[],const char[],void**);
916: EXTERN  PetscErrorCode (*PetscTrFree)(void*,int,const char[],const char[],const char[]);
917: EXTERN PetscErrorCode   PetscSetMalloc(PetscErrorCode (*)(size_t,int,const char[],const char[],const char[],void**),PetscErrorCode (*)(void*,int,const char[],const char[],const char[]));
918: EXTERN PetscErrorCode   PetscClearMalloc(void);

920: /*
921:    Routines for tracing memory corruption/bleeding with default PETSc 
922:    memory allocation
923: */
924: EXTERN PetscErrorCode    PetscMallocDump(FILE *);
925: EXTERN PetscErrorCode    PetscMallocDumpLog(FILE *);
926: EXTERN PetscErrorCode    PetscMallocGetCurrentUsage(PetscLogDouble *);
927: EXTERN PetscErrorCode    PetscMallocGetMaximumUsage(PetscLogDouble *);
928: EXTERN PetscErrorCode    PetscMallocDebug(PetscTruth);
929: EXTERN PetscErrorCode    PetscMallocValidate(int,const char[],const char[],const char[]);
930: EXTERN PetscErrorCode    PetscMallocSetDumpLog(void);


933: /*
934:     Variable type where we stash PETSc object pointers in Fortran.
935:     On most machines size(pointer) == sizeof(long) - except windows
936:     where its sizeof(long long)
937: */

939: #if (PETSC_SIZEOF_VOID_P) == (PETSC_SIZEOF_LONG)
940: #define PetscFortranAddr   long
941: #elif  (PETSC_SIZEOF_VOID_P) == (PETSC_SIZEOF_LONG_LONG)
942: #define PetscFortranAddr   long long
943: #else
944: #error "Unknown size for PetscFortranAddr! Send us a bugreport at petsc-maint@mcs.anl.gov"
945: #endif

947: /*E
948:     PetscDataType - Used for handling different basic data types.

950:    Level: beginner

952: .seealso: PetscBinaryRead(), PetscBinaryWrite(), PetscDataTypeToMPIDataType(),
953:           PetscDataTypeGetSize()

955: E*/
956: typedef enum {PETSC_INT = 0,PETSC_DOUBLE = 1,PETSC_COMPLEX = 2, PETSC_LONG = 3 ,PETSC_SHORT = 4,PETSC_FLOAT = 5,
957:               PETSC_CHAR = 6,PETSC_LOGICAL = 7,PETSC_ENUM = 8,PETSC_TRUTH=9, PETSC_LONG_DOUBLE = 10} PetscDataType;

960: #if defined(PETSC_USE_COMPLEX)
961: #define PETSC_SCALAR PETSC_COMPLEX
962: #else
963: #if defined(PETSC_USE_SINGLE)
964: #define PETSC_SCALAR PETSC_FLOAT
965: #elif defined(PETSC_USE_LONG_DOUBLE)
966: #define PETSC_SCALAR PETSC_LONG_DOUBLE
967: #elif defined(PETSC_USE_INT)
968: #define PETSC_SCALAR PETSC_INT
969: #else
970: #define PETSC_SCALAR PETSC_DOUBLE
971: #endif
972: #endif
973: #if defined(PETSC_USE_SINGLE)
974: #define PETSC_REAL PETSC_FLOAT
975: #elif defined(PETSC_USE_LONG_DOUBLE)
976: #define PETSC_REAL PETSC_LONG_DOUBLE
977: #elif defined(PETSC_USE_INT)
978: #define PETSC_REAL PETSC_INT
979: #else
980: #define PETSC_REAL PETSC_DOUBLE
981: #endif
982: #define PETSC_FORTRANADDR PETSC_LONG

984: EXTERN PetscErrorCode  PetscDataTypeToMPIDataType(PetscDataType,MPI_Datatype*);
985: EXTERN PetscErrorCode  PetscDataTypeGetSize(PetscDataType,PetscInt*);

987: /*
988:     Basic memory and string operations. These are usually simple wrappers
989:    around the basic Unix system calls, but a few of them have additional
990:    functionality and/or error checking.
991: */
992: EXTERN PetscErrorCode    PetscMemcpy(void*,const void *,size_t);
993: EXTERN PetscErrorCode    PetscBitMemcpy(void*,PetscInt,const void*,PetscInt,PetscInt,PetscDataType);
994: EXTERN PetscErrorCode    PetscMemmove(void*,void *,size_t);
995: EXTERN PetscErrorCode    PetscMemzero(void*,size_t);
996: EXTERN PetscErrorCode    PetscMemcmp(const void*,const void*,size_t,PetscTruth *);
997: EXTERN PetscErrorCode    PetscStrlen(const char[],size_t*);
998: EXTERN PetscErrorCode    PetscStrcmp(const char[],const char[],PetscTruth *);
999: EXTERN PetscErrorCode    PetscStrgrt(const char[],const char[],PetscTruth *);
1000: EXTERN PetscErrorCode    PetscStrcasecmp(const char[],const char[],PetscTruth*);
1001: EXTERN PetscErrorCode    PetscStrncmp(const char[],const char[],size_t,PetscTruth*);
1002: EXTERN PetscErrorCode    PetscStrcpy(char[],const char[]);
1003: EXTERN PetscErrorCode    PetscStrcat(char[],const char[]);
1004: EXTERN PetscErrorCode    PetscStrncat(char[],const char[],size_t);
1005: EXTERN PetscErrorCode    PetscStrncpy(char[],const char[],size_t);
1006: EXTERN PetscErrorCode    PetscStrchr(const char[],char,char *[]);
1007: EXTERN PetscErrorCode    PetscStrtolower(char[]);
1008: EXTERN PetscErrorCode    PetscStrrchr(const char[],char,char *[]);
1009: EXTERN PetscErrorCode    PetscStrstr(const char[],const char[],char *[]);
1010: EXTERN PetscErrorCode    PetscStrrstr(const char[],const char[],char *[]);
1011: EXTERN PetscErrorCode    PetscStrallocpy(const char[],char *[]);
1012: EXTERN PetscErrorCode    PetscStrreplace(MPI_Comm,const char[],char[],size_t);
1013: #define      PetscStrfree(a) ((a) ? PetscFree(a) : 0) 

1015: /*S
1016:     PetscToken - 'Token' used for managing tokenizing strings

1018:   Level: intermediate

1020: .seealso: PetscTokenCreate(), PetscTokenFind(), PetscTokenDestroy()
1021: S*/
1022: typedef struct {char token;char *array;char *current;} PetscToken;

1024: EXTERN PetscErrorCode    PetscTokenCreate(const char[],const char,PetscToken**);
1025: EXTERN PetscErrorCode    PetscTokenFind(PetscToken*,char *[]);
1026: EXTERN PetscErrorCode    PetscTokenDestroy(PetscToken*);

1028: /*
1029:    These are  MPI operations for MPI_Allreduce() etc
1030: */
1031: EXTERN  MPI_Op PetscMaxSum_Op;
1032: #if defined(PETSC_USE_COMPLEX)
1033: EXTERN  MPI_Op PetscSum_Op;
1034: #else
1035: #define PetscSum_Op MPI_SUM
1036: #endif
1037: EXTERN PetscErrorCode  PetscMaxSum(MPI_Comm,const PetscInt[],PetscInt*,PetscInt*);

1039: /*S
1040:      PetscObject - any PETSc object, PetscViewer, Mat, Vec, KSP etc

1042:    Level: beginner

1044:    Note: This is the base class from which all objects appear.

1046: .seealso:  PetscObjectDestroy(), PetscObjectView(), PetscObjectGetName(), PetscObjectSetName()
1047: S*/
1048: typedef struct _p_PetscObject* PetscObject;

1050: /*S
1051:      PetscFList - Linked list of functions, possibly stored in dynamic libraries, accessed
1052:       by string name

1054:    Level: advanced

1056: .seealso:  PetscFListAdd(), PetscFListDestroy()
1057: S*/
1058: typedef struct _n_PetscFList *PetscFList;

1060: /*E
1061:   PetscFileMode - Access mode for a file.

1063:   Level: beginner

1065:   FILE_MODE_READ - open a file at its beginning for reading

1067:   FILE_MODE_WRITE - open a file at its beginning for writing (will create if the file does not exist)

1069:   FILE_MODE_APPEND - open a file at end for writing

1071:   FILE_MODE_UPDATE - open a file for updating, meaning for reading and writing

1073:   FILE_MODE_APPEND_UPDATE - open a file for updating, meaning for reading and writing, at the end

1075: .seealso: PetscViewerFileSetMode()
1076: E*/
1077: typedef enum {FILE_MODE_READ, FILE_MODE_WRITE, FILE_MODE_APPEND, FILE_MODE_UPDATE, FILE_MODE_APPEND_UPDATE} PetscFileMode;

1079:  #include petscviewer.h
1080:  #include petscoptions.h

1082: #define PETSC_SMALLEST_COOKIE 1211211
1085: EXTERN PetscErrorCode  PetscCookieRegister(PetscCookie *);

1087: /*
1088:    Routines that get memory usage information from the OS
1089: */
1090: EXTERN PetscErrorCode  PetscMemoryGetCurrentUsage(PetscLogDouble *);
1091: EXTERN PetscErrorCode  PetscMemoryGetMaximumUsage(PetscLogDouble *);
1092: EXTERN PetscErrorCode  PetscMemorySetGetMaximumUsage(void);
1093: EXTERN PetscErrorCode  PetscMemoryShowUsage(PetscViewer,const char[]);

1095: EXTERN PetscErrorCode  PetscInfoAllow(PetscTruth,const char []);
1096: EXTERN PetscErrorCode  PetscGetTime(PetscLogDouble*);
1097: EXTERN PetscErrorCode  PetscGetCPUTime(PetscLogDouble*);
1098: EXTERN PetscErrorCode  PetscSleep(int);

1100: /*
1101:     Initialization of PETSc
1102: */
1103: EXTERN PetscErrorCode  PetscInitialize(int*,char***,const char[],const char[]);
1104: PetscPolymorphicSubroutine(PetscInitialize,(int *argc,char ***args),(argc,args,PETSC_NULL,PETSC_NULL))
1105: EXTERN PetscErrorCode  PetscInitializeNoArguments(void);
1106: EXTERN PetscErrorCode  PetscInitialized(PetscTruth *);
1107: EXTERN PetscErrorCode  PetscFinalized(PetscTruth *);
1108: EXTERN PetscErrorCode  PetscFinalize(void);
1109: EXTERN PetscErrorCode PetscInitializeFortran(void);
1110: EXTERN PetscErrorCode  PetscGetArgs(int*,char ***);
1111: EXTERN PetscErrorCode  PetscGetArguments(char ***args);
1112: EXTERN PetscErrorCode  PetscFreeArguments(char **args);

1114: EXTERN PetscErrorCode  PetscEnd(void);
1115: EXTERN PetscErrorCode  PetscInitializePackage(char *);

1117: EXTERN PetscErrorCode  PetscOpenMPMerge(PetscMPIInt);
1118: EXTERN PetscErrorCode  PetscOpenMPSpawn(PetscMPIInt);
1119: EXTERN PetscErrorCode  PetscOpenMPFinalize(void);
1120: EXTERN PetscErrorCode  PetscOpenMPRun(MPI_Comm,PetscErrorCode (*)(MPI_Comm,void *),void*);
1121: EXTERN PetscErrorCode  PetscOpenMPFree(MPI_Comm,void*);
1122: EXTERN PetscErrorCode  PetscOpenMPNew(MPI_Comm,size_t,void**);

1124: /*
1126:    function pointers. Since the regular C++ code expects its function pointers to be 
1127:    C++.
1128: */
1129: typedef void (**PetscVoidStarFunction)(void);
1130: typedef void (*PetscVoidFunction)(void);
1131: typedef PetscErrorCode (*PetscErrorCodeFunction)(void);

1133: /*
1134:    PetscTryMethod - Queries an object for a method, if it exists then calls it.
1135:               These are intended to be used only inside PETSc functions.
1136: */
1137: #define  PetscTryMethod(obj,A,B,C) \
1138:   0;{ PetscErrorCode (*f)B, __ierr; \
1139:     __PetscObjectQueryFunction((PetscObject)obj,#A,(PetscVoidStarFunction)&f);CHKERRQ(__ierr); \
1140:     if (f) {__(*f)C;CHKERRQ(__ierr);}\
1141:   }
1142: #define  PetscUseMethod(obj,A,B,C) \
1143:   0;{ PetscErrorCode (*f)B, __ierr; \
1144:     __PetscObjectQueryFunction((PetscObject)obj,A,(PetscVoidStarFunction)&f);CHKERRQ(__ierr); \
1145:     if (f) {__(*f)C;CHKERRQ(__ierr);}\
1146:     else {SETERRQ1(PETSC_ERR_SUP,"Cannot locate function %s in object",A);} \
1147:   }
1148: /*
1149:     Functions that can act on any PETSc object.
1150: */
1151: EXTERN PetscErrorCode  PetscObjectCreate(MPI_Comm,PetscObject*);
1152: EXTERN PetscErrorCode  PetscObjectCreateGeneric(MPI_Comm, PetscCookie, const char [], PetscObject *);
1153: EXTERN PetscErrorCode  PetscObjectDestroy(PetscObject);
1154: EXTERN PetscErrorCode  PetscObjectExists(PetscObject,PetscTruth*);
1155: EXTERN PetscErrorCode  PetscObjectGetComm(PetscObject,MPI_Comm *);
1156: EXTERN PetscErrorCode  PetscObjectGetCookie(PetscObject,int *);
1157: EXTERN PetscErrorCode  PetscObjectSetType(PetscObject,const char []);
1158: EXTERN PetscErrorCode  PetscObjectGetType(PetscObject,const char *[]);
1159: EXTERN PetscErrorCode  PetscObjectSetName(PetscObject,const char[]);
1160: EXTERN PetscErrorCode  PetscObjectGetName(PetscObject,const char*[]);
1161: EXTERN PetscErrorCode  PetscObjectReference(PetscObject);
1162: EXTERN PetscErrorCode  PetscObjectGetReference(PetscObject,PetscInt*);
1163: EXTERN PetscErrorCode  PetscObjectDereference(PetscObject);
1164: EXTERN PetscErrorCode  PetscObjectGetNewTag(PetscObject,PetscMPIInt *);
1165: EXTERN PetscErrorCode  PetscObjectView(PetscObject,PetscViewer);
1166: EXTERN PetscErrorCode  PetscObjectCompose(PetscObject,const char[],PetscObject);
1167: EXTERN PetscErrorCode  PetscObjectQuery(PetscObject,const char[],PetscObject *);
1168: EXTERN PetscErrorCode  PetscObjectComposeFunction(PetscObject,const char[],const char[],void (*)(void));
1169: EXTERN PetscErrorCode  PetscObjectSetFromOptions(PetscObject);
1170: EXTERN PetscErrorCode  PetscObjectSetUp(PetscObject);
1171: EXTERN PetscErrorCode  PetscCommGetNewTag(MPI_Comm,PetscMPIInt *);
1172: EXTERN PetscErrorCode  PetscCommSynchronizeTags(MPI_Comm);
1173: EXTERN PetscErrorCode  PetscCommCheckTags(MPI_Comm);

1175: /*MC
1176:    PetscObjectComposeFunctionDynamic - Associates a function with a given PETSc object. 
1177:                        
1178:    Collective on PetscObject

1180:    Input Parameters:
1181: +  obj - the PETSc object; this must be cast with a (PetscObject), for example, 
1182:          PetscObjectCompose((PetscObject)mat,...);
1183: .  name - name associated with the child function
1184: .  fname - name of the function
1185: -  ptr - function pointer (or PETSC_NULL if using dynamic libraries)

1187:    Level: advanced

1189:     Synopsis:
1190:     PetscErrorCode PetscObjectComposeFunctionDynamic(PetscObject obj,const char name[],const char fname[],void *ptr)

1192:    Notes:
1193:    To remove a registered routine, pass in a PETSC_NULL rname and fnc().

1195:    PetscObjectComposeFunctionDynamic() can be used with any PETSc object (such as
1196:    Mat, Vec, KSP, SNES, etc.) or any user-provided object. 

1199:    work in C++/complex with dynamic link libraries (config/configure.py options --with-shared --with-dynamic)
1200:    enabled.

1202:    Concepts: objects^composing functions
1203:    Concepts: composing functions
1204:    Concepts: functions^querying
1205:    Concepts: objects^querying
1206:    Concepts: querying objects

1208: .seealso: PetscObjectQueryFunction()
1209: M*/
1210: #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
1211: #define PetscObjectComposeFunctionDynamic(a,b,c,d) PetscObjectComposeFunction(a,b,c,0)
1212: #else
1213: #define PetscObjectComposeFunctionDynamic(a,b,c,d) PetscObjectComposeFunction(a,b,c,(PetscVoidFunction)(d))
1214: #endif

1216: EXTERN PetscErrorCode  PetscObjectQueryFunction(PetscObject,const char[],void (**)(void));
1217: EXTERN PetscErrorCode  PetscObjectSetOptionsPrefix(PetscObject,const char[]);
1218: EXTERN PetscErrorCode  PetscObjectAppendOptionsPrefix(PetscObject,const char[]);
1219: EXTERN PetscErrorCode  PetscObjectPrependOptionsPrefix(PetscObject,const char[]);
1220: EXTERN PetscErrorCode  PetscObjectGetOptionsPrefix(PetscObject,const char*[]);
1221: EXTERN PetscErrorCode  PetscObjectPublish(PetscObject);
1222: EXTERN PetscErrorCode  PetscObjectChangeTypeName(PetscObject,const char[]);
1223: EXTERN PetscErrorCode  PetscObjectRegisterDestroy(PetscObject);
1224: EXTERN PetscErrorCode  PetscObjectRegisterDestroyAll(void);
1225: EXTERN PetscErrorCode  PetscObjectName(PetscObject);
1226: EXTERN PetscErrorCode  PetscTypeCompare(PetscObject,const char[],PetscTruth*);

1228: /*
1229:     Defines PETSc error handling.
1230: */
1231:  #include petscerror.h

1233: /*S
1234:      PetscOList - Linked list of PETSc objects, accessable by string name

1236:    Level: advanced

1238: .seealso:  PetscOListAdd(), PetscOListDestroy(), PetscOListFind()
1239: S*/
1240: typedef struct _n_PetscOList *PetscOList;

1242: EXTERN PetscErrorCode  PetscOListDestroy(PetscOList *);
1243: EXTERN PetscErrorCode  PetscOListFind(PetscOList,const char[],PetscObject*);
1244: EXTERN PetscErrorCode  PetscOListReverseFind(PetscOList,PetscObject,char**);
1245: EXTERN PetscErrorCode  PetscOListAdd(PetscOList *,const char[],PetscObject);
1246: EXTERN PetscErrorCode  PetscOListDuplicate(PetscOList,PetscOList *);

1248: /*
1249:     Dynamic library lists. Lists of names of routines in dynamic 
1250:   link libraries that will be loaded as needed.
1251: */
1252: EXTERN PetscErrorCode  PetscFListAdd(PetscFList*,const char[],const char[],void (*)(void));
1253: EXTERN PetscErrorCode  PetscFListDestroy(PetscFList*);
1254: EXTERN PetscErrorCode  PetscFListFind(MPI_Comm,PetscFList,const char[],void (**)(void));
1255: EXTERN PetscErrorCode  PetscFListPrintTypes(MPI_Comm,FILE*,const char[],const char[],const char[],const char[],PetscFList);
1256: #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
1257: #define    PetscFListAddDynamic(a,b,p,c) PetscFListAdd(a,b,p,0)
1258: #else
1259: #define    PetscFListAddDynamic(a,b,p,c) PetscFListAdd(a,b,p,(void (*)(void))c)
1260: #endif
1261: EXTERN PetscErrorCode  PetscFListDuplicate(PetscFList,PetscFList *);
1262: EXTERN PetscErrorCode  PetscFListView(PetscFList,PetscViewer);
1263: EXTERN PetscErrorCode  PetscFListConcat(const char [],const char [],char []);
1264: EXTERN PetscErrorCode  PetscFListGet(PetscFList,char ***,int*);

1266: /*S
1267:      PetscDLLibraryList - Linked list of dynamics libraries to search for functions

1269:    Level: advanced

1271:    --with-shared --with-dynamic must be used with config/configure.py to use dynamic libraries

1273: .seealso:  PetscDLLibraryOpen()
1274: S*/
1275: typedef struct _n_PetscDLLibraryList *PetscDLLibraryList;
1277: EXTERN PetscErrorCode  PetscDLLibraryRetrieve(MPI_Comm,const char[],char *,int,PetscTruth *);
1278: EXTERN PetscErrorCode  PetscDLLibraryOpen(MPI_Comm,const char[],void **);
1279: EXTERN PetscErrorCode  PetscDLLibrarySym(MPI_Comm,PetscDLLibraryList *,const char[],const char[],void **);
1280: EXTERN PetscErrorCode  PetscDLLibraryAppend(MPI_Comm,PetscDLLibraryList *,const char[]);
1281: EXTERN PetscErrorCode  PetscDLLibraryPrepend(MPI_Comm,PetscDLLibraryList *,const char[]);
1282: EXTERN PetscErrorCode  PetscDLLibraryClose(PetscDLLibraryList);
1283: EXTERN PetscErrorCode  PetscDLLibraryPrintPath(void);
1284: EXTERN PetscErrorCode  PetscDLLibraryGetInfo(void*,const char[],const char *[]);
1285: EXTERN PetscErrorCode  PetscDLLibraryCCAAppend(MPI_Comm,PetscDLLibraryList *,const char[]);

1287: /*
1288:      Useful utility routines
1289: */
1290: EXTERN PetscErrorCode  PetscSplitOwnership(MPI_Comm,PetscInt*,PetscInt*);
1291: EXTERN PetscErrorCode  PetscSplitOwnershipBlock(MPI_Comm,PetscInt,PetscInt*,PetscInt*);
1292: EXTERN PetscErrorCode  PetscSequentialPhaseBegin(MPI_Comm,PetscMPIInt);
1293: PetscPolymorphicSubroutine(PetscSequentialPhaseBegin,(MPI_Comm comm),(comm,1))
1294: PetscPolymorphicSubroutine(PetscSequentialPhaseBegin,(void),(PETSC_COMM_WORLD,1))
1295: EXTERN PetscErrorCode  PetscSequentialPhaseEnd(MPI_Comm,PetscMPIInt);
1296: PetscPolymorphicSubroutine(PetscSequentialPhaseEnd,(MPI_Comm comm),(comm,1))
1297: PetscPolymorphicSubroutine(PetscSequentialPhaseEnd,(void),(PETSC_COMM_WORLD,1))
1298: EXTERN PetscErrorCode  PetscBarrier(PetscObject);
1299: EXTERN PetscErrorCode  PetscMPIDump(FILE*);

1301: #define PetscNot(a) ((a) ? PETSC_FALSE : PETSC_TRUE)
1302: /*
1303:     Defines basic graphics available from PETSc.
1304: */
1305:  #include petscdraw.h

1307: /*
1308:     Defines the base data structures for all PETSc objects
1309: */
1310:  #include private/petscimpl.h
1311: /*
1312:      Defines PETSc profiling.
1313: */
1314:  #include petsclog.h

1316: /*
1317:           For locking, unlocking and destroying AMS memories associated with 
1318:     PETSc objects. Not currently used.
1319: */
1320: #define PetscPublishAll(v)           0
1321: #define PetscObjectTakeAccess(obj)   0
1322: #define PetscObjectGrantAccess(obj)  0
1323: #define PetscObjectDepublish(obj)    0



1327: /*
1328:       This code allows one to pass a MPI communicator between 
1329:     C and Fortran. MPI 2.0 defines a standard API for doing this.
1330:     The code here is provided to allow PETSc to work with MPI 1.1
1331:     standard MPI libraries.
1332: */
1333: EXTERN PetscErrorCode MPICCommToFortranComm(MPI_Comm,int *);
1334: EXTERN PetscErrorCode MPIFortranCommToCComm(int,MPI_Comm*);

1336: /*
1337:       Simple PETSc parallel IO for ASCII printing
1338: */
1339: EXTERN PetscErrorCode   PetscFixFilename(const char[],char[]);
1340: EXTERN PetscErrorCode   PetscFOpen(MPI_Comm,const char[],const char[],FILE**);
1341: EXTERN PetscErrorCode   PetscFClose(MPI_Comm,FILE*);
1342: EXTERN PetscErrorCode   PetscFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4);
1343: EXTERN PetscErrorCode   PetscPrintf(MPI_Comm,const char[],...)  PETSC_PRINTF_FORMAT_CHECK(2,3);
1344: EXTERN PetscErrorCode   PetscSNPrintf(char*,size_t,const char [],...);

1346: /* These are used internally by PETSc ASCII IO routines*/
1347: #include <stdarg.h>
1348: EXTERN PetscErrorCode   PetscVSNPrintf(char*,size_t,const char[],va_list);
1349: EXTERN PetscErrorCode   PetscVFPrintf(FILE*,const char[],va_list);

1351: /*MC
1352:     PetscErrorPrintf - Prints error messages.

1354:     Not Collective

1356:    Synopsis:
1357:      PetscErrorCode (*PetscErrorPrintf)(const char format[],...);

1359:     Input Parameters:
1360: .   format - the usual printf() format string 

1362:    Options Database Keys:
1363: .    -error_output_stderr - cause error messages to be printed to stderr instead of the
1364:          (default) stdout


1367:    Level: developer

1369:     Fortran Note:
1370:     This routine is not supported in Fortran.

1372:     Concepts: error messages^printing
1373:     Concepts: printing^error messages

1375: .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf()
1376: M*/
1377: EXTERN  PetscErrorCode (*PetscErrorPrintf)(const char[],...);

1379: /*MC
1380:     PetscHelpPrintf - Prints help messages.

1382:     Not Collective

1384:    Synopsis:
1385:      PetscErrorCode (*PetscHelpPrintf)(const char format[],...);

1387:     Input Parameters:
1388: .   format - the usual printf() format string 

1390:    Level: developer

1392:     Fortran Note:
1393:     This routine is not supported in Fortran.

1395:     Concepts: help messages^printing
1396:     Concepts: printing^help messages

1398: .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscErrorPrintf()
1399: M*/
1400: EXTERN  PetscErrorCode  (*PetscHelpPrintf)(MPI_Comm,const char[],...);

1402: EXTERN PetscErrorCode   PetscPOpen(MPI_Comm,const char[],const char[],const char[],FILE **);
1403: EXTERN PetscErrorCode   PetscPClose(MPI_Comm,FILE*);
1404: EXTERN PetscErrorCode   PetscSynchronizedPrintf(MPI_Comm,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3);
1405: EXTERN PetscErrorCode   PetscSynchronizedFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4);
1406: EXTERN PetscErrorCode   PetscSynchronizedFlush(MPI_Comm);
1407: EXTERN PetscErrorCode   PetscSynchronizedFGets(MPI_Comm,FILE*,size_t,char[]);
1408: EXTERN PetscErrorCode   PetscStartMatlab(MPI_Comm,const char[],const char[],FILE**);
1409: EXTERN PetscErrorCode   PetscStartJava(MPI_Comm,const char[],const char[],FILE**);
1410: EXTERN PetscErrorCode   PetscGetPetscDir(const char*[]);

1412: EXTERN PetscErrorCode   PetscPopUpSelect(MPI_Comm,char*,char*,int,char**,int*);

1414: /*S
1415:      PetscContainer - Simple PETSc object that contains a pointer to any required data

1417:    Level: advanced

1419: .seealso:  PetscObject, PetscContainerCreate()
1420: S*/
1422: typedef struct _p_PetscContainer*  PetscContainer;
1423: EXTERN PetscErrorCode  PetscContainerGetPointer(PetscContainer,void **);
1424: EXTERN PetscErrorCode  PetscContainerSetPointer(PetscContainer,void *);
1425: EXTERN PetscErrorCode  PetscContainerDestroy(PetscContainer);
1426: EXTERN PetscErrorCode  PetscContainerCreate(MPI_Comm comm,PetscContainer *);
1427: EXTERN PetscErrorCode  PetscContainerSetUserDestroy(PetscContainer, PetscErrorCode (*)(void*));

1429: /*
1430:    For use in debuggers 
1431: */

1435: EXTERN PetscErrorCode  PetscIntView(PetscInt,PetscInt[],PetscViewer);
1436: EXTERN PetscErrorCode  PetscRealView(PetscInt,PetscReal[],PetscViewer);
1437: EXTERN PetscErrorCode  PetscScalarView(PetscInt,PetscScalar[],PetscViewer);

1439: /*
1440:     Allows accessing Matlab Engine
1441: */
1442:  #include petscmatlab.h

1444: /*
1445:       Determine if some of the kernel computation routines use
1446:    Fortran (rather than C) for the numerical calculations. On some machines
1447:    and compilers (like complex numbers) the Fortran version of the routines
1448:    is faster than the C/C++ versions. The flag --with-fortran-kernels
1449:    should be used with config/configure.py to turn these on.
1450: */
1451: #if defined(PETSC_USE_FORTRAN_KERNELS)

1453: #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTCRL)
1454: #define PETSC_USE_FORTRAN_KERNEL_MULTCRL
1455: #endif

1457: #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTCSRPERM)
1458: #define PETSC_USE_FORTRAN_KERNEL_MULTCSRPERM
1459: #endif

1461: #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ)
1462: #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ
1463: #endif

1465: #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ)
1466: #define PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ
1467: #endif

1469: #if !defined(PETSC_USE_FORTRAN_KERNEL_NORM)
1470: #define PETSC_USE_FORTRAN_KERNEL_NORM
1471: #endif

1473: #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY)
1474: #define PETSC_USE_FORTRAN_KERNEL_MAXPY
1475: #endif

1477: #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ)
1478: #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ
1479: #endif

1481: #if !defined(PETSC_USE_FORTRAN_KERNEL_RELAXAIJ)
1482: #define PETSC_USE_FORTRAN_KERNEL_RELAXAIJ
1483: #endif

1485: #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ)
1486: #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ
1487: #endif

1489: #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ)
1490: #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ
1491: #endif

1493: #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT)
1494: #define PETSC_USE_FORTRAN_KERNEL_MDOT
1495: #endif

1497: #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY)
1498: #define PETSC_USE_FORTRAN_KERNEL_XTIMESY
1499: #endif

1501: #if !defined(PETSC_USE_FORTRAN_KERNEL_AYPX)
1502: #define PETSC_USE_FORTRAN_KERNEL_AYPX
1503: #endif

1505: #if !defined(PETSC_USE_FORTRAN_KERNEL_WAXPY)
1506: #define PETSC_USE_FORTRAN_KERNEL_WAXPY
1507: #endif

1509: #endif

1511: /*
1512:     Macros for indicating code that should be compiled with a C interface,
1513:    rather than a C++ interface. Any routines that are dynamically loaded
1514:    (such as the PCCreate_XXX() routines) must be wrapped so that the name
1515:    mangler does not change the functions symbol name. This just hides the 
1517: */
1518: #if defined(__cplusplus)
1521: #else
1524: #endif

1526: /* --------------------------------------------------------------------*/

1528: /*MC
1529:     size - integer variable used to contain the number of processors in
1530:            the relevent MPI_Comm

1532:    Level: beginner

1534: .seealso: rank, comm
1535: M*/

1537: /*MC
1538:     rank - integer variable used to contain the number of this processor relative
1539:            to all in the relevent MPI_Comm

1541:    Level: beginner

1543: .seealso: size, comm
1544: M*/

1546: /*MC
1547:     comm - MPI_Comm used in the current routine or object

1549:    Level: beginner

1551: .seealso: size, rank
1552: M*/

1554: /*MC
1555:     MPI_Comm - the basic object used by MPI to determine which processes are involved in a 
1556:         communication

1558:    Level: beginner

1560:    Note: This manual page is a place-holder because MPICH does not have a manual page for MPI_Comm

1562: .seealso: size, rank, comm, PETSC_COMM_WORLD, PETSC_COMM_SELF
1563: M*/

1565: /*MC
1566:     PetscScalar - PETSc type that represents either a double precision real number,  
1567:        a double precision complex number, a single precision real number, a long double or an int
1568:        if the code is configured with --with-scalar-type=complex,float,longdouble,int

1570:    Level: beginner

1572: .seealso: PetscReal, PassiveReal, PassiveScalar
1573: M*/

1575: /*MC
1576:     PetscReal - PETSc type that represents a real number version of PetscScalar

1578:    Level: beginner

1580: .seealso: PetscScalar, PassiveReal, PassiveScalar
1581: M*/

1583: /*MC
1584:     PassiveScalar - PETSc type that represents a PetscScalar
1585:    Level: beginner

1587:     This is the same as a PetscScalar except in code that is automatically differentiated it is
1588:    treated as a constant (not an indendent or dependent variable)

1590: .seealso: PetscReal, PassiveReal, PetscScalar
1591: M*/

1593: /*MC
1594:     PassiveReal - PETSc type that represents a PetscReal

1596:    Level: beginner

1598:     This is the same as a PetscReal except in code that is automatically differentiated it is
1599:    treated as a constant (not an indendent or dependent variable)

1601: .seealso: PetscScalar, PetscReal, PassiveScalar
1602: M*/

1604: /*MC
1605:     MPIU_SCALAR - MPI datatype corresponding to PetscScalar

1607:    Level: beginner

1609:     Note: In MPI calls that require an MPI datatype that matches a PetscScalar or array of PetscScalars
1610:           pass this value

1612: .seealso: PetscReal, PassiveReal, PassiveScalar, PetscScalar
1613: M*/

1615: /*
1616:      The IBM include files define hz, here we hide it so that it may be used
1617:    as a regular user variable.
1618: */
1619: #if defined(hz)
1620: #undef hz
1621: #endif

1623: /*  For arrays that contain filenames or paths */


1626: #if defined(PETSC_HAVE_LIMITS_H)
1627: #include <limits.h>
1628: #endif
1629: #if defined(PETSC_HAVE_SYS_PARAM_H)
1630: #include <sys/param.h>
1631: #endif
1632: #if defined(PETSC_HAVE_SYS_TYPES_H)
1633: #include <sys/types.h>
1634: #endif
1635: #if defined(MAXPATHLEN)
1636: #  define PETSC_MAX_PATH_LEN     MAXPATHLEN
1637: #elif defined(MAX_PATH)
1638: #  define PETSC_MAX_PATH_LEN     MAX_PATH
1639: #elif defined(_MAX_PATH)
1640: #  define PETSC_MAX_PATH_LEN     _MAX_PATH
1641: #else
1642: #  define PETSC_MAX_PATH_LEN     4096
1643: #endif

1646: #endif