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