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