Actual source code: petscsys.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 ${PETSC_ARCH}/include/petscconf.h it is 
 10:    found automatically by the compiler due to the -I${PETSC_DIR}/${PETSC_ARCH}/include
 11:    in the conf/variables definition of PETSC_INCLUDE
 12: */
 13: #include "petscconf.h"
 14: #include "petscfix.h"

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

 28: #else
 31: #endif
 32: /* ========================================================================== */
 33: /* 
 34:    Current PETSc version number and release date. Also listed in
 35:     Web page
 36:     src/docs/tex/manual/intro.tex,
 37:     src/docs/tex/manual/manual.tex.
 38:     src/docs/website/index.html.
 39: */
 40:  #include petscversion.h
 41: #define PETSC_AUTHOR_INFO        "\
 42:        The PETSc Team\n\
 43:     petsc-maint@mcs.anl.gov\n\
 44:  http://www.mcs.anl.gov/petsc/\n"
 45: #if (PETSC_VERSION_RELEASE == 1)
 46: #define PetscGetVersion(version,len) (PetscSNPrintf(version,len,"Petsc Release Version %d.%d.%d, Patch %d, ", \
 47:                                          PETSC_VERSION_MAJOR,PETSC_VERSION_MINOR, PETSC_VERSION_SUBMINOR, \
 48:                                          PETSC_VERSION_PATCH),PetscStrcat(version,PETSC_VERSION_PATCH_DATE))
 49: #else
 50: #define PetscGetVersion(version,len) (PetscSNPrintf(version,len,"Petsc Development"), \
 51:                                          PetscStrcat(version," HG revision: "),PetscStrcat(version,PETSC_VERSION_HG), \
 52:                                          PetscStrcat(version," HG Date: "),PetscStrcat(version,PETSC_VERSION_DATE_HG))
 53: #endif

 55: /*MC
 56:     PetscGetVersion - Gets the PETSc version information in a string.

 58:     Input Parameter:
 59: .   len - length of the string

 61:     Output Parameter:
 62: .   version - version string

 64:     Level: developer

 66:     Usage:
 67:     char version[256];
 68:     PetscGetVersion(version,256);CHKERRQ(ierr)

 70:     Fortran Note:
 71:     This routine is not supported in Fortran.

 73: .seealso: PetscGetProgramName()

 75: M*/

 77: /* ========================================================================== */

 79: /*
 80:    Currently cannot check formatting for PETSc print statements because we have our
 81:    own format %D and %G
 82: */
 83: #undef  PETSC_PRINTF_FORMAT_CHECK
 84: #define PETSC_PRINTF_FORMAT_CHECK(a,b)
 85: #undef  PETSC_FPRINTF_FORMAT_CHECK
 86: #define PETSC_FPRINTF_FORMAT_CHECK(a,b)

 88: /*
 89:    Fixes for config/configure.py time choices which impact our interface. Currently only
 90:    calling conventions and extra compiler checking falls under this category.
 91: */
 92: #if !defined(PETSC_STDCALL)
 93: #define PETSC_STDCALL
 94: #endif
 95: #if !defined(PETSC_TEMPLATE)
 96: #define PETSC_TEMPLATE
 97: #endif
 98: #if !defined(PETSC_HAVE_DLL_EXPORT)
 99: #define PETSC_DLL_EXPORT
100: #define PETSC_DLL_IMPORT
101: #endif
102: #if !defined()
103: #define 
104: #endif
105: #if !defined()
106: #define 
107: #endif
108: #if !defined()
109: #define 
110: #endif
111: #if !defined()
112: #define 
113: #endif
114: #if !defined()
115: #define 
116: #endif
117: #if !defined()
118: #define 
119: #endif
120: #if !defined()
121: #define 
122: #endif
123: #if !defined()
124: #define 
125: #endif
126: /* ========================================================================== */

128: /*
129:     Defines the interface to MPI allowing the use of all MPI functions.

131:     PETSc does not use the C++ binding of MPI at ALL. The following flag
132:     makes sure the C++ bindings are not included. The C++ bindings REQUIRE
133:     putting mpi.h before ANY C++ include files, we cannot control this
134:     with all PETSc users. Users who want to use the MPI C++ bindings can include 
135:     mpicxx.h directly in their code
136: */
137: #define MPICH_SKIP_MPICXX 1
138: #define OMPI_SKIP_MPICXX 1
139: #include "mpi.h"

141: /*
142:     Yuck, we need to put stdio.h AFTER mpi.h for MPICH2 with C++ compiler 
143:     see the top of mpicxx.h in the MPICH2 distribution.

145:     The MPI STANDARD HAS TO BE CHANGED to prevent this nonsense.
146: */
147: #include <stdio.h>

149: /* MSMPI on 32bit windows requires this yukky hack - that breaks MPI standard compliance */
150: #if !defined(MPIAPI)
151: #define MPIAPI
152: #endif

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

157:     Level: beginner

159: .seealso: CHKERRQ, SETERRQ
160: M*/
161: typedef int PetscErrorCode;

163: /*MC

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

170:     Level: advanced

172: .seealso: PetscCookieRegister(), PetscLogEventRegister(), PetscHeaderCreate()
173: M*/
174: typedef int PetscCookie;

176: /*MC
177:     PetscLogEvent - id used to identify PETSc or user events - primarily for logging

179:     Level: intermediate

181: .seealso: PetscLogEventRegister(), PetscLogEventBegin(), PetscLogEventEnd(), PetscLogStage
182: M*/
183: typedef int PetscLogEvent;

185: /*MC
186:     PetscLogStage - id used to identify user stages of runs - for logging

188:     Level: intermediate

190: .seealso: PetscLogStageRegister(), PetscLogStageBegin(), PetscLogStageEnd(), PetscLogEvent
191: M*/
192: typedef int PetscLogStage;

194: /*MC
195:     PetscBLASInt - datatype used to represent 'int' parameters to BLAS/LAPACK functions.

197:     Level: intermediate

199:     Notes: usually this is the same as PetscInt, but if PETSc was built with --with-64-bit-indices but 
200:            standard C/Fortran integers are 32 bit then this is NOT the same as PetscInt

202: .seealso: PetscMPIInt, PetscInt

204: M*/
205: typedef int PetscBLASInt;

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

210:     Level: intermediate

212:     Notes: usually this is the same as PetscInt, but if PETSc was built with --with-64-bit-indices but 
213:            standard C/Fortran integers are 32 bit then this is NOT the same as PetscInt

215:     PetscBLASIntCheck(a) checks if the given PetscInt a will fit in a PetscBLASInt, if not it generates a 
216:       PETSC_ERR_ARG_OUTOFRANGE.

218:     PetscBLASInt b = PetscBLASIntCast(a) checks if the given PetscInt a will fit in a PetscBLASInt, if not it 
219:       generates a PETSC_ERR_ARG_OUTOFRANGE

221: .seealso: PetscBLASInt, PetscInt

223: M*/
224: typedef int PetscMPIInt;

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

229:     Level: intermediate

231:     PetscMPIIntCheck(a) checks if the given PetscInt a will fit in a PetscMPIInt, if not it generates a 
232:       PETSC_ERR_ARG_OUTOFRANGE.

234:     PetscMPIInt b = PetscMPIIntCast(a) checks if the given PetscInt a will fit in a PetscMPIInt, if not it 
235:       generates a PETSC_ERR_ARG_OUTOFRANGE

237: .seealso: PetscOptionsGetEnum(), PetscOptionsEnum(), PetscBagRegisterEnum()
238: M*/
239: typedef enum { ENUM_DUMMY } PetscEnum;

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

246:    Level: intermediate


249: .seealso: PetscScalar, PetscBLASInt, PetscMPIInt
250: M*/
251: #if defined(PETSC_USE_64BIT_INDICES)
252: typedef long long PetscInt;
253: #define MPIU_INT MPI_LONG_LONG_INT
254: #else
255: typedef int PetscInt;
256: #define MPIU_INT MPI_INT
257: #endif

259: /* add in MPIU type for size_t */
260: #if (PETSC_SIZEOF_SIZE_T) == (PETSC_SIZEOF_INT)
261: #define MPIU_SIZE_T MPI_INT
262: #elif  (PETSC_SIZEOF_SIZE_T) == (PETSC_SIZEOF_LONG)
263: #define MPIU_SIZE_T MPI_LONG
264: #elif  (PETSC_SIZEOF_SIZE_T) == (PETSC_SIZEOF_LONG_LONG)
265: #define MPIU_SIZE_T MPI_LONG_LONG_INT
266: #else
267: #error "Unknown size for size_t! Send us a bugreport at petsc-maint@mcs.anl.gov"
268: #endif


271: /*
272:       You can use PETSC_STDOUT as a replacement of stdout. You can also change
273:     the value of PETSC_STDOUT to redirect all standard output elsewhere
274: */


278: /*
279:       You can use PETSC_STDERR as a replacement of stderr. You can also change
280:     the value of PETSC_STDERR to redirect all standard error elsewhere
281: */

284: /*
285:       PETSC_ZOPEFD is used to send data to the PETSc webpage.  It can be used
286:     in conjunction with PETSC_STDOUT, or by itself.
287: */

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

295:    Synopsis:
296:    PetscPolymorphicSubroutine(Functionname,(arguments of C++ function),(arguments of C function))
297:  
298:      Not collective

300:    Level: developer

302:     Example:
303:       PetscPolymorphicSubroutine(VecNorm,(Vec x,PetscReal *r),(x,NORM_2,r)) generates the new routine
304:            PetscErrorCode VecNorm(Vec x,PetscReal *r) = VecNorm(x,NORM_2,r)

306: .seealso: PetscPolymorphicFunction()

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

311: /*MC
312:       PetscPolymorphicScalar - allows defining a C++ polymorphic version of 
313:             a PETSc function that replaces a PetscScalar * argument with a PetscScalar argument

315:    Synopsis:
316:    PetscPolymorphicScalar(Functionname,(arguments of C++ function),(arguments of C function))
317:  
318:    Not collective

320:    Level: developer

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

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

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

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

336:    Synopsis:
337:    PetscPolymorphicFunction(Functionname,(arguments of C++ function),(arguments of C function),return type,return variable name)
338:  
339:      Not collective

341:    Level: developer

343:     Example:
344:       PetscPolymorphicFunction(VecNorm,(Vec x,NormType t),(x,t,&r),PetscReal,r) generates the new routine
345:          PetscReal VecNorm(Vec x,NormType t) = {PetscReal r; VecNorm(x,t,&r); return r;}

347: .seealso: PetscPolymorphicSubroutine()

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

352: #else
353: #define PetscPolymorphicSubroutine(A,B,C)
354: #define PetscPolymorphicScalar(A,B,C)
355: #define PetscPolymorphicFunction(A,B,C,D,E)
356: #endif

358: /*MC
359:     PetscUnlikely - hints the compiler that the given condition is usually FALSE

361:     Synopsis:
362:     PetscTruth PetscUnlikely(PetscTruth cond)

364:     Not Collective

366:     Input Parameters:
367: .   cond - condition or expression

369:     Note: This returns the same truth value, it is only a hint to compilers that the resulting
370:     branch is unlikely.

372:     Level: advanced

374: .seealso: PetscLikely(), CHKERRQ
375: M*/

377: /*MC
378:     PetscLikely - hints the compiler that the given condition is usually TRUE

380:     Synopsis:
381:     PetscTruth PetscUnlikely(PetscTruth cond)

383:     Not Collective

385:     Input Parameters:
386: .   cond - condition or expression

388:     Note: This returns the same truth value, it is only a hint to compilers that the resulting
389:     branch is likely.

391:     Level: advanced

393: .seealso: PetscUnlikely()
394: M*/
395: #if defined(PETSC_HAVE_BUILTIN_EXPECT)
396: #  define PetscUnlikely(cond)   __builtin_expect(!!(cond),0)
397: #  define PetscLikely(cond)     __builtin_expect(!!(cond),1)
398: #else
399: #  define PetscUnlikely(cond)   cond
400: #  define PetscLikely(cond)     cond
401: #endif

403: /*
404:     Extern indicates a PETSc function defined elsewhere
405: */
406: #if !defined(EXTERN)
407: #define EXTERN extern
408: #endif

410: /*
411:     Defines some elementary mathematics functions and constants.
412: */
413:  #include petscmath.h

415: /*
417: */


421: /*
422:        Basic PETSc constants
423: */

425: /*E
426:     PetscTruth - Logical variable. Actually an integer

428:    Level: beginner

430: E*/
431: typedef enum { PETSC_FALSE,PETSC_TRUE } PetscTruth;

434: /*MC
435:     PETSC_FALSE - False value of PetscTruth

437:     Level: beginner

439:     Note: Zero integer

441: .seealso: PetscTruth, PETSC_TRUE
442: M*/

444: /*MC
445:     PETSC_TRUE - True value of PetscTruth

447:     Level: beginner

449:     Note: Nonzero integer

451: .seealso: PetscTruth, PETSC_FALSE
452: M*/

454: /*MC
455:     PETSC_YES - Alias for PETSC_TRUE

457:     Level: beginner

459:     Note: Zero integer

461: .seealso: PetscTruth, PETSC_TRUE, PETSC_FALSE, PETSC_NO
462: M*/
463: #define PETSC_YES            PETSC_TRUE

465: /*MC
466:     PETSC_NO - Alias for PETSC_FALSE

468:     Level: beginner

470:     Note: Nonzero integer

472: .seealso: PetscTruth, PETSC_TRUE, PETSC_FALSE, PETSC_YES
473: M*/
474: #define PETSC_NO             PETSC_FALSE

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

479:    Level: beginner

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

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

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

489: M*/
490: #define PETSC_NULL           0

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

496:    Level: beginner

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

500: M*/
501: #define PETSC_DECIDE         -1

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

507:    Level: beginner

509:    Fortran Notes: You need to use PETSC_DEFAULT_INTEGER or PETSC_DEFAULT_DOUBLE_PRECISION.

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

513: M*/
514: #define PETSC_DEFAULT        -2


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

520:    Level: beginner

522:    Note: accepted by many PETSc functions to not set a parameter and instead use
523:           some default

525:    Fortran Notes: This macro does not exist in Fortran; you must use PETSC_NULL_INTEGER, 
526:           PETSC_NULL_DOUBLE_PRECISION etc

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

530: M*/
531: #define PETSC_IGNORE         PETSC_NULL

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

537:    Level: beginner

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

541: M*/
542: #define PETSC_DETERMINE      PETSC_DECIDE

544: /*MC
545:     PETSC_COMM_WORLD - the equivalent of the MPI_COMM_WORLD communicator which represents
546:            all the processs that PETSc knows about. 

548:    Level: beginner

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

555: .seealso: PETSC_COMM_SELF

557: M*/

560: /*MC
561:     PETSC_COMM_SELF - a duplicate of the MPI_COMM_SELF communicator which represents
562:            the current process

564:    Level: beginner

566:    Notes: PETSC_COMM_SELF and MPI_COMM_SELF are equivalent.

568: .seealso: PETSC_COMM_WORLD

570: M*/
571: #define PETSC_COMM_SELF MPI_COMM_SELF


576: EXTERN PetscErrorCode  PetscSetHelpVersionFunctions(PetscErrorCode (*)(MPI_Comm),PetscErrorCode (*)(MPI_Comm));
577: EXTERN PetscErrorCode  PetscCommDuplicate(MPI_Comm,MPI_Comm*,int*);
578: EXTERN PetscErrorCode  PetscCommDestroy(MPI_Comm*);

580: /*MC
581:    PetscMalloc - Allocates memory

583:    Synopsis:
584:    PetscErrorCode PetscMalloc(size_t m,void **result)

586:    Not Collective

588:    Input Parameter:
589: .  m - number of bytes to allocate

591:    Output Parameter:
592: .  result - memory allocated

594:    Level: beginner

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

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

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

603:   Concepts: memory allocation

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

608: /*MC
609:    PetscAddrAlign - Returns an address with PETSC_MEMALIGN alignment

611:    Synopsis:
612:    void *PetscAddrAlign(void *addr)

614:    Not Collective

616:    Input Parameters:
617: .  addr - address to align (any pointer type)

619:    Level: developer

621: .seealso: PetscMallocAlign()

623:   Concepts: memory allocation
624: M*/
625: #if defined PETSC_UINTPTR_T
626: #  define PetscAddrAlign(a) (void*)((((PETSC_UINTPTR_T)(a))+(PETSC_MEMALIGN-1)) & ~(PETSC_MEMALIGN-1))
627: #else
628: #  define PetscAddrAlign(a) (void*)(a)
629: #endif

631: /*MC
632:    PetscMalloc2 - Allocates 2 chunks of  memory

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

637:    Not Collective

639:    Input Parameter:
640: +  m1 - number of elements to allocate in 1st chunk  (may be zero)
641: .  t1 - type of first memory elements 
642: .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
643: -  t2 - type of second memory elements

645:    Output Parameter:
646: +  r1 - memory allocated in first chunk
647: -  r2 - memory allocated in second chunk

649:    Level: developer

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

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

655:   Concepts: memory allocation

657: M*/
658: #if defined(PETSC_USE_DEBUG)
659: #define PetscMalloc2(m1,t1,r1,m2,t2,r2) (PetscMalloc((m1)*sizeof(t1),r1) || PetscMalloc((m2)*sizeof(t2),r2))
660: #else
661: #define PetscMalloc2(m1,t1,r1,m2,t2,r2) ((*(r2) = 0,PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(PETSC_MEMALIGN-1),r1)) \
662:                                          || (*(r2) = (t2*)PetscAddrAlign(*(r1)+m1),0))
663: #endif

665: /*MC
666:    PetscMalloc3 - Allocates 3 chunks of  memory

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

671:    Not Collective

673:    Input Parameter:
674: +  m1 - number of elements to allocate in 1st chunk  (may be zero)
675: .  t1 - type of first memory elements 
676: .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
677: .  t2 - type of second memory elements
678: .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
679: -  t3 - type of third memory elements

681:    Output Parameter:
682: +  r1 - memory allocated in first chunk
683: .  r2 - memory allocated in second chunk
684: -  r3 - memory allocated in third chunk


687:    Level: developer

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

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

693:   Concepts: memory allocation

695: M*/
696: #if defined(PETSC_USE_DEBUG)
697: #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))
698: #else
699: #define PetscMalloc3(m1,t1,r1,m2,t2,r2,m3,t3,r3) ((*(r2) = 0,*(r3) = 0,PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3)+2*(PETSC_MEMALIGN-1),r1)) \
700:                                                   || (*(r2) = (t2*)PetscAddrAlign(*(r1)+m1),*(r3) = (t3*)PetscAddrAlign(*(r2)+m2),0))
701: #endif

703: /*MC
704:    PetscMalloc4 - Allocates 4 chunks of  memory

706:    Synopsis:
707:    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)

709:    Not Collective

711:    Input Parameter:
712: +  m1 - number of elements to allocate in 1st chunk  (may be zero)
713: .  t1 - type of first memory elements 
714: .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
715: .  t2 - type of second memory elements
716: .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
717: .  t3 - type of third memory elements
718: .  m4 - number of elements to allocate in 4th chunk  (may be zero)
719: -  t4 - type of fourth memory elements

721:    Output Parameter:
722: +  r1 - memory allocated in first chunk
723: .  r2 - memory allocated in second chunk
724: .  r3 - memory allocated in third chunk
725: -  r4 - memory allocated in fourth chunk

727:    Level: developer

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

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

733:   Concepts: memory allocation

735: M*/
736: #if defined(PETSC_USE_DEBUG)
737: #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))
738: #else
739: #define PetscMalloc4(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4)               \
740:   ((*(r2) = 0, *(r3) = 0, *(r4) = 0,PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3)+(m4)*sizeof(t4)+3*(PETSC_MEMALIGN-1),r1)) \
741:    || (*(r2) = (t2*)PetscAddrAlign(*(r1)+m1),*(r3) = (t3*)PetscAddrAlign(*(r2)+m2),*(r4) = (t4*)PetscAddrAlign(*(r3)+m3),0))
742: #endif

744: /*MC
745:    PetscMalloc5 - Allocates 5 chunks of  memory

747:    Synopsis:
748:    PetscErrorCode PetscMalloc5(size_t m1,type, t1,void **r1,size_t m2,type t2,void **r2,size_t m3,type t3,void **r3,size_t m4,type t4,void **r4,size_t m5,type t5,void **r5)

750:    Not Collective

752:    Input Parameter:
753: +  m1 - number of elements to allocate in 1st chunk  (may be zero)
754: .  t1 - type of first memory elements 
755: .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
756: .  t2 - type of second memory elements
757: .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
758: .  t3 - type of third memory elements
759: .  m4 - number of elements to allocate in 4th chunk  (may be zero)
760: .  t4 - type of fourth memory elements
761: .  m5 - number of elements to allocate in 5th chunk  (may be zero)
762: -  t5 - type of fifth memory elements

764:    Output Parameter:
765: +  r1 - memory allocated in first chunk
766: .  r2 - memory allocated in second chunk
767: .  r3 - memory allocated in third chunk
768: .  r4 - memory allocated in fourth chunk
769: -  r5 - memory allocated in fifth chunk

771:    Level: developer

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

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

777:   Concepts: memory allocation

779: M*/
780: #if defined(PETSC_USE_DEBUG)
781: #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))
782: #else
783: #define PetscMalloc5(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4,m5,t5,r5)      \
784:   ((*(r2) = 0, *(r3) = 0, *(r4) = 0,*(r5) = 0,PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3)+(m4)*sizeof(t4)+(m5)*sizeof(t5)+4*(PETSC_MEMALIGN-1),r1)) \
785:    || (*(r2) = (t2*)PetscAddrAlign(*(r1)+m1),*(r3) = (t3*)PetscAddrAlign(*(r2)+m2),*(r4) = (t4*)PetscAddrAlign(*(r3)+m3),*(r5) = (t5*)PetscAddrAlign(*(r4)+m4),0))
786: #endif


789: /*MC
790:    PetscMalloc6 - Allocates 6 chunks of  memory

792:    Synopsis:
793:    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)

795:    Not Collective

797:    Input Parameter:
798: +  m1 - number of elements to allocate in 1st chunk  (may be zero)
799: .  t1 - type of first memory elements 
800: .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
801: .  t2 - type of second memory elements
802: .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
803: .  t3 - type of third memory elements
804: .  m4 - number of elements to allocate in 4th chunk  (may be zero)
805: .  t4 - type of fourth memory elements
806: .  m5 - number of elements to allocate in 5th chunk  (may be zero)
807: .  t5 - type of fifth memory elements
808: .  m6 - number of elements to allocate in 6th chunk  (may be zero)
809: -  t6 - type of sixth memory elements

811:    Output Parameter:
812: +  r1 - memory allocated in first chunk
813: .  r2 - memory allocated in second chunk
814: .  r3 - memory allocated in third chunk
815: .  r4 - memory allocated in fourth chunk
816: .  r5 - memory allocated in fifth chunk
817: -  r6 - memory allocated in sixth chunk

819:    Level: developer

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

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

825:   Concepts: memory allocation

827: M*/
828: #if defined(PETSC_USE_DEBUG)
829: #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))
830: #else
831: #define PetscMalloc6(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4,m5,t5,r5,m6,t6,r6) \
832:   ((*(r2) = 0, *(r3) = 0, *(r4) = 0,*(r5) = 0,*(r6) = 0,PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3)+(m4)*sizeof(t4)+(m5)*sizeof(t5)+(m6)*sizeof(t6)+5*(PETSC_MEMALIGN-1),r1)) \
833:    || (*(r2) = (t2*)PetscAddrAlign(*(r1)+m1),*(r3) = (t3*)PetscAddrAlign(*(r2)+m2),*(r4) = (t4*)PetscAddrAlign(*(r3)+m3),*(r5) = (t5*)PetscAddrAlign(*(r4)+m4),*(r6) = (t6*)PetscAddrAlign(*(r5)+m5),0))
834: #endif

836: /*MC
837:    PetscMalloc7 - Allocates 7 chunks of  memory

839:    Synopsis:
840:    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)

842:    Not Collective

844:    Input Parameter:
845: +  m1 - number of elements to allocate in 1st chunk  (may be zero)
846: .  t1 - type of first memory elements 
847: .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
848: .  t2 - type of second memory elements
849: .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
850: .  t3 - type of third memory elements
851: .  m4 - number of elements to allocate in 4th chunk  (may be zero)
852: .  t4 - type of fourth memory elements
853: .  m5 - number of elements to allocate in 5th chunk  (may be zero)
854: .  t5 - type of fifth memory elements
855: .  m6 - number of elements to allocate in 6th chunk  (may be zero)
856: .  t6 - type of sixth memory elements
857: .  m7 - number of elements to allocate in 7th chunk  (may be zero)
858: -  t7 - type of sixth memory elements

860:    Output Parameter:
861: +  r1 - memory allocated in first chunk
862: .  r2 - memory allocated in second chunk
863: .  r3 - memory allocated in third chunk
864: .  r4 - memory allocated in fourth chunk
865: .  r5 - memory allocated in fifth chunk
866: .  r6 - memory allocated in sixth chunk
867: -  r7 - memory allocated in seventh chunk

869:    Level: developer

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

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

875:   Concepts: memory allocation

877: M*/
878: #if defined(PETSC_USE_DEBUG)
879: #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))
880: #else
881: #define PetscMalloc7(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4,m5,t5,r5,m6,t6,r6,m7,t7,r7) \
882:   ((*(r2) = 0, *(r3) = 0, *(r4) = 0,*(r5) = 0,*(r6) = 0,*(r7) = 0,PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3)+(m4)*sizeof(t4)+(m5)*sizeof(t5)+(m6)*sizeof(t6)+(m7)*sizeof(t7)+6*(PETSC_MEMALIGN-1),r1)) \
883:    || (*(r2) = (t2*)PetscAddrAlign(*(r1)+m1),*(r3) = (t3*)PetscAddrAlign(*(r2)+m2),*(r4) = (t4*)PetscAddrAlign(*(r3)+m3),*(r5) = (t5*)PetscAddrAlign(*(r4)+m4),*(r6) = (t6*)PetscAddrAlign(*(r5)+m5),*(r7) = (t7*)PetscAddrAlign(*(r6)+m6),0))
884: #endif

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

889:    Synopsis:
890:    PetscErrorCode PetscNew(struct type,((type *))result)

892:    Not Collective

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

897:    Output Parameter:
898: .  result - memory allocated

900:    Level: beginner

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

904:   Concepts: memory allocation

906: M*/
907: #define PetscNew(A,b)      (PetscMalloc(sizeof(A),(b)) || PetscMemzero(*(b),sizeof(A)))
908: #define PetscNewLog(o,A,b) (PetscNew(A,b) || ((o) ? PetscLogObjectMemory(o,sizeof(A)) : 0))

910: /*MC
911:    PetscFree - Frees memory

913:    Synopsis:
914:    PetscErrorCode PetscFree(void *memory)

916:    Not Collective

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


922:    Level: beginner

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

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

928:   Concepts: memory allocation

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

933: /*MC
934:    PetscFreeVoid - Frees memory

936:    Synopsis:
937:    void PetscFreeVoid(void *memory)

939:    Not Collective

941:    Input Parameter:
942: .   memory - memory to free

944:    Level: beginner

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

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

950:   Concepts: memory allocation

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


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

959:    Synopsis:
960:    PetscErrorCode PetscFree2(void *memory1,void *memory2)

962:    Not Collective

964:    Input Parameter:
965: +   memory1 - memory to free
966: -   memory2 - 2nd memory to free

968:    Level: developer

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

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

974:   Concepts: memory allocation

976: M*/
977: #if defined(PETSC_USE_DEBUG)
978: #define PetscFree2(m1,m2)   (PetscFree(m2) || PetscFree(m1))
979: #else
980: #define PetscFree2(m1,m2)   (PetscFree(m1))
981: #endif

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

986:    Synopsis:
987:    PetscErrorCode PetscFree3(void *memory1,void *memory2,void *memory3)

989:    Not Collective

991:    Input Parameter:
992: +   memory1 - memory to free
993: .   memory2 - 2nd memory to free
994: -   memory3 - 3rd memory to free

996:    Level: developer

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

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

1002:   Concepts: memory allocation

1004: M*/
1005: #if defined(PETSC_USE_DEBUG)
1006: #define PetscFree3(m1,m2,m3)   (PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
1007: #else
1008: #define PetscFree3(m1,m2,m3)   (PetscFree(m1))
1009: #endif

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

1014:    Synopsis:
1015:    PetscErrorCode PetscFree4(void *m1,void *m2,void *m3,void *m4)

1017:    Not Collective

1019:    Input Parameter:
1020: +   m1 - memory to free
1021: .   m2 - 2nd memory to free
1022: .   m3 - 3rd memory to free
1023: -   m4 - 4th memory to free

1025:    Level: developer

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

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

1031:   Concepts: memory allocation

1033: M*/
1034: #if defined(PETSC_USE_DEBUG)
1035: #define PetscFree4(m1,m2,m3,m4)   (PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
1036: #else
1037: #define PetscFree4(m1,m2,m3,m4)   (PetscFree(m1))
1038: #endif

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

1043:    Synopsis:
1044:    PetscErrorCode PetscFree5(void *m1,void *m2,void *m3,void *m4,void *m5)

1046:    Not Collective

1048:    Input Parameter:
1049: +   m1 - memory to free
1050: .   m2 - 2nd memory to free
1051: .   m3 - 3rd memory to free
1052: .   m4 - 4th memory to free
1053: -   m5 - 5th memory to free

1055:    Level: developer

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

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

1061:   Concepts: memory allocation

1063: M*/
1064: #if defined(PETSC_USE_DEBUG)
1065: #define PetscFree5(m1,m2,m3,m4,m5)   (PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
1066: #else
1067: #define PetscFree5(m1,m2,m3,m4,m5)   (PetscFree(m1))
1068: #endif


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

1074:    Synopsis:
1075:    PetscErrorCode PetscFree6(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6)

1077:    Not Collective

1079:    Input Parameter:
1080: +   m1 - memory to free
1081: .   m2 - 2nd memory to free
1082: .   m3 - 3rd memory to free
1083: .   m4 - 4th memory to free
1084: .   m5 - 5th memory to free
1085: -   m6 - 6th memory to free


1088:    Level: developer

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

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

1094:   Concepts: memory allocation

1096: M*/
1097: #if defined(PETSC_USE_DEBUG)
1098: #define PetscFree6(m1,m2,m3,m4,m5,m6)   (PetscFree(m6) || PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
1099: #else
1100: #define PetscFree6(m1,m2,m3,m4,m5,m6)   (PetscFree(m1))
1101: #endif

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

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

1109:    Not Collective

1111:    Input Parameter:
1112: +   m1 - memory to free
1113: .   m2 - 2nd memory to free
1114: .   m3 - 3rd memory to free
1115: .   m4 - 4th memory to free
1116: .   m5 - 5th memory to free
1117: .   m6 - 6th memory to free
1118: -   m7 - 7th memory to free


1121:    Level: developer

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

1125: .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5(), PetscMalloc6(),
1126:           PetscMalloc7()

1128:   Concepts: memory allocation

1130: M*/
1131: #if defined(PETSC_USE_DEBUG)
1132: #define PetscFree7(m1,m2,m3,m4,m5,m6,m7)   (PetscFree(m7) || PetscFree(m6) || PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
1133: #else
1134: #define PetscFree7(m1,m2,m3,m4,m5,m6,m7)   (PetscFree(m1))
1135: #endif

1137: EXTERN  PetscErrorCode (*PetscTrMalloc)(size_t,int,const char[],const char[],const char[],void**);
1138: EXTERN  PetscErrorCode (*PetscTrFree)(void*,int,const char[],const char[],const char[]);
1139: EXTERN PetscErrorCode   PetscMallocSet(PetscErrorCode (*)(size_t,int,const char[],const char[],const char[],void**),PetscErrorCode (*)(void*,int,const char[],const char[],const char[]));
1140: EXTERN PetscErrorCode   PetscMallocClear(void);

1142: /*
1143:    Routines for tracing memory corruption/bleeding with default PETSc 
1144:    memory allocation
1145: */
1146: EXTERN PetscErrorCode    PetscMallocDump(FILE *);
1147: EXTERN PetscErrorCode    PetscMallocDumpLog(FILE *);
1148: EXTERN PetscErrorCode    PetscMallocGetCurrentUsage(PetscLogDouble *);
1149: EXTERN PetscErrorCode    PetscMallocGetMaximumUsage(PetscLogDouble *);
1150: EXTERN PetscErrorCode    PetscMallocDebug(PetscTruth);
1151: EXTERN PetscErrorCode    PetscMallocValidate(int,const char[],const char[],const char[]);
1152: EXTERN PetscErrorCode    PetscMallocSetDumpLog(void);


1155: /*
1156:     Variable type where we stash PETSc object pointers in Fortran.
1157:     On most machines size(pointer) == sizeof(long) - except windows
1158:     where its sizeof(long long)
1159: */

1161: #if (PETSC_SIZEOF_VOID_P) == (PETSC_SIZEOF_LONG)
1162: #define PetscFortranAddr   long
1163: #elif  (PETSC_SIZEOF_VOID_P) == (PETSC_SIZEOF_LONG_LONG)
1164: #define PetscFortranAddr   long long
1165: #else
1166: #error "Unknown size for PetscFortranAddr! Send us a bugreport at petsc-maint@mcs.anl.gov"
1167: #endif

1169: /*E
1170:     PetscDataType - Used for handling different basic data types.

1172:    Level: beginner

1174:    Developer comment: It would be nice if we could always just use MPI Datatypes, why can we not?

1176: .seealso: PetscBinaryRead(), PetscBinaryWrite(), PetscDataTypeToMPIDataType(),
1177:           PetscDataTypeGetSize()

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

1184: #if defined(PETSC_USE_COMPLEX)
1185: #define PETSC_SCALAR PETSC_COMPLEX
1186: #else
1187: #if defined(PETSC_USE_SCALAR_SINGLE)
1188: #define PETSC_SCALAR PETSC_FLOAT
1189: #elif defined(PETSC_USE_SCALAR_LONG_DOUBLE)
1190: #define PETSC_SCALAR PETSC_LONG_DOUBLE
1191: #elif defined(PETSC_USE_SCALAR_INT)
1192: #define PETSC_SCALAR PETSC_INT
1193: #elif defined(PETSC_USE_SCALAR_QD_DD)
1194: #define PETSC_SCALAR PETSC_QD_DD
1195: #else
1196: #define PETSC_SCALAR PETSC_DOUBLE
1197: #endif
1198: #endif
1199: #if defined(PETSC_USE_SCALAR_SINGLE)
1200: #define PETSC_REAL PETSC_FLOAT
1201: #elif defined(PETSC_USE_SCALAR_LONG_DOUBLE)
1202: #define PETSC_REAL PETSC_LONG_DOUBLE
1203: #elif defined(PETSC_USE_SCALAR_INT)
1204: #define PETSC_REAL PETSC_INT
1205: #elif defined(PETSC_USE_SCALAR_QD_DD)
1206: #define PETSC_REAL PETSC_QD_DD
1207: #else
1208: #define PETSC_REAL PETSC_DOUBLE
1209: #endif
1210: #define PETSC_FORTRANADDR PETSC_LONG

1212: EXTERN PetscErrorCode  PetscDataTypeToMPIDataType(PetscDataType,MPI_Datatype*);
1213: EXTERN PetscErrorCode  PetscMPIDataTypeToPetscDataType(MPI_Datatype,PetscDataType*);
1214: EXTERN PetscErrorCode  PetscDataTypeGetSize(PetscDataType,size_t*);

1216: /*
1217:     Basic memory and string operations. These are usually simple wrappers
1218:    around the basic Unix system calls, but a few of them have additional
1219:    functionality and/or error checking.
1220: */
1221: EXTERN PetscErrorCode    PetscBitMemcpy(void*,PetscInt,const void*,PetscInt,PetscInt,PetscDataType);
1222: EXTERN PetscErrorCode    PetscMemmove(void*,void *,size_t);
1223: EXTERN PetscErrorCode    PetscMemcmp(const void*,const void*,size_t,PetscTruth *);
1224: EXTERN PetscErrorCode    PetscStrlen(const char[],size_t*);
1225: EXTERN PetscErrorCode    PetscStrcmp(const char[],const char[],PetscTruth *);
1226: EXTERN PetscErrorCode    PetscStrgrt(const char[],const char[],PetscTruth *);
1227: EXTERN PetscErrorCode    PetscStrcasecmp(const char[],const char[],PetscTruth*);
1228: EXTERN PetscErrorCode    PetscStrncmp(const char[],const char[],size_t,PetscTruth*);
1229: EXTERN PetscErrorCode    PetscStrcpy(char[],const char[]);
1230: EXTERN PetscErrorCode    PetscStrcat(char[],const char[]);
1231: EXTERN PetscErrorCode    PetscStrncat(char[],const char[],size_t);
1232: EXTERN PetscErrorCode    PetscStrncpy(char[],const char[],size_t);
1233: EXTERN PetscErrorCode    PetscStrchr(const char[],char,char *[]);
1234: EXTERN PetscErrorCode    PetscStrtolower(char[]);
1235: EXTERN PetscErrorCode    PetscStrrchr(const char[],char,char *[]);
1236: EXTERN PetscErrorCode    PetscStrstr(const char[],const char[],char *[]);
1237: EXTERN PetscErrorCode    PetscStrrstr(const char[],const char[],char *[]);
1238: EXTERN PetscErrorCode    PetscStrallocpy(const char[],char *[]);
1239: EXTERN PetscErrorCode    PetscStrreplace(MPI_Comm,const char[],char[],size_t);
1240: #define      PetscStrfree(a) ((a) ? PetscFree(a) : 0) 


1243: /*S
1244:     PetscToken - 'Token' used for managing tokenizing strings

1246:   Level: intermediate

1248: .seealso: PetscTokenCreate(), PetscTokenFind(), PetscTokenDestroy()
1249: S*/
1250: typedef struct _p_PetscToken* PetscToken;

1252: EXTERN PetscErrorCode    PetscTokenCreate(const char[],const char,PetscToken*);
1253: EXTERN PetscErrorCode    PetscTokenFind(PetscToken,char *[]);
1254: EXTERN PetscErrorCode    PetscTokenDestroy(PetscToken);

1256: /*
1257:    These are  MPI operations for MPI_Allreduce() etc
1258: */
1259: EXTERN  MPI_Op PetscMaxSum_Op;
1260: #if defined(PETSC_USE_COMPLEX) && !defined(PETSC_HAVE_MPI_C_DOUBLE_COMPLEX)
1261: EXTERN  MPI_Op MPIU_SUM;
1262: #else
1263: #define MPIU_SUM MPI_SUM
1264: #endif
1265: EXTERN PetscErrorCode  PetscMaxSum(MPI_Comm,const PetscInt[],PetscInt*,PetscInt*);

1267: /*S
1268:      PetscObject - any PETSc object, PetscViewer, Mat, Vec, KSP etc

1270:    Level: beginner

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

1274: .seealso:  PetscObjectDestroy(), PetscObjectView(), PetscObjectGetName(), PetscObjectSetName(), PetscObjectReference(), PetscObjectDereferenc()
1275: S*/
1276: typedef struct _p_PetscObject* PetscObject;

1278: /*S
1279:      PetscFList - Linked list of functions, possibly stored in dynamic libraries, accessed
1280:       by string name

1282:    Level: advanced

1284: .seealso:  PetscFListAdd(), PetscFListDestroy()
1285: S*/
1286: typedef struct _n_PetscFList *PetscFList;

1288: /*E
1289:   PetscFileMode - Access mode for a file.

1291:   Level: beginner

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

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

1297:   FILE_MODE_APPEND - open a file at end for writing

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

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

1303: .seealso: PetscViewerFileSetMode()
1304: E*/
1305: typedef enum {FILE_MODE_READ, FILE_MODE_WRITE, FILE_MODE_APPEND, FILE_MODE_UPDATE, FILE_MODE_APPEND_UPDATE} PetscFileMode;

1307:  #include petscviewer.h
1308:  #include petscoptions.h

1310: #define PETSC_SMALLEST_COOKIE 1211211
1313: EXTERN PetscErrorCode  PetscCookieRegister(const char[],PetscCookie *);

1315: /*
1316:    Routines that get memory usage information from the OS
1317: */
1318: EXTERN PetscErrorCode  PetscMemoryGetCurrentUsage(PetscLogDouble *);
1319: EXTERN PetscErrorCode  PetscMemoryGetMaximumUsage(PetscLogDouble *);
1320: EXTERN PetscErrorCode  PetscMemorySetGetMaximumUsage(void);
1321: EXTERN PetscErrorCode  PetscMemoryShowUsage(PetscViewer,const char[]);

1323: EXTERN PetscErrorCode  PetscInfoAllow(PetscTruth,const char []);
1324: EXTERN PetscErrorCode  PetscGetTime(PetscLogDouble*);
1325: EXTERN PetscErrorCode  PetscGetCPUTime(PetscLogDouble*);
1326: EXTERN PetscErrorCode  PetscSleep(PetscReal);

1328: /*
1329:     Initialization of PETSc
1330: */
1331: EXTERN PetscErrorCode  PetscInitialize(int*,char***,const char[],const char[]);
1332: PetscPolymorphicSubroutine(PetscInitialize,(int *argc,char ***args),(argc,args,PETSC_NULL,PETSC_NULL))
1333: EXTERN PetscErrorCode  PetscInitializeNoArguments(void);
1334: EXTERN PetscErrorCode  PetscInitialized(PetscTruth *);
1335: EXTERN PetscErrorCode  PetscFinalized(PetscTruth *);
1336: EXTERN PetscErrorCode  PetscFinalize(void);
1337: EXTERN PetscErrorCode PetscInitializeFortran(void);
1338: EXTERN PetscErrorCode  PetscGetArgs(int*,char ***);
1339: EXTERN PetscErrorCode  PetscGetArguments(char ***);
1340: EXTERN PetscErrorCode  PetscFreeArguments(char **);

1342: EXTERN PetscErrorCode  PetscEnd(void);
1343: EXTERN PetscErrorCode  PetscInitializePackage(const char[]);

1346: EXTERN PetscErrorCode  PetscOpenMPMerge(PetscMPIInt,PetscErrorCode (*)(void*),void*);
1347: EXTERN PetscErrorCode  PetscOpenMPSpawn(PetscMPIInt);
1348: EXTERN PetscErrorCode  PetscOpenMPFinalize(void);
1349: EXTERN PetscErrorCode  PetscOpenMPRun(MPI_Comm,PetscErrorCode (*)(MPI_Comm,void *),void*);
1350: EXTERN PetscErrorCode  PetscOpenMPRunCtx(MPI_Comm,PetscErrorCode (*)(MPI_Comm,void*,void *),void*);
1351: EXTERN PetscErrorCode  PetscOpenMPFree(MPI_Comm,void*);
1352: EXTERN PetscErrorCode  PetscOpenMPMalloc(MPI_Comm,size_t,void**);

1354: EXTERN PetscErrorCode  PetscPythonInitialize(const char[],const char[]);
1355: EXTERN PetscErrorCode  PetscPythonFinalize(void);

1357: /*
1359:    function pointers. Since the regular C++ code expects its function pointers to be 
1360:    C++.
1361: */
1362: typedef void (**PetscVoidStarFunction)(void);
1363: typedef void (*PetscVoidFunction)(void);
1364: typedef PetscErrorCode (*PetscErrorCodeFunction)(void);

1366: /*
1367:    PetscTryMethod - Queries an object for a method, if it exists then calls it.
1368:               These are intended to be used only inside PETSc functions.
1369: */
1370: #define  PetscTryMethod(obj,A,B,C) \
1371:   0;{ PetscErrorCode (*f)B, __ierr; \
1372:     __PetscObjectQueryFunction((PetscObject)obj,A,(PetscVoidStarFunction)&f);CHKERRQ(__ierr); \
1373:     if (f) {__(*f)C;CHKERRQ(__ierr);}\
1374:   }
1375: #define  PetscUseMethod(obj,A,B,C) \
1376:   0;{ PetscErrorCode (*f)B, __ierr; \
1377:     __PetscObjectQueryFunction((PetscObject)obj,A,(PetscVoidStarFunction)&f);CHKERRQ(__ierr); \
1378:     if (f) {__(*f)C;CHKERRQ(__ierr);}\
1379:     else {SETERRQ1(PETSC_ERR_SUP,"Cannot locate function %s in object",A);} \
1380:   }
1381: /*
1382:     Functions that can act on any PETSc object.
1383: */
1384: EXTERN PetscErrorCode  PetscObjectCreate(MPI_Comm,PetscObject*);
1385: EXTERN PetscErrorCode  PetscObjectCreateGeneric(MPI_Comm, PetscCookie, const char [], PetscObject *);
1386: EXTERN PetscErrorCode  PetscObjectDestroy(PetscObject);
1387: EXTERN PetscErrorCode  PetscObjectGetComm(PetscObject,MPI_Comm *);
1388: EXTERN PetscErrorCode  PetscObjectGetCookie(PetscObject,PetscCookie *);
1389: EXTERN PetscErrorCode  PetscObjectSetType(PetscObject,const char []);
1390: EXTERN PetscErrorCode  PetscObjectGetType(PetscObject,const char *[]);
1391: EXTERN PetscErrorCode  PetscObjectSetName(PetscObject,const char[]);
1392: EXTERN PetscErrorCode  PetscObjectGetName(PetscObject,const char*[]);
1393: EXTERN PetscErrorCode  PetscObjectSetTabLevel(PetscObject,PetscInt);
1394: EXTERN PetscErrorCode  PetscObjectGetTabLevel(PetscObject,PetscInt*);
1395: EXTERN PetscErrorCode  PetscObjectIncrementTabLevel(PetscObject,PetscObject,PetscInt);
1396: EXTERN PetscErrorCode  PetscObjectReference(PetscObject);
1397: EXTERN PetscErrorCode  PetscObjectGetReference(PetscObject,PetscInt*);
1398: EXTERN PetscErrorCode  PetscObjectDereference(PetscObject);
1399: EXTERN PetscErrorCode  PetscObjectGetNewTag(PetscObject,PetscMPIInt *);
1400: EXTERN PetscErrorCode  PetscObjectView(PetscObject,PetscViewer);
1401: EXTERN PetscErrorCode  PetscObjectCompose(PetscObject,const char[],PetscObject);
1402: EXTERN PetscErrorCode  PetscObjectQuery(PetscObject,const char[],PetscObject *);
1403: EXTERN PetscErrorCode  PetscObjectComposeFunction(PetscObject,const char[],const char[],void (*)(void));
1404: EXTERN PetscErrorCode  PetscObjectSetFromOptions(PetscObject);
1405: EXTERN PetscErrorCode  PetscObjectSetUp(PetscObject);
1406: EXTERN PetscErrorCode  PetscCommGetNewTag(MPI_Comm,PetscMPIInt *);

1408: /*MC
1409:    PetscObjectComposeFunctionDynamic - Associates a function with a given PETSc object. 
1410:                        
1411:     Synopsis:
1412:     PetscErrorCode PetscObjectComposeFunctionDynamic(PetscObject obj,const char name[],const char fname[],void *ptr)

1414:    Collective on PetscObject

1416:    Input Parameters:
1417: +  obj - the PETSc object; this must be cast with a (PetscObject), for example, 
1418:          PetscObjectCompose((PetscObject)mat,...);
1419: .  name - name associated with the child function
1420: .  fname - name of the function
1421: -  ptr - function pointer (or PETSC_NULL if using dynamic libraries)

1423:    Level: advanced


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

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

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

1436:    Concepts: objects^composing functions
1437:    Concepts: composing functions
1438:    Concepts: functions^querying
1439:    Concepts: objects^querying
1440:    Concepts: querying objects

1442: .seealso: PetscObjectQueryFunction()
1443: M*/
1444: #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
1445: #define PetscObjectComposeFunctionDynamic(a,b,c,d) PetscObjectComposeFunction(a,b,c,0)
1446: #else
1447: #define PetscObjectComposeFunctionDynamic(a,b,c,d) PetscObjectComposeFunction(a,b,c,(PetscVoidFunction)(d))
1448: #endif

1450: EXTERN PetscErrorCode  PetscObjectQueryFunction(PetscObject,const char[],void (**)(void));
1451: EXTERN PetscErrorCode  PetscObjectSetOptionsPrefix(PetscObject,const char[]);
1452: EXTERN PetscErrorCode  PetscObjectAppendOptionsPrefix(PetscObject,const char[]);
1453: EXTERN PetscErrorCode  PetscObjectPrependOptionsPrefix(PetscObject,const char[]);
1454: EXTERN PetscErrorCode  PetscObjectGetOptionsPrefix(PetscObject,const char*[]);
1455: EXTERN PetscErrorCode  PetscObjectPublish(PetscObject);
1456: EXTERN PetscErrorCode  PetscObjectChangeTypeName(PetscObject,const char[]);
1457: EXTERN PetscErrorCode  PetscObjectRegisterDestroy(PetscObject);
1458: EXTERN PetscErrorCode  PetscObjectRegisterDestroyAll(void);
1459: EXTERN PetscErrorCode  PetscObjectName(PetscObject);
1460: EXTERN PetscErrorCode  PetscTypeCompare(PetscObject,const char[],PetscTruth*);
1461: EXTERN PetscErrorCode  PetscRegisterFinalize(PetscErrorCode (*)(void));
1462: EXTERN PetscErrorCode  PetscRegisterFinalizeAll(void);

1464: /*
1465:     Defines PETSc error handling.
1466: */
1467:  #include petscerror.h

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

1472:    Level: developer

1474:    Notes: Used by PetscObjectCompose() and PetscObjectQuery() 

1476: .seealso:  PetscOListAdd(), PetscOListDestroy(), PetscOListFind(), PetscObjectCompose(), PetscObjectQuery() 
1477: S*/
1478: typedef struct _n_PetscOList *PetscOList;

1480: EXTERN PetscErrorCode  PetscOListDestroy(PetscOList);
1481: EXTERN PetscErrorCode  PetscOListFind(PetscOList,const char[],PetscObject*);
1482: EXTERN PetscErrorCode  PetscOListReverseFind(PetscOList,PetscObject,char**);
1483: EXTERN PetscErrorCode  PetscOListAdd(PetscOList *,const char[],PetscObject);
1484: EXTERN PetscErrorCode  PetscOListDuplicate(PetscOList,PetscOList *);

1486: /*
1487:     Dynamic library lists. Lists of names of routines in dynamic 
1488:   link libraries that will be loaded as needed.
1489: */
1490: EXTERN PetscErrorCode  PetscFListAdd(PetscFList*,const char[],const char[],void (*)(void));
1491: EXTERN PetscErrorCode  PetscFListDestroy(PetscFList*);
1492: EXTERN PetscErrorCode  PetscFListFind(PetscFList,MPI_Comm,const char[],void (**)(void));
1493: EXTERN PetscErrorCode  PetscFListPrintTypes(MPI_Comm,FILE*,const char[],const char[],const char[],const char[],PetscFList,const char[]);
1494: #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
1495: #define    PetscFListAddDynamic(a,b,p,c) PetscFListAdd(a,b,p,0)
1496: #else
1497: #define    PetscFListAddDynamic(a,b,p,c) PetscFListAdd(a,b,p,(void (*)(void))c)
1498: #endif
1499: EXTERN PetscErrorCode  PetscFListDuplicate(PetscFList,PetscFList *);
1500: EXTERN PetscErrorCode  PetscFListView(PetscFList,PetscViewer);
1501: EXTERN PetscErrorCode  PetscFListConcat(const char [],const char [],char []);
1502: EXTERN PetscErrorCode  PetscFListGet(PetscFList,char ***,int*);

1504: /*S
1505:      PetscDLLibrary - Linked list of dynamics libraries to search for functions

1507:    Level: advanced

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

1511: .seealso:  PetscDLLibraryOpen()
1512: S*/
1513: typedef struct _n_PetscDLLibrary *PetscDLLibrary;
1515: EXTERN PetscErrorCode  PetscDLLibraryAppend(MPI_Comm,PetscDLLibrary *,const char[]);
1516: EXTERN PetscErrorCode  PetscDLLibraryPrepend(MPI_Comm,PetscDLLibrary *,const char[]);
1517: EXTERN PetscErrorCode  PetscDLLibrarySym(MPI_Comm,PetscDLLibrary *,const char[],const char[],void **);
1518: EXTERN PetscErrorCode  PetscDLLibraryPrintPath(PetscDLLibrary);
1519: EXTERN PetscErrorCode  PetscDLLibraryRetrieve(MPI_Comm,const char[],char *,size_t,PetscTruth *);
1520: EXTERN PetscErrorCode  PetscDLLibraryOpen(MPI_Comm,const char[],PetscDLLibrary *);
1521: EXTERN PetscErrorCode  PetscDLLibraryClose(PetscDLLibrary);
1522: EXTERN PetscErrorCode  PetscDLLibraryCCAAppend(MPI_Comm,PetscDLLibrary *,const char[]);

1524: /*
1525:      Useful utility routines
1526: */
1527: EXTERN PetscErrorCode  PetscSplitOwnership(MPI_Comm,PetscInt*,PetscInt*);
1528: EXTERN PetscErrorCode  PetscSplitOwnershipBlock(MPI_Comm,PetscInt,PetscInt*,PetscInt*);
1529: EXTERN PetscErrorCode  PetscSequentialPhaseBegin(MPI_Comm,PetscMPIInt);
1530: PetscPolymorphicSubroutine(PetscSequentialPhaseBegin,(MPI_Comm comm),(comm,1))
1531: PetscPolymorphicSubroutine(PetscSequentialPhaseBegin,(void),(PETSC_COMM_WORLD,1))
1532: EXTERN PetscErrorCode  PetscSequentialPhaseEnd(MPI_Comm,PetscMPIInt);
1533: PetscPolymorphicSubroutine(PetscSequentialPhaseEnd,(MPI_Comm comm),(comm,1))
1534: PetscPolymorphicSubroutine(PetscSequentialPhaseEnd,(void),(PETSC_COMM_WORLD,1))
1535: EXTERN PetscErrorCode  PetscBarrier(PetscObject);
1536: EXTERN PetscErrorCode  PetscMPIDump(FILE*);

1538: #define PetscNot(a) ((a) ? PETSC_FALSE : PETSC_TRUE)
1539: /*
1540:     Defines basic graphics available from PETSc.
1541: */
1542:  #include petscdraw.h

1544: /*
1545:     Defines the base data structures for all PETSc objects
1546: */
1547:  #include private/petscimpl.h
1548: /*
1549:      Defines PETSc profiling.
1550: */
1551:  #include petsclog.h


1554: /*
1555:           For locking, unlocking and destroying AMS memories associated with 
1556:     PETSc objects. Not currently used.
1557: */
1558: #define PetscPublishAll(v)           0
1559: #define PetscObjectTakeAccess(obj)   0
1560: #define PetscObjectGrantAccess(obj)  0
1561: #define PetscObjectDepublish(obj)    0

1563: /*
1564:       Simple PETSc parallel IO for ASCII printing
1565: */
1566: EXTERN PetscErrorCode   PetscFixFilename(const char[],char[]);
1567: EXTERN PetscErrorCode   PetscFOpen(MPI_Comm,const char[],const char[],FILE**);
1568: EXTERN PetscErrorCode   PetscFClose(MPI_Comm,FILE*);
1569: EXTERN PetscErrorCode   PetscFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4);
1570: EXTERN PetscErrorCode   PetscPrintf(MPI_Comm,const char[],...)  PETSC_PRINTF_FORMAT_CHECK(2,3);
1571: EXTERN PetscErrorCode   PetscSNPrintf(char*,size_t,const char [],...);

1573: /* These are used internally by PETSc ASCII IO routines*/
1574: #include <stdarg.h>
1575: EXTERN PetscErrorCode   PetscVSNPrintf(char*,size_t,const char[],int*,va_list);
1576: EXTERN PetscErrorCode   (*PetscVFPrintf)(FILE*,const char[],va_list);
1577: EXTERN PetscErrorCode   PetscVFPrintfDefault(FILE*,const char[],va_list);

1579: /*MC
1580:     PetscErrorPrintf - Prints error messages.

1582:    Synopsis:
1583:      PetscErrorCode (*PetscErrorPrintf)(const char format[],...);

1585:     Not Collective

1587:     Input Parameters:
1588: .   format - the usual printf() format string 

1590:    Options Database Keys:
1591: +    -error_output_stdout - cause error messages to be printed to stdout instead of the
1592:          (default) stderr
1593: -    -error_output_none to turn off all printing of error messages (does not change the way the 
1594:           error is handled.)

1596:    Notes: Use
1597: $     PetscErrorPrintf = PetscErrorPrintfNone; to turn off all printing of error messages (does not change the way the 
1598: $                        error is handled.) and
1599: $     PetscErrorPrintf = PetscErrorPrintfDefault; to turn it back on

1601:           Use
1602:      PETSC_STDERR = FILE* obtained from a file open etc. to have stderr printed to the file. 
1603:      PETSC_STDOUT = FILE* obtained from a file open etc. to have stdout printed to the file. 

1605:           Use
1606:       PetscPushErrorHandler() to provide your own error handler that determines what kind of messages to print

1608:    Level: developer

1610:     Fortran Note:
1611:     This routine is not supported in Fortran.

1613:     Concepts: error messages^printing
1614:     Concepts: printing^error messages

1616: .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf(), PetscPrintf(), PetscErrorHandlerPush()
1617: M*/
1618: EXTERN  PetscErrorCode (*PetscErrorPrintf)(const char[],...);

1620: /*MC
1621:     PetscHelpPrintf - Prints help messages.

1623:    Synopsis:
1624:      PetscErrorCode (*PetscHelpPrintf)(const char format[],...);

1626:     Not Collective

1628:     Input Parameters:
1629: .   format - the usual printf() format string 

1631:    Level: developer

1633:     Fortran Note:
1634:     This routine is not supported in Fortran.

1636:     Concepts: help messages^printing
1637:     Concepts: printing^help messages

1639: .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscErrorPrintf()
1640: M*/
1641: EXTERN  PetscErrorCode  (*PetscHelpPrintf)(MPI_Comm,const char[],...);

1643: EXTERN PetscErrorCode  PetscErrorPrintfDefault(const char [],...);
1644: EXTERN PetscErrorCode  PetscErrorPrintfNone(const char [],...);
1645: EXTERN PetscErrorCode  PetscHelpPrintfDefault(MPI_Comm,const char [],...);

1647: #if defined(PETSC_HAVE_POPEN)
1648: EXTERN PetscErrorCode   PetscPOpen(MPI_Comm,const char[],const char[],const char[],FILE **);
1649: EXTERN PetscErrorCode   PetscPClose(MPI_Comm,FILE*);
1650: #endif

1652: EXTERN PetscErrorCode   PetscSynchronizedPrintf(MPI_Comm,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3);
1653: EXTERN PetscErrorCode   PetscSynchronizedFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4);
1654: EXTERN PetscErrorCode   PetscSynchronizedFlush(MPI_Comm);
1655: EXTERN PetscErrorCode   PetscSynchronizedFGets(MPI_Comm,FILE*,size_t,char[]);
1656: EXTERN PetscErrorCode   PetscStartMatlab(MPI_Comm,const char[],const char[],FILE**);
1657: EXTERN PetscErrorCode   PetscStartJava(MPI_Comm,const char[],const char[],FILE**);
1658: EXTERN PetscErrorCode   PetscGetPetscDir(const char*[]);

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

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

1665:    Level: advanced

1667: .seealso:  PetscObject, PetscContainerCreate()
1668: S*/
1670: typedef struct _p_PetscContainer*  PetscContainer;
1671: EXTERN PetscErrorCode  PetscContainerGetPointer(PetscContainer,void **);
1672: EXTERN PetscErrorCode  PetscContainerSetPointer(PetscContainer,void *);
1673: EXTERN PetscErrorCode  PetscContainerDestroy(PetscContainer);
1674: EXTERN PetscErrorCode  PetscContainerCreate(MPI_Comm,PetscContainer *);
1675: EXTERN PetscErrorCode  PetscContainerSetUserDestroy(PetscContainer, PetscErrorCode (*)(void*));

1677: /*
1678:    For use in debuggers 
1679: */

1683: EXTERN PetscErrorCode  PetscIntView(PetscInt,const PetscInt[],PetscViewer);
1684: EXTERN PetscErrorCode  PetscRealView(PetscInt,const PetscReal[],PetscViewer);
1685: EXTERN PetscErrorCode  PetscScalarView(PetscInt,const PetscScalar[],PetscViewer);

1687: #if defined(PETSC_HAVE_MEMORY_H)
1688: #include <memory.h>
1689: #endif
1690: #if defined(PETSC_HAVE_STDLIB_H)
1691: #include <stdlib.h>
1692: #endif
1693: #if defined(PETSC_HAVE_STRINGS_H)
1694: #include <strings.h>
1695: #endif
1696: #if defined(PETSC_HAVE_STRING_H)
1697: #include <string.h>
1698: #endif


1701: #if defined(PETSC_HAVE_XMMINTRIN_H)
1702: #include <xmmintrin.h>
1703: #endif
1704: #if defined(PETSC_HAVE_STDINT_H)
1705: #include <stdint.h>
1706: #endif

1708: /*@C
1709:    PetscMemcpy - Copies n bytes, beginning at location b, to the space
1710:    beginning at location a. The two memory regions CANNOT overlap, use
1711:    PetscMemmove() in that case.

1713:    Not Collective

1715:    Input Parameters:
1716: +  b - pointer to initial memory space
1717: -  n - length (in bytes) of space to copy

1719:    Output Parameter:
1720: .  a - pointer to copy space

1722:    Level: intermediate

1724:    Compile Option:
1725:     PETSC_PREFER_DCOPY_FOR_MEMCPY will cause the BLAS dcopy() routine to be used 
1726:                                   for memory copies on double precision values.
1727:     PETSC_PREFER_COPY_FOR_MEMCPY will cause C code to be used 
1728:                                   for memory copies on double precision values.
1729:     PETSC_PREFER_FORTRAN_FORMEMCPY will cause Fortran code to be used 
1730:                                   for memory copies on double precision values.

1732:    Note:
1733:    This routine is analogous to memcpy().

1735:   Concepts: memory^copying
1736:   Concepts: copying^memory
1737:   
1738: .seealso: PetscMemmove()

1740: @*/
1741: PETSC_STATIC_INLINE PetscErrorCode  PetscMemcpy(void *a,const void *b,size_t n)
1742: {
1743: #if defined(PETSC_USE_DEBUG)
1744:   unsigned long al = (unsigned long) a,bl = (unsigned long) b;
1745:   unsigned long nl = (unsigned long) n;
1746:   if (n > 0 && !b) SETERRQ(PETSC_ERR_ARG_NULL,"Trying to copy from a null pointer");
1747:   if (n > 0 && !a) SETERRQ(PETSC_ERR_ARG_NULL,"Trying to copy to a null pointer");
1748: #endif
1750:   if (a != b) {
1751: #if defined(PETSC_USE_DEBUG)
1752:     if ((al > bl && (al - bl) < nl) || (bl - al) < nl) {
1753:       SETERRQ3(PETSC_ERR_ARG_INCOMP,"Memory regions overlap: either use PetscMemmov()\n\
1754:               or make sure your copy regions and lengths are correct. \n\
1755:               Length (bytes) %ld first address %ld second address %ld",nl,al,bl);
1756:     }
1757: #endif
1758: #if (defined(PETSC_PREFER_DCOPY_FOR_MEMCPY) || defined(PETSC_PREFER_COPY_FOR_MEMCPY) || defined(PETSC_PREFER_FORTRAN_FORMEMCPY))
1759:    if (!(((long) a) % sizeof(PetscScalar)) && !(n % sizeof(PetscScalar))) {
1760:       size_t len = n/sizeof(PetscScalar);
1761: #if defined(PETSC_PREFER_DCOPY_FOR_MEMCPY)
1762:       PetscBLASInt one = 1,blen = PetscBLASIntCast(len);
1763:       BLAScopy_(&blen,(PetscScalar *)b,&one,(PetscScalar *)a,&one);
1764: #elif defined(PETSC_PREFER_FORTRAN_FORMEMCPY)
1765:       fortrancopy_(&len,(PetscScalar*)b,(PetscScalar*)a);
1766: #else
1767:       size_t      i;
1768:       PetscScalar *x = (PetscScalar*)b, *y = (PetscScalar*)a;
1769:       for (i=0; i<len; i++) y[i] = x[i];
1770: #endif
1771:     } else {
1772:       memcpy((char*)(a),(char*)(b),n);
1773:     }
1774: #elif defined(PETSC_HAVE__INTEL_FAST_MEMCPY)
1775:     _intel_fast_memcpy((char*)(a),(char*)(b),n);
1776: #else
1777:     memcpy((char*)(a),(char*)(b),n);
1778: #endif
1779:   }
1780:   return(0);
1781: }

1783: /*@C
1784:    PetscMemzero - Zeros the specified memory.

1786:    Not Collective

1788:    Input Parameters:
1789: +  a - pointer to beginning memory location
1790: -  n - length (in bytes) of memory to initialize

1792:    Level: intermediate

1794:    Compile Option:
1795:    PETSC_PREFER_BZERO - on certain machines (the IBM RS6000) the bzero() routine happens
1796:   to be faster than the memset() routine. This flag causes the bzero() routine to be used.

1798:    Concepts: memory^zeroing
1799:    Concepts: zeroing^memory

1801: .seealso: PetscMemcpy()
1802: @*/
1803: PETSC_STATIC_INLINE PetscErrorCode  PetscMemzero(void *a,size_t n)
1804: {
1805:   if (n > 0) {
1806: #if defined(PETSC_USE_DEBUG)
1807:     if (!a) SETERRQ(PETSC_ERR_ARG_NULL,"Trying to zero at a null pointer");
1808: #endif
1809: #if defined(PETSC_PREFER_ZERO_FOR_MEMZERO)
1810:     if (!(((long) a) % sizeof(PetscScalar)) && !(n % sizeof(PetscScalar))) {
1811:       size_t      i,len = n/sizeof(PetscScalar);
1812:       PetscScalar *x = (PetscScalar*)a;
1813:       for (i=0; i<len; i++) x[i] = 0.0;
1814:     } else {
1815: #elif defined(PETSC_PREFER_FORTRAN_FOR_MEMZERO)
1816:     if (!(((long) a) % sizeof(PetscScalar)) && !(n % sizeof(PetscScalar))) {
1817:       PetscInt len = n/sizeof(PetscScalar);
1818:       fortranzero_(&len,(PetscScalar*)a);
1819:     } else {
1820: #endif
1821: #if defined(PETSC_PREFER_BZERO)
1822:       bzero((char *)a,n);
1823: #elif defined (PETSC_HAVE__INTEL_FAST_MEMSET)
1824:       _intel_fast_memset((char*)a,0,n);
1825: #else
1826:       memset((char*)a,0,n);
1827: #endif
1828: #if defined(PETSC_PREFER_ZERO_FOR_MEMZERO) || defined(PETSC_PREFER_FORTRAN_FOR_MEMZERO)
1829:     }
1830: #endif
1831:   }
1832:   return 0;
1833: }

1835: /*MC
1836:    PetscPrefetchBlock - Prefetches a block of memory

1838:    Synopsis:
1839:     void PetscPrefetchBlock(const anytype *a,size_t n,int rw,int t)

1841:    Not Collective

1843:    Input Parameters:
1844: +  a - pointer to first element to fetch (any type but usually PetscInt or PetscScalar)
1845: .  n - number of elements to fetch
1846: .  rw - 1 if the memory will be written to, otherwise 0 (ignored by many processors)
1847: -  t - temporal locality (0,1,2,3), see note

1849:    Level: developer

1851:    Notes:
1852:    The last two arguments (rw and t) must be compile-time constants.

1854:    There are four levels of temporal locality (not all architectures distinguish)
1855: +  0 - Non-temporal.  Prefetches directly to L1, evicts to memory (skips higher level cache unless it was already there when prefetched).
1856: .  1 - Temporal with respect to high-level cache only.  Only prefetches to high-level cache (not L1), kept at high levels after eviction from L1.
1857: .  2 - Same as 1, but keep in mid-level cache.  (On most systems, 1 and 2 are equivalent.)
1858: -  3 - Fetch to all levels of cache and evict to the closest level.  Use this when the memory will be reused regularly despite necessary eviction from L1.

1860:    This function does nothing on architectures that do not support prefetch and never errors (even if passed an invalid
1861:    address).

1863:    Concepts: memory
1864: M*/
1865: #define PetscPrefetchBlock(a,n,rw,t) do {                               \
1866:     const char *_p = (const char*)(a),*_end = (const char*)((a)+(n));   \
1867:     for ( ; _p < _end; _p += PETSC_LEVEL1_DCACHE_LINESIZE) PETSC_Prefetch(_p,(rw),(t)); \
1868:   } while (0)

1870: /*
1871:     Allows accessing Matlab Engine
1872: */
1873:  #include petscmatlab.h

1875: /*
1876:       Determine if some of the kernel computation routines use
1877:    Fortran (rather than C) for the numerical calculations. On some machines
1878:    and compilers (like complex numbers) the Fortran version of the routines
1879:    is faster than the C/C++ versions. The flag --with-fortran-kernels
1880:    should be used with config/configure.py to turn these on.
1881: */
1882: #if defined(PETSC_USE_FORTRAN_KERNELS)

1884: #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTCRL)
1885: #define PETSC_USE_FORTRAN_KERNEL_MULTCRL
1886: #endif

1888: #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTCSRPERM)
1889: #define PETSC_USE_FORTRAN_KERNEL_MULTCSRPERM
1890: #endif

1892: #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ)
1893: #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ
1894: #endif

1896: #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ)
1897: #define PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ
1898: #endif

1900: #if !defined(PETSC_USE_FORTRAN_KERNEL_NORM)
1901: #define PETSC_USE_FORTRAN_KERNEL_NORM
1902: #endif

1904: #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY)
1905: #define PETSC_USE_FORTRAN_KERNEL_MAXPY
1906: #endif

1908: #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ)
1909: #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ
1910: #endif

1912: #if !defined(PETSC_USE_FORTRAN_KERNEL_RELAXAIJ)
1913: #define PETSC_USE_FORTRAN_KERNEL_RELAXAIJ
1914: #endif

1916: #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ)
1917: #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ
1918: #endif

1920: #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ)
1921: #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ
1922: #endif

1924: #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT)
1925: #define PETSC_USE_FORTRAN_KERNEL_MDOT
1926: #endif

1928: #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY)
1929: #define PETSC_USE_FORTRAN_KERNEL_XTIMESY
1930: #endif

1932: #if !defined(PETSC_USE_FORTRAN_KERNEL_AYPX)
1933: #define PETSC_USE_FORTRAN_KERNEL_AYPX
1934: #endif

1936: #if !defined(PETSC_USE_FORTRAN_KERNEL_WAXPY)
1937: #define PETSC_USE_FORTRAN_KERNEL_WAXPY
1938: #endif

1940: #endif

1942: /*
1943:     Macros for indicating code that should be compiled with a C interface,
1944:    rather than a C++ interface. Any routines that are dynamically loaded
1945:    (such as the PCCreate_XXX() routines) must be wrapped so that the name
1946:    mangler does not change the functions symbol name. This just hides the 
1948: */
1949: #if defined(__cplusplus)
1952: #else
1955: #endif

1957: /* --------------------------------------------------------------------*/

1959: /*MC
1960:     MPI_Comm - the basic object used by MPI to determine which processes are involved in a 
1961:         communication

1963:    Level: beginner

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

1967: .seealso: PETSC_COMM_WORLD, PETSC_COMM_SELF
1968: M*/

1970: /*MC
1971:     PetscScalar - PETSc type that represents either a double precision real number, a double precision
1972:        complex number, a single precision real number, a long double or an int - if the code is configured 
1973:        with --with-scalar-type=real,complex --with-precision=single,double,longdouble,int,matsingle


1976:    Level: beginner

1978: .seealso: PetscReal, PassiveReal, PassiveScalar, MPIU_SCALAR, PetscInt
1979: M*/

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

1984:    Level: beginner

1986: .seealso: PetscScalar, PassiveReal, PassiveScalar
1987: M*/

1989: /*MC
1990:     PassiveScalar - PETSc type that represents a PetscScalar
1991:    Level: beginner

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

1996: .seealso: PetscReal, PassiveReal, PetscScalar
1997: M*/

1999: /*MC
2000:     PassiveReal - PETSc type that represents a PetscReal

2002:    Level: beginner

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

2007: .seealso: PetscScalar, PetscReal, PassiveScalar
2008: M*/

2010: /*MC
2011:     MPIU_SCALAR - MPI datatype corresponding to PetscScalar

2013:    Level: beginner

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

2018: .seealso: PetscReal, PassiveReal, PassiveScalar, PetscScalar, MPIU_INT
2019: M*/

2021: #if defined(PETSC_HAVE_MPIIO)
2022: #if !defined(PETSC_WORDS_BIGENDIAN)
2025: #else
2026: #define MPIU_File_write_all(a,b,c,d,e) MPI_File_write_all(a,b,c,d,e) 
2027: #define MPIU_File_read_all(a,b,c,d,e) MPI_File_read_all(a,b,c,d,e) 
2028: #endif
2029: #endif

2031: /* the following petsc_static_inline require petscerror.h */

2033: /* Limit MPI to 32-bits */
2034: #define PETSC_MPI_INT_MAX  2147483647
2035: #define PETSC_MPI_INT_MIN -2147483647
2036: /* Limit BLAS to 32-bits */
2037: #define PETSC_BLAS_INT_MAX  2147483647
2038: #define PETSC_BLAS_INT_MIN -2147483647
2039: /* On 32 bit systems HDF5 is limited by size of integer, because hsize_t is defined as size_t */
2040: #define PETSC_HDF5_INT_MAX  2147483647
2041: #define PETSC_HDF5_INT_MIN -2147483647

2043: #if defined(PETSC_USE_64BIT_INDICES)
2044: #define PetscMPIIntCheck(a)  if ((a) > PETSC_MPI_INT_MAX) SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Message too long for MPI")
2045: #define PetscBLASIntCheck(a)  if ((a) > PETSC_BLAS_INT_MAX) SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Array too long for BLAS/LAPACK")
2046: #define PetscMPIIntCast(a) (a);PetscMPIIntCheck(a)
2047: #define PetscBLASIntCast(a) (a);PetscBLASIntCheck(a)

2049: #if (PETSC_SIZEOF_SIZE_T == 4)
2050: #define PetscHDF5IntCheck(a)  if ((a) > PETSC_HDF5_INT_MAX) SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Array too long for HDF5")
2051: #define PetscHDF5IntCast(a) (a);PetscHDF5IntCheck(a)
2052: #else
2053: #define PetscHDF5IntCheck(a)
2054: #define PetscHDF5IntCast(a) a
2055: #endif

2057: #else
2058: #define PetscMPIIntCheck(a) 
2059: #define PetscBLASIntCheck(a) 
2060: #define PetscHDF5IntCheck(a)
2061: #define PetscMPIIntCast(a) a
2062: #define PetscBLASIntCast(a) a
2063: #define PetscHDF5IntCast(a) a
2064: #endif  


2067: /*
2068:      The IBM include files define hz, here we hide it so that it may be used
2069:    as a regular user variable.
2070: */
2071: #if defined(hz)
2072: #undef hz
2073: #endif

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


2078: #if defined(PETSC_HAVE_LIMITS_H)
2079: #include <limits.h>
2080: #endif
2081: #if defined(PETSC_HAVE_SYS_PARAM_H)
2082: #include <sys/param.h>
2083: #endif
2084: #if defined(PETSC_HAVE_SYS_TYPES_H)
2085: #include <sys/types.h>
2086: #endif
2087: #if defined(MAXPATHLEN)
2088: #  define PETSC_MAX_PATH_LEN     MAXPATHLEN
2089: #elif defined(MAX_PATH)
2090: #  define PETSC_MAX_PATH_LEN     MAX_PATH
2091: #elif defined(_MAX_PATH)
2092: #  define PETSC_MAX_PATH_LEN     _MAX_PATH
2093: #else
2094: #  define PETSC_MAX_PATH_LEN     4096
2095: #endif

2097: /* Special support for C++ */
2098:  #include petscsys.hh


2101: /*MC

2103:     UsingFortran - Fortran can be used with PETSc in four distinct approaches

2105: $    1) classic Fortran 77 style
2106: $#include "finclude/petscXXX.h" to work with material from the XXX component of PETSc
2107: $       XXX variablename
2108: $      You cannot use this approach if you wish to use the Fortran 90 specific PETSc routines
2109: $      which end in F90; such as VecGetArrayF90()
2110: $
2111: $    2) classic Fortran 90 style
2112: $#include "finclude/petscXXX.h" 
2113: $#include "finclude/petscXXX.h90" to work with material from the XXX component of PETSc
2114: $       XXX variablename
2115: $
2116: $    3) Using Fortran modules
2117: $#include "finclude/petscXXXdef.h" 
2118: $         use petscXXXX
2119: $       XXX variablename
2120: $
2121: $    4) Use Fortran modules and Fortran data types for PETSc types
2122: $#include "finclude/petscXXXdef.h" 
2123: $         use petscXXXX
2124: $       type(XXX) variablename
2125: $      To use this approach you must config/configure.py PETSc with the additional
2126: $      option --with-fortran-datatypes You cannot use the type(XXX) declaration approach without using Fortran modules

2128:     Finally if you absolutely do not want to use any #include you can use either 

2130: $    3a) skip the #include BUT you cannot use any PETSc data type names like Vec, Mat, PetscInt, PetscErrorCode etc
2131: $        and you must declare the variables as integer, for example 
2132: $        integer variablename
2133: $
2134: $    4a) skip the #include, you use the object types like type(Vec) type(Mat) but cannot use the data type
2135: $        names like PetscErrorCode, PetscInt etc. again for those you must use integer

2137:    We recommend either 2 or 3. Approaches 2 and 3 provide type checking for most PETSc function calls; 4 has type checking 
2138: for only a few PETSc functions.

2140:    Fortran type checking with interfaces is strick, this means you cannot pass a scalar value when an array value
2141: is expected (even though it is legal Fortran). For example when setting a single value in a matrix with MatSetValues()
2142: you cannot have something like
2143: $      PetscInt row,col
2144: $      PetscScalar val
2145: $        ...
2146: $      call MatSetValues(mat,1,row,1,col,val,INSERT_VALUES,ierr)
2147: You must instead have 
2148: $      PetscInt row(1),col(1)
2149: $      PetscScalar val(1)
2150: $        ...
2151: $      call MatSetValues(mat,1,row,1,col,val,INSERT_VALUES,ierr)


2154:     See the example src/vec/vec/examples/tutorials/ex20f90.F90 for an example that can use all four approaches

2156:     Developer Notes: The finclude/petscXXXdef.h contain all the #defines (would be typedefs in C code) these
2157:      automatically include their predecessors; for example finclude/petscvecdef.h includes finclude/petscisdef.h

2159:      The finclude/petscXXXX.h contain all the parameter statements for that package. These automatically include
2160:      their finclude/petscXXXdef.h file but DO NOT automatically include their predecessors;  for example 
2161:      finclude/petscvec.h does NOT automatically include finclude/petscis.h

2163:      The finclude/ftn-custom/petscXXXdef.h90 are not intended to be used directly in code, they define the
2164:      Fortran data type type(XXX) (for example type(Vec)) when PETSc is config/configure.py with the --with-fortran-datatypes option.

2166:      The finclude/ftn-custom/petscXXX.h90 (not included directly by code) contain interface definitions for
2167:      the PETSc Fortran stubs that have different bindings then their C version (for example VecGetArrayF90).

2169:      The finclude/ftn-auto/petscXXX.h90 (not included directly by code) contain interface definitions generated
2170:      automatically by "make allfortranstubs".

2172:      The finclude/petscXXX.h90 includes the custom finclude/ftn-custom/petscXXX.h90 and if config/configure.py 
2173:      was run with --with-fortran-interfaces it also includes the finclude/ftn-auto/petscXXX.h90 These DO NOT automatically
2174:      include their predecessors

2176:     Level: beginner

2178: M*/

2180: EXTERN PetscErrorCode  PetscGetArchType(char[],size_t);
2181: EXTERN PetscErrorCode  PetscGetHostName(char[],size_t);
2182: EXTERN PetscErrorCode  PetscGetUserName(char[],size_t);
2183: EXTERN PetscErrorCode  PetscGetProgramName(char[],size_t);
2184: EXTERN PetscErrorCode  PetscSetProgramName(const char[]);
2185: EXTERN PetscErrorCode  PetscGetDate(char[],size_t);

2187: EXTERN PetscErrorCode  PetscSortInt(PetscInt,PetscInt[]);
2188: EXTERN PetscErrorCode  PetscSortIntWithPermutation(PetscInt,const PetscInt[],PetscInt[]);
2189: EXTERN PetscErrorCode  PetscSortStrWithPermutation(PetscInt,const char*[],PetscInt[]);
2190: EXTERN PetscErrorCode  PetscSortIntWithArray(PetscInt,PetscInt[],PetscInt[]);
2191: EXTERN PetscErrorCode  PetscSortMPIIntWithArray(PetscMPIInt,PetscMPIInt[],PetscMPIInt[]);
2192: EXTERN PetscErrorCode  PetscSortIntWithScalarArray(PetscInt,PetscInt[],PetscScalar[]);
2193: EXTERN PetscErrorCode  PetscSortReal(PetscInt,PetscReal[]);
2194: EXTERN PetscErrorCode  PetscSortRealWithPermutation(PetscInt,const PetscReal[],PetscInt[]);
2195: EXTERN PetscErrorCode  PetscSortSplit(PetscInt,PetscInt,PetscScalar[],PetscInt[]);
2196: EXTERN PetscErrorCode  PetscSortSplitReal(PetscInt,PetscInt,PetscReal[],PetscInt[]);

2198: EXTERN PetscErrorCode  PetscSetDisplay(void);
2199: EXTERN PetscErrorCode  PetscGetDisplay(char[],size_t);

2201: /*E
2202:     PetscRandomType - String with the name of a PETSc randomizer
2203:        with an optional dynamic library name, for example
2204:        http://www.mcs.anl.gov/petsc/lib.a:myrandcreate()

2206:    Level: beginner

2208:    Notes: to use the SPRNG you must have config/configure.py PETSc
2209:    with the option --download-sprng

2211: .seealso: PetscRandomSetType(), PetscRandom
2212: E*/
2213: #define PetscRandomType char*
2214: #define PETSCRAND       "rand"
2215: #define PETSCRAND48     "rand48"
2216: #define PETSCSPRNG      "sprng"          

2218: /* Logging support */

2221: EXTERN PetscErrorCode  PetscRandomInitializePackage(const char[]);

2223: /*S
2224:      PetscRandom - Abstract PETSc object that manages generating random numbers

2226:    Level: intermediate

2228:   Concepts: random numbers

2230: .seealso:  PetscRandomCreate(), PetscRandomGetValue(), PetscRandomType
2231: S*/
2232: typedef struct _p_PetscRandom*   PetscRandom;

2234: /* Dynamic creation and loading functions */

2238: EXTERN PetscErrorCode  PetscRandomRegisterAll(const char []);
2239: EXTERN PetscErrorCode  PetscRandomRegister(const char[],const char[],const char[],PetscErrorCode (*)(PetscRandom));
2240: EXTERN PetscErrorCode  PetscRandomRegisterDestroy(void);
2241: EXTERN PetscErrorCode  PetscRandomSetType(PetscRandom, const PetscRandomType);
2242: EXTERN PetscErrorCode  PetscRandomSetFromOptions(PetscRandom);
2243: EXTERN PetscErrorCode  PetscRandomGetType(PetscRandom, const PetscRandomType*);
2244: EXTERN PetscErrorCode  PetscRandomViewFromOptions(PetscRandom,char*);
2245: EXTERN PetscErrorCode  PetscRandomView(PetscRandom,PetscViewer);

2247: /*MC
2248:   PetscRandomRegisterDynamic - Adds a new PetscRandom component implementation

2250:   Synopsis:
2251:   PetscErrorCode PetscRandomRegisterDynamic(const char *name, const char *path, const char *func_name, PetscErrorCode (*create_func)(PetscRandom))

2253:   Not Collective

2255:   Input Parameters:
2256: + name        - The name of a new user-defined creation routine
2257: . path        - The path (either absolute or relative) of the library containing this routine
2258: . func_name   - The name of routine to create method context
2259: - create_func - The creation routine itself

2261:   Notes:
2262:   PetscRandomRegisterDynamic() may be called multiple times to add several user-defined randome number generators

2264:   If dynamic libraries are used, then the fourth input argument (routine_create) is ignored.

2266:   Sample usage:
2267: .vb
2268:     PetscRandomRegisterDynamic("my_rand","/home/username/my_lib/lib/libO/solaris/libmy.a", "MyPetscRandomtorCreate", MyPetscRandomtorCreate);
2269: .ve

2271:   Then, your random type can be chosen with the procedural interface via
2272: .vb
2273:     PetscRandomCreate(MPI_Comm, PetscRandom *);
2274:     PetscRandomSetType(PetscRandom,"my_random_name");
2275: .ve
2276:    or at runtime via the option
2277: .vb
2278:     -random_type my_random_name
2279: .ve

2281:   Notes: $PETSC_ARCH occuring in pathname will be replaced with appropriate values.

2283:          For an example of the code needed to interface your own random number generator see
2284:          src/sys/random/impls/rand/rand.c
2285:         
2286:   Level: advanced

2288: .keywords: PetscRandom, register
2289: .seealso: PetscRandomRegisterAll(), PetscRandomRegisterDestroy(), PetscRandomRegister()
2290: M*/
2291: #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
2292: #define PetscRandomRegisterDynamic(a,b,c,d) PetscRandomRegister(a,b,c,0)
2293: #else
2294: #define PetscRandomRegisterDynamic(a,b,c,d) PetscRandomRegister(a,b,c,d)
2295: #endif

2297: EXTERN PetscErrorCode  PetscRandomCreate(MPI_Comm,PetscRandom*);
2298: EXTERN PetscErrorCode  PetscRandomGetValue(PetscRandom,PetscScalar*);
2299: EXTERN PetscErrorCode  PetscRandomGetValueReal(PetscRandom,PetscReal*);
2300: EXTERN PetscErrorCode  PetscRandomGetInterval(PetscRandom,PetscScalar*,PetscScalar*);
2301: EXTERN PetscErrorCode  PetscRandomSetInterval(PetscRandom,PetscScalar,PetscScalar);
2302: EXTERN PetscErrorCode  PetscRandomSetSeed(PetscRandom,unsigned long);
2303: EXTERN PetscErrorCode  PetscRandomGetSeed(PetscRandom,unsigned long *);
2304: EXTERN PetscErrorCode  PetscRandomSeed(PetscRandom);
2305: EXTERN PetscErrorCode  PetscRandomDestroy(PetscRandom);

2307: EXTERN PetscErrorCode  PetscGetFullPath(const char[],char[],size_t);
2308: EXTERN PetscErrorCode  PetscGetRelativePath(const char[],char[],size_t);
2309: EXTERN PetscErrorCode  PetscGetWorkingDirectory(char[],size_t);
2310: EXTERN PetscErrorCode  PetscGetRealPath(const char[],char[]);
2311: EXTERN PetscErrorCode  PetscGetHomeDirectory(char[],size_t);
2312: EXTERN PetscErrorCode  PetscTestFile(const char[],char,PetscTruth*);
2313: EXTERN PetscErrorCode  PetscTestDirectory(const char[],char,PetscTruth*);

2315: EXTERN PetscErrorCode  PetscBinaryRead(int,void*,PetscInt,PetscDataType);
2316: EXTERN PetscErrorCode  PetscBinarySynchronizedRead(MPI_Comm,int,void*,PetscInt,PetscDataType);
2317: EXTERN PetscErrorCode  PetscBinarySynchronizedWrite(MPI_Comm,int,void*,PetscInt,PetscDataType,PetscTruth);
2318: EXTERN PetscErrorCode  PetscBinaryWrite(int,void*,PetscInt,PetscDataType,PetscTruth);
2319: EXTERN PetscErrorCode  PetscBinaryOpen(const char[],PetscFileMode,int *);
2320: EXTERN PetscErrorCode  PetscBinaryClose(int);
2321: EXTERN PetscErrorCode  PetscSharedTmp(MPI_Comm,PetscTruth *);
2322: EXTERN PetscErrorCode  PetscSharedWorkingDirectory(MPI_Comm,PetscTruth *);
2323: EXTERN PetscErrorCode  PetscGetTmp(MPI_Comm,char[],size_t);
2324: EXTERN PetscErrorCode  PetscFileRetrieve(MPI_Comm,const char[],char[],size_t,PetscTruth*);
2325: EXTERN PetscErrorCode  PetscLs(MPI_Comm,const char[],char[],size_t,PetscTruth*);
2326: EXTERN PetscErrorCode  PetscOpenSocket(char*,int,int*);

2328: /*
2329:    In binary files variables are stored using the following lengths,
2330:   regardless of how they are stored in memory on any one particular
2331:   machine. Use these rather then sizeof() in computing sizes for 
2332:   PetscBinarySeek().
2333: */
2334: #define PETSC_BINARY_INT_SIZE    (32/8)
2335: #define PETSC_BINARY_FLOAT_SIZE  (32/8)
2336: #define PETSC_BINARY_CHAR_SIZE    (8/8)
2337: #define PETSC_BINARY_SHORT_SIZE  (16/8)
2338: #define PETSC_BINARY_DOUBLE_SIZE (64/8)
2339: #define PETSC_BINARY_SCALAR_SIZE sizeof(PetscScalar)

2341: /*E
2342:   PetscBinarySeekType - argument to PetscBinarySeek()

2344:   Level: advanced

2346: .seealso: PetscBinarySeek(), PetscBinarySynchronizedSeek()
2347: E*/
2348: typedef enum {PETSC_BINARY_SEEK_SET = 0,PETSC_BINARY_SEEK_CUR = 1,PETSC_BINARY_SEEK_END = 2} PetscBinarySeekType;
2349: EXTERN PetscErrorCode  PetscBinarySeek(int,off_t,PetscBinarySeekType,off_t*);
2350: EXTERN PetscErrorCode  PetscBinarySynchronizedSeek(MPI_Comm,int,off_t,PetscBinarySeekType,off_t*);

2352: EXTERN PetscErrorCode  PetscSetDebugTerminal(const char[]);
2353: EXTERN PetscErrorCode  PetscSetDebugger(const char[],PetscTruth);
2354: EXTERN PetscErrorCode  PetscSetDefaultDebugger(void);
2355: EXTERN PetscErrorCode  PetscSetDebuggerFromString(char*);
2356: EXTERN PetscErrorCode  PetscAttachDebugger(void);
2357: EXTERN PetscErrorCode  PetscStopForDebugger(void);

2359: EXTERN PetscErrorCode  PetscGatherNumberOfMessages(MPI_Comm,const PetscMPIInt[],const PetscMPIInt[],PetscMPIInt*);
2360: EXTERN PetscErrorCode  PetscGatherMessageLengths(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],PetscMPIInt**,PetscMPIInt**);
2361: EXTERN PetscErrorCode  PetscGatherMessageLengths2(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],const PetscMPIInt[],PetscMPIInt**,PetscMPIInt**,PetscMPIInt**);
2362: EXTERN PetscErrorCode  PetscPostIrecvInt(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],const PetscMPIInt[],PetscInt***,MPI_Request**);
2363: EXTERN PetscErrorCode  PetscPostIrecvScalar(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],const PetscMPIInt[],PetscScalar***,MPI_Request**);

2365: EXTERN PetscErrorCode  PetscSSEIsEnabled(MPI_Comm,PetscTruth *,PetscTruth *);

2367: /*E
2368:   InsertMode - Whether entries are inserted or added into vectors or matrices

2370:   Level: beginner

2372: .seealso: VecSetValues(), MatSetValues(), VecSetValue(), VecSetValuesBlocked(),
2373:           VecSetValuesLocal(), VecSetValuesBlockedLocal(), MatSetValuesBlocked(),
2374:           MatSetValuesBlockedLocal(), MatSetValuesLocal(), VecScatterBegin(), VecScatterEnd()
2375: E*/
2376: typedef enum {NOT_SET_VALUES, INSERT_VALUES, ADD_VALUES, MAX_VALUES} InsertMode;

2378: /*MC
2379:     INSERT_VALUES - Put a value into a vector or matrix, overwrites any previous value

2381:     Level: beginner

2383: .seealso: InsertMode, VecSetValues(), MatSetValues(), VecSetValue(), VecSetValuesBlocked(),
2384:           VecSetValuesLocal(), VecSetValuesBlockedLocal(), MatSetValuesBlocked(), ADD_VALUES,
2385:           MatSetValuesBlockedLocal(), MatSetValuesLocal(), VecScatterBegin(), VecScatterEnd(), MAX_VALUES

2387: M*/

2389: /*MC
2390:     ADD_VALUES - Adds a value into a vector or matrix, if there previously was no value, just puts the
2391:                 value into that location

2393:     Level: beginner

2395: .seealso: InsertMode, VecSetValues(), MatSetValues(), VecSetValue(), VecSetValuesBlocked(),
2396:           VecSetValuesLocal(), VecSetValuesBlockedLocal(), MatSetValuesBlocked(), INSERT_VALUES,
2397:           MatSetValuesBlockedLocal(), MatSetValuesLocal(), VecScatterBegin(), VecScatterEnd(), MAX_VALUES

2399: M*/

2401: /*MC
2402:     MAX_VALUES - Puts the maximum of the scattered/gathered value and the current value into each location

2404:     Level: beginner

2406: .seealso: InsertMode, VecScatterBegin(), VecScatterEnd(), ADD_VALUES, INSERT_VALUES

2408: M*/

2410: /*E
2411:   ScatterMode - Determines the direction of a scatter

2413:   Level: beginner

2415: .seealso: VecScatter, VecScatterBegin(), VecScatterEnd()
2416: E*/
2417: typedef enum {SCATTER_FORWARD=0, SCATTER_REVERSE=1, SCATTER_FORWARD_LOCAL=2, SCATTER_REVERSE_LOCAL=3, SCATTER_LOCAL=2} ScatterMode;

2419: /*MC
2420:     SCATTER_FORWARD - Scatters the values as dictated by the VecScatterCreate() call

2422:     Level: beginner

2424: .seealso: VecScatter, ScatterMode, VecScatterCreate(), VecScatterBegin(), VecScatterEnd(), SCATTER_REVERSE, SCATTER_FORWARD_LOCAL,
2425:           SCATTER_REVERSE_LOCAL

2427: M*/

2429: /*MC
2430:     SCATTER_REVERSE - Moves the values in the opposite direction then the directions indicated in
2431:          in the VecScatterCreate()

2433:     Level: beginner

2435: .seealso: VecScatter, ScatterMode, VecScatterCreate(), VecScatterBegin(), VecScatterEnd(), SCATTER_FORWARD, SCATTER_FORWARD_LOCAL,
2436:           SCATTER_REVERSE_LOCAL

2438: M*/

2440: /*MC
2441:     SCATTER_FORWARD_LOCAL - Scatters the values as dictated by the VecScatterCreate() call except NO parallel communication
2442:        is done. Any variables that have be moved between processes are ignored

2444:     Level: developer

2446: .seealso: VecScatter, ScatterMode, VecScatterCreate(), VecScatterBegin(), VecScatterEnd(), SCATTER_REVERSE, SCATTER_FORWARD,
2447:           SCATTER_REVERSE_LOCAL

2449: M*/

2451: /*MC
2452:     SCATTER_REVERSE_LOCAL - Moves the values in the opposite direction then the directions indicated in
2453:          in the VecScatterCreate()  except NO parallel communication
2454:        is done. Any variables that have be moved between processes are ignored

2456:     Level: developer

2458: .seealso: VecScatter, ScatterMode, VecScatterCreate(), VecScatterBegin(), VecScatterEnd(), SCATTER_FORWARD, SCATTER_FORWARD_LOCAL,
2459:           SCATTER_REVERSE

2461: M*/

2463: /*S
2464:    PetscSubcomm - Context of MPI subcommunicators, used by PCREDUNDANT

2466:    Level: advanced

2468:    Concepts: communicator, create
2469: S*/
2470: typedef struct _n_PetscSubcomm* PetscSubcomm;

2472: struct _n_PetscSubcomm {
2473:   MPI_Comm   parent;      /* parent communicator */
2474:   MPI_Comm   dupparent;   /* duplicate parent communicator, under which the processors of this subcomm have contiguous rank */
2475:   MPI_Comm   comm;        /* this communicator */
2476:   PetscInt   n;           /* num of subcommunicators under the parent communicator */
2477:   PetscInt   color;       /* color of processors belong to this communicator */
2478: };

2480: EXTERN PetscErrorCode  PetscSubcommCreate(MPI_Comm,PetscInt,PetscSubcomm*);
2481: EXTERN PetscErrorCode  PetscSubcommDestroy(PetscSubcomm);


2485: #endif