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