xref: /petsc/include/petsc.h (revision ce0a2cd1da0658c2b28aad1be2e2c8e41567bece)
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 .seealso: PETSC_DECIDE, PETSC_NULL, PETSC_IGNORE, PETSC_DETERMINE
448 
449 M*/
450 #define PETSC_DEFAULT        -2
451 
452 
453 /*MC
454     PETSC_IGNORE - same as PETSC_NULL, means PETSc will ignore this argument
455 
456    Level: beginner
457 
458    Notes: accepted by many PETSc functions to not set a parameter and instead use
459           some default
460 
461           This macro does not exist in Fortran; you must use PETSC_NULL_INTEGER,
462           PETSC_NULL_DOUBLE_PRECISION etc
463 
464 .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_NULL, PETSC_DETERMINE
465 
466 M*/
467 #define PETSC_IGNORE         PETSC_NULL
468 
469 /*MC
470     PETSC_DETERMINE - standard way of passing in integer or floating point parameter
471        where you wish PETSc to compute the required value.
472 
473    Level: beginner
474 
475 .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_IGNORE, PETSC_NULL, VecSetSizes()
476 
477 M*/
478 #define PETSC_DETERMINE      PETSC_DECIDE
479 
480 /*MC
481     PETSC_COMM_WORLD - the equivalent of the MPI_COMM_WORLD communicator which represents
482            all the processs that PETSc knows about.
483 
484    Level: beginner
485 
486    Notes: By default PETSC_COMM_WORLD and MPI_COMM_WORLD are identical unless you wish to
487           run PETSc on ONLY a subset of MPI_COMM_WORLD. In that case create your new (smaller)
488           communicator, call it, say comm, and set PETSC_COMM_WORLD = comm BEFORE calling
489           PetscInitialize()
490 
491 .seealso: PETSC_COMM_SELF
492 
493 M*/
494 extern MPI_Comm PETSC_COMM_WORLD;
495 
496 /*MC
497     PETSC_COMM_SELF - a duplicate of the MPI_COMM_SELF communicator which represents
498            the current process
499 
500    Level: beginner
501 
502    Notes: PETSC_COMM_SELF and MPI_COMM_SELF are equivalent.
503 
504 .seealso: PETSC_COMM_WORLD
505 
506 M*/
507 #define PETSC_COMM_SELF MPI_COMM_SELF
508 
509 extern PETSC_DLLEXPORT PetscTruth PetscInitializeCalled;
510 extern PETSC_DLLEXPORT PetscTruth PetscFinalizeCalled;
511 
512 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSetHelpVersionFunctions(PetscErrorCode (*)(MPI_Comm),PetscErrorCode (*)(MPI_Comm));
513 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscCommDuplicate(MPI_Comm,MPI_Comm*,int*);
514 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscCommDestroy(MPI_Comm*);
515 
516 /*MC
517    PetscMalloc - Allocates memory
518 
519    Input Parameter:
520 .  m - number of bytes to allocate
521 
522    Output Parameter:
523 .  result - memory allocated
524 
525    Synopsis:
526    PetscErrorCode PetscMalloc(size_t m,void **result)
527 
528    Level: beginner
529 
530    Notes: Memory is always allocated at least double aligned
531 
532           If you request memory of zero size it will allocate no space and assign the pointer to 0; PetscFree() will
533           properly handle not freeing the null pointer.
534 
535 .seealso: PetscFree(), PetscNew()
536 
537   Concepts: memory allocation
538 
539 M*/
540 #define PetscMalloc(a,b)  ((a != 0) ? (*PetscTrMalloc)((a),__LINE__,__FUNCT__,__FILE__,__SDIR__,(void**)(b)) : (*(b) = 0,0) )
541 
542 /*MC
543    PetscMalloc2 - Allocates 2 chunks of  memory
544 
545    Input Parameter:
546 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
547 .  t1 - type of first memory elements
548 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
549 -  t2 - type of second memory elements
550 
551    Output Parameter:
552 +  r1 - memory allocated in first chunk
553 -  r2 - memory allocated in second chunk
554 
555    Synopsis:
556    PetscErrorCode PetscMalloc2(size_t m1,type, t1,void **r1,size_t m2,type t2,void **r2)
557 
558    Level: developer
559 
560    Notes: Memory of first chunk is always allocated at least double aligned
561 
562 .seealso: PetscFree(), PetscNew(), PetscMalloc()
563 
564   Concepts: memory allocation
565 
566 M*/
567 #if defined(PETSC_USE_DEBUG)
568 #define PetscMalloc2(m1,t1,r1,m2,t2,r2) (PetscMalloc((m1)*sizeof(t1),r1) || PetscMalloc((m2)*sizeof(t2),r2))
569 #else
570 #define PetscMalloc2(m1,t1,r1,m2,t2,r2) (PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2),r1) || (*(r2) = (t2*)(*(r1)+m1),0))
571 #endif
572 
573 /*MC
574    PetscMalloc3 - Allocates 3 chunks of  memory
575 
576    Input Parameter:
577 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
578 .  t1 - type of first memory elements
579 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
580 .  t2 - type of second memory elements
581 .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
582 -  t3 - type of third memory elements
583 
584    Output Parameter:
585 +  r1 - memory allocated in first chunk
586 .  r2 - memory allocated in second chunk
587 -  r3 - memory allocated in third chunk
588 
589    Synopsis:
590    PetscErrorCode PetscMalloc3(size_t m1,type, t1,void **r1,size_t m2,type t2,void **r2,size_t m3,type t3,void **r3)
591 
592    Level: developer
593 
594    Notes: Memory of first chunk is always allocated at least double aligned
595 
596 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3()
597 
598   Concepts: memory allocation
599 
600 M*/
601 #if defined(PETSC_USE_DEBUG)
602 #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))
603 #else
604 #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))
605 #endif
606 
607 /*MC
608    PetscMalloc4 - Allocates 4 chunks of  memory
609 
610    Input Parameter:
611 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
612 .  t1 - type of first memory elements
613 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
614 .  t2 - type of second memory elements
615 .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
616 .  t3 - type of third memory elements
617 .  m4 - number of elements to allocate in 4th chunk  (may be zero)
618 -  t4 - type of fourth memory elements
619 
620    Output Parameter:
621 +  r1 - memory allocated in first chunk
622 .  r2 - memory allocated in second chunk
623 .  r3 - memory allocated in third chunk
624 -  r4 - memory allocated in fourth chunk
625 
626    Synopsis:
627    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)
628 
629    Level: developer
630 
631    Notes: Memory of first chunk is always allocated at least double aligned
632 
633 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4()
634 
635   Concepts: memory allocation
636 
637 M*/
638 #if defined(PETSC_USE_DEBUG)
639 #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))
640 #else
641 #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))
642 #endif
643 
644 /*MC
645    PetscMalloc5 - Allocates 5 chunks of  memory
646 
647    Input Parameter:
648 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
649 .  t1 - type of first memory elements
650 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
651 .  t2 - type of second memory elements
652 .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
653 .  t3 - type of third memory elements
654 .  m4 - number of elements to allocate in 4th chunk  (may be zero)
655 .  t4 - type of fourth memory elements
656 .  m5 - number of elements to allocate in 5th chunk  (may be zero)
657 -  t5 - type of fifth memory elements
658 
659    Output Parameter:
660 +  r1 - memory allocated in first chunk
661 .  r2 - memory allocated in second chunk
662 .  r3 - memory allocated in third chunk
663 .  r4 - memory allocated in fourth chunk
664 -  r5 - memory allocated in fifth chunk
665 
666    Synopsis:
667    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)
668 
669    Level: developer
670 
671    Notes: Memory of first chunk is always allocated at least double aligned
672 
673 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4(), PetscFree5()
674 
675   Concepts: memory allocation
676 
677 M*/
678 #if defined(PETSC_USE_DEBUG)
679 #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))
680 #else
681 #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))
682 #endif
683 
684 
685 /*MC
686    PetscMalloc6 - Allocates 6 chunks of  memory
687 
688    Input Parameter:
689 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
690 .  t1 - type of first memory elements
691 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
692 .  t2 - type of second memory elements
693 .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
694 .  t3 - type of third memory elements
695 .  m4 - number of elements to allocate in 4th chunk  (may be zero)
696 .  t4 - type of fourth memory elements
697 .  m5 - number of elements to allocate in 5th chunk  (may be zero)
698 .  t5 - type of fifth memory elements
699 .  m6 - number of elements to allocate in 6th chunk  (may be zero)
700 -  t6 - type of sixth memory elements
701 
702    Output Parameter:
703 +  r1 - memory allocated in first chunk
704 .  r2 - memory allocated in second chunk
705 .  r3 - memory allocated in third chunk
706 .  r4 - memory allocated in fourth chunk
707 .  r5 - memory allocated in fifth chunk
708 -  r6 - memory allocated in sixth chunk
709 
710    Synopsis:
711    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)
712 
713    Level: developer
714 
715    Notes: Memory of first chunk is always allocated at least double aligned
716 
717 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4(), PetscFree5(), PetscFree6()
718 
719   Concepts: memory allocation
720 
721 M*/
722 #if defined(PETSC_USE_DEBUG)
723 #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))
724 #else
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)+(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))
726 #endif
727 
728 /*MC
729    PetscMalloc7 - Allocates 7 chunks of  memory
730 
731    Input Parameter:
732 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
733 .  t1 - type of first memory elements
734 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
735 .  t2 - type of second memory elements
736 .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
737 .  t3 - type of third memory elements
738 .  m4 - number of elements to allocate in 4th chunk  (may be zero)
739 .  t4 - type of fourth memory elements
740 .  m5 - number of elements to allocate in 5th chunk  (may be zero)
741 .  t5 - type of fifth memory elements
742 .  m6 - number of elements to allocate in 6th chunk  (may be zero)
743 .  t6 - type of sixth memory elements
744 .  m7 - number of elements to allocate in 7th chunk  (may be zero)
745 -  t7 - type of sixth memory elements
746 
747    Output Parameter:
748 +  r1 - memory allocated in first chunk
749 .  r2 - memory allocated in second chunk
750 .  r3 - memory allocated in third chunk
751 .  r4 - memory allocated in fourth chunk
752 .  r5 - memory allocated in fifth chunk
753 .  r6 - memory allocated in sixth chunk
754 -  r7 - memory allocated in sixth chunk
755 
756    Synopsis:
757    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)
758 
759    Level: developer
760 
761    Notes: Memory of first chunk is always allocated at least double aligned
762 
763 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4(), PetscFree5(), PetscFree6(), PetscFree7()
764 
765   Concepts: memory allocation
766 
767 M*/
768 #if defined(PETSC_USE_DEBUG)
769 #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))
770 #else
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)+(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))
772 #endif
773 
774 /*MC
775    PetscNew - Allocates memory of a particular type, zeros the memory!
776 
777    Input Parameter:
778 .  type - structure name of space to be allocated. Memory of size sizeof(type) is allocated
779 
780    Output Parameter:
781 .  result - memory allocated
782 
783    Synopsis:
784    PetscErrorCode PetscNew(struct type,((type *))result)
785 
786    Level: beginner
787 
788 .seealso: PetscFree(), PetscMalloc()
789 
790   Concepts: memory allocation
791 
792 M*/
793 #define PetscNew(A,b)      (PetscMalloc(sizeof(A),(b)) || PetscMemzero(*(b),sizeof(A)))
794 #define PetscNewLog(o,A,b) (PetscNew(A,b) || ((o) ? PetscLogObjectMemory(o,sizeof(A)) : 0))
795 
796 /*MC
797    PetscFree - Frees memory
798 
799    Input Parameter:
800 .   memory - memory to free (the pointer is ALWAYS set to 0 upon sucess)
801 
802    Synopsis:
803    PetscErrorCode PetscFree(void *memory)
804 
805    Level: beginner
806 
807    Notes: Memory must have been obtained with PetscNew() or PetscMalloc()
808 
809 .seealso: PetscNew(), PetscMalloc(), PetscFreeVoid()
810 
811   Concepts: memory allocation
812 
813 M*/
814 #define PetscFree(a)   ((a) ? ((*PetscTrFree)((a),__LINE__,__FUNCT__,__FILE__,__SDIR__) || ((a = 0),0)) : 0)
815 
816 /*MC
817    PetscFreeVoid - Frees memory
818 
819    Input Parameter:
820 .   memory - memory to free
821 
822    Synopsis:
823    void PetscFreeVoid(void *memory)
824 
825    Level: beginner
826 
827    Notes: This is different from PetscFree() in that no error code is returned
828 
829 .seealso: PetscFree(), PetscNew(), PetscMalloc()
830 
831   Concepts: memory allocation
832 
833 M*/
834 #define PetscFreeVoid(a) ((*PetscTrFree)((a),__LINE__,__FUNCT__,__FILE__,__SDIR__),(a) = 0)
835 
836 
837 /*MC
838    PetscFree2 - Frees 2 chunks of memory obtained with PetscMalloc2()
839 
840    Input Parameter:
841 +   memory1 - memory to free
842 -   memory2 - 2nd memory to free
843 
844 
845    Synopsis:
846    PetscErrorCode PetscFree2(void *memory1,void *memory2)
847 
848    Level: developer
849 
850    Notes: Memory must have been obtained with PetscMalloc2()
851 
852 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree()
853 
854   Concepts: memory allocation
855 
856 M*/
857 #if defined(PETSC_USE_DEBUG)
858 #define PetscFree2(m1,m2)   (PetscFree(m2) || PetscFree(m1))
859 #else
860 #define PetscFree2(m1,m2)   (PetscFree(m1))
861 #endif
862 
863 /*MC
864    PetscFree3 - Frees 3 chunks of memory obtained with PetscMalloc3()
865 
866    Input Parameter:
867 +   memory1 - memory to free
868 .   memory2 - 2nd memory to free
869 -   memory3 - 3rd memory to free
870 
871 
872    Synopsis:
873    PetscErrorCode PetscFree3(void *memory1,void *memory2,void *memory3)
874 
875    Level: developer
876 
877    Notes: Memory must have been obtained with PetscMalloc3()
878 
879 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3()
880 
881   Concepts: memory allocation
882 
883 M*/
884 #if defined(PETSC_USE_DEBUG)
885 #define PetscFree3(m1,m2,m3)   (PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
886 #else
887 #define PetscFree3(m1,m2,m3)   (PetscFree(m1))
888 #endif
889 
890 /*MC
891    PetscFree4 - Frees 4 chunks of memory obtained with PetscMalloc4()
892 
893    Input Parameter:
894 +   m1 - memory to free
895 .   m2 - 2nd memory to free
896 .   m3 - 3rd memory to free
897 -   m4 - 4th memory to free
898 
899 
900    Synopsis:
901    PetscErrorCode PetscFree4(void *m1,void *m2,void *m3,void *m4)
902 
903    Level: developer
904 
905    Notes: Memory must have been obtained with PetscMalloc4()
906 
907 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4()
908 
909   Concepts: memory allocation
910 
911 M*/
912 #if defined(PETSC_USE_DEBUG)
913 #define PetscFree4(m1,m2,m3,m4)   (PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
914 #else
915 #define PetscFree4(m1,m2,m3,m4)   (PetscFree(m1))
916 #endif
917 
918 /*MC
919    PetscFree5 - Frees 5 chunks of memory obtained with PetscMalloc5()
920 
921    Input Parameter:
922 +   m1 - memory to free
923 .   m2 - 2nd memory to free
924 .   m3 - 3rd memory to free
925 .   m4 - 4th memory to free
926 -   m5 - 5th memory to free
927 
928 
929    Synopsis:
930    PetscErrorCode PetscFree5(void *m1,void *m2,void *m3,void *m4,void *m5)
931 
932    Level: developer
933 
934    Notes: Memory must have been obtained with PetscMalloc5()
935 
936 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5()
937 
938   Concepts: memory allocation
939 
940 M*/
941 #if defined(PETSC_USE_DEBUG)
942 #define PetscFree5(m1,m2,m3,m4,m5)   (PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
943 #else
944 #define PetscFree5(m1,m2,m3,m4,m5)   (PetscFree(m1))
945 #endif
946 
947 
948 /*MC
949    PetscFree6 - Frees 6 chunks of memory obtained with PetscMalloc6()
950 
951    Input Parameter:
952 +   m1 - memory to free
953 .   m2 - 2nd memory to free
954 .   m3 - 3rd memory to free
955 .   m4 - 4th memory to free
956 .   m5 - 5th memory to free
957 -   m6 - 6th memory to free
958 
959 
960    Synopsis:
961    PetscErrorCode PetscFree6(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6)
962 
963    Level: developer
964 
965    Notes: Memory must have been obtained with PetscMalloc6()
966 
967 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5(), PetscMalloc6()
968 
969   Concepts: memory allocation
970 
971 M*/
972 #if defined(PETSC_USE_DEBUG)
973 #define PetscFree6(m1,m2,m3,m4,m5,m6)   (PetscFree(m6) || PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
974 #else
975 #define PetscFree6(m1,m2,m3,m4,m5,m6)   (PetscFree(m1))
976 #endif
977 
978 /*MC
979    PetscFree7 - Frees 7 chunks of memory obtained with PetscMalloc7()
980 
981    Input Parameter:
982 +   m1 - memory to free
983 .   m2 - 2nd memory to free
984 .   m3 - 3rd memory to free
985 .   m4 - 4th memory to free
986 .   m5 - 5th memory to free
987 .   m6 - 6th memory to free
988 -   m7 - 7th memory to free
989 
990 
991    Synopsis:
992    PetscErrorCode PetscFree7(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6,void *m7)
993 
994    Level: developer
995 
996    Notes: Memory must have been obtained with PetscMalloc7()
997 
998 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5(), PetscMalloc6(),
999           PetscMalloc7()
1000 
1001   Concepts: memory allocation
1002 
1003 M*/
1004 #if defined(PETSC_USE_DEBUG)
1005 #define PetscFree7(m1,m2,m3,m4,m5,m6,m7)   (PetscFree(m7) || PetscFree(m6) || PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
1006 #else
1007 #define PetscFree7(m1,m2,m3,m4,m5,m6,m7)   (PetscFree(m1))
1008 #endif
1009 
1010 EXTERN PETSC_DLLEXPORT PetscErrorCode (*PetscTrMalloc)(size_t,int,const char[],const char[],const char[],void**);
1011 EXTERN PETSC_DLLEXPORT PetscErrorCode (*PetscTrFree)(void*,int,const char[],const char[],const char[]);
1012 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[]));
1013 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscMallocClear(void);
1014 
1015 /*
1016    Routines for tracing memory corruption/bleeding with default PETSc
1017    memory allocation
1018 */
1019 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMallocDump(FILE *);
1020 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMallocDumpLog(FILE *);
1021 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMallocGetCurrentUsage(PetscLogDouble *);
1022 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMallocGetMaximumUsage(PetscLogDouble *);
1023 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMallocDebug(PetscTruth);
1024 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMallocValidate(int,const char[],const char[],const char[]);
1025 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMallocSetDumpLog(void);
1026 
1027 
1028 /*
1029     Variable type where we stash PETSc object pointers in Fortran.
1030     On most machines size(pointer) == sizeof(long) - except windows
1031     where its sizeof(long long)
1032 */
1033 
1034 #if (PETSC_SIZEOF_VOID_P) == (PETSC_SIZEOF_LONG)
1035 #define PetscFortranAddr   long
1036 #elif  (PETSC_SIZEOF_VOID_P) == (PETSC_SIZEOF_LONG_LONG)
1037 #define PetscFortranAddr   long long
1038 #else
1039 #error "Unknown size for PetscFortranAddr! Send us a bugreport at petsc-maint@mcs.anl.gov"
1040 #endif
1041 
1042 /*E
1043     PetscDataType - Used for handling different basic data types.
1044 
1045    Level: beginner
1046 
1047 .seealso: PetscBinaryRead(), PetscBinaryWrite(), PetscDataTypeToMPIDataType(),
1048           PetscDataTypeGetSize()
1049 
1050 E*/
1051 typedef enum {PETSC_INT = 0,PETSC_DOUBLE = 1,PETSC_COMPLEX = 2, PETSC_LONG = 3 ,PETSC_SHORT = 4,PETSC_FLOAT = 5,
1052               PETSC_CHAR = 6,PETSC_LOGICAL = 7,PETSC_ENUM = 8,PETSC_TRUTH=9, PETSC_LONG_DOUBLE = 10} PetscDataType;
1053 extern const char *PetscDataTypes[];
1054 
1055 #if defined(PETSC_USE_COMPLEX)
1056 #define PETSC_SCALAR PETSC_COMPLEX
1057 #else
1058 #if defined(PETSC_USE_SINGLE)
1059 #define PETSC_SCALAR PETSC_FLOAT
1060 #elif defined(PETSC_USE_LONG_DOUBLE)
1061 #define PETSC_SCALAR PETSC_LONG_DOUBLE
1062 #elif defined(PETSC_USE_INT)
1063 #define PETSC_SCALAR PETSC_INT
1064 #else
1065 #define PETSC_SCALAR PETSC_DOUBLE
1066 #endif
1067 #endif
1068 #if defined(PETSC_USE_SINGLE)
1069 #define PETSC_REAL PETSC_FLOAT
1070 #elif defined(PETSC_USE_LONG_DOUBLE)
1071 #define PETSC_REAL PETSC_LONG_DOUBLE
1072 #elif defined(PETSC_USE_INT)
1073 #define PETSC_REAL PETSC_INT
1074 #else
1075 #define PETSC_REAL PETSC_DOUBLE
1076 #endif
1077 #define PETSC_FORTRANADDR PETSC_LONG
1078 
1079 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDataTypeToMPIDataType(PetscDataType,MPI_Datatype*);
1080 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDataTypeGetSize(PetscDataType,size_t*);
1081 
1082 /*
1083     Basic memory and string operations. These are usually simple wrappers
1084    around the basic Unix system calls, but a few of them have additional
1085    functionality and/or error checking.
1086 */
1087 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMemcpy(void*,const void *,size_t);
1088 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscBitMemcpy(void*,PetscInt,const void*,PetscInt,PetscInt,PetscDataType);
1089 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMemmove(void*,void *,size_t);
1090 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMemzero(void*,size_t);
1091 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMemcmp(const void*,const void*,size_t,PetscTruth *);
1092 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrlen(const char[],size_t*);
1093 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrcmp(const char[],const char[],PetscTruth *);
1094 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrgrt(const char[],const char[],PetscTruth *);
1095 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrcasecmp(const char[],const char[],PetscTruth*);
1096 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrncmp(const char[],const char[],size_t,PetscTruth*);
1097 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrcpy(char[],const char[]);
1098 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrcat(char[],const char[]);
1099 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrncat(char[],const char[],size_t);
1100 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrncpy(char[],const char[],size_t);
1101 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrchr(const char[],char,char *[]);
1102 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrtolower(char[]);
1103 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrrchr(const char[],char,char *[]);
1104 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrstr(const char[],const char[],char *[]);
1105 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrrstr(const char[],const char[],char *[]);
1106 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrallocpy(const char[],char *[]);
1107 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrreplace(MPI_Comm,const char[],char[],size_t);
1108 #define      PetscStrfree(a) ((a) ? PetscFree(a) : 0)
1109 
1110 /*S
1111     PetscToken - 'Token' used for managing tokenizing strings
1112 
1113   Level: intermediate
1114 
1115 .seealso: PetscTokenCreate(), PetscTokenFind(), PetscTokenDestroy()
1116 S*/
1117 typedef struct _p_PetscToken* PetscToken;
1118 
1119 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscTokenCreate(const char[],const char,PetscToken*);
1120 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscTokenFind(PetscToken,char *[]);
1121 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscTokenDestroy(PetscToken);
1122 
1123 /*
1124    These are  MPI operations for MPI_Allreduce() etc
1125 */
1126 EXTERN PETSC_DLLEXPORT MPI_Op PetscMaxSum_Op;
1127 #if defined(PETSC_USE_COMPLEX)
1128 EXTERN PETSC_DLLEXPORT MPI_Op PetscSum_Op;
1129 #else
1130 #define PetscSum_Op MPI_SUM
1131 #endif
1132 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMaxSum(MPI_Comm,const PetscInt[],PetscInt*,PetscInt*);
1133 
1134 /*S
1135      PetscObject - any PETSc object, PetscViewer, Mat, Vec, KSP etc
1136 
1137    Level: beginner
1138 
1139    Note: This is the base class from which all objects appear.
1140 
1141 .seealso:  PetscObjectDestroy(), PetscObjectView(), PetscObjectGetName(), PetscObjectSetName()
1142 S*/
1143 typedef struct _p_PetscObject* PetscObject;
1144 
1145 /*S
1146      PetscFList - Linked list of functions, possibly stored in dynamic libraries, accessed
1147       by string name
1148 
1149    Level: advanced
1150 
1151 .seealso:  PetscFListAdd(), PetscFListDestroy()
1152 S*/
1153 typedef struct _n_PetscFList *PetscFList;
1154 
1155 /*E
1156   PetscFileMode - Access mode for a file.
1157 
1158   Level: beginner
1159 
1160   FILE_MODE_READ - open a file at its beginning for reading
1161 
1162   FILE_MODE_WRITE - open a file at its beginning for writing (will create if the file does not exist)
1163 
1164   FILE_MODE_APPEND - open a file at end for writing
1165 
1166   FILE_MODE_UPDATE - open a file for updating, meaning for reading and writing
1167 
1168   FILE_MODE_APPEND_UPDATE - open a file for updating, meaning for reading and writing, at the end
1169 
1170 .seealso: PetscViewerFileSetMode()
1171 E*/
1172 typedef enum {FILE_MODE_READ, FILE_MODE_WRITE, FILE_MODE_APPEND, FILE_MODE_UPDATE, FILE_MODE_APPEND_UPDATE} PetscFileMode;
1173 
1174 #include "petscviewer.h"
1175 #include "petscoptions.h"
1176 
1177 #define PETSC_SMALLEST_COOKIE 1211211
1178 extern PETSC_DLLEXPORT PetscCookie PETSC_LARGEST_COOKIE;
1179 extern PETSC_DLLEXPORT PetscCookie PETSC_OBJECT_COOKIE;
1180 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscCookieRegister(PetscCookie *);
1181 
1182 /*
1183    Routines that get memory usage information from the OS
1184 */
1185 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemoryGetCurrentUsage(PetscLogDouble *);
1186 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemoryGetMaximumUsage(PetscLogDouble *);
1187 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemorySetGetMaximumUsage(void);
1188 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemoryShowUsage(PetscViewer,const char[]);
1189 
1190 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscInfoAllow(PetscTruth,const char []);
1191 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetTime(PetscLogDouble*);
1192 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetCPUTime(PetscLogDouble*);
1193 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSleep(int);
1194 
1195 /*
1196     Initialization of PETSc
1197 */
1198 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscInitialize(int*,char***,const char[],const char[]);
1199 PetscPolymorphicSubroutine(PetscInitialize,(int *argc,char ***args),(argc,args,PETSC_NULL,PETSC_NULL))
1200 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscInitializeNoArguments(void);
1201 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscInitialized(PetscTruth *);
1202 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFinalized(PetscTruth *);
1203 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFinalize(void);
1204 EXTERN PetscErrorCode PetscInitializeFortran(void);
1205 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetArgs(int*,char ***);
1206 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetArguments(char ***);
1207 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFreeArguments(char **);
1208 
1209 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscEnd(void);
1210 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscInitializePackage(const char[]);
1211 
1212 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOpenMPMerge(PetscMPIInt);
1213 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOpenMPSpawn(PetscMPIInt);
1214 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOpenMPFinalize(void);
1215 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOpenMPRun(MPI_Comm,PetscErrorCode (*)(MPI_Comm,void *),void*);
1216 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOpenMPFree(MPI_Comm,void*);
1217 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOpenMPNew(MPI_Comm,PetscInt,void**);
1218 
1219 /*
1220      These are so that in extern C code we can caste function pointers to non-extern C
1221    function pointers. Since the regular C++ code expects its function pointers to be
1222    C++.
1223 */
1224 typedef void (**PetscVoidStarFunction)(void);
1225 typedef void (*PetscVoidFunction)(void);
1226 typedef PetscErrorCode (*PetscErrorCodeFunction)(void);
1227 
1228 /*
1229    PetscTryMethod - Queries an object for a method, if it exists then calls it.
1230               These are intended to be used only inside PETSc functions.
1231 */
1232 #define  PetscTryMethod(obj,A,B,C) \
1233   0;{ PetscErrorCode (*f)B, __ierr; \
1234     __ierr = PetscObjectQueryFunction((PetscObject)obj,A,(PetscVoidStarFunction)&f);CHKERRQ(__ierr); \
1235     if (f) {__ierr = (*f)C;CHKERRQ(__ierr);}\
1236   }
1237 #define  PetscUseMethod(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     else {SETERRQ1(PETSC_ERR_SUP,"Cannot locate function %s in object",A);} \
1242   }
1243 /*
1244     Functions that can act on any PETSc object.
1245 */
1246 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectCreate(MPI_Comm,PetscObject*);
1247 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectCreateGeneric(MPI_Comm, PetscCookie, const char [], PetscObject *);
1248 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectDestroy(PetscObject);
1249 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectExists(PetscObject,PetscTruth*);
1250 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetComm(PetscObject,MPI_Comm *);
1251 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetCookie(PetscObject,PetscCookie *);
1252 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectSetType(PetscObject,const char []);
1253 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetType(PetscObject,const char *[]);
1254 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectSetName(PetscObject,const char[]);
1255 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetName(PetscObject,const char*[]);
1256 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectReference(PetscObject);
1257 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetReference(PetscObject,PetscInt*);
1258 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectDereference(PetscObject);
1259 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetNewTag(PetscObject,PetscMPIInt *);
1260 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectView(PetscObject,PetscViewer);
1261 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectCompose(PetscObject,const char[],PetscObject);
1262 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectQuery(PetscObject,const char[],PetscObject *);
1263 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectComposeFunction(PetscObject,const char[],const char[],void (*)(void));
1264 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectSetFromOptions(PetscObject);
1265 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectSetUp(PetscObject);
1266 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscCommGetNewTag(MPI_Comm,PetscMPIInt *);
1267 
1268 /*MC
1269    PetscObjectComposeFunctionDynamic - Associates a function with a given PETSc object.
1270 
1271    Collective on PetscObject
1272 
1273    Input Parameters:
1274 +  obj - the PETSc object; this must be cast with a (PetscObject), for example,
1275          PetscObjectCompose((PetscObject)mat,...);
1276 .  name - name associated with the child function
1277 .  fname - name of the function
1278 -  ptr - function pointer (or PETSC_NULL if using dynamic libraries)
1279 
1280    Level: advanced
1281 
1282     Synopsis:
1283     PetscErrorCode PetscObjectComposeFunctionDynamic(PetscObject obj,const char name[],const char fname[],void *ptr)
1284 
1285    Notes:
1286    To remove a registered routine, pass in a PETSC_NULL rname and fnc().
1287 
1288    PetscObjectComposeFunctionDynamic() can be used with any PETSc object (such as
1289    Mat, Vec, KSP, SNES, etc.) or any user-provided object.
1290 
1291    The composed function must be wrapped in a EXTERN_C_BEGIN/END for this to
1292    work in C++/complex with dynamic link libraries (config/configure.py options --with-shared --with-dynamic)
1293    enabled.
1294 
1295    Concepts: objects^composing functions
1296    Concepts: composing functions
1297    Concepts: functions^querying
1298    Concepts: objects^querying
1299    Concepts: querying objects
1300 
1301 .seealso: PetscObjectQueryFunction()
1302 M*/
1303 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
1304 #define PetscObjectComposeFunctionDynamic(a,b,c,d) PetscObjectComposeFunction(a,b,c,0)
1305 #else
1306 #define PetscObjectComposeFunctionDynamic(a,b,c,d) PetscObjectComposeFunction(a,b,c,(PetscVoidFunction)(d))
1307 #endif
1308 
1309 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectQueryFunction(PetscObject,const char[],void (**)(void));
1310 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectSetOptionsPrefix(PetscObject,const char[]);
1311 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectAppendOptionsPrefix(PetscObject,const char[]);
1312 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectPrependOptionsPrefix(PetscObject,const char[]);
1313 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetOptionsPrefix(PetscObject,const char*[]);
1314 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectPublish(PetscObject);
1315 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectChangeTypeName(PetscObject,const char[]);
1316 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectRegisterDestroy(PetscObject);
1317 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectRegisterDestroyAll(void);
1318 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectName(PetscObject);
1319 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscTypeCompare(PetscObject,const char[],PetscTruth*);
1320 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRegisterFinalize(PetscErrorCode (*)(void));
1321 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRegisterFinalizeAll(void);
1322 
1323 /*
1324     Defines PETSc error handling.
1325 */
1326 #include "petscerror.h"
1327 
1328 /*S
1329      PetscOList - Linked list of PETSc objects, accessable by string name
1330 
1331    Level: advanced
1332 
1333 .seealso:  PetscOListAdd(), PetscOListDestroy(), PetscOListFind()
1334 S*/
1335 typedef struct _n_PetscOList *PetscOList;
1336 
1337 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOListDestroy(PetscOList);
1338 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOListFind(PetscOList,const char[],PetscObject*);
1339 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOListReverseFind(PetscOList,PetscObject,char**);
1340 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOListAdd(PetscOList *,const char[],PetscObject);
1341 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOListDuplicate(PetscOList,PetscOList *);
1342 
1343 /*
1344     Dynamic library lists. Lists of names of routines in dynamic
1345   link libraries that will be loaded as needed.
1346 */
1347 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListAdd(PetscFList*,const char[],const char[],void (*)(void));
1348 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListDestroy(PetscFList*);
1349 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListFind(PetscFList,MPI_Comm,const char[],void (**)(void));
1350 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListPrintTypes(PetscFList,MPI_Comm,FILE*,const char[],const char[],const char[],const char[]);
1351 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
1352 #define    PetscFListAddDynamic(a,b,p,c) PetscFListAdd(a,b,p,0)
1353 #else
1354 #define    PetscFListAddDynamic(a,b,p,c) PetscFListAdd(a,b,p,(void (*)(void))c)
1355 #endif
1356 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListDuplicate(PetscFList,PetscFList *);
1357 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListView(PetscFList,PetscViewer);
1358 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListConcat(const char [],const char [],char []);
1359 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListGet(PetscFList,char ***,int*);
1360 
1361 /*S
1362      PetscDLLibrary - Linked list of dynamics libraries to search for functions
1363 
1364    Level: advanced
1365 
1366    --with-shared --with-dynamic must be used with config/configure.py to use dynamic libraries
1367 
1368 .seealso:  PetscDLLibraryOpen()
1369 S*/
1370 typedef struct _n_PetscDLLibrary *PetscDLLibrary;
1371 extern PetscDLLibrary DLLibrariesLoaded;
1372 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryRetrieve(MPI_Comm,const char[],char *,int,PetscTruth *);
1373 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryOpen(MPI_Comm,const char[],void **);
1374 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibrarySym(MPI_Comm,PetscDLLibrary *,const char[],const char[],void **);
1375 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryAppend(MPI_Comm,PetscDLLibrary *,const char[]);
1376 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryPrepend(MPI_Comm,PetscDLLibrary *,const char[]);
1377 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryClose(PetscDLLibrary);
1378 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryPrintPath(void);
1379 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryGetInfo(void*,const char[],const char *[]);
1380 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryCCAAppend(MPI_Comm,PetscDLLibrary *,const char[]);
1381 
1382 /*
1383      Useful utility routines
1384 */
1385 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSplitOwnership(MPI_Comm,PetscInt*,PetscInt*);
1386 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSplitOwnershipBlock(MPI_Comm,PetscInt,PetscInt*,PetscInt*);
1387 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSequentialPhaseBegin(MPI_Comm,PetscMPIInt);
1388 PetscPolymorphicSubroutine(PetscSequentialPhaseBegin,(MPI_Comm comm),(comm,1))
1389 PetscPolymorphicSubroutine(PetscSequentialPhaseBegin,(void),(PETSC_COMM_WORLD,1))
1390 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSequentialPhaseEnd(MPI_Comm,PetscMPIInt);
1391 PetscPolymorphicSubroutine(PetscSequentialPhaseEnd,(MPI_Comm comm),(comm,1))
1392 PetscPolymorphicSubroutine(PetscSequentialPhaseEnd,(void),(PETSC_COMM_WORLD,1))
1393 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscBarrier(PetscObject);
1394 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMPIDump(FILE*);
1395 
1396 #define PetscNot(a) ((a) ? PETSC_FALSE : PETSC_TRUE)
1397 /*
1398     Defines basic graphics available from PETSc.
1399 */
1400 #include "petscdraw.h"
1401 
1402 /*
1403     Defines the base data structures for all PETSc objects
1404 */
1405 #include "private/petscimpl.h"
1406 /*
1407      Defines PETSc profiling.
1408 */
1409 #include "petsclog.h"
1410 
1411 /*
1412           For locking, unlocking and destroying AMS memories associated with
1413     PETSc objects. Not currently used.
1414 */
1415 #define PetscPublishAll(v)           0
1416 #define PetscObjectTakeAccess(obj)   0
1417 #define PetscObjectGrantAccess(obj)  0
1418 #define PetscObjectDepublish(obj)    0
1419 
1420 /*
1421       This code allows one to pass a MPI communicator between
1422     C and Fortran. MPI 2.0 defines a standard API for doing this.
1423     The code here is provided to allow PETSc to work with MPI 1.1
1424     standard MPI libraries.
1425 */
1426 EXTERN PetscErrorCode MPICCommToFortranComm(MPI_Comm,int *);
1427 EXTERN PetscErrorCode MPIFortranCommToCComm(int,MPI_Comm*);
1428 
1429 /*
1430       Simple PETSc parallel IO for ASCII printing
1431 */
1432 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscFixFilename(const char[],char[]);
1433 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscFOpen(MPI_Comm,const char[],const char[],FILE**);
1434 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscFClose(MPI_Comm,FILE*);
1435 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4);
1436 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscPrintf(MPI_Comm,const char[],...)  PETSC_PRINTF_FORMAT_CHECK(2,3);
1437 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscSNPrintf(char*,size_t,const char [],...);
1438 
1439 /* These are used internally by PETSc ASCII IO routines*/
1440 #include <stdarg.h>
1441 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscVSNPrintf(char*,size_t,const char[],va_list);
1442 EXTERN PetscErrorCode PETSC_DLLEXPORT  (*PetscVFPrintf)(FILE*,const char[],va_list);
1443 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscVFPrintfDefault(FILE*,const char[],va_list);
1444 
1445 /*MC
1446     PetscErrorPrintf - Prints error messages.
1447 
1448     Not Collective
1449 
1450    Synopsis:
1451      PetscErrorCode (*PetscErrorPrintf)(const char format[],...);
1452 
1453     Input Parameters:
1454 .   format - the usual printf() format string
1455 
1456    Options Database Keys:
1457 +    -error_output_stdout - cause error messages to be printed to stdout instead of the
1458          (default) stderr
1459 -    -error_output_none to turn off all printing of error messages (does not change the way the
1460           error is handled.)
1461 
1462    Notes: Use
1463 $     PetscErrorPrintf = PetscErrorPrintfNone; to turn off all printing of error messages (does not change the way the
1464 $                        error is handled.) and
1465 $     PetscErrorPrintf = PetscErrorPrintfDefault; to turn it back on
1466 
1467           Use
1468      PETSC_STDERR = FILE* obtained from a file open etc. to have stderr printed to the file.
1469      PETSC_STDOUT = FILE* obtained from a file open etc. to have stdout printed to the file.
1470 
1471           Use
1472       PetscPushErrorHandler() to provide your own error handler that determines what kind of messages to print
1473 
1474    Level: developer
1475 
1476     Fortran Note:
1477     This routine is not supported in Fortran.
1478 
1479     Concepts: error messages^printing
1480     Concepts: printing^error messages
1481 
1482 .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf(), PetscPrintf(), PetscErrorHandlerPush()
1483 M*/
1484 EXTERN PETSC_DLLEXPORT PetscErrorCode (*PetscErrorPrintf)(const char[],...);
1485 
1486 /*MC
1487     PetscHelpPrintf - Prints help messages.
1488 
1489     Not Collective
1490 
1491    Synopsis:
1492      PetscErrorCode (*PetscHelpPrintf)(const char format[],...);
1493 
1494     Input Parameters:
1495 .   format - the usual printf() format string
1496 
1497    Level: developer
1498 
1499     Fortran Note:
1500     This routine is not supported in Fortran.
1501 
1502     Concepts: help messages^printing
1503     Concepts: printing^help messages
1504 
1505 .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscErrorPrintf()
1506 M*/
1507 EXTERN PETSC_DLLEXPORT PetscErrorCode  (*PetscHelpPrintf)(MPI_Comm,const char[],...);
1508 
1509 EXTERN PetscErrorCode  PetscErrorPrintfDefault(const char [],...);
1510 EXTERN PetscErrorCode  PetscErrorPrintfNone(const char [],...);
1511 EXTERN PetscErrorCode  PetscHelpPrintfDefault(MPI_Comm,const char [],...);
1512 
1513 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscPOpen(MPI_Comm,const char[],const char[],const char[],FILE **);
1514 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscPClose(MPI_Comm,FILE*);
1515 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscSynchronizedPrintf(MPI_Comm,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3);
1516 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscSynchronizedFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4);
1517 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscSynchronizedFlush(MPI_Comm);
1518 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscSynchronizedFGets(MPI_Comm,FILE*,size_t,char[]);
1519 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscStartMatlab(MPI_Comm,const char[],const char[],FILE**);
1520 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscStartJava(MPI_Comm,const char[],const char[],FILE**);
1521 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscGetPetscDir(const char*[]);
1522 
1523 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscPopUpSelect(MPI_Comm,const char*,const char*,int,const char**,int*);
1524 
1525 /*S
1526      PetscContainer - Simple PETSc object that contains a pointer to any required data
1527 
1528    Level: advanced
1529 
1530 .seealso:  PetscObject, PetscContainerCreate()
1531 S*/
1532 extern PetscCookie PETSC_DLLEXPORT PETSC_CONTAINER_COOKIE;
1533 typedef struct _p_PetscContainer*  PetscContainer;
1534 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscContainerGetPointer(PetscContainer,void **);
1535 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscContainerSetPointer(PetscContainer,void *);
1536 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscContainerDestroy(PetscContainer);
1537 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscContainerCreate(MPI_Comm,PetscContainer *);
1538 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscContainerSetUserDestroy(PetscContainer, PetscErrorCode (*)(void*));
1539 
1540 /*
1541    For use in debuggers
1542 */
1543 extern PETSC_DLLEXPORT PetscMPIInt PetscGlobalRank;
1544 extern PETSC_DLLEXPORT PetscMPIInt PetscGlobalSize;
1545 
1546 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscIntView(PetscInt,PetscInt[],PetscViewer);
1547 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRealView(PetscInt,PetscReal[],PetscViewer);
1548 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscScalarView(PetscInt,PetscScalar[],PetscViewer);
1549 
1550 /*
1551     Allows accessing Matlab Engine
1552 */
1553 #include "petscmatlab.h"
1554 
1555 /*
1556       Determine if some of the kernel computation routines use
1557    Fortran (rather than C) for the numerical calculations. On some machines
1558    and compilers (like complex numbers) the Fortran version of the routines
1559    is faster than the C/C++ versions. The flag --with-fortran-kernels
1560    should be used with config/configure.py to turn these on.
1561 */
1562 #if defined(PETSC_USE_FORTRAN_KERNELS)
1563 
1564 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTCRL)
1565 #define PETSC_USE_FORTRAN_KERNEL_MULTCRL
1566 #endif
1567 
1568 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTCSRPERM)
1569 #define PETSC_USE_FORTRAN_KERNEL_MULTCSRPERM
1570 #endif
1571 
1572 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ)
1573 #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ
1574 #endif
1575 
1576 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ)
1577 #define PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ
1578 #endif
1579 
1580 #if !defined(PETSC_USE_FORTRAN_KERNEL_NORM)
1581 #define PETSC_USE_FORTRAN_KERNEL_NORM
1582 #endif
1583 
1584 #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY)
1585 #define PETSC_USE_FORTRAN_KERNEL_MAXPY
1586 #endif
1587 
1588 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ)
1589 #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ
1590 #endif
1591 
1592 #if !defined(PETSC_USE_FORTRAN_KERNEL_RELAXAIJ)
1593 #define PETSC_USE_FORTRAN_KERNEL_RELAXAIJ
1594 #endif
1595 
1596 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ)
1597 #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ
1598 #endif
1599 
1600 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ)
1601 #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ
1602 #endif
1603 
1604 #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT)
1605 #define PETSC_USE_FORTRAN_KERNEL_MDOT
1606 #endif
1607 
1608 #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY)
1609 #define PETSC_USE_FORTRAN_KERNEL_XTIMESY
1610 #endif
1611 
1612 #if !defined(PETSC_USE_FORTRAN_KERNEL_AYPX)
1613 #define PETSC_USE_FORTRAN_KERNEL_AYPX
1614 #endif
1615 
1616 #if !defined(PETSC_USE_FORTRAN_KERNEL_WAXPY)
1617 #define PETSC_USE_FORTRAN_KERNEL_WAXPY
1618 #endif
1619 
1620 #endif
1621 
1622 /*
1623     Macros for indicating code that should be compiled with a C interface,
1624    rather than a C++ interface. Any routines that are dynamically loaded
1625    (such as the PCCreate_XXX() routines) must be wrapped so that the name
1626    mangler does not change the functions symbol name. This just hides the
1627    ugly extern "C" {} wrappers.
1628 */
1629 #if defined(__cplusplus)
1630 #define EXTERN_C_BEGIN extern "C" {
1631 #define EXTERN_C_END }
1632 #else
1633 #define EXTERN_C_BEGIN
1634 #define EXTERN_C_END
1635 #endif
1636 
1637 /* --------------------------------------------------------------------*/
1638 
1639 /*MC
1640     size - integer variable used to contain the number of processors in
1641            the relevent MPI_Comm
1642 
1643    Level: beginner
1644 
1645 .seealso: rank, comm
1646 M*/
1647 
1648 /*MC
1649     rank - integer variable used to contain the number of this processor relative
1650            to all in the relevent MPI_Comm
1651 
1652    Level: beginner
1653 
1654 .seealso: size, comm
1655 M*/
1656 
1657 /*MC
1658     comm - MPI_Comm used in the current routine or object
1659 
1660    Level: beginner
1661 
1662 .seealso: size, rank
1663 M*/
1664 
1665 /*MC
1666     MPI_Comm - the basic object used by MPI to determine which processes are involved in a
1667         communication
1668 
1669    Level: beginner
1670 
1671    Note: This manual page is a place-holder because MPICH does not have a manual page for MPI_Comm
1672 
1673 .seealso: size, rank, comm, PETSC_COMM_WORLD, PETSC_COMM_SELF
1674 M*/
1675 
1676 /*MC
1677     PetscScalar - PETSc type that represents either a double precision real number, a double precision
1678        complex number, a single precision real number, a long double or an int - if the code is configured
1679        with --with-scalar-type=real,complex --with-precision=single,double,longdouble,int,matsingle
1680 
1681 
1682    Level: beginner
1683 
1684 .seealso: PetscReal, PassiveReal, PassiveScalar, MPIU_SCALAR, PetscInt
1685 M*/
1686 
1687 /*MC
1688     PetscReal - PETSc type that represents a real number version of PetscScalar
1689 
1690    Level: beginner
1691 
1692 .seealso: PetscScalar, PassiveReal, PassiveScalar
1693 M*/
1694 
1695 /*MC
1696     PassiveScalar - PETSc type that represents a PetscScalar
1697    Level: beginner
1698 
1699     This is the same as a PetscScalar except in code that is automatically differentiated it is
1700    treated as a constant (not an indendent or dependent variable)
1701 
1702 .seealso: PetscReal, PassiveReal, PetscScalar
1703 M*/
1704 
1705 /*MC
1706     PassiveReal - PETSc type that represents a PetscReal
1707 
1708    Level: beginner
1709 
1710     This is the same as a PetscReal except in code that is automatically differentiated it is
1711    treated as a constant (not an indendent or dependent variable)
1712 
1713 .seealso: PetscScalar, PetscReal, PassiveScalar
1714 M*/
1715 
1716 /*MC
1717     MPIU_SCALAR - MPI datatype corresponding to PetscScalar
1718 
1719    Level: beginner
1720 
1721     Note: In MPI calls that require an MPI datatype that matches a PetscScalar or array of PetscScalars
1722           pass this value
1723 
1724 .seealso: PetscReal, PassiveReal, PassiveScalar, PetscScalar, MPIU_INT
1725 M*/
1726 
1727 /*
1728      The IBM include files define hz, here we hide it so that it may be used
1729    as a regular user variable.
1730 */
1731 #if defined(hz)
1732 #undef hz
1733 #endif
1734 
1735 /*  For arrays that contain filenames or paths */
1736 
1737 
1738 #if defined(PETSC_HAVE_LIMITS_H)
1739 #include <limits.h>
1740 #endif
1741 #if defined(PETSC_HAVE_SYS_PARAM_H)
1742 #include <sys/param.h>
1743 #endif
1744 #if defined(PETSC_HAVE_SYS_TYPES_H)
1745 #include <sys/types.h>
1746 #endif
1747 #if defined(MAXPATHLEN)
1748 #  define PETSC_MAX_PATH_LEN     MAXPATHLEN
1749 #elif defined(MAX_PATH)
1750 #  define PETSC_MAX_PATH_LEN     MAX_PATH
1751 #elif defined(_MAX_PATH)
1752 #  define PETSC_MAX_PATH_LEN     _MAX_PATH
1753 #else
1754 #  define PETSC_MAX_PATH_LEN     4096
1755 #endif
1756 
1757 /* Special support for C++ */
1758 #include "petsc.hh"
1759 
1760 /*MC
1761 
1762     FortranModules - it is possible to use PETSc from Fortran using Fortran 90 modules instead of C style include macros.
1763 
1764 $   Objects are named type(XXXX)  instead of XXXX, for example
1765 $      use petscvec
1766 $      type(Vec) v instead of
1767 $
1768 $#include "finclude/petsc.h"
1769 $#include "finclude/petscvec.h"
1770 $      Vec v
1771 
1772     The PETSc macros, PetscInt, PetscErrorCode etc are not available, you should use integer for these
1773 
1774     See the example src/vec/vec/examples/tutorials/ex20f90.F90
1775 
1776 M*/
1777 PETSC_EXTERN_CXX_END
1778 #endif
1779