xref: /petsc/include/petsc.h (revision e39fd77f588fe8a9f63ea3dd3ce9052e17ee1991)
1 /*
2    This is the main PETSc include file (for C and C++).  It is included by all
3    other PETSc include files, so it almost never has to be specifically included.
4 */
5 #if !defined(__PETSC_H)
6 #define __PETSC_H
7 /* ========================================================================== */
8 /*
9    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"
15 
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 */
21 #if defined(PETSC_CLANGUAGE_CXX) && !defined(PETSC_USE_EXTERN_CXX) && !defined(__cplusplus)
22 #error "PETSc configured with --with-clanguage=c++ and NOT --with-c-support - it can be used only with a C++ compiler"
23 #endif
24 
25 #if defined(PETSC_USE_EXTERN_CXX) && defined(__cplusplus)
26 #define PETSC_EXTERN_CXX_BEGIN extern "C" {
27 #define PETSC_EXTERN_CXX_END  }
28 #else
29 #define PETSC_EXTERN_CXX_BEGIN
30 #define PETSC_EXTERN_CXX_END
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                                          PetscStrcat(version," HG revision: "),PetscStrcat(version,PETSC_VERSION_HG))
50 #else
51 #define PetscGetVersion(version,len) (PetscSNPrintf(version,len,"Petsc Development Version %d.%d.%d, Patch %d, ", \
52                                          PETSC_VERSION_MAJOR,PETSC_VERSION_MINOR, PETSC_VERSION_SUBMINOR, \
53                                          PETSC_VERSION_PATCH),PetscStrcat(version,PETSC_VERSION_PATCH_DATE), \
54                                          PetscStrcat(version," HG revision: "),PetscStrcat(version,PETSC_VERSION_HG))
55 #endif
56 
57 /*MC
58     PetscGetVersion - Gets the PETSc version information in a string.
59 
60     Input Parameter:
61 .   len - length of the string
62 
63     Output Parameter:
64 .   version - version string
65 
66     Level: developer
67 
68     Usage:
69     char version[256];
70     ierr = PetscGetVersion(version,256);CHKERRQ(ierr)
71 
72     Fortran Note:
73     This routine is not supported in Fortran.
74 
75 .seealso: PetscGetProgramName()
76 
77 M*/
78 
79 /* ========================================================================== */
80 
81 /*
82    Currently cannot check formatting for PETSc print statements because we have our
83    own format %D and %G
84 */
85 #undef  PETSC_PRINTF_FORMAT_CHECK
86 #define PETSC_PRINTF_FORMAT_CHECK(a,b)
87 #undef  PETSC_FPRINTF_FORMAT_CHECK
88 #define PETSC_FPRINTF_FORMAT_CHECK(a,b)
89 
90 /*
91    Fixes for config/configure.py time choices which impact our interface. Currently only
92    calling conventions and extra compiler checking falls under this category.
93 */
94 #if !defined(PETSC_STDCALL)
95 #define PETSC_STDCALL
96 #endif
97 #if !defined(PETSC_TEMPLATE)
98 #define PETSC_TEMPLATE
99 #endif
100 #if !defined(PETSC_HAVE_DLL_EXPORT)
101 #define PETSC_DLL_EXPORT
102 #define PETSC_DLL_IMPORT
103 #endif
104 #if !defined(PETSC_DLLEXPORT)
105 #define PETSC_DLLEXPORT
106 #endif
107 #if !defined(PETSCVEC_DLLEXPORT)
108 #define PETSCVEC_DLLEXPORT
109 #endif
110 #if !defined(PETSCMAT_DLLEXPORT)
111 #define PETSCMAT_DLLEXPORT
112 #endif
113 #if !defined(PETSCDM_DLLEXPORT)
114 #define PETSCDM_DLLEXPORT
115 #endif
116 #if !defined(PETSCKSP_DLLEXPORT)
117 #define PETSCKSP_DLLEXPORT
118 #endif
119 #if !defined(PETSCSNES_DLLEXPORT)
120 #define PETSCSNES_DLLEXPORT
121 #endif
122 #if !defined(PETSCTS_DLLEXPORT)
123 #define PETSCTS_DLLEXPORT
124 #endif
125 #if !defined(PETSCFORTRAN_DLLEXPORT)
126 #define PETSCFORTRAN_DLLEXPORT
127 #endif
128 /* ========================================================================== */
129 
130 /*
131     Defines the interface to MPI allowing the use of all MPI functions.
132 
133     PETSc does not use the C++ binding of MPI at ALL. The following flag
134     makes sure the C++ bindings are not included. The C++ bindings REQUIRE
135     putting mpi.h before ANY C++ include files, we cannot control this
136     with all PETSc users.
137 */
138 #define MPICH_SKIP_MPICXX 1
139 #include "mpi.h"
140 /*
141     Yuck, we need to put stdio.h AFTER mpi.h for MPICH2 with C++ compiler
142     see the top of mpicxx.h in the MPICH2 distribution.
143 
144     The MPI STANDARD HAS TO BE CHANGED to prevent this nonsense.
145 */
146 #include <stdio.h>
147 
148 /*MC
149     PetscErrorCode - datatype used for return error code from all PETSc functions
150 
151     Level: beginner
152 
153 .seealso: CHKERRQ, SETERRQ
154 M*/
155 typedef int PetscErrorCode;
156 
157 /*MC
158 
159     PetscCookie - A unique id used to identify each PETSc object.
160          (internal integer in the data structure used for error
161          checking). These are all defined by an offset from the lowest
162          one, PETSC_SMALLEST_COOKIE.
163 
164     Level: advanced
165 
166 .seealso: PetscLogClassRegister(), PetscLogEventRegister(), PetscHeaderCreate()
167 M*/
168 typedef int PetscCookie;
169 
170 /*MC
171     PetscEvent - id used to identify PETSc or user events - primarily for logging
172 
173     Level: intermediate
174 
175 .seealso: PetscLogEventRegister(), PetscLogEventBegin(), PetscLogEventEnd()
176 M*/
177 typedef int PetscEvent;
178 
179 /*MC
180     PetscBLASInt - datatype used to represent 'int' parameters to BLAS/LAPACK functions.
181 
182     Level: intermediate
183 
184     Notes: usually this is the same as PetscInt, but if PETSc was built with --with-64-bit-indices but
185            standard C/Fortran integers are 32 bit then this is NOT the same as PetscInt
186 
187 .seealso: PetscMPIInt, PetscInt
188 
189 M*/
190 typedef int PetscBLASInt;
191 
192 /*MC
193     PetscMPIInt - datatype used to represent 'int' parameters to MPI functions.
194 
195     Level: intermediate
196 
197     Notes: usually this is the same as PetscInt, but if PETSc was built with --with-64-bit-indices but
198            standard C/Fortran integers are 32 bit then this is NOT the same as PetscInt
199 
200     PetscBLASIntCheck(a) checks if the given PetscInt a will fit in a PetscBLASInt, if not it generates a
201       PETSC_ERR_ARG_OUTOFRANGE.
202 
203     PetscBLASInt b = PetscBLASIntCast(a) checks if the given PetscInt a will fit in a PetscBLASInt, if not it
204       generates a PETSC_ERR_ARG_OUTOFRANGE
205 
206 .seealso: PetscBLASInt, PetscInt
207 
208 M*/
209 typedef int PetscMPIInt;
210 
211 /*MC
212     PetscEnum - datatype used to pass enum types within PETSc functions.
213 
214     Level: intermediate
215 
216     PetscMPIIntCheck(a) checks if the given PetscInt a will fit in a PetscMPIInt, if not it generates a
217       PETSC_ERR_ARG_OUTOFRANGE.
218 
219     PetscMPIInt b = PetscMPIIntCast(a) checks if the given PetscInt a will fit in a PetscMPIInt, if not it
220       generates a PETSC_ERR_ARG_OUTOFRANGE
221 
222 .seealso: PetscOptionsGetEnum(), PetscOptionsEnum(), PetscBagRegisterEnum()
223 M*/
224 typedef enum { ENUM_DUMMY } PetscEnum;
225 
226 /*MC
227     PetscInt - PETSc type that represents integer - used primarily to
228       represent size of objects. Its size can be configured with the option
229       --with-64-bit-indices - to be either 32bit or 64bit [default 32 bit ints]
230 
231    Level: intermediate
232 
233 
234 .seealso: PetscScalar, PetscBLASInt, PetscMPIInt
235 M*/
236 #if defined(PETSC_USE_64BIT_INDICES)
237 typedef long long PetscInt;
238 #define MPIU_INT MPI_LONG_LONG_INT
239 #define PETSC_MPI_INT_MAX 2147483647
240 #define PetscMPIIntCheck(a)  if ((a) > PETSC_MPI_INT_MAX) SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Message too long for MPI")
241 #define PetscMPIIntCast(a) (a);PetscMPIIntCheck(a)
242 #define PETSC_BLAS_INT_MAX 2147483647
243 #define PetscBLASIntCheck(a)  if ((a) > PETSC_BLAS_INT_MAX) SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Array too long for BLAS/LAPACK")
244 #define PetscBLASIntCast(a) (a);PetscBLASIntCheck(a)
245 #else
246 typedef int PetscInt;
247 #define MPIU_INT MPI_INT
248 #define PetscMPIIntCheck(a)
249 #define PetscMPIIntCast(a) a
250 #define PetscBLASIntCheck(a)
251 #define PetscBLASIntCast(a) a
252 #endif
253 
254 /*
255       You can use PETSC_STDOUT as a replacement of stdout. You can also change
256     the value of PETSC_STDOUT to redirect all standard output elsewhere
257 */
258 
259 extern FILE* PETSC_STDOUT;
260 
261 /*
262       You can use PETSC_STDERR as a replacement of stderr. You can also change
263     the value of PETSC_STDERR to redirect all standard error elsewhere
264 */
265 extern FILE* PETSC_STDERR;
266 
267 /*
268       PETSC_ZOPEFD is used to send data to the PETSc webpage.  It can be used
269     in conjunction with PETSC_STDOUT, or by itself.
270 */
271 extern FILE* PETSC_ZOPEFD;
272 
273 #if !defined(PETSC_USE_EXTERN_CXX) && defined(__cplusplus)
274 /*MC
275       PetscPolymorphicSubroutine - allows defining a C++ polymorphic version of
276             a PETSc function that remove certain optional arguments for a simplier user interface
277 
278      Not collective
279 
280    Synopsis:
281    PetscPolymorphicSubroutine(Functionname,(arguments of C++ function),(arguments of C function))
282 
283    Level: developer
284 
285     Example:
286       PetscPolymorphicSubroutine(VecNorm,(Vec x,PetscReal *r),(x,NORM_2,r)) generates the new routine
287            PetscErrorCode VecNorm(Vec x,PetscReal *r) = VecNorm(x,NORM_2,r)
288 
289 .seealso: PetscPolymorphicFunction()
290 
291 M*/
292 #define PetscPolymorphicSubroutine(A,B,C) PETSC_STATIC_INLINE PetscErrorCode A B {return A C;}
293 
294 /*MC
295       PetscPolymorphicScalar - allows defining a C++ polymorphic version of
296             a PETSc function that replaces a PetscScalar * argument with a PetscScalar argument
297 
298      Not collective
299 
300    Synopsis:
301    PetscPolymorphicScalar(Functionname,(arguments of C++ function),(arguments of C function))
302 
303    Level: developer
304 
305     Example:
306       PetscPolymorphicScalar(VecAXPY,(PetscScalar _val,Vec x,Vec y),(&_Val,x,y)) generates the new routine
307            PetscErrorCode VecAXPY(PetscScalar _val,Vec x,Vec y) = {PetscScalar _Val = _val; return VecAXPY(&_Val,x,y);}
308 
309 .seealso: PetscPolymorphicFunction(),PetscPolymorphicSubroutine()
310 
311 M*/
312 #define PetscPolymorphicScalar(A,B,C) PETSC_STATIC_INLINE PetscErrorCode A B {PetscScalar _Val = _val; return A C;}
313 
314 /*MC
315       PetscPolymorphicFunction - allows defining a C++ polymorphic version of
316             a PETSc function that remove certain optional arguments for a simplier user interface
317             and returns the computed value (istead of an error code)
318 
319      Not collective
320 
321    Synopsis:
322    PetscPolymorphicFunction(Functionname,(arguments of C++ function),(arguments of C function),return type,return variable name)
323 
324    Level: developer
325 
326     Example:
327       PetscPolymorphicFunction(VecNorm,(Vec x,NormType t),(x,t,&r),PetscReal,r) generates the new routine
328          PetscReal VecNorm(Vec x,NormType t) = {PetscReal r; VecNorm(x,t,&r); return r;}
329 
330 .seealso: PetscPolymorphicSubroutine()
331 
332 M*/
333 #define PetscPolymorphicFunction(A,B,C,D,E) PETSC_STATIC_INLINE D A B {D E; A C;return E;}
334 
335 #else
336 #define PetscPolymorphicSubroutine(A,B,C)
337 #define PetscPolymorphicScalar(A,B,C)
338 #define PetscPolymorphicFunction(A,B,C,D,E)
339 #endif
340 
341 /*
342     Extern indicates a PETSc function defined elsewhere
343 */
344 #if !defined(EXTERN)
345 #define EXTERN extern
346 #endif
347 
348 /*
349     Defines some elementary mathematics functions and constants.
350 */
351 #include "petscmath.h"
352 
353 /*
354     Declare extern C stuff after including external header files
355 */
356 
357 PETSC_EXTERN_CXX_BEGIN
358 
359 /*
360        Basic PETSc constants
361 */
362 
363 /*E
364     PetscTruth - Logical variable. Actually an integer
365 
366    Level: beginner
367 
368 E*/
369 typedef enum { PETSC_FALSE,PETSC_TRUE } PetscTruth;
370 extern const char *PetscTruths[];
371 
372 /*MC
373     PETSC_FALSE - False value of PetscTruth
374 
375     Level: beginner
376 
377     Note: Zero integer
378 
379 .seealso: PetscTruth, PETSC_TRUE
380 M*/
381 
382 /*MC
383     PETSC_TRUE - True value of PetscTruth
384 
385     Level: beginner
386 
387     Note: Nonzero integer
388 
389 .seealso: PetscTruth, PETSC_FALSE
390 M*/
391 
392 /*MC
393     PETSC_YES - Alias for PETSC_TRUE
394 
395     Level: beginner
396 
397     Note: Zero integer
398 
399 .seealso: PetscTruth, PETSC_TRUE, PETSC_FALSE, PETSC_NO
400 M*/
401 #define PETSC_YES            PETSC_TRUE
402 
403 /*MC
404     PETSC_NO - Alias for PETSC_FALSE
405 
406     Level: beginner
407 
408     Note: Nonzero integer
409 
410 .seealso: PetscTruth, PETSC_TRUE, PETSC_FALSE, PETSC_YES
411 M*/
412 #define PETSC_NO             PETSC_FALSE
413 
414 /*MC
415     PETSC_NULL - standard way of passing in a null or array or pointer
416 
417    Level: beginner
418 
419    Notes: accepted by many PETSc functions to not set a parameter and instead use
420           some default
421 
422           This macro does not exist in Fortran; you must use PETSC_NULL_INTEGER,
423           PETSC_NULL_DOUBLE_PRECISION etc
424 
425 .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_IGNORE, PETSC_DETERMINE
426 
427 M*/
428 #define PETSC_NULL           0
429 
430 /*MC
431     PETSC_DECIDE - standard way of passing in integer or floating point parameter
432        where you wish PETSc to use the default.
433 
434    Level: beginner
435 
436 .seealso: PETSC_NULL, PETSC_DEFAULT, PETSC_IGNORE, PETSC_DETERMINE
437 
438 M*/
439 #define PETSC_DECIDE         -1
440 
441 /*MC
442     PETSC_DEFAULT - standard way of passing in integer or floating point parameter
443        where you wish PETSc to use the default.
444 
445    Level: beginner
446 
447    Fortran Notes: You need to use PETSC_DEFAULT_INTEGER or PETSC_DEFAULT_DOUBLE_PRECISION.
448 
449 .seealso: PETSC_DECIDE, PETSC_NULL, PETSC_IGNORE, PETSC_DETERMINE
450 
451 M*/
452 #define PETSC_DEFAULT        -2
453 
454 
455 /*MC
456     PETSC_IGNORE - same as PETSC_NULL, means PETSc will ignore this argument
457 
458    Level: beginner
459 
460    Note: accepted by many PETSc functions to not set a parameter and instead use
461           some default
462 
463    Fortran Notes: This macro does not exist in Fortran; you must use PETSC_NULL_INTEGER,
464           PETSC_NULL_DOUBLE_PRECISION etc
465 
466 .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_NULL, PETSC_DETERMINE
467 
468 M*/
469 #define PETSC_IGNORE         PETSC_NULL
470 
471 /*MC
472     PETSC_DETERMINE - standard way of passing in integer or floating point parameter
473        where you wish PETSc to compute the required value.
474 
475    Level: beginner
476 
477 .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_IGNORE, PETSC_NULL, VecSetSizes()
478 
479 M*/
480 #define PETSC_DETERMINE      PETSC_DECIDE
481 
482 /*MC
483     PETSC_COMM_WORLD - the equivalent of the MPI_COMM_WORLD communicator which represents
484            all the processs that PETSc knows about.
485 
486    Level: beginner
487 
488    Notes: By default PETSC_COMM_WORLD and MPI_COMM_WORLD are identical unless you wish to
489           run PETSc on ONLY a subset of MPI_COMM_WORLD. In that case create your new (smaller)
490           communicator, call it, say comm, and set PETSC_COMM_WORLD = comm BEFORE calling
491           PetscInitialize()
492 
493 .seealso: PETSC_COMM_SELF
494 
495 M*/
496 extern MPI_Comm PETSC_COMM_WORLD;
497 
498 /*MC
499     PETSC_COMM_SELF - a duplicate of the MPI_COMM_SELF communicator which represents
500            the current process
501 
502    Level: beginner
503 
504    Notes: PETSC_COMM_SELF and MPI_COMM_SELF are equivalent.
505 
506 .seealso: PETSC_COMM_WORLD
507 
508 M*/
509 #define PETSC_COMM_SELF MPI_COMM_SELF
510 
511 extern PETSC_DLLEXPORT PetscTruth PetscInitializeCalled;
512 extern PETSC_DLLEXPORT PetscTruth PetscFinalizeCalled;
513 
514 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSetHelpVersionFunctions(PetscErrorCode (*)(MPI_Comm),PetscErrorCode (*)(MPI_Comm));
515 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscCommDuplicate(MPI_Comm,MPI_Comm*,int*);
516 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscCommDestroy(MPI_Comm*);
517 
518 /*MC
519    PetscMalloc - Allocates memory
520 
521    Input Parameter:
522 .  m - number of bytes to allocate
523 
524    Output Parameter:
525 .  result - memory allocated
526 
527    Synopsis:
528    PetscErrorCode PetscMalloc(size_t m,void **result)
529 
530    Level: beginner
531 
532    Notes: Memory is always allocated at least double aligned
533 
534           If you request memory of zero size it will allocate no space and assign the pointer to 0; PetscFree() will
535           properly handle not freeing the null pointer.
536 
537 .seealso: PetscFree(), PetscNew()
538 
539   Concepts: memory allocation
540 
541 M*/
542 #define PetscMalloc(a,b)  ((a != 0) ? (*PetscTrMalloc)((a),__LINE__,__FUNCT__,__FILE__,__SDIR__,(void**)(b)) : (*(b) = 0,0) )
543 
544 /*MC
545    PetscMalloc2 - Allocates 2 chunks of  memory
546 
547    Input Parameter:
548 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
549 .  t1 - type of first memory elements
550 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
551 -  t2 - type of second memory elements
552 
553    Output Parameter:
554 +  r1 - memory allocated in first chunk
555 -  r2 - memory allocated in second chunk
556 
557    Synopsis:
558    PetscErrorCode PetscMalloc2(size_t m1,type, t1,void **r1,size_t m2,type t2,void **r2)
559 
560    Level: developer
561 
562    Notes: Memory of first chunk is always allocated at least double aligned
563 
564 .seealso: PetscFree(), PetscNew(), PetscMalloc()
565 
566   Concepts: memory allocation
567 
568 M*/
569 #if defined(PETSC_USE_DEBUG)
570 #define PetscMalloc2(m1,t1,r1,m2,t2,r2) (PetscMalloc((m1)*sizeof(t1),r1) || PetscMalloc((m2)*sizeof(t2),r2))
571 #else
572 #define PetscMalloc2(m1,t1,r1,m2,t2,r2) (PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2),r1) || (*(r2) = (t2*)(*(r1)+m1),0))
573 #endif
574 
575 /*MC
576    PetscMalloc3 - Allocates 3 chunks of  memory
577 
578    Input Parameter:
579 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
580 .  t1 - type of first memory elements
581 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
582 .  t2 - type of second memory elements
583 .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
584 -  t3 - type of third memory elements
585 
586    Output Parameter:
587 +  r1 - memory allocated in first chunk
588 .  r2 - memory allocated in second chunk
589 -  r3 - memory allocated in third chunk
590 
591    Synopsis:
592    PetscErrorCode PetscMalloc3(size_t m1,type, t1,void **r1,size_t m2,type t2,void **r2,size_t m3,type t3,void **r3)
593 
594    Level: developer
595 
596    Notes: Memory of first chunk is always allocated at least double aligned
597 
598 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3()
599 
600   Concepts: memory allocation
601 
602 M*/
603 #if defined(PETSC_USE_DEBUG)
604 #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))
605 #else
606 #define PetscMalloc3(m1,t1,r1,m2,t2,r2,m3,t3,r3) (PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3),r1) || (*(r2) = (t2*)(*(r1)+m1),*(r3) = (t3*)(*(r2)+m2),0))
607 #endif
608 
609 /*MC
610    PetscMalloc4 - Allocates 4 chunks of  memory
611 
612    Input Parameter:
613 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
614 .  t1 - type of first memory elements
615 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
616 .  t2 - type of second memory elements
617 .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
618 .  t3 - type of third memory elements
619 .  m4 - number of elements to allocate in 4th chunk  (may be zero)
620 -  t4 - type of fourth memory elements
621 
622    Output Parameter:
623 +  r1 - memory allocated in first chunk
624 .  r2 - memory allocated in second chunk
625 .  r3 - memory allocated in third chunk
626 -  r4 - memory allocated in fourth chunk
627 
628    Synopsis:
629    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)
630 
631    Level: developer
632 
633    Notes: Memory of first chunk is always allocated at least double aligned
634 
635 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4()
636 
637   Concepts: memory allocation
638 
639 M*/
640 #if defined(PETSC_USE_DEBUG)
641 #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))
642 #else
643 #define PetscMalloc4(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4) (PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3)+(m4)*sizeof(t4),r1) || (*(r2) = (t2*)(*(r1)+m1),*(r3) = (t3*)(*(r2)+m2),*(r4) = (t4*)(*(r3)+m3),0))
644 #endif
645 
646 /*MC
647    PetscMalloc5 - Allocates 5 chunks of  memory
648 
649    Input Parameter:
650 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
651 .  t1 - type of first memory elements
652 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
653 .  t2 - type of second memory elements
654 .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
655 .  t3 - type of third memory elements
656 .  m4 - number of elements to allocate in 4th chunk  (may be zero)
657 .  t4 - type of fourth memory elements
658 .  m5 - number of elements to allocate in 5th chunk  (may be zero)
659 -  t5 - type of fifth memory elements
660 
661    Output Parameter:
662 +  r1 - memory allocated in first chunk
663 .  r2 - memory allocated in second chunk
664 .  r3 - memory allocated in third chunk
665 .  r4 - memory allocated in fourth chunk
666 -  r5 - memory allocated in fifth chunk
667 
668    Synopsis:
669    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)
670 
671    Level: developer
672 
673    Notes: Memory of first chunk is always allocated at least double aligned
674 
675 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4(), PetscFree5()
676 
677   Concepts: memory allocation
678 
679 M*/
680 #if defined(PETSC_USE_DEBUG)
681 #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))
682 #else
683 #define PetscMalloc5(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4,m5,t5,r5) (PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3)+(m4)*sizeof(t4)+(m5)*sizeof(t5),r1) || (*(r2) = (t2*)(*(r1)+m1),*(r3) = (t3*)(*(r2)+m2),*(r4) = (t4*)(*(r3)+m3),*(r5) = (t5*)(*(r4)+m4),0))
684 #endif
685 
686 
687 /*MC
688    PetscMalloc6 - Allocates 6 chunks of  memory
689 
690    Input Parameter:
691 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
692 .  t1 - type of first memory elements
693 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
694 .  t2 - type of second memory elements
695 .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
696 .  t3 - type of third memory elements
697 .  m4 - number of elements to allocate in 4th chunk  (may be zero)
698 .  t4 - type of fourth memory elements
699 .  m5 - number of elements to allocate in 5th chunk  (may be zero)
700 .  t5 - type of fifth memory elements
701 .  m6 - number of elements to allocate in 6th chunk  (may be zero)
702 -  t6 - type of sixth memory elements
703 
704    Output Parameter:
705 +  r1 - memory allocated in first chunk
706 .  r2 - memory allocated in second chunk
707 .  r3 - memory allocated in third chunk
708 .  r4 - memory allocated in fourth chunk
709 .  r5 - memory allocated in fifth chunk
710 -  r6 - memory allocated in sixth chunk
711 
712    Synopsis:
713    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)
714 
715    Level: developer
716 
717    Notes: Memory of first chunk is always allocated at least double aligned
718 
719 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4(), PetscFree5(), PetscFree6()
720 
721   Concepts: memory allocation
722 
723 M*/
724 #if defined(PETSC_USE_DEBUG)
725 #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))
726 #else
727 #define PetscMalloc6(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4,m5,t5,r5,m6,t6,r6) (PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3)+(m4)*sizeof(t4)+(m5)*sizeof(t5)+(m6)*sizeof(t6),r1) || (*(r2) = (t2*)(*(r1)+m1),*(r3) = (t3*)(*(r2)+m2),*(r4) = (t4*)(*(r3)+m3),*(r5) = (t5*)(*(r4)+m4),*(r6) = (t6*)(*(r5)+m5),0))
728 #endif
729 
730 /*MC
731    PetscMalloc7 - Allocates 7 chunks of  memory
732 
733    Input Parameter:
734 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
735 .  t1 - type of first memory elements
736 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
737 .  t2 - type of second memory elements
738 .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
739 .  t3 - type of third memory elements
740 .  m4 - number of elements to allocate in 4th chunk  (may be zero)
741 .  t4 - type of fourth memory elements
742 .  m5 - number of elements to allocate in 5th chunk  (may be zero)
743 .  t5 - type of fifth memory elements
744 .  m6 - number of elements to allocate in 6th chunk  (may be zero)
745 .  t6 - type of sixth memory elements
746 .  m7 - number of elements to allocate in 7th chunk  (may be zero)
747 -  t7 - type of sixth memory elements
748 
749    Output Parameter:
750 +  r1 - memory allocated in first chunk
751 .  r2 - memory allocated in second chunk
752 .  r3 - memory allocated in third chunk
753 .  r4 - memory allocated in fourth chunk
754 .  r5 - memory allocated in fifth chunk
755 .  r6 - memory allocated in sixth chunk
756 -  r7 - memory allocated in sixth chunk
757 
758    Synopsis:
759    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)
760 
761    Level: developer
762 
763    Notes: Memory of first chunk is always allocated at least double aligned
764 
765 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4(), PetscFree5(), PetscFree6(), PetscFree7()
766 
767   Concepts: memory allocation
768 
769 M*/
770 #if defined(PETSC_USE_DEBUG)
771 #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))
772 #else
773 #define PetscMalloc7(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4,m5,t5,r5,m6,t6,r6,m7,t7,r7) (PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3)+(m4)*sizeof(t4)+(m5)*sizeof(t5)+(m6)*sizeof(t6)+(m7)*sizeof(t7),r1) || (*(r2) = (t2*)(*(r1)+m1),*(r3) = (t3*)(*(r2)+m2),*(r4) = (t4*)(*(r3)+m3),*(r5) = (t5*)(*(r4)+m4),*(r6) = (t6*)(*(r5)+m5),*(r7) = (t7*)(*(r6)+m6),0))
774 #endif
775 
776 /*MC
777    PetscNew - Allocates memory of a particular type, zeros the memory!
778 
779    Input Parameter:
780 .  type - structure name of space to be allocated. Memory of size sizeof(type) is allocated
781 
782    Output Parameter:
783 .  result - memory allocated
784 
785    Synopsis:
786    PetscErrorCode PetscNew(struct type,((type *))result)
787 
788    Level: beginner
789 
790 .seealso: PetscFree(), PetscMalloc()
791 
792   Concepts: memory allocation
793 
794 M*/
795 #define PetscNew(A,b)      (PetscMalloc(sizeof(A),(b)) || PetscMemzero(*(b),sizeof(A)))
796 #define PetscNewLog(o,A,b) (PetscNew(A,b) || ((o) ? PetscLogObjectMemory(o,sizeof(A)) : 0))
797 
798 /*MC
799    PetscFree - Frees memory
800 
801    Input Parameter:
802 .   memory - memory to free (the pointer is ALWAYS set to 0 upon sucess)
803 
804    Synopsis:
805    PetscErrorCode PetscFree(void *memory)
806 
807    Level: beginner
808 
809    Notes: Memory must have been obtained with PetscNew() or PetscMalloc()
810 
811 .seealso: PetscNew(), PetscMalloc(), PetscFreeVoid()
812 
813   Concepts: memory allocation
814 
815 M*/
816 #define PetscFree(a)   ((a) ? ((*PetscTrFree)((a),__LINE__,__FUNCT__,__FILE__,__SDIR__) || ((a = 0),0)) : 0)
817 
818 /*MC
819    PetscFreeVoid - Frees memory
820 
821    Input Parameter:
822 .   memory - memory to free
823 
824    Synopsis:
825    void PetscFreeVoid(void *memory)
826 
827    Level: beginner
828 
829    Notes: This is different from PetscFree() in that no error code is returned
830 
831 .seealso: PetscFree(), PetscNew(), PetscMalloc()
832 
833   Concepts: memory allocation
834 
835 M*/
836 #define PetscFreeVoid(a) ((*PetscTrFree)((a),__LINE__,__FUNCT__,__FILE__,__SDIR__),(a) = 0)
837 
838 
839 /*MC
840    PetscFree2 - Frees 2 chunks of memory obtained with PetscMalloc2()
841 
842    Input Parameter:
843 +   memory1 - memory to free
844 -   memory2 - 2nd memory to free
845 
846 
847    Synopsis:
848    PetscErrorCode PetscFree2(void *memory1,void *memory2)
849 
850    Level: developer
851 
852    Notes: Memory must have been obtained with PetscMalloc2()
853 
854 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree()
855 
856   Concepts: memory allocation
857 
858 M*/
859 #if defined(PETSC_USE_DEBUG)
860 #define PetscFree2(m1,m2)   (PetscFree(m2) || PetscFree(m1))
861 #else
862 #define PetscFree2(m1,m2)   (PetscFree(m1))
863 #endif
864 
865 /*MC
866    PetscFree3 - Frees 3 chunks of memory obtained with PetscMalloc3()
867 
868    Input Parameter:
869 +   memory1 - memory to free
870 .   memory2 - 2nd memory to free
871 -   memory3 - 3rd memory to free
872 
873 
874    Synopsis:
875    PetscErrorCode PetscFree3(void *memory1,void *memory2,void *memory3)
876 
877    Level: developer
878 
879    Notes: Memory must have been obtained with PetscMalloc3()
880 
881 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3()
882 
883   Concepts: memory allocation
884 
885 M*/
886 #if defined(PETSC_USE_DEBUG)
887 #define PetscFree3(m1,m2,m3)   (PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
888 #else
889 #define PetscFree3(m1,m2,m3)   (PetscFree(m1))
890 #endif
891 
892 /*MC
893    PetscFree4 - Frees 4 chunks of memory obtained with PetscMalloc4()
894 
895    Input Parameter:
896 +   m1 - memory to free
897 .   m2 - 2nd memory to free
898 .   m3 - 3rd memory to free
899 -   m4 - 4th memory to free
900 
901 
902    Synopsis:
903    PetscErrorCode PetscFree4(void *m1,void *m2,void *m3,void *m4)
904 
905    Level: developer
906 
907    Notes: Memory must have been obtained with PetscMalloc4()
908 
909 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4()
910 
911   Concepts: memory allocation
912 
913 M*/
914 #if defined(PETSC_USE_DEBUG)
915 #define PetscFree4(m1,m2,m3,m4)   (PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
916 #else
917 #define PetscFree4(m1,m2,m3,m4)   (PetscFree(m1))
918 #endif
919 
920 /*MC
921    PetscFree5 - Frees 5 chunks of memory obtained with PetscMalloc5()
922 
923    Input Parameter:
924 +   m1 - memory to free
925 .   m2 - 2nd memory to free
926 .   m3 - 3rd memory to free
927 .   m4 - 4th memory to free
928 -   m5 - 5th memory to free
929 
930 
931    Synopsis:
932    PetscErrorCode PetscFree5(void *m1,void *m2,void *m3,void *m4,void *m5)
933 
934    Level: developer
935 
936    Notes: Memory must have been obtained with PetscMalloc5()
937 
938 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5()
939 
940   Concepts: memory allocation
941 
942 M*/
943 #if defined(PETSC_USE_DEBUG)
944 #define PetscFree5(m1,m2,m3,m4,m5)   (PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
945 #else
946 #define PetscFree5(m1,m2,m3,m4,m5)   (PetscFree(m1))
947 #endif
948 
949 
950 /*MC
951    PetscFree6 - Frees 6 chunks of memory obtained with PetscMalloc6()
952 
953    Input Parameter:
954 +   m1 - memory to free
955 .   m2 - 2nd memory to free
956 .   m3 - 3rd memory to free
957 .   m4 - 4th memory to free
958 .   m5 - 5th memory to free
959 -   m6 - 6th memory to free
960 
961 
962    Synopsis:
963    PetscErrorCode PetscFree6(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6)
964 
965    Level: developer
966 
967    Notes: Memory must have been obtained with PetscMalloc6()
968 
969 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5(), PetscMalloc6()
970 
971   Concepts: memory allocation
972 
973 M*/
974 #if defined(PETSC_USE_DEBUG)
975 #define PetscFree6(m1,m2,m3,m4,m5,m6)   (PetscFree(m6) || PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
976 #else
977 #define PetscFree6(m1,m2,m3,m4,m5,m6)   (PetscFree(m1))
978 #endif
979 
980 /*MC
981    PetscFree7 - Frees 7 chunks of memory obtained with PetscMalloc7()
982 
983    Input Parameter:
984 +   m1 - memory to free
985 .   m2 - 2nd memory to free
986 .   m3 - 3rd memory to free
987 .   m4 - 4th memory to free
988 .   m5 - 5th memory to free
989 .   m6 - 6th memory to free
990 -   m7 - 7th memory to free
991 
992 
993    Synopsis:
994    PetscErrorCode PetscFree7(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6,void *m7)
995 
996    Level: developer
997 
998    Notes: Memory must have been obtained with PetscMalloc7()
999 
1000 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5(), PetscMalloc6(),
1001           PetscMalloc7()
1002 
1003   Concepts: memory allocation
1004 
1005 M*/
1006 #if defined(PETSC_USE_DEBUG)
1007 #define PetscFree7(m1,m2,m3,m4,m5,m6,m7)   (PetscFree(m7) || PetscFree(m6) || PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
1008 #else
1009 #define PetscFree7(m1,m2,m3,m4,m5,m6,m7)   (PetscFree(m1))
1010 #endif
1011 
1012 EXTERN PETSC_DLLEXPORT PetscErrorCode (*PetscTrMalloc)(size_t,int,const char[],const char[],const char[],void**);
1013 EXTERN PETSC_DLLEXPORT PetscErrorCode (*PetscTrFree)(void*,int,const char[],const char[],const char[]);
1014 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscMallocSet(PetscErrorCode (*)(size_t,int,const char[],const char[],const char[],void**),PetscErrorCode (*)(void*,int,const char[],const char[],const char[]));
1015 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscMallocClear(void);
1016 
1017 /*
1018    Routines for tracing memory corruption/bleeding with default PETSc
1019    memory allocation
1020 */
1021 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMallocDump(FILE *);
1022 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMallocDumpLog(FILE *);
1023 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMallocGetCurrentUsage(PetscLogDouble *);
1024 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMallocGetMaximumUsage(PetscLogDouble *);
1025 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMallocDebug(PetscTruth);
1026 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMallocValidate(int,const char[],const char[],const char[]);
1027 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMallocSetDumpLog(void);
1028 
1029 
1030 /*
1031     Variable type where we stash PETSc object pointers in Fortran.
1032     On most machines size(pointer) == sizeof(long) - except windows
1033     where its sizeof(long long)
1034 */
1035 
1036 #if (PETSC_SIZEOF_VOID_P) == (PETSC_SIZEOF_LONG)
1037 #define PetscFortranAddr   long
1038 #elif  (PETSC_SIZEOF_VOID_P) == (PETSC_SIZEOF_LONG_LONG)
1039 #define PetscFortranAddr   long long
1040 #else
1041 #error "Unknown size for PetscFortranAddr! Send us a bugreport at petsc-maint@mcs.anl.gov"
1042 #endif
1043 
1044 /*E
1045     PetscDataType - Used for handling different basic data types.
1046 
1047    Level: beginner
1048 
1049    Developer comment: It would be nice if we could always just use MPI Datatypes, why can we not?
1050 
1051 .seealso: PetscBinaryRead(), PetscBinaryWrite(), PetscDataTypeToMPIDataType(),
1052           PetscDataTypeGetSize()
1053 
1054 E*/
1055 typedef enum {PETSC_INT = 0,PETSC_DOUBLE = 1,PETSC_COMPLEX = 2, PETSC_LONG = 3 ,PETSC_SHORT = 4,PETSC_FLOAT = 5,
1056               PETSC_CHAR = 6,PETSC_LOGICAL = 7,PETSC_ENUM = 8,PETSC_TRUTH=9, PETSC_LONG_DOUBLE = 10} PetscDataType;
1057 extern const char *PetscDataTypes[];
1058 
1059 #if defined(PETSC_USE_COMPLEX)
1060 #define PETSC_SCALAR PETSC_COMPLEX
1061 #else
1062 #if defined(PETSC_USE_SINGLE)
1063 #define PETSC_SCALAR PETSC_FLOAT
1064 #elif defined(PETSC_USE_LONG_DOUBLE)
1065 #define PETSC_SCALAR PETSC_LONG_DOUBLE
1066 #elif defined(PETSC_USE_INT)
1067 #define PETSC_SCALAR PETSC_INT
1068 #else
1069 #define PETSC_SCALAR PETSC_DOUBLE
1070 #endif
1071 #endif
1072 #if defined(PETSC_USE_SINGLE)
1073 #define PETSC_REAL PETSC_FLOAT
1074 #elif defined(PETSC_USE_LONG_DOUBLE)
1075 #define PETSC_REAL PETSC_LONG_DOUBLE
1076 #elif defined(PETSC_USE_INT)
1077 #define PETSC_REAL PETSC_INT
1078 #else
1079 #define PETSC_REAL PETSC_DOUBLE
1080 #endif
1081 #define PETSC_FORTRANADDR PETSC_LONG
1082 
1083 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDataTypeToMPIDataType(PetscDataType,MPI_Datatype*);
1084 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMPIDataTypeToPetscDataType(MPI_Datatype,PetscDataType*);
1085 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDataTypeGetSize(PetscDataType,size_t*);
1086 
1087 /*
1088     Basic memory and string operations. These are usually simple wrappers
1089    around the basic Unix system calls, but a few of them have additional
1090    functionality and/or error checking.
1091 */
1092 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMemcpy(void*,const void *,size_t);
1093 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscBitMemcpy(void*,PetscInt,const void*,PetscInt,PetscInt,PetscDataType);
1094 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMemmove(void*,void *,size_t);
1095 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMemzero(void*,size_t);
1096 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMemcmp(const void*,const void*,size_t,PetscTruth *);
1097 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrlen(const char[],size_t*);
1098 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrcmp(const char[],const char[],PetscTruth *);
1099 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrgrt(const char[],const char[],PetscTruth *);
1100 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrcasecmp(const char[],const char[],PetscTruth*);
1101 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrncmp(const char[],const char[],size_t,PetscTruth*);
1102 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrcpy(char[],const char[]);
1103 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrcat(char[],const char[]);
1104 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrncat(char[],const char[],size_t);
1105 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrncpy(char[],const char[],size_t);
1106 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrchr(const char[],char,char *[]);
1107 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrtolower(char[]);
1108 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrrchr(const char[],char,char *[]);
1109 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrstr(const char[],const char[],char *[]);
1110 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrrstr(const char[],const char[],char *[]);
1111 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrallocpy(const char[],char *[]);
1112 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrreplace(MPI_Comm,const char[],char[],size_t);
1113 #define      PetscStrfree(a) ((a) ? PetscFree(a) : 0)
1114 
1115 /*S
1116     PetscToken - 'Token' used for managing tokenizing strings
1117 
1118   Level: intermediate
1119 
1120 .seealso: PetscTokenCreate(), PetscTokenFind(), PetscTokenDestroy()
1121 S*/
1122 typedef struct _p_PetscToken* PetscToken;
1123 
1124 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscTokenCreate(const char[],const char,PetscToken*);
1125 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscTokenFind(PetscToken,char *[]);
1126 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscTokenDestroy(PetscToken);
1127 
1128 /*
1129    These are  MPI operations for MPI_Allreduce() etc
1130 */
1131 EXTERN PETSC_DLLEXPORT MPI_Op PetscMaxSum_Op;
1132 #if defined(PETSC_USE_COMPLEX)
1133 EXTERN PETSC_DLLEXPORT MPI_Op PetscSum_Op;
1134 #else
1135 #define PetscSum_Op MPI_SUM
1136 #endif
1137 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMaxSum(MPI_Comm,const PetscInt[],PetscInt*,PetscInt*);
1138 
1139 /*S
1140      PetscObject - any PETSc object, PetscViewer, Mat, Vec, KSP etc
1141 
1142    Level: beginner
1143 
1144    Note: This is the base class from which all objects appear.
1145 
1146 .seealso:  PetscObjectDestroy(), PetscObjectView(), PetscObjectGetName(), PetscObjectSetName()
1147 S*/
1148 typedef struct _p_PetscObject* PetscObject;
1149 
1150 /*S
1151      PetscFList - Linked list of functions, possibly stored in dynamic libraries, accessed
1152       by string name
1153 
1154    Level: advanced
1155 
1156 .seealso:  PetscFListAdd(), PetscFListDestroy()
1157 S*/
1158 typedef struct _n_PetscFList *PetscFList;
1159 
1160 /*E
1161   PetscFileMode - Access mode for a file.
1162 
1163   Level: beginner
1164 
1165   FILE_MODE_READ - open a file at its beginning for reading
1166 
1167   FILE_MODE_WRITE - open a file at its beginning for writing (will create if the file does not exist)
1168 
1169   FILE_MODE_APPEND - open a file at end for writing
1170 
1171   FILE_MODE_UPDATE - open a file for updating, meaning for reading and writing
1172 
1173   FILE_MODE_APPEND_UPDATE - open a file for updating, meaning for reading and writing, at the end
1174 
1175 .seealso: PetscViewerFileSetMode()
1176 E*/
1177 typedef enum {FILE_MODE_READ, FILE_MODE_WRITE, FILE_MODE_APPEND, FILE_MODE_UPDATE, FILE_MODE_APPEND_UPDATE} PetscFileMode;
1178 
1179 #include "petscviewer.h"
1180 #include "petscoptions.h"
1181 
1182 #define PETSC_SMALLEST_COOKIE 1211211
1183 extern PETSC_DLLEXPORT PetscCookie PETSC_LARGEST_COOKIE;
1184 extern PETSC_DLLEXPORT PetscCookie PETSC_OBJECT_COOKIE;
1185 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscCookieRegister(PetscCookie *);
1186 
1187 /*
1188    Routines that get memory usage information from the OS
1189 */
1190 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemoryGetCurrentUsage(PetscLogDouble *);
1191 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemoryGetMaximumUsage(PetscLogDouble *);
1192 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemorySetGetMaximumUsage(void);
1193 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemoryShowUsage(PetscViewer,const char[]);
1194 
1195 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscInfoAllow(PetscTruth,const char []);
1196 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetTime(PetscLogDouble*);
1197 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetCPUTime(PetscLogDouble*);
1198 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSleep(int);
1199 
1200 /*
1201     Initialization of PETSc
1202 */
1203 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscInitialize(int*,char***,const char[],const char[]);
1204 PetscPolymorphicSubroutine(PetscInitialize,(int *argc,char ***args),(argc,args,PETSC_NULL,PETSC_NULL))
1205 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscInitializeNoArguments(void);
1206 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscInitialized(PetscTruth *);
1207 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFinalized(PetscTruth *);
1208 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFinalize(void);
1209 EXTERN PetscErrorCode PetscInitializeFortran(void);
1210 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetArgs(int*,char ***);
1211 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetArguments(char ***);
1212 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFreeArguments(char **);
1213 
1214 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscEnd(void);
1215 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscInitializePackage(const char[]);
1216 
1217 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOpenMPMerge(PetscMPIInt);
1218 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOpenMPSpawn(PetscMPIInt);
1219 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOpenMPFinalize(void);
1220 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOpenMPRun(MPI_Comm,PetscErrorCode (*)(MPI_Comm,void *),void*);
1221 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOpenMPFree(MPI_Comm,void*);
1222 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOpenMPNew(MPI_Comm,PetscInt,void**);
1223 
1224 /*
1225      These are so that in extern C code we can caste function pointers to non-extern C
1226    function pointers. Since the regular C++ code expects its function pointers to be
1227    C++.
1228 */
1229 typedef void (**PetscVoidStarFunction)(void);
1230 typedef void (*PetscVoidFunction)(void);
1231 typedef PetscErrorCode (*PetscErrorCodeFunction)(void);
1232 
1233 /*
1234    PetscTryMethod - Queries an object for a method, if it exists then calls it.
1235               These are intended to be used only inside PETSc functions.
1236 */
1237 #define  PetscTryMethod(obj,A,B,C) \
1238   0;{ PetscErrorCode (*f)B, __ierr; \
1239     __ierr = PetscObjectQueryFunction((PetscObject)obj,A,(PetscVoidStarFunction)&f);CHKERRQ(__ierr); \
1240     if (f) {__ierr = (*f)C;CHKERRQ(__ierr);}\
1241   }
1242 #define  PetscUseMethod(obj,A,B,C) \
1243   0;{ PetscErrorCode (*f)B, __ierr; \
1244     __ierr = PetscObjectQueryFunction((PetscObject)obj,A,(PetscVoidStarFunction)&f);CHKERRQ(__ierr); \
1245     if (f) {__ierr = (*f)C;CHKERRQ(__ierr);}\
1246     else {SETERRQ1(PETSC_ERR_SUP,"Cannot locate function %s in object",A);} \
1247   }
1248 /*
1249     Functions that can act on any PETSc object.
1250 */
1251 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectCreate(MPI_Comm,PetscObject*);
1252 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectCreateGeneric(MPI_Comm, PetscCookie, const char [], PetscObject *);
1253 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectDestroy(PetscObject);
1254 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectExists(PetscObject,PetscTruth*);
1255 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetComm(PetscObject,MPI_Comm *);
1256 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetCookie(PetscObject,PetscCookie *);
1257 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectSetType(PetscObject,const char []);
1258 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetType(PetscObject,const char *[]);
1259 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectSetName(PetscObject,const char[]);
1260 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetName(PetscObject,const char*[]);
1261 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectReference(PetscObject);
1262 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetReference(PetscObject,PetscInt*);
1263 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectDereference(PetscObject);
1264 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetNewTag(PetscObject,PetscMPIInt *);
1265 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectView(PetscObject,PetscViewer);
1266 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectCompose(PetscObject,const char[],PetscObject);
1267 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectQuery(PetscObject,const char[],PetscObject *);
1268 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectComposeFunction(PetscObject,const char[],const char[],void (*)(void));
1269 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectSetFromOptions(PetscObject);
1270 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectSetUp(PetscObject);
1271 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscCommGetNewTag(MPI_Comm,PetscMPIInt *);
1272 
1273 /*MC
1274    PetscObjectComposeFunctionDynamic - Associates a function with a given PETSc object.
1275 
1276    Collective on PetscObject
1277 
1278    Input Parameters:
1279 +  obj - the PETSc object; this must be cast with a (PetscObject), for example,
1280          PetscObjectCompose((PetscObject)mat,...);
1281 .  name - name associated with the child function
1282 .  fname - name of the function
1283 -  ptr - function pointer (or PETSC_NULL if using dynamic libraries)
1284 
1285    Level: advanced
1286 
1287     Synopsis:
1288     PetscErrorCode PetscObjectComposeFunctionDynamic(PetscObject obj,const char name[],const char fname[],void *ptr)
1289 
1290    Notes:
1291    To remove a registered routine, pass in a PETSC_NULL rname and fnc().
1292 
1293    PetscObjectComposeFunctionDynamic() can be used with any PETSc object (such as
1294    Mat, Vec, KSP, SNES, etc.) or any user-provided object.
1295 
1296    The composed function must be wrapped in a EXTERN_C_BEGIN/END for this to
1297    work in C++/complex with dynamic link libraries (config/configure.py options --with-shared --with-dynamic)
1298    enabled.
1299 
1300    Concepts: objects^composing functions
1301    Concepts: composing functions
1302    Concepts: functions^querying
1303    Concepts: objects^querying
1304    Concepts: querying objects
1305 
1306 .seealso: PetscObjectQueryFunction()
1307 M*/
1308 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
1309 #define PetscObjectComposeFunctionDynamic(a,b,c,d) PetscObjectComposeFunction(a,b,c,0)
1310 #else
1311 #define PetscObjectComposeFunctionDynamic(a,b,c,d) PetscObjectComposeFunction(a,b,c,(PetscVoidFunction)(d))
1312 #endif
1313 
1314 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectQueryFunction(PetscObject,const char[],void (**)(void));
1315 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectSetOptionsPrefix(PetscObject,const char[]);
1316 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectAppendOptionsPrefix(PetscObject,const char[]);
1317 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectPrependOptionsPrefix(PetscObject,const char[]);
1318 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetOptionsPrefix(PetscObject,const char*[]);
1319 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectPublish(PetscObject);
1320 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectChangeTypeName(PetscObject,const char[]);
1321 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectRegisterDestroy(PetscObject);
1322 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectRegisterDestroyAll(void);
1323 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectName(PetscObject);
1324 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscTypeCompare(PetscObject,const char[],PetscTruth*);
1325 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRegisterFinalize(PetscErrorCode (*)(void));
1326 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRegisterFinalizeAll(void);
1327 
1328 /*
1329     Defines PETSc error handling.
1330 */
1331 #include "petscerror.h"
1332 
1333 /*S
1334      PetscOList - Linked list of PETSc objects, accessable by string name
1335 
1336    Level: advanced
1337 
1338 .seealso:  PetscOListAdd(), PetscOListDestroy(), PetscOListFind()
1339 S*/
1340 typedef struct _n_PetscOList *PetscOList;
1341 
1342 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOListDestroy(PetscOList);
1343 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOListFind(PetscOList,const char[],PetscObject*);
1344 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOListReverseFind(PetscOList,PetscObject,char**);
1345 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOListAdd(PetscOList *,const char[],PetscObject);
1346 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOListDuplicate(PetscOList,PetscOList *);
1347 
1348 /*
1349     Dynamic library lists. Lists of names of routines in dynamic
1350   link libraries that will be loaded as needed.
1351 */
1352 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListAdd(PetscFList*,const char[],const char[],void (*)(void));
1353 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListDestroy(PetscFList*);
1354 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListFind(PetscFList,MPI_Comm,const char[],void (**)(void));
1355 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListPrintTypes(PetscFList,MPI_Comm,FILE*,const char[],const char[],const char[],const char[]);
1356 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
1357 #define    PetscFListAddDynamic(a,b,p,c) PetscFListAdd(a,b,p,0)
1358 #else
1359 #define    PetscFListAddDynamic(a,b,p,c) PetscFListAdd(a,b,p,(void (*)(void))c)
1360 #endif
1361 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListDuplicate(PetscFList,PetscFList *);
1362 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListView(PetscFList,PetscViewer);
1363 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListConcat(const char [],const char [],char []);
1364 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListGet(PetscFList,char ***,int*);
1365 
1366 /*S
1367      PetscDLLibrary - Linked list of dynamics libraries to search for functions
1368 
1369    Level: advanced
1370 
1371    --with-shared --with-dynamic must be used with config/configure.py to use dynamic libraries
1372 
1373 .seealso:  PetscDLLibraryOpen()
1374 S*/
1375 typedef struct _n_PetscDLLibrary *PetscDLLibrary;
1376 extern PetscDLLibrary DLLibrariesLoaded;
1377 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryRetrieve(MPI_Comm,const char[],char *,int,PetscTruth *);
1378 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryOpen(MPI_Comm,const char[],void **);
1379 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibrarySym(MPI_Comm,PetscDLLibrary *,const char[],const char[],void **);
1380 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryAppend(MPI_Comm,PetscDLLibrary *,const char[]);
1381 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryPrepend(MPI_Comm,PetscDLLibrary *,const char[]);
1382 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryClose(PetscDLLibrary);
1383 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryPrintPath(void);
1384 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryGetInfo(void*,const char[],const char *[]);
1385 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryCCAAppend(MPI_Comm,PetscDLLibrary *,const char[]);
1386 
1387 /*
1388      Useful utility routines
1389 */
1390 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSplitOwnership(MPI_Comm,PetscInt*,PetscInt*);
1391 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSplitOwnershipBlock(MPI_Comm,PetscInt,PetscInt*,PetscInt*);
1392 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSequentialPhaseBegin(MPI_Comm,PetscMPIInt);
1393 PetscPolymorphicSubroutine(PetscSequentialPhaseBegin,(MPI_Comm comm),(comm,1))
1394 PetscPolymorphicSubroutine(PetscSequentialPhaseBegin,(void),(PETSC_COMM_WORLD,1))
1395 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSequentialPhaseEnd(MPI_Comm,PetscMPIInt);
1396 PetscPolymorphicSubroutine(PetscSequentialPhaseEnd,(MPI_Comm comm),(comm,1))
1397 PetscPolymorphicSubroutine(PetscSequentialPhaseEnd,(void),(PETSC_COMM_WORLD,1))
1398 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscBarrier(PetscObject);
1399 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMPIDump(FILE*);
1400 
1401 #define PetscNot(a) ((a) ? PETSC_FALSE : PETSC_TRUE)
1402 /*
1403     Defines basic graphics available from PETSc.
1404 */
1405 #include "petscdraw.h"
1406 
1407 /*
1408     Defines the base data structures for all PETSc objects
1409 */
1410 #include "private/petscimpl.h"
1411 /*
1412      Defines PETSc profiling.
1413 */
1414 #include "petsclog.h"
1415 
1416 /*
1417           For locking, unlocking and destroying AMS memories associated with
1418     PETSc objects. Not currently used.
1419 */
1420 #define PetscPublishAll(v)           0
1421 #define PetscObjectTakeAccess(obj)   0
1422 #define PetscObjectGrantAccess(obj)  0
1423 #define PetscObjectDepublish(obj)    0
1424 
1425 /*
1426       Simple PETSc parallel IO for ASCII printing
1427 */
1428 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscFixFilename(const char[],char[]);
1429 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscFOpen(MPI_Comm,const char[],const char[],FILE**);
1430 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscFClose(MPI_Comm,FILE*);
1431 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4);
1432 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscPrintf(MPI_Comm,const char[],...)  PETSC_PRINTF_FORMAT_CHECK(2,3);
1433 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscSNPrintf(char*,size_t,const char [],...);
1434 
1435 /* These are used internally by PETSc ASCII IO routines*/
1436 #include <stdarg.h>
1437 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscVSNPrintf(char*,size_t,const char[],va_list);
1438 EXTERN PetscErrorCode PETSC_DLLEXPORT  (*PetscVFPrintf)(FILE*,const char[],va_list);
1439 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscVFPrintfDefault(FILE*,const char[],va_list);
1440 
1441 /*MC
1442     PetscErrorPrintf - Prints error messages.
1443 
1444     Not Collective
1445 
1446    Synopsis:
1447      PetscErrorCode (*PetscErrorPrintf)(const char format[],...);
1448 
1449     Input Parameters:
1450 .   format - the usual printf() format string
1451 
1452    Options Database Keys:
1453 +    -error_output_stdout - cause error messages to be printed to stdout instead of the
1454          (default) stderr
1455 -    -error_output_none to turn off all printing of error messages (does not change the way the
1456           error is handled.)
1457 
1458    Notes: Use
1459 $     PetscErrorPrintf = PetscErrorPrintfNone; to turn off all printing of error messages (does not change the way the
1460 $                        error is handled.) and
1461 $     PetscErrorPrintf = PetscErrorPrintfDefault; to turn it back on
1462 
1463           Use
1464      PETSC_STDERR = FILE* obtained from a file open etc. to have stderr printed to the file.
1465      PETSC_STDOUT = FILE* obtained from a file open etc. to have stdout printed to the file.
1466 
1467           Use
1468       PetscPushErrorHandler() to provide your own error handler that determines what kind of messages to print
1469 
1470    Level: developer
1471 
1472     Fortran Note:
1473     This routine is not supported in Fortran.
1474 
1475     Concepts: error messages^printing
1476     Concepts: printing^error messages
1477 
1478 .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf(), PetscPrintf(), PetscErrorHandlerPush()
1479 M*/
1480 EXTERN PETSC_DLLEXPORT PetscErrorCode (*PetscErrorPrintf)(const char[],...);
1481 
1482 /*MC
1483     PetscHelpPrintf - Prints help messages.
1484 
1485     Not Collective
1486 
1487    Synopsis:
1488      PetscErrorCode (*PetscHelpPrintf)(const char format[],...);
1489 
1490     Input Parameters:
1491 .   format - the usual printf() format string
1492 
1493    Level: developer
1494 
1495     Fortran Note:
1496     This routine is not supported in Fortran.
1497 
1498     Concepts: help messages^printing
1499     Concepts: printing^help messages
1500 
1501 .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscErrorPrintf()
1502 M*/
1503 EXTERN PETSC_DLLEXPORT PetscErrorCode  (*PetscHelpPrintf)(MPI_Comm,const char[],...);
1504 
1505 EXTERN PetscErrorCode  PetscErrorPrintfDefault(const char [],...);
1506 EXTERN PetscErrorCode  PetscErrorPrintfNone(const char [],...);
1507 EXTERN PetscErrorCode  PetscHelpPrintfDefault(MPI_Comm,const char [],...);
1508 
1509 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscPOpen(MPI_Comm,const char[],const char[],const char[],FILE **);
1510 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscPClose(MPI_Comm,FILE*);
1511 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscSynchronizedPrintf(MPI_Comm,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3);
1512 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscSynchronizedFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4);
1513 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscSynchronizedFlush(MPI_Comm);
1514 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscSynchronizedFGets(MPI_Comm,FILE*,size_t,char[]);
1515 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscStartMatlab(MPI_Comm,const char[],const char[],FILE**);
1516 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscStartJava(MPI_Comm,const char[],const char[],FILE**);
1517 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscGetPetscDir(const char*[]);
1518 
1519 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscPopUpSelect(MPI_Comm,const char*,const char*,int,const char**,int*);
1520 
1521 /*S
1522      PetscContainer - Simple PETSc object that contains a pointer to any required data
1523 
1524    Level: advanced
1525 
1526 .seealso:  PetscObject, PetscContainerCreate()
1527 S*/
1528 extern PetscCookie PETSC_DLLEXPORT PETSC_CONTAINER_COOKIE;
1529 typedef struct _p_PetscContainer*  PetscContainer;
1530 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscContainerGetPointer(PetscContainer,void **);
1531 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscContainerSetPointer(PetscContainer,void *);
1532 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscContainerDestroy(PetscContainer);
1533 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscContainerCreate(MPI_Comm,PetscContainer *);
1534 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscContainerSetUserDestroy(PetscContainer, PetscErrorCode (*)(void*));
1535 
1536 /*
1537    For use in debuggers
1538 */
1539 extern PETSC_DLLEXPORT PetscMPIInt PetscGlobalRank;
1540 extern PETSC_DLLEXPORT PetscMPIInt PetscGlobalSize;
1541 
1542 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscIntView(PetscInt,PetscInt[],PetscViewer);
1543 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRealView(PetscInt,PetscReal[],PetscViewer);
1544 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscScalarView(PetscInt,PetscScalar[],PetscViewer);
1545 
1546 /*
1547     Allows accessing Matlab Engine
1548 */
1549 #include "petscmatlab.h"
1550 
1551 /*
1552       Determine if some of the kernel computation routines use
1553    Fortran (rather than C) for the numerical calculations. On some machines
1554    and compilers (like complex numbers) the Fortran version of the routines
1555    is faster than the C/C++ versions. The flag --with-fortran-kernels
1556    should be used with config/configure.py to turn these on.
1557 */
1558 #if defined(PETSC_USE_FORTRAN_KERNELS)
1559 
1560 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTCRL)
1561 #define PETSC_USE_FORTRAN_KERNEL_MULTCRL
1562 #endif
1563 
1564 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTCSRPERM)
1565 #define PETSC_USE_FORTRAN_KERNEL_MULTCSRPERM
1566 #endif
1567 
1568 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ)
1569 #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ
1570 #endif
1571 
1572 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ)
1573 #define PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ
1574 #endif
1575 
1576 #if !defined(PETSC_USE_FORTRAN_KERNEL_NORM)
1577 #define PETSC_USE_FORTRAN_KERNEL_NORM
1578 #endif
1579 
1580 #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY)
1581 #define PETSC_USE_FORTRAN_KERNEL_MAXPY
1582 #endif
1583 
1584 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ)
1585 #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ
1586 #endif
1587 
1588 #if !defined(PETSC_USE_FORTRAN_KERNEL_RELAXAIJ)
1589 #define PETSC_USE_FORTRAN_KERNEL_RELAXAIJ
1590 #endif
1591 
1592 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ)
1593 #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ
1594 #endif
1595 
1596 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ)
1597 #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ
1598 #endif
1599 
1600 #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT)
1601 #define PETSC_USE_FORTRAN_KERNEL_MDOT
1602 #endif
1603 
1604 #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY)
1605 #define PETSC_USE_FORTRAN_KERNEL_XTIMESY
1606 #endif
1607 
1608 #if !defined(PETSC_USE_FORTRAN_KERNEL_AYPX)
1609 #define PETSC_USE_FORTRAN_KERNEL_AYPX
1610 #endif
1611 
1612 #if !defined(PETSC_USE_FORTRAN_KERNEL_WAXPY)
1613 #define PETSC_USE_FORTRAN_KERNEL_WAXPY
1614 #endif
1615 
1616 #endif
1617 
1618 /*
1619     Macros for indicating code that should be compiled with a C interface,
1620    rather than a C++ interface. Any routines that are dynamically loaded
1621    (such as the PCCreate_XXX() routines) must be wrapped so that the name
1622    mangler does not change the functions symbol name. This just hides the
1623    ugly extern "C" {} wrappers.
1624 */
1625 #if defined(__cplusplus)
1626 #define EXTERN_C_BEGIN extern "C" {
1627 #define EXTERN_C_END }
1628 #else
1629 #define EXTERN_C_BEGIN
1630 #define EXTERN_C_END
1631 #endif
1632 
1633 /* --------------------------------------------------------------------*/
1634 
1635 /*MC
1636     size - integer variable used to contain the number of processors in
1637            the relevent MPI_Comm
1638 
1639    Level: beginner
1640 
1641 .seealso: rank, comm
1642 M*/
1643 
1644 /*MC
1645     rank - integer variable used to contain the number of this processor relative
1646            to all in the relevent MPI_Comm
1647 
1648    Level: beginner
1649 
1650 .seealso: size, comm
1651 M*/
1652 
1653 /*MC
1654     comm - MPI_Comm used in the current routine or object
1655 
1656    Level: beginner
1657 
1658 .seealso: size, rank
1659 M*/
1660 
1661 /*MC
1662     MPI_Comm - the basic object used by MPI to determine which processes are involved in a
1663         communication
1664 
1665    Level: beginner
1666 
1667    Note: This manual page is a place-holder because MPICH does not have a manual page for MPI_Comm
1668 
1669 .seealso: size, rank, comm, PETSC_COMM_WORLD, PETSC_COMM_SELF
1670 M*/
1671 
1672 /*MC
1673     PetscScalar - PETSc type that represents either a double precision real number, a double precision
1674        complex number, a single precision real number, a long double or an int - if the code is configured
1675        with --with-scalar-type=real,complex --with-precision=single,double,longdouble,int,matsingle
1676 
1677 
1678    Level: beginner
1679 
1680 .seealso: PetscReal, PassiveReal, PassiveScalar, MPIU_SCALAR, PetscInt
1681 M*/
1682 
1683 /*MC
1684     PetscReal - PETSc type that represents a real number version of PetscScalar
1685 
1686    Level: beginner
1687 
1688 .seealso: PetscScalar, PassiveReal, PassiveScalar
1689 M*/
1690 
1691 /*MC
1692     PassiveScalar - PETSc type that represents a PetscScalar
1693    Level: beginner
1694 
1695     This is the same as a PetscScalar except in code that is automatically differentiated it is
1696    treated as a constant (not an indendent or dependent variable)
1697 
1698 .seealso: PetscReal, PassiveReal, PetscScalar
1699 M*/
1700 
1701 /*MC
1702     PassiveReal - PETSc type that represents a PetscReal
1703 
1704    Level: beginner
1705 
1706     This is the same as a PetscReal except in code that is automatically differentiated it is
1707    treated as a constant (not an indendent or dependent variable)
1708 
1709 .seealso: PetscScalar, PetscReal, PassiveScalar
1710 M*/
1711 
1712 /*MC
1713     MPIU_SCALAR - MPI datatype corresponding to PetscScalar
1714 
1715    Level: beginner
1716 
1717     Note: In MPI calls that require an MPI datatype that matches a PetscScalar or array of PetscScalars
1718           pass this value
1719 
1720 .seealso: PetscReal, PassiveReal, PassiveScalar, PetscScalar, MPIU_INT
1721 M*/
1722 
1723 #if !defined(PETSC_WORDS_BIGENDIAN)
1724 extern PetscErrorCode MPIU_File_write_all(MPI_File,void*,PetscMPIInt,MPI_Datatype,MPI_Status*);
1725 extern PetscErrorCode MPIU_File_read_all(MPI_File,void*,PetscMPIInt,MPI_Datatype,MPI_Status*);
1726 #else
1727 #define MPIU_File_write_all(a,b,c,d,e) MPI_File_write_all(a,b,c,d,e)
1728 #define MPIU_File_read_all(a,b,c,d,e) MPI_File_read_all(a,b,c,d,e)
1729 #endif
1730 
1731 /*
1732      The IBM include files define hz, here we hide it so that it may be used
1733    as a regular user variable.
1734 */
1735 #if defined(hz)
1736 #undef hz
1737 #endif
1738 
1739 /*  For arrays that contain filenames or paths */
1740 
1741 
1742 #if defined(PETSC_HAVE_LIMITS_H)
1743 #include <limits.h>
1744 #endif
1745 #if defined(PETSC_HAVE_SYS_PARAM_H)
1746 #include <sys/param.h>
1747 #endif
1748 #if defined(PETSC_HAVE_SYS_TYPES_H)
1749 #include <sys/types.h>
1750 #endif
1751 #if defined(MAXPATHLEN)
1752 #  define PETSC_MAX_PATH_LEN     MAXPATHLEN
1753 #elif defined(MAX_PATH)
1754 #  define PETSC_MAX_PATH_LEN     MAX_PATH
1755 #elif defined(_MAX_PATH)
1756 #  define PETSC_MAX_PATH_LEN     _MAX_PATH
1757 #else
1758 #  define PETSC_MAX_PATH_LEN     4096
1759 #endif
1760 
1761 /* Special support for C++ */
1762 #include "petsc.hh"
1763 
1764 /*MC
1765 
1766     FortranModules - it is possible to use PETSc from Fortran using Fortran 90 modules instead of C style include macros.
1767 
1768 $   Objects are named type(XXXX)  instead of XXXX, for example
1769 $      use petscvec
1770 $      type(Vec) v instead of
1771 $
1772 $#include "finclude/petsc.h"
1773 $#include "finclude/petscvec.h"
1774 $      Vec v
1775 
1776     The PETSc macros, PetscInt, PetscErrorCode etc are not available, you should use integer for these
1777 
1778     See the example src/vec/vec/examples/tutorials/ex20f90.F90
1779 
1780     Level: beginner
1781 
1782 M*/
1783 PETSC_EXTERN_CXX_END
1784 #endif
1785