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