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