xref: /petsc/include/petscsys.h (revision 31aafd4856760b35ad080bbf2ed04a4a81f7c91d)
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(__PETSCSYS_H)
6 #define __PETSCSYS_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    For --prefix installs the ${PETSC_ARCH}/ does not exist and petscconf.h is in the same
12    directory as the other PETSc include files.
13 */
14 #include <petscconf.h>
15 #include <petscfix.h>
16 
17 #if defined(PETSC_DESIRE_FEATURE_TEST_MACROS)
18 /*
19    Feature test macros must be included before headers defined by IEEE Std 1003.1-2001
20    We only turn these in PETSc source files that require them by setting PETSC_DESIRE_FEATURE_TEST_MACROS
21 */
22 #if defined(PETSC__POSIX_C_SOURCE_200112L) && !defined(_POSIX_C_SOURCE)
23 #define _POSIX_C_SOURCE 200112L
24 #endif
25 #if defined(PETSC__BSD_SOURCE) && !defined(_BSD_SOURCE)
26 #define _BSD_SOURCE
27 #endif
28 #if defined(PETSC__DEFAULT_SOURCE) && !defined(_DEFAULT_SOURCE)
29 #define _DEFAULT_SOURCE
30 #endif
31 #if defined(PETSC__GNU_SOURCE) && !defined(_GNU_SOURCE)
32 #define _GNU_SOURCE
33 #endif
34 #endif
35 
36 /* ========================================================================== */
37 /*
38    This facilitates using the C version of PETSc from C++ and the C++ version from C.
39 */
40 #if defined(__cplusplus)
41 #  define PETSC_FUNCTION_NAME PETSC_FUNCTION_NAME_CXX
42 #else
43 #  define PETSC_FUNCTION_NAME PETSC_FUNCTION_NAME_C
44 #endif
45 
46 /* ========================================================================== */
47 /*
48    Since PETSc manages its own extern "C" handling users should never include PETSc include
49    files within extern "C". This will generate a compiler error if a user does put the include
50    file within an extern "C".
51 */
52 #if defined(__cplusplus)
53 void assert_never_put_petsc_headers_inside_an_extern_c(int); void assert_never_put_petsc_headers_inside_an_extern_c(double);
54 #endif
55 
56 #if defined(__cplusplus)
57 #  define PETSC_RESTRICT PETSC_CXX_RESTRICT
58 #else
59 #  define PETSC_RESTRICT PETSC_C_RESTRICT
60 #endif
61 
62 #if defined(__cplusplus)
63 #  define PETSC_STATIC_INLINE PETSC_CXX_STATIC_INLINE
64 #else
65 #  define PETSC_STATIC_INLINE PETSC_C_STATIC_INLINE
66 #endif
67 
68 #if defined(_WIN32) && defined(PETSC_USE_SHARED_LIBRARIES) /* For Win32 shared libraries */
69 #  define PETSC_DLLEXPORT __declspec(dllexport)
70 #  define PETSC_DLLIMPORT __declspec(dllimport)
71 #  define PETSC_VISIBILITY_INTERNAL
72 #elif defined(PETSC_USE_VISIBILITY_CXX) && defined(__cplusplus)
73 #  define PETSC_DLLEXPORT __attribute__((visibility ("default")))
74 #  define PETSC_DLLIMPORT __attribute__((visibility ("default")))
75 #  define PETSC_VISIBILITY_INTERNAL __attribute__((visibility ("hidden")))
76 #elif defined(PETSC_USE_VISIBILITY_C) && !defined(__cplusplus)
77 #  define PETSC_DLLEXPORT __attribute__((visibility ("default")))
78 #  define PETSC_DLLIMPORT __attribute__((visibility ("default")))
79 #  define PETSC_VISIBILITY_INTERNAL __attribute__((visibility ("hidden")))
80 #else
81 #  define PETSC_DLLEXPORT
82 #  define PETSC_DLLIMPORT
83 #  define PETSC_VISIBILITY_INTERNAL
84 #endif
85 
86 #if defined(petsc_EXPORTS)      /* CMake defines this when building the shared library */
87 #  define PETSC_VISIBILITY_PUBLIC PETSC_DLLEXPORT
88 #else  /* Win32 users need this to import symbols from petsc.dll */
89 #  define PETSC_VISIBILITY_PUBLIC PETSC_DLLIMPORT
90 #endif
91 
92 /*
93     Functions tagged with PETSC_EXTERN in the header files are
94   always defined as extern "C" when compiled with C++ so they may be
95   used from C and are always visible in the shared libraries
96 */
97 #if defined(__cplusplus)
98 #define PETSC_EXTERN extern "C" PETSC_VISIBILITY_PUBLIC
99 #define PETSC_EXTERN_TYPEDEF extern "C"
100 #define PETSC_INTERN extern "C" PETSC_VISIBILITY_INTERNAL
101 #else
102 #define PETSC_EXTERN extern PETSC_VISIBILITY_PUBLIC
103 #define PETSC_EXTERN_TYPEDEF
104 #define PETSC_INTERN extern PETSC_VISIBILITY_INTERNAL
105 #endif
106 
107 #include <petscversion.h>
108 #define PETSC_AUTHOR_INFO  "       The PETSc Team\n    petsc-maint@mcs.anl.gov\n http://www.mcs.anl.gov/petsc/\n"
109 
110 /* ========================================================================== */
111 
112 /*
113     Defines the interface to MPI allowing the use of all MPI functions.
114 
115     PETSc does not use the C++ binding of MPI at ALL. The following flag
116     makes sure the C++ bindings are not included. The C++ bindings REQUIRE
117     putting mpi.h before ANY C++ include files, we cannot control this
118     with all PETSc users. Users who want to use the MPI C++ bindings can include
119     mpicxx.h directly in their code
120 */
121 #if !defined(MPICH_SKIP_MPICXX)
122 #  define MPICH_SKIP_MPICXX 1
123 #endif
124 #if !defined(OMPI_SKIP_MPICXX)
125 #  define OMPI_SKIP_MPICXX 1
126 #endif
127 #if !defined(OMPI_WANT_MPI_INTERFACE_WARNING)
128 #  define OMPI_WANT_MPI_INTERFACE_WARNING 0
129 #endif
130 #include <mpi.h>
131 
132 /*
133    Perform various sanity checks that the correct mpi.h is being included at compile time.
134    This usually happens because
135       * either an unexpected mpi.h is in the default compiler path (i.e. in /usr/include) or
136       * an extra include path -I/something (which contains the unexpected mpi.h) is being passed to the compiler
137 */
138 #if defined(PETSC_HAVE_MPIUNI)
139 #  if !defined(__MPIUNI_H)
140 #    error "PETSc was configured with --with-mpi=0 but now appears to be compiling using a different mpi.h"
141 #  endif
142 #elif defined(PETSC_HAVE_MPICH_NUMVERSION)
143 #  if !defined(MPICH_NUMVERSION)
144 #    error "PETSc was configured with MPICH but now appears to be compiling using a non-MPICH mpi.h"
145 #  elif MPICH_NUMVERSION != PETSC_HAVE_MPICH_NUMVERSION
146 #    error "PETSc was configured with one MPICH mpi.h version but now appears to be compiling using a different MPICH mpi.h version"
147 #  endif
148 #elif defined(PETSC_HAVE_OMPI_MAJOR_VERSION)
149 #  if !defined(OMPI_MAJOR_VERSION)
150 #    error "PETSc was configured with OpenMPI but now appears to be compiling using a non-OpenMPI mpi.h"
151 #  elif (OMPI_MAJOR_VERSION != PETSC_HAVE_OMPI_MAJOR_VERSION) || (OMPI_MINOR_VERSION != PETSC_HAVE_OMPI_MINOR_VERSION) || (OMPI_RELEASE_VERSION != PETSC_HAVE_OMPI_RELEASE_VERSION)
152 #    error "PETSc was configured with one OpenMPI mpi.h version but now appears to be compiling using a different OpenMPI mpi.h version"
153 #  endif
154 #endif
155 
156 /*
157     Need to put stdio.h AFTER mpi.h for MPICH2 with C++ compiler
158     see the top of mpicxx.h in the MPICH2 distribution.
159 */
160 #include <stdio.h>
161 
162 /* MSMPI on 32bit windows requires this yukky hack - that breaks MPI standard compliance */
163 #if !defined(MPIAPI)
164 #define MPIAPI
165 #endif
166 
167 /*
168    Support for Clang (>=3.2) matching type tag arguments with void* buffer types.
169    This allows the compiler to detect cases where the MPI datatype argument passed to a MPI routine
170    does not match the actual type of the argument being passed in
171 */
172 #if defined(__has_attribute) && defined(works_with_const_which_is_not_true)
173 #  if __has_attribute(argument_with_type_tag) && __has_attribute(pointer_with_type_tag) && __has_attribute(type_tag_for_datatype)
174 #    define PetscAttrMPIPointerWithType(bufno,typeno) __attribute__((pointer_with_type_tag(MPI,bufno,typeno)))
175 #    define PetscAttrMPITypeTag(type)                 __attribute__((type_tag_for_datatype(MPI,type)))
176 #    define PetscAttrMPITypeTagLayoutCompatible(type) __attribute__((type_tag_for_datatype(MPI,type,layout_compatible)))
177 #  endif
178 #endif
179 #if !defined(PetscAttrMPIPointerWithType)
180 #  define PetscAttrMPIPointerWithType(bufno,typeno)
181 #  define PetscAttrMPITypeTag(type)
182 #  define PetscAttrMPITypeTagLayoutCompatible(type)
183 #endif
184 
185 /*MC
186     PetscErrorCode - datatype used for return error code from almost all PETSc functions
187 
188     Level: beginner
189 
190 .seealso: CHKERRQ, SETERRQ
191 M*/
192 typedef int PetscErrorCode;
193 
194 /*MC
195 
196     PetscClassId - A unique id used to identify each PETSc class.
197 
198     Notes: Use PetscClassIdRegister() to obtain a new value for a new class being created. Usually
199          XXXInitializePackage() calls it for each class it defines.
200 
201     Developer Notes: Internal integer stored in the _p_PetscObject data structure.
202          These are all computed by an offset from the lowest one, PETSC_SMALLEST_CLASSID.
203 
204     Level: developer
205 
206 .seealso: PetscClassIdRegister(), PetscLogEventRegister(), PetscHeaderCreate()
207 M*/
208 typedef int PetscClassId;
209 
210 
211 /*MC
212     PetscMPIInt - datatype used to represent 'int' parameters to MPI functions.
213 
214     Level: intermediate
215 
216     Notes: usually this is the same as PetscInt, but if PETSc was built with --with-64-bit-indices but
217            standard C/Fortran integers are 32 bit then this is NOT the same as PetscInt it remains 32 bit
218 
219     PetscMPIIntCast(a,&b) checks if the given PetscInt a will fit in a PetscMPIInt, if not it
220       generates a PETSC_ERR_ARG_OUTOFRANGE error.
221 
222 .seealso: PetscBLASInt, PetscInt, PetscMPIIntCast()
223 
224 M*/
225 typedef int PetscMPIInt;
226 
227 /*MC
228     PetscEnum - datatype used to pass enum types within PETSc functions.
229 
230     Level: intermediate
231 
232 .seealso: PetscOptionsGetEnum(), PetscOptionsEnum(), PetscBagRegisterEnum()
233 M*/
234 typedef enum { ENUM_DUMMY } PetscEnum;
235 PETSC_EXTERN MPI_Datatype MPIU_ENUM PetscAttrMPITypeTag(PetscEnum);
236 
237 #if defined(PETSC_HAVE_STDINT_H)
238 #include <stdint.h>
239 #endif
240 #if defined (PETSC_HAVE_INTTYPES_H)
241 #define __STDC_FORMAT_MACROS /* required for using PRId64 from c++ */
242 #include <inttypes.h>
243 # if !defined(PRId64)
244 # define PRId64 "ld"
245 # endif
246 #endif
247 
248 typedef short PetscShort;
249 typedef char PetscChar;
250 typedef float PetscFloat;
251 
252 /*MC
253     PetscInt - PETSc type that represents integer - used primarily to
254       represent size of arrays and indexing into arrays. Its size can be configured with the option
255       --with-64-bit-indices - to be either 32bit or 64bit [default 32 bit ints]
256 
257    Level: intermediate
258 
259 .seealso: PetscScalar, PetscBLASInt, PetscMPIInt
260 M*/
261 #if defined(PETSC_HAVE_STDINT_H) && defined(PETSC_HAVE_INTTYPES_H) && defined(PETSC_HAVE_MPI_INT64_T) /* MPI_INT64_T is not guaranteed to be a macro */
262 typedef int64_t PetscInt64;
263 # define MPIU_INT64 MPI_INT64_T
264 # define PetscInt64_FMT PRId64
265 #elif (PETSC_SIZEOF_LONG_LONG == 8)
266 typedef long long PetscInt64;
267 # define MPIU_INT64 MPI_LONG_LONG_INT
268 # define PetscInt64_FMT "lld"
269 #elif defined(PETSC_HAVE___INT64)
270 typedef __int64 PetscInt64;
271 # define MPIU_INT64 MPI_INT64_T
272 # define PetscInt64_FMT "ld"
273 #else
274 #error "cannot determine PetscInt64 type"
275 #endif
276 #if defined(PETSC_USE_64BIT_INDICES)
277 typedef PetscInt64 PetscInt;
278 #define MPIU_INT MPIU_INT64
279 #define PetscInt_FMT PetscInt64_FMT
280 #else
281 typedef int PetscInt;
282 #define MPIU_INT MPI_INT
283 #define PetscInt_FMT "d"
284 #endif
285 
286 /*MC
287     PetscBLASInt - datatype used to represent 'int' parameters to BLAS/LAPACK functions.
288 
289     Level: intermediate
290 
291     Notes: usually this is the same as PetscInt, but if PETSc was built with --with-64-bit-indices but
292            standard C/Fortran integers are 32 bit then this is NOT the same as PetscInt it remains 32 bit
293            (except on very rare BLAS/LAPACK implementations that support 64 bit integers see the note below).
294 
295     PetscErrorCode PetscBLASIntCast(a,&b) checks if the given PetscInt a will fit in a PetscBLASInt, if not it
296       generates a PETSC_ERR_ARG_OUTOFRANGE error
297 
298     Installation Notes: The 64bit versions of MATLAB ship with BLAS and LAPACK that use 64 bit integers for sizes etc,
299      if you run ./configure with the option
300      --with-blas-lapack-lib=[/Applications/MATLAB_R2010b.app/bin/maci64/libmwblas.dylib,/Applications/MATLAB_R2010b.app/bin/maci64/libmwlapack.dylib]
301      but you need to also use --known-64-bit-blas-indices.
302 
303         MKL also ships with 64 bit integer versions of the BLAS and LAPACK, if you select those you must also ./configure with --known-64-bit-blas-indices
304 
305      Developer Notes: Eventually ./configure should automatically determine the size of the integers used by BLAS/LAPACK.
306 
307      External packages such as hypre, ML, SuperLU etc do not provide any support for passing 64 bit integers to BLAS/LAPACK so cannot
308      be used with PETSc if you have set PetscBLASInt to long int.
309 
310 .seealso: PetscMPIInt, PetscInt, PetscBLASIntCast()
311 
312 M*/
313 #if defined(PETSC_HAVE_64BIT_BLAS_INDICES)
314 typedef PetscInt64 PetscBLASInt;
315 #else
316 typedef int PetscBLASInt;
317 #endif
318 
319 /*EC
320 
321     PetscPrecision - indicates what precision the object is using. This is currently not used.
322 
323     Level: advanced
324 
325 .seealso: PetscObjectSetPrecision()
326 E*/
327 typedef enum { PETSC_PRECISION_SINGLE=4,PETSC_PRECISION_DOUBLE=8 } PetscPrecision;
328 PETSC_EXTERN const char *PetscPrecisions[];
329 
330 /*
331     For the rare cases when one needs to send a size_t object with MPI
332 */
333 #if (PETSC_SIZEOF_SIZE_T) == (PETSC_SIZEOF_INT)
334 #define MPIU_SIZE_T MPI_UNSIGNED
335 #elif  (PETSC_SIZEOF_SIZE_T) == (PETSC_SIZEOF_LONG)
336 #define MPIU_SIZE_T MPI_UNSIGNED_LONG
337 #elif  (PETSC_SIZEOF_SIZE_T) == (PETSC_SIZEOF_LONG_LONG)
338 #define MPIU_SIZE_T MPI_UNSIGNED_LONG_LONG
339 #else
340 #error "Unknown size for size_t! Send us a bugreport at petsc-maint@mcs.anl.gov"
341 #endif
342 
343 /*
344       You can use PETSC_STDOUT as a replacement of stdout. You can also change
345     the value of PETSC_STDOUT to redirect all standard output elsewhere
346 */
347 PETSC_EXTERN FILE* PETSC_STDOUT;
348 
349 /*
350       You can use PETSC_STDERR as a replacement of stderr. You can also change
351     the value of PETSC_STDERR to redirect all standard error elsewhere
352 */
353 PETSC_EXTERN FILE* PETSC_STDERR;
354 
355 /*MC
356     PetscUnlikely - hints the compiler that the given condition is usually FALSE
357 
358     Synopsis:
359     #include <petscsys.h>
360     PetscBool  PetscUnlikely(PetscBool  cond)
361 
362     Not Collective
363 
364     Input Parameters:
365 .   cond - condition or expression
366 
367     Note: This returns the same truth value, it is only a hint to compilers that the resulting
368     branch is unlikely.
369 
370     Level: advanced
371 
372 .seealso: PetscLikely(), CHKERRQ
373 M*/
374 
375 /*MC
376     PetscLikely - hints the compiler that the given condition is usually TRUE
377 
378     Synopsis:
379     #include <petscsys.h>
380     PetscBool  PetscUnlikely(PetscBool  cond)
381 
382     Not Collective
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     Declare extern C stuff after including external header files
404 */
405 
406 
407 /*
408        Basic PETSc constants
409 */
410 
411 /*E
412     PetscBool  - Logical variable. Actually an int in C and a logical in Fortran.
413 
414    Level: beginner
415 
416    Developer Note: Why have PetscBool , why not use bool in C? The problem is that K and R C, C99 and C++ all have different mechanisms for
417       boolean values. It is not easy to have a simple macro that that will work properly in all circumstances with all three mechanisms.
418 
419 .seealso: PETSC_TRUE, PETSC_FALSE, PetscNot()
420 E*/
421 typedef enum { PETSC_FALSE,PETSC_TRUE } PetscBool;
422 PETSC_EXTERN const char *const PetscBools[];
423 PETSC_EXTERN MPI_Datatype MPIU_BOOL PetscAttrMPITypeTag(PetscBool);
424 
425 /*
426     Defines some elementary mathematics functions and constants.
427 */
428 #include <petscmath.h>
429 
430 /*E
431     PetscCopyMode  - Determines how an array passed to certain functions is copied or retained
432 
433    Level: beginner
434 
435 $   PETSC_COPY_VALUES - the array values are copied into new space, the user is free to reuse or delete the passed in array
436 $   PETSC_OWN_POINTER - the array values are NOT copied, the object takes ownership of the array and will free it later, the user cannot change or
437 $                       delete the array. The array MUST have been obtained with PetscMalloc(). Hence this mode cannot be used in Fortran.
438 $   PETSC_USE_POINTER - the array values are NOT copied, the object uses the array but does NOT take ownership of the array. The user cannot use
439                         the array but the user must delete the array after the object is destroyed.
440 
441 E*/
442 typedef enum { PETSC_COPY_VALUES, PETSC_OWN_POINTER, PETSC_USE_POINTER} PetscCopyMode;
443 PETSC_EXTERN const char *const PetscCopyModes[];
444 
445 /*MC
446     PETSC_FALSE - False value of PetscBool
447 
448     Level: beginner
449 
450     Note: Zero integer
451 
452 .seealso: PetscBool, PETSC_TRUE
453 M*/
454 
455 /*MC
456     PETSC_TRUE - True value of PetscBool
457 
458     Level: beginner
459 
460     Note: Nonzero integer
461 
462 .seealso: PetscBool, PETSC_FALSE
463 M*/
464 
465 /*MC
466     PETSC_NULL - standard way of passing in a null or array or pointer. This is deprecated in C/C++ simply use NULL
467 
468    Level: beginner
469 
470    Notes: accepted by many PETSc functions to not set a parameter and instead use
471           some default
472 
473           This macro does not exist in Fortran; you must use PETSC_NULL_INTEGER,
474           PETSC_NULL_DOUBLE_PRECISION, PETSC_NULL_FUNCTION, PETSC_NULL_VEC etc
475 
476 .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_IGNORE, PETSC_DETERMINE
477 
478 M*/
479 #define PETSC_NULL           NULL
480 
481 /*MC
482     PETSC_IGNORE - same as NULL, means PETSc will ignore this argument
483 
484    Level: beginner
485 
486    Note: accepted by many PETSc functions to not set a parameter and instead use
487           some default
488 
489    Fortran Notes: This macro does not exist in Fortran; you must use PETSC_NULL_INTEGER,
490           PETSC_NULL_DOUBLE_PRECISION etc
491 
492 .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_NULL, PETSC_DETERMINE
493 
494 M*/
495 #define PETSC_IGNORE         NULL
496 
497 /*MC
498     PETSC_DECIDE - standard way of passing in integer or floating point parameter
499        where you wish PETSc to use the default.
500 
501    Level: beginner
502 
503 .seealso: PETSC_NULL, PETSC_DEFAULT, PETSC_IGNORE, PETSC_DETERMINE
504 
505 M*/
506 #define PETSC_DECIDE  -1
507 
508 /*MC
509     PETSC_DETERMINE - standard way of passing in integer or floating point parameter
510        where you wish PETSc to compute the required value.
511 
512    Level: beginner
513 
514    Developer Note: I would like to use const PetscInt PETSC_DETERMINE = PETSC_DECIDE; but for
515      some reason this is not allowed by the standard even though PETSC_DECIDE is a constant value.
516 
517 .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_IGNORE, VecSetSizes()
518 
519 M*/
520 #define PETSC_DETERMINE PETSC_DECIDE
521 
522 /*MC
523     PETSC_DEFAULT - standard way of passing in integer or floating point parameter
524        where you wish PETSc to use the default.
525 
526    Level: beginner
527 
528    Fortran Notes: You need to use PETSC_DEFAULT_INTEGER or PETSC_DEFAULT_REAL.
529 
530 .seealso: PETSC_DECIDE, PETSC_IGNORE, PETSC_DETERMINE
531 
532 M*/
533 #define PETSC_DEFAULT  -2
534 
535 /*MC
536     PETSC_COMM_WORLD - the equivalent of the MPI_COMM_WORLD communicator which represents
537            all the processs that PETSc knows about.
538 
539    Level: beginner
540 
541    Notes: By default PETSC_COMM_WORLD and MPI_COMM_WORLD are identical unless you wish to
542           run PETSc on ONLY a subset of MPI_COMM_WORLD. In that case create your new (smaller)
543           communicator, call it, say comm, and set PETSC_COMM_WORLD = comm BEFORE calling
544           PetscInitialize(), but after MPI_Init() has been called.
545 
546           The value of PETSC_COMM_WORLD should never be USED/accessed before PetscInitialize()
547           is called because it may not have a valid value yet.
548 
549 .seealso: PETSC_COMM_SELF
550 
551 M*/
552 PETSC_EXTERN MPI_Comm PETSC_COMM_WORLD;
553 
554 /*MC
555     PETSC_COMM_SELF - This is always MPI_COMM_SELF
556 
557    Level: beginner
558 
559    Notes: Do not USE/access or set this variable before PetscInitialize() has been called.
560 
561 .seealso: PETSC_COMM_WORLD
562 
563 M*/
564 #define PETSC_COMM_SELF MPI_COMM_SELF
565 
566 PETSC_EXTERN PetscBool PetscBeganMPI;
567 PETSC_EXTERN PetscBool PetscInitializeCalled;
568 PETSC_EXTERN PetscBool PetscFinalizeCalled;
569 PETSC_EXTERN PetscBool PetscCUSPSynchronize;
570 PETSC_EXTERN PetscBool PetscViennaCLSynchronize;
571 PETSC_EXTERN PetscBool PetscCUDASynchronize;
572 
573 PETSC_EXTERN PetscErrorCode PetscSetHelpVersionFunctions(PetscErrorCode (*)(MPI_Comm),PetscErrorCode (*)(MPI_Comm));
574 PETSC_EXTERN PetscErrorCode PetscCommDuplicate(MPI_Comm,MPI_Comm*,int*);
575 PETSC_EXTERN PetscErrorCode PetscCommDestroy(MPI_Comm*);
576 
577 /*MC
578    PetscMalloc - Allocates memory, One should use PetscNew(), PetscMalloc1() or PetscCalloc1() usually instead of this
579 
580    Synopsis:
581     #include <petscsys.h>
582    PetscErrorCode PetscMalloc(size_t m,void **result)
583 
584    Not Collective
585 
586    Input Parameter:
587 .  m - number of bytes to allocate
588 
589    Output Parameter:
590 .  result - memory allocated
591 
592    Level: beginner
593 
594    Notes:
595    Memory is always allocated at least double aligned
596 
597    It is safe to allocate size 0 and pass the resulting pointer (which may or may not be NULL) to PetscFree().
598 
599 .seealso: PetscFree(), PetscNew()
600 
601   Concepts: memory allocation
602 
603 M*/
604 #define PetscMalloc(a,b)  ((*PetscTrMalloc)((a),__LINE__,PETSC_FUNCTION_NAME,__FILE__,(void**)(b)))
605 
606 /*MC
607    PetscRealloc - Rellocates memory
608 
609    Synopsis:
610     #include <petscsys.h>
611    PetscErrorCode PetscRealloc(size_t m,void **result)
612 
613    Not Collective
614 
615    Input Parameters:
616 +  m - number of bytes to allocate
617 -  result - initial memory allocated
618 
619    Output Parameter:
620 .  result - new memory allocated
621 
622    Level: developer
623 
624    Notes:
625    Memory is always allocated at least double aligned
626 
627 .seealso: PetscMalloc(), PetscFree(), PetscNew()
628 
629   Concepts: memory allocation
630 
631 M*/
632 #define PetscRealloc(a,b)  ((*PetscTrRealloc)((a),__LINE__,PETSC_FUNCTION_NAME,__FILE__,(void**)(b)))
633 
634 /*MC
635    PetscAddrAlign - Rounds up an address to PETSC_MEMALIGN alignment
636 
637    Synopsis:
638     #include <petscsys.h>
639    void *PetscAddrAlign(void *addr)
640 
641    Not Collective
642 
643    Input Parameters:
644 .  addr - address to align (any pointer type)
645 
646    Level: developer
647 
648 .seealso: PetscMallocAlign()
649 
650   Concepts: memory allocation
651 M*/
652 #define PetscAddrAlign(a) (void*)((((PETSC_UINTPTR_T)(a))+(PETSC_MEMALIGN-1)) & ~(PETSC_MEMALIGN-1))
653 
654 /*MC
655    PetscMalloc1 - Allocates an array of memory aligned to PETSC_MEMALIGN
656 
657    Synopsis:
658     #include <petscsys.h>
659    PetscErrorCode PetscMalloc1(size_t m1,type **r1)
660 
661    Not Collective
662 
663    Input Parameter:
664 .  m1 - number of elements to allocate in 1st chunk  (may be zero)
665 
666    Output Parameter:
667 .  r1 - memory allocated in first chunk
668 
669    Level: developer
670 
671 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscCalloc1(), PetscMalloc2()
672 
673   Concepts: memory allocation
674 
675 M*/
676 #define PetscMalloc1(m1,r1) PetscMalloc((m1)*sizeof(**(r1)),r1)
677 
678 /*MC
679    PetscCalloc1 - Allocates a cleared (zeroed) array of memory aligned to PETSC_MEMALIGN
680 
681    Synopsis:
682     #include <petscsys.h>
683    PetscErrorCode PetscCalloc1(size_t m1,type **r1)
684 
685    Not Collective
686 
687    Input Parameter:
688 .  m1 - number of elements to allocate in 1st chunk  (may be zero)
689 
690    Output Parameter:
691 .  r1 - memory allocated in first chunk
692 
693    Level: developer
694 
695 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc1(), PetscCalloc2()
696 
697   Concepts: memory allocation
698 
699 M*/
700 #define PetscCalloc1(m1,r1) (PetscMalloc1((m1),r1) || PetscMemzero(*(r1),(m1)*sizeof(**(r1))))
701 
702 /*MC
703    PetscMalloc2 - Allocates 2 arrays of memory both aligned to PETSC_MEMALIGN
704 
705    Synopsis:
706     #include <petscsys.h>
707    PetscErrorCode PetscMalloc2(size_t m1,type **r1,size_t m2,type **r2)
708 
709    Not Collective
710 
711    Input Parameter:
712 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
713 -  m2 - number of elements to allocate in 2nd chunk  (may be zero)
714 
715    Output Parameter:
716 +  r1 - memory allocated in first chunk
717 -  r2 - memory allocated in second chunk
718 
719    Level: developer
720 
721 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc1(), PetscCalloc2()
722 
723   Concepts: memory allocation
724 
725 M*/
726 #if !defined(PETSC_USE_MALLOC_COALESCED)
727 #define PetscMalloc2(m1,r1,m2,r2) (PetscMalloc1((m1),(r1)) || PetscMalloc1((m2),(r2)))
728 #else
729 #define PetscMalloc2(m1,r1,m2,r2) ((((m1)+(m2)) ? (*(r2) = 0,PetscMalloc((m1)*sizeof(**(r1))+(m2)*sizeof(**(r2))+(PETSC_MEMALIGN-1),r1)) : 0) \
730                                    || (*(void**)(r2) = PetscAddrAlign(*(r1)+(m1)),0) \
731                                    || (!(m1) ? (*(r1) = 0,0) : 0) || (!(m2) ? (*(r2) = 0,0) : 0))
732 #endif
733 
734 /*MC
735    PetscCalloc2 - Allocates 2 cleared (zeroed) arrays of memory both aligned to PETSC_MEMALIGN
736 
737    Synopsis:
738     #include <petscsys.h>
739    PetscErrorCode PetscCalloc2(size_t m1,type **r1,size_t m2,type **r2)
740 
741    Not Collective
742 
743    Input Parameter:
744 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
745 -  m2 - number of elements to allocate in 2nd chunk  (may be zero)
746 
747    Output Parameter:
748 +  r1 - memory allocated in first chunk
749 -  r2 - memory allocated in second chunk
750 
751    Level: developer
752 
753 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscCalloc1(), PetscMalloc2()
754 
755   Concepts: memory allocation
756 M*/
757 #define PetscCalloc2(m1,r1,m2,r2) (PetscMalloc2((m1),(r1),(m2),(r2)) || PetscMemzero(*(r1),(m1)*sizeof(**(r1))) || PetscMemzero(*(r2),(m2)*sizeof(**(r2))))
758 
759 /*MC
760    PetscMalloc3 - Allocates 3 arrays of memory, all aligned to PETSC_MEMALIGN
761 
762    Synopsis:
763     #include <petscsys.h>
764    PetscErrorCode PetscMalloc3(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3)
765 
766    Not Collective
767 
768    Input Parameter:
769 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
770 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
771 -  m3 - number of elements to allocate in 3rd chunk  (may be zero)
772 
773    Output Parameter:
774 +  r1 - memory allocated in first chunk
775 .  r2 - memory allocated in second chunk
776 -  r3 - memory allocated in third chunk
777 
778    Level: developer
779 
780 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscCalloc3(), PetscFree3()
781 
782   Concepts: memory allocation
783 
784 M*/
785 #if !defined(PETSC_USE_MALLOC_COALESCED)
786 #define PetscMalloc3(m1,r1,m2,r2,m3,r3) (PetscMalloc1((m1),(r1)) || PetscMalloc1((m2),(r2)) || PetscMalloc1((m3),(r3)))
787 #else
788 #define PetscMalloc3(m1,r1,m2,r2,m3,r3) ((((m1)+(m2)+(m3)) ? (*(r2) = 0,*(r3) = 0,PetscMalloc((m1)*sizeof(**(r1))+(m2)*sizeof(**(r2))+(m3)*sizeof(**(r3))+2*(PETSC_MEMALIGN-1),r1)) : 0) \
789                                          || (*(void**)(r2) = PetscAddrAlign(*(r1)+(m1)),*(void**)(r3) = PetscAddrAlign(*(r2)+(m2)),0) \
790                                          || (!(m1) ? (*(r1) = 0,0) : 0) || (!(m2) ? (*(r2) = 0,0) : 0) || (!(m3) ? (*(r3) = 0,0) : 0))
791 #endif
792 
793 /*MC
794    PetscCalloc3 - Allocates 3 cleared (zeroed) arrays of memory, all aligned to PETSC_MEMALIGN
795 
796    Synopsis:
797     #include <petscsys.h>
798    PetscErrorCode PetscCalloc3(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3)
799 
800    Not Collective
801 
802    Input Parameter:
803 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
804 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
805 -  m3 - number of elements to allocate in 3rd chunk  (may be zero)
806 
807    Output Parameter:
808 +  r1 - memory allocated in first chunk
809 .  r2 - memory allocated in second chunk
810 -  r3 - memory allocated in third chunk
811 
812    Level: developer
813 
814 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscCalloc2(), PetscMalloc3(), PetscFree3()
815 
816   Concepts: memory allocation
817 M*/
818 #define PetscCalloc3(m1,r1,m2,r2,m3,r3)                                 \
819   (PetscMalloc3((m1),(r1),(m2),(r2),(m3),(r3))                          \
820    || PetscMemzero(*(r1),(m1)*sizeof(**(r1))) || PetscMemzero(*(r2),(m2)*sizeof(**(r2))) || PetscMemzero(*(r3),(m3)*sizeof(**(r3))))
821 
822 /*MC
823    PetscMalloc4 - Allocates 4 arrays of memory, all aligned to PETSC_MEMALIGN
824 
825    Synopsis:
826     #include <petscsys.h>
827    PetscErrorCode PetscMalloc4(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4)
828 
829    Not Collective
830 
831    Input Parameter:
832 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
833 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
834 .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
835 -  m4 - number of elements to allocate in 4th chunk  (may be zero)
836 
837    Output Parameter:
838 +  r1 - memory allocated in first chunk
839 .  r2 - memory allocated in second chunk
840 .  r3 - memory allocated in third chunk
841 -  r4 - memory allocated in fourth chunk
842 
843    Level: developer
844 
845 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscCalloc4(), PetscFree4()
846 
847   Concepts: memory allocation
848 
849 M*/
850 #if !defined(PETSC_USE_MALLOC_COALESCED)
851 #define PetscMalloc4(m1,r1,m2,r2,m3,r3,m4,r4) (PetscMalloc1((m1),(r1)) || PetscMalloc1((m2),(r2)) || PetscMalloc1((m3),(r3)) || PetscMalloc1((m4),(r4)))
852 #else
853 #define PetscMalloc4(m1,r1,m2,r2,m3,r3,m4,r4)                           \
854   ((((m1)+(m2)+(m3)+(m4)) ? (*(r2) = 0, *(r3) = 0, *(r4) = 0,PetscMalloc((m1)*sizeof(**(r1))+(m2)*sizeof(**(r2))+(m3)*sizeof(**(r3))+(m4)*sizeof(**(r4))+3*(PETSC_MEMALIGN-1),r1)) : 0) \
855    || (*(void**)(r2) = PetscAddrAlign(*(r1)+(m1)),*(void**)(r3) = PetscAddrAlign(*(r2)+(m2)),*(void**)(r4) = PetscAddrAlign(*(r3)+(m3)),0) \
856    || (!(m1) ? (*(r1) = 0,0) : 0) || (!(m2) ? (*(r2) = 0,0) : 0) || (!(m3) ? (*(r3) = 0,0) : 0) || (!(m4) ? (*(r4) = 0,0) : 0))
857 #endif
858 
859 /*MC
860    PetscCalloc4 - Allocates 4 cleared (zeroed) arrays of memory, all aligned to PETSC_MEMALIGN
861 
862    Synopsis:
863     #include <petscsys.h>
864    PetscErrorCode PetscCalloc4(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4)
865 
866    Not Collective
867 
868    Input Parameter:
869 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
870 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
871 .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
872 -  m4 - number of elements to allocate in 4th chunk  (may be zero)
873 
874    Output Parameter:
875 +  r1 - memory allocated in first chunk
876 .  r2 - memory allocated in second chunk
877 .  r3 - memory allocated in third chunk
878 -  r4 - memory allocated in fourth chunk
879 
880    Level: developer
881 
882 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscCalloc4(), PetscFree4()
883 
884   Concepts: memory allocation
885 
886 M*/
887 #define PetscCalloc4(m1,r1,m2,r2,m3,r3,m4,r4)                           \
888   (PetscMalloc4(m1,r1,m2,r2,m3,r3,m4,r4)                                \
889    || PetscMemzero(*(r1),(m1)*sizeof(**(r1))) || PetscMemzero(*(r2),(m2)*sizeof(**(r2))) || PetscMemzero(*(r3),(m3)*sizeof(**(r3))) \
890    || PetscMemzero(*(r4),(m4)*sizeof(**(r4))))
891 
892 /*MC
893    PetscMalloc5 - Allocates 5 arrays of memory, all aligned to PETSC_MEMALIGN
894 
895    Synopsis:
896     #include <petscsys.h>
897    PetscErrorCode PetscMalloc5(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4,size_t m5,type **r5)
898 
899    Not Collective
900 
901    Input Parameter:
902 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
903 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
904 .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
905 .  m4 - number of elements to allocate in 4th chunk  (may be zero)
906 -  m5 - number of elements to allocate in 5th chunk  (may be zero)
907 
908    Output Parameter:
909 +  r1 - memory allocated in first chunk
910 .  r2 - memory allocated in second chunk
911 .  r3 - memory allocated in third chunk
912 .  r4 - memory allocated in fourth chunk
913 -  r5 - memory allocated in fifth chunk
914 
915    Level: developer
916 
917 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscCalloc5(), PetscFree5()
918 
919   Concepts: memory allocation
920 
921 M*/
922 #if !defined(PETSC_USE_MALLOC_COALESCED)
923 #define PetscMalloc5(m1,r1,m2,r2,m3,r3,m4,r4,m5,r5) (PetscMalloc1((m1),(r1)) || PetscMalloc1((m2),(r2)) || PetscMalloc1((m3),(r3)) || PetscMalloc1((m4),(r4)) || PetscMalloc1((m5),(r5)))
924 #else
925 #define PetscMalloc5(m1,r1,m2,r2,m3,r3,m4,r4,m5,r5)      \
926   ((((m1)+(m2)+(m3)+(m4)+(m5)) ? (*(r2) = 0, *(r3) = 0, *(r4) = 0,*(r5) = 0,PetscMalloc((m1)*sizeof(**(r1))+(m2)*sizeof(**(r2))+(m3)*sizeof(**(r3))+(m4)*sizeof(**(r4))+(m5)*sizeof(**(r5))+4*(PETSC_MEMALIGN-1),r1)) : 0) \
927    || (*(void**)(r2) = PetscAddrAlign(*(r1)+(m1)),*(void**)(r3) = PetscAddrAlign(*(r2)+(m2)),*(void**)(r4) = PetscAddrAlign(*(r3)+(m3)),*(void**)(r5) = PetscAddrAlign(*(r4)+(m4)),0) \
928    || (!(m1) ? (*(r1) = 0,0) : 0) || (!(m2) ? (*(r2) = 0,0) : 0) || (!(m3) ? (*(r3) = 0,0) : 0) || (!(m4) ? (*(r4) = 0,0) : 0) || (!(m5) ? (*(r5) = 0,0) : 0))
929 #endif
930 
931 /*MC
932    PetscCalloc5 - Allocates 5 cleared (zeroed) arrays of memory, all aligned to PETSC_MEMALIGN
933 
934    Synopsis:
935     #include <petscsys.h>
936    PetscErrorCode PetscCalloc5(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4,size_t m5,type **r5)
937 
938    Not Collective
939 
940    Input Parameter:
941 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
942 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
943 .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
944 .  m4 - number of elements to allocate in 4th chunk  (may be zero)
945 -  m5 - number of elements to allocate in 5th chunk  (may be zero)
946 
947    Output Parameter:
948 +  r1 - memory allocated in first chunk
949 .  r2 - memory allocated in second chunk
950 .  r3 - memory allocated in third chunk
951 .  r4 - memory allocated in fourth chunk
952 -  r5 - memory allocated in fifth chunk
953 
954    Level: developer
955 
956 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc5(), PetscFree5()
957 
958   Concepts: memory allocation
959 
960 M*/
961 #define PetscCalloc5(m1,r1,m2,r2,m3,r3,m4,r4,m5,r5)                     \
962   (PetscMalloc5(m1,r1,m2,r2,m3,r3,m4,r4,m5,r5)                          \
963    || PetscMemzero(*(r1),(m1)*sizeof(**(r1))) || PetscMemzero(*(r2),(m2)*sizeof(**(r2))) || PetscMemzero(*(r3),(m3)*sizeof(**(r3))) \
964    || PetscMemzero(*(r4),(m4)*sizeof(**(r4))) || PetscMemzero(*(r5),(m5)*sizeof(**(r5))))
965 
966 /*MC
967    PetscMalloc6 - Allocates 6 arrays of memory, all aligned to PETSC_MEMALIGN
968 
969    Synopsis:
970     #include <petscsys.h>
971    PetscErrorCode PetscMalloc6(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4,size_t m5,type **r5,size_t m6,type **r6)
972 
973    Not Collective
974 
975    Input Parameter:
976 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
977 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
978 .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
979 .  m4 - number of elements to allocate in 4th chunk  (may be zero)
980 .  m5 - number of elements to allocate in 5th chunk  (may be zero)
981 -  m6 - number of elements to allocate in 6th chunk  (may be zero)
982 
983    Output Parameter:
984 +  r1 - memory allocated in first chunk
985 .  r2 - memory allocated in second chunk
986 .  r3 - memory allocated in third chunk
987 .  r4 - memory allocated in fourth chunk
988 .  r5 - memory allocated in fifth chunk
989 -  r6 - memory allocated in sixth chunk
990 
991    Level: developer
992 
993 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscCalloc6(), PetscFree3(), PetscFree4(), PetscFree5(), PetscFree6()
994 
995   Concepts: memory allocation
996 
997 M*/
998 #if !defined(PETSC_USE_MALLOC_COALESCED)
999 #define PetscMalloc6(m1,r1,m2,r2,m3,r3,m4,r4,m5,r5,m6,r6) (PetscMalloc1((m1),(r1)) || PetscMalloc1((m2),(r2)) || PetscMalloc1((m3),(r3)) || PetscMalloc1((m4),(r4)) || PetscMalloc1((m5),(r5)) || PetscMalloc1((m6),(r6)))
1000 #else
1001 #define PetscMalloc6(m1,r1,m2,r2,m3,r3,m4,r4,m5,r5,m6,r6) \
1002   ((((m1)+(m2)+(m3)+(m4)+(m5)+(m6)) ? (*(r2) = 0, *(r3) = 0, *(r4) = 0,*(r5) = 0,*(r6) = 0,PetscMalloc((m1)*sizeof(**(r1))+(m2)*sizeof(**(r2))+(m3)*sizeof(**(r3))+(m4)*sizeof(**(r4))+(m5)*sizeof(**(r5))+(m6)*sizeof(**(r6))+5*(PETSC_MEMALIGN-1),r1)) : 0) \
1003    || (*(void**)(r2) = PetscAddrAlign(*(r1)+(m1)),*(void**)(r3) = PetscAddrAlign(*(r2)+(m2)),*(void**)(r4) = PetscAddrAlign(*(r3)+(m3)),*(void**)(r5) = PetscAddrAlign(*(r4)+(m4)),*(void**)(r6) = PetscAddrAlign(*(r5)+(m5)),0) \
1004    || (!(m1) ? (*(r1) = 0,0) : 0) || (!(m2) ? (*(r2) = 0,0) : 0) || (!(m3) ? (*(r3) = 0,0) : 0) || (!(m4) ? (*(r4) = 0,0) : 0) || (!(m5) ? (*(r5) = 0,0) : 0) || (!(m6) ? (*(r6) = 0,0) : 0))
1005 #endif
1006 
1007 /*MC
1008    PetscCalloc6 - Allocates 6 cleared (zeroed) arrays of memory, all aligned to PETSC_MEMALIGN
1009 
1010    Synopsis:
1011     #include <petscsys.h>
1012    PetscErrorCode PetscCalloc6(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4,size_t m5,type **r5,size_t m6,type **r6)
1013 
1014    Not Collective
1015 
1016    Input Parameter:
1017 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
1018 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
1019 .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
1020 .  m4 - number of elements to allocate in 4th chunk  (may be zero)
1021 .  m5 - number of elements to allocate in 5th chunk  (may be zero)
1022 -  m6 - number of elements to allocate in 6th chunk  (may be zero)
1023 
1024    Output Parameter:
1025 +  r1 - memory allocated in first chunk
1026 .  r2 - memory allocated in second chunk
1027 .  r3 - memory allocated in third chunk
1028 .  r4 - memory allocated in fourth chunk
1029 .  r5 - memory allocated in fifth chunk
1030 -  r6 - memory allocated in sixth chunk
1031 
1032    Level: developer
1033 
1034 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscMalloc6(), PetscFree6()
1035 
1036   Concepts: memory allocation
1037 M*/
1038 #define PetscCalloc6(m1,r1,m2,r2,m3,r3,m4,r4,m5,r5,m6,r6)               \
1039   (PetscMalloc6(m1,r1,m2,r2,m3,r3,m4,r4,m5,r5,m6,r6)                    \
1040    || PetscMemzero(*(r1),(m1)*sizeof(**(r1))) || PetscMemzero(*(r2),(m2)*sizeof(**(r2))) || PetscMemzero(*(r3),(m3)*sizeof(**(r3))) \
1041    || PetscMemzero(*(r4),(m4)*sizeof(**(r4))) || PetscMemzero(*(r5),(m5)*sizeof(**(r5))) || PetscMemzero(*(r6),(m6)*sizeof(**(r6))))
1042 
1043 /*MC
1044    PetscMalloc7 - Allocates 7 arrays of memory, all aligned to PETSC_MEMALIGN
1045 
1046    Synopsis:
1047     #include <petscsys.h>
1048    PetscErrorCode PetscMalloc7(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4,size_t m5,type **r5,size_t m6,type **r6,size_t m7,type **r7)
1049 
1050    Not Collective
1051 
1052    Input Parameter:
1053 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
1054 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
1055 .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
1056 .  m4 - number of elements to allocate in 4th chunk  (may be zero)
1057 .  m5 - number of elements to allocate in 5th chunk  (may be zero)
1058 .  m6 - number of elements to allocate in 6th chunk  (may be zero)
1059 -  m7 - number of elements to allocate in 7th chunk  (may be zero)
1060 
1061    Output Parameter:
1062 +  r1 - memory allocated in first chunk
1063 .  r2 - memory allocated in second chunk
1064 .  r3 - memory allocated in third chunk
1065 .  r4 - memory allocated in fourth chunk
1066 .  r5 - memory allocated in fifth chunk
1067 .  r6 - memory allocated in sixth chunk
1068 -  r7 - memory allocated in seventh chunk
1069 
1070    Level: developer
1071 
1072 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscCalloc7(), PetscFree7()
1073 
1074   Concepts: memory allocation
1075 
1076 M*/
1077 #if !defined(PETSC_USE_MALLOC_COALESCED)
1078 #define PetscMalloc7(m1,r1,m2,r2,m3,r3,m4,r4,m5,r5,m6,r6,m7,r7) (PetscMalloc1((m1),(r1)) || PetscMalloc1((m2),(r2)) || PetscMalloc1((m3),(r3)) || PetscMalloc1((m4),(r4)) || PetscMalloc1((m5),(r5)) || PetscMalloc1((m6),(r6)) || PetscMalloc1((m7),(r7)))
1079 #else
1080 #define PetscMalloc7(m1,r1,m2,r2,m3,r3,m4,r4,m5,r5,m6,r6,m7,r7) \
1081   ((((m1)+(m2)+(m3)+(m4)+(m5)+(m6)+(m7)) ? (*(r2) = 0, *(r3) = 0, *(r4) = 0,*(r5) = 0,*(r6) = 0,*(r7) = 0,PetscMalloc((m1)*sizeof(**(r1))+(m2)*sizeof(**(r2))+(m3)*sizeof(**(r3))+(m4)*sizeof(**(r4))+(m5)*sizeof(**(r5))+(m6)*sizeof(**(r6))+(m7)*sizeof(**(r7))+6*(PETSC_MEMALIGN-1),r1)) : 0) \
1082    || (*(void**)(r2) = PetscAddrAlign(*(r1)+(m1)),*(void**)(r3) = PetscAddrAlign(*(r2)+(m2)),*(void**)(r4) = PetscAddrAlign(*(r3)+(m3)),*(void**)(r5) = PetscAddrAlign(*(r4)+(m4)),*(void**)(r6) = PetscAddrAlign(*(r5)+(m5)),*(void**)(r7) = PetscAddrAlign(*(r6)+(m6)),0) \
1083    || (!(m1) ? (*(r1) = 0,0) : 0) || (!(m2) ? (*(r2) = 0,0) : 0) || (!(m3) ? (*(r3) = 0,0) : 0) || (!(m4) ? (*(r4) = 0,0) : 0) || (!(m5) ? (*(r5) = 0,0) : 0) || (!(m6) ? (*(r6) = 0,0) : 0) || (!(m7) ? (*(r7) = 0,0) : 0))
1084 #endif
1085 
1086 /*MC
1087    PetscCalloc7 - Allocates 7 cleared (zeroed) arrays of memory, all aligned to PETSC_MEMALIGN
1088 
1089    Synopsis:
1090     #include <petscsys.h>
1091    PetscErrorCode PetscCalloc7(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4,size_t m5,type **r5,size_t m6,type **r6,size_t m7,type **r7)
1092 
1093    Not Collective
1094 
1095    Input Parameter:
1096 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
1097 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
1098 .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
1099 .  m4 - number of elements to allocate in 4th chunk  (may be zero)
1100 .  m5 - number of elements to allocate in 5th chunk  (may be zero)
1101 .  m6 - number of elements to allocate in 6th chunk  (may be zero)
1102 -  m7 - number of elements to allocate in 7th chunk  (may be zero)
1103 
1104    Output Parameter:
1105 +  r1 - memory allocated in first chunk
1106 .  r2 - memory allocated in second chunk
1107 .  r3 - memory allocated in third chunk
1108 .  r4 - memory allocated in fourth chunk
1109 .  r5 - memory allocated in fifth chunk
1110 .  r6 - memory allocated in sixth chunk
1111 -  r7 - memory allocated in seventh chunk
1112 
1113    Level: developer
1114 
1115 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscMalloc7(), PetscFree7()
1116 
1117   Concepts: memory allocation
1118 M*/
1119 #define PetscCalloc7(m1,r1,m2,r2,m3,r3,m4,r4,m5,r5,m6,r6,m7,r7)         \
1120   (PetscMalloc7(m1,r1,m2,r2,m3,r3,m4,r4,m5,r5,m6,r6,m7,r7)              \
1121    || PetscMemzero(*(r1),(m1)*sizeof(**(r1))) || PetscMemzero(*(r2),(m2)*sizeof(**(r2))) || PetscMemzero(*(r3),(m3)*sizeof(**(r3))) \
1122    || PetscMemzero(*(r4),(m4)*sizeof(**(r4))) || PetscMemzero(*(r5),(m5)*sizeof(**(r5))) || PetscMemzero(*(r6),(m6)*sizeof(**(r6))) \
1123    || PetscMemzero(*(r7),(m7)*sizeof(**(r7))))
1124 
1125 /*MC
1126    PetscNew - Allocates memory of a particular type, zeros the memory! Aligned to PETSC_MEMALIGN
1127 
1128    Synopsis:
1129     #include <petscsys.h>
1130    PetscErrorCode PetscNew(type **result)
1131 
1132    Not Collective
1133 
1134    Output Parameter:
1135 .  result - memory allocated, sized to match pointer type
1136 
1137    Level: beginner
1138 
1139 .seealso: PetscFree(), PetscMalloc(), PetscNewLog()
1140 
1141   Concepts: memory allocation
1142 
1143 M*/
1144 #define PetscNew(b)      PetscCalloc1(1,(b))
1145 
1146 /*MC
1147    PetscNewLog - Allocates memory of a type matching pointer, zeros the memory! Aligned to PETSC_MEMALIGN. Associates the memory allocated
1148          with the given object using PetscLogObjectMemory().
1149 
1150    Synopsis:
1151     #include <petscsys.h>
1152    PetscErrorCode PetscNewLog(PetscObject obj,type **result)
1153 
1154    Not Collective
1155 
1156    Input Parameter:
1157 .  obj - object memory is logged to
1158 
1159    Output Parameter:
1160 .  result - memory allocated, sized to match pointer type
1161 
1162    Level: developer
1163 
1164 .seealso: PetscFree(), PetscMalloc(), PetscNew(), PetscLogObjectMemory()
1165 
1166   Concepts: memory allocation
1167 
1168 M*/
1169 #define PetscNewLog(o,b) (PetscNew((b)) || PetscLogObjectMemory((PetscObject)o,sizeof(**(b))))
1170 
1171 /*MC
1172    PetscFree - Frees memory
1173 
1174    Synopsis:
1175     #include <petscsys.h>
1176    PetscErrorCode PetscFree(void *memory)
1177 
1178    Not Collective
1179 
1180    Input Parameter:
1181 .   memory - memory to free (the pointer is ALWAYS set to 0 upon sucess)
1182 
1183    Level: beginner
1184 
1185    Notes:
1186    Memory must have been obtained with PetscNew() or PetscMalloc().
1187    It is safe to call PetscFree() on a NULL pointer.
1188 
1189 .seealso: PetscNew(), PetscMalloc(), PetscFreeVoid()
1190 
1191   Concepts: memory allocation
1192 
1193 M*/
1194 #define PetscFree(a)   ((*PetscTrFree)((void*)(a),__LINE__,PETSC_FUNCTION_NAME,__FILE__) || ((a) = 0,0))
1195 
1196 /*MC
1197    PetscFreeVoid - Frees memory
1198 
1199    Synopsis:
1200     #include <petscsys.h>
1201    void PetscFreeVoid(void *memory)
1202 
1203    Not Collective
1204 
1205    Input Parameter:
1206 .   memory - memory to free
1207 
1208    Level: beginner
1209 
1210    Notes: This is different from PetscFree() in that no error code is returned
1211 
1212 .seealso: PetscFree(), PetscNew(), PetscMalloc()
1213 
1214   Concepts: memory allocation
1215 
1216 M*/
1217 #define PetscFreeVoid(a) ((*PetscTrFree)((a),__LINE__,PETSC_FUNCTION_NAME,__FILE__),(a) = 0)
1218 
1219 
1220 /*MC
1221    PetscFree2 - Frees 2 chunks of memory obtained with PetscMalloc2()
1222 
1223    Synopsis:
1224     #include <petscsys.h>
1225    PetscErrorCode PetscFree2(void *memory1,void *memory2)
1226 
1227    Not Collective
1228 
1229    Input Parameter:
1230 +   memory1 - memory to free
1231 -   memory2 - 2nd memory to free
1232 
1233    Level: developer
1234 
1235    Notes: Memory must have been obtained with PetscMalloc2()
1236 
1237 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree()
1238 
1239   Concepts: memory allocation
1240 
1241 M*/
1242 #if !defined(PETSC_USE_MALLOC_COALESCED)
1243 #define PetscFree2(m1,m2)   (PetscFree(m2) || PetscFree(m1))
1244 #else
1245 #define PetscFree2(m1,m2)   ((m1) ? ((m2)=0,PetscFree(m1)) : ((m1)=0,PetscFree(m2)))
1246 #endif
1247 
1248 /*MC
1249    PetscFree3 - Frees 3 chunks of memory obtained with PetscMalloc3()
1250 
1251    Synopsis:
1252     #include <petscsys.h>
1253    PetscErrorCode PetscFree3(void *memory1,void *memory2,void *memory3)
1254 
1255    Not Collective
1256 
1257    Input Parameter:
1258 +   memory1 - memory to free
1259 .   memory2 - 2nd memory to free
1260 -   memory3 - 3rd memory to free
1261 
1262    Level: developer
1263 
1264    Notes: Memory must have been obtained with PetscMalloc3()
1265 
1266 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3()
1267 
1268   Concepts: memory allocation
1269 
1270 M*/
1271 #if !defined(PETSC_USE_MALLOC_COALESCED)
1272 #define PetscFree3(m1,m2,m3)   (PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
1273 #else
1274 #define PetscFree3(m1,m2,m3)   ((m1) ? ((m3)=0,(m2)=0,PetscFree(m1)) : ((m2) ? ((m3)=0,(m1)=0,PetscFree(m2)) : ((m2)=0,(m1)=0,PetscFree(m3))))
1275 #endif
1276 
1277 /*MC
1278    PetscFree4 - Frees 4 chunks of memory obtained with PetscMalloc4()
1279 
1280    Synopsis:
1281     #include <petscsys.h>
1282    PetscErrorCode PetscFree4(void *m1,void *m2,void *m3,void *m4)
1283 
1284    Not Collective
1285 
1286    Input Parameter:
1287 +   m1 - memory to free
1288 .   m2 - 2nd memory to free
1289 .   m3 - 3rd memory to free
1290 -   m4 - 4th memory to free
1291 
1292    Level: developer
1293 
1294    Notes: Memory must have been obtained with PetscMalloc4()
1295 
1296 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4()
1297 
1298   Concepts: memory allocation
1299 
1300 M*/
1301 #if !defined(PETSC_USE_MALLOC_COALESCED)
1302 #define PetscFree4(m1,m2,m3,m4)   (PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
1303 #else
1304 #define PetscFree4(m1,m2,m3,m4)   ((m1) ? ((m4)=0,(m3)=0,(m2)=0,PetscFree(m1)) : ((m2) ? ((m4)=0,(m3)=0,(m1)=0,PetscFree(m2)) : ((m3) ? ((m4)=0,(m2)=0,(m1)=0,PetscFree(m3)) : ((m3)=0,(m2)=0,(m1)=0,PetscFree(m4)))))
1305 #endif
1306 
1307 /*MC
1308    PetscFree5 - Frees 5 chunks of memory obtained with PetscMalloc5()
1309 
1310    Synopsis:
1311     #include <petscsys.h>
1312    PetscErrorCode PetscFree5(void *m1,void *m2,void *m3,void *m4,void *m5)
1313 
1314    Not Collective
1315 
1316    Input Parameter:
1317 +   m1 - memory to free
1318 .   m2 - 2nd memory to free
1319 .   m3 - 3rd memory to free
1320 .   m4 - 4th memory to free
1321 -   m5 - 5th memory to free
1322 
1323    Level: developer
1324 
1325    Notes: Memory must have been obtained with PetscMalloc5()
1326 
1327 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5()
1328 
1329   Concepts: memory allocation
1330 
1331 M*/
1332 #if !defined(PETSC_USE_MALLOC_COALESCED)
1333 #define PetscFree5(m1,m2,m3,m4,m5)   (PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
1334 #else
1335 #define PetscFree5(m1,m2,m3,m4,m5)   ((m1) ? ((m5)=0,(m4)=0,(m3)=0,(m2)=0,PetscFree(m1)) : ((m2) ? ((m5)=0,(m4)=0,(m3)=0,(m1)=0,PetscFree(m2)) : ((m3) ? ((m5)=0,(m4)=0,(m2)=0,(m1)=0,PetscFree(m3)) : \
1336                                      ((m4) ? ((m5)=0,(m3)=0,(m2)=0,(m1)=0,PetscFree(m4)) : ((m4)=0,(m3)=0,(m2)=0,(m1)=0,PetscFree(m5))))))
1337 #endif
1338 
1339 
1340 /*MC
1341    PetscFree6 - Frees 6 chunks of memory obtained with PetscMalloc6()
1342 
1343    Synopsis:
1344     #include <petscsys.h>
1345    PetscErrorCode PetscFree6(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6)
1346 
1347    Not Collective
1348 
1349    Input Parameter:
1350 +   m1 - memory to free
1351 .   m2 - 2nd memory to free
1352 .   m3 - 3rd memory to free
1353 .   m4 - 4th memory to free
1354 .   m5 - 5th memory to free
1355 -   m6 - 6th memory to free
1356 
1357 
1358    Level: developer
1359 
1360    Notes: Memory must have been obtained with PetscMalloc6()
1361 
1362 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5(), PetscMalloc6()
1363 
1364   Concepts: memory allocation
1365 
1366 M*/
1367 #if !defined(PETSC_USE_MALLOC_COALESCED)
1368 #define PetscFree6(m1,m2,m3,m4,m5,m6)   (PetscFree(m6) || PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
1369 #else
1370 #define PetscFree6(m1,m2,m3,m4,m5,m6)   ((m1) ? ((m6)=0,(m5)=0,(m4)=0,(m3)=0,(m2)=0,PetscFree(m1)) : ((m2) ? ((m6)=0,(m5)=0,(m4)=0,(m3)=0,(m1)=0,PetscFree(m2)) : \
1371                                         ((m3) ? ((m6)=0,(m5)=0,(m4)=0,(m2)=0,(m1)=0,PetscFree(m3)) : ((m4) ? ((m6)=0,(m5)=0,(m3)=0,(m2)=0,(m1)=0,PetscFree(m4)) : \
1372                                         ((m5) ? ((m6)=0,(m4)=0,(m3)=0,(m2)=0,(m1)=0,PetscFree(m5)) : ((m5)=0,(m4)=0,(m3)=0,(m2)=0,(m1)=0,PetscFree(m6)))))))
1373 #endif
1374 
1375 /*MC
1376    PetscFree7 - Frees 7 chunks of memory obtained with PetscMalloc7()
1377 
1378    Synopsis:
1379     #include <petscsys.h>
1380    PetscErrorCode PetscFree7(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6,void *m7)
1381 
1382    Not Collective
1383 
1384    Input Parameter:
1385 +   m1 - memory to free
1386 .   m2 - 2nd memory to free
1387 .   m3 - 3rd memory to free
1388 .   m4 - 4th memory to free
1389 .   m5 - 5th memory to free
1390 .   m6 - 6th memory to free
1391 -   m7 - 7th memory to free
1392 
1393 
1394    Level: developer
1395 
1396    Notes: Memory must have been obtained with PetscMalloc7()
1397 
1398 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5(), PetscMalloc6(),
1399           PetscMalloc7()
1400 
1401   Concepts: memory allocation
1402 
1403 M*/
1404 #if !defined(PETSC_USE_MALLOC_COALESCED)
1405 #define PetscFree7(m1,m2,m3,m4,m5,m6,m7)   (PetscFree(m7) || PetscFree(m6) || PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
1406 #else
1407 #define PetscFree7(m1,m2,m3,m4,m5,m6,m7)   ((m1) ? ((m7)=0,(m6)=0,(m5)=0,(m4)=0,(m3)=0,(m2)=0,PetscFree(m1)) : ((m2) ? ((m7)=0,(m6)=0,(m5)=0,(m4)=0,(m3)=0,(m1)=0,PetscFree(m2)) : \
1408                                            ((m3) ? ((m7)=0,(m6)=0,(m5)=0,(m4)=0,(m2)=0,(m1)=0,PetscFree(m3)) : ((m4) ? ((m7)=0,(m6)=0,(m5)=0,(m3)=0,(m2)=0,(m1)=0,PetscFree(m4)) : \
1409                                            ((m5) ? ((m7)=0,(m6)=0,(m4)=0,(m3)=0,(m2)=0,(m1)=0,PetscFree(m5)) : ((m6) ? ((m7)=0,(m5)=0,(m4)=0,(m3)=0,(m2)=0,(m1)=0,PetscFree(m6)) : \
1410                                                    ((m6)=0,(m5)=0,(m4)=0,(m3)=0,(m2)=0,(m1)=0,PetscFree(m7))))))))
1411 #endif
1412 
1413 PETSC_EXTERN PetscErrorCode (*PetscTrMalloc)(size_t,int,const char[],const char[],void**);
1414 PETSC_EXTERN PetscErrorCode (*PetscTrFree)(void*,int,const char[],const char[]);
1415 PETSC_EXTERN PetscErrorCode (*PetscTrRealloc)(size_t,int,const char[],const char[],void**);
1416 PETSC_EXTERN PetscErrorCode PetscMallocSet(PetscErrorCode (*)(size_t,int,const char[],const char[],void**),PetscErrorCode (*)(void*,int,const char[],const char[]));
1417 PETSC_EXTERN PetscErrorCode PetscMallocClear(void);
1418 
1419 /*
1420     PetscLogDouble variables are used to contain double precision numbers
1421   that are not used in the numerical computations, but rather in logging,
1422   timing etc.
1423 */
1424 typedef double PetscLogDouble;
1425 #define MPIU_PETSCLOGDOUBLE MPI_DOUBLE
1426 
1427 /*
1428    Routines for tracing memory corruption/bleeding with default PETSc memory allocation
1429 */
1430 PETSC_EXTERN PetscErrorCode PetscMallocDump(FILE *);
1431 PETSC_EXTERN PetscErrorCode PetscMallocDumpLog(FILE *);
1432 PETSC_EXTERN PetscErrorCode PetscMallocGetCurrentUsage(PetscLogDouble *);
1433 PETSC_EXTERN PetscErrorCode PetscMallocGetMaximumUsage(PetscLogDouble *);
1434 PETSC_EXTERN PetscErrorCode PetscMallocDebug(PetscBool);
1435 PETSC_EXTERN PetscErrorCode PetscMallocGetDebug(PetscBool*);
1436 PETSC_EXTERN PetscErrorCode PetscMallocValidate(int,const char[],const char[]);
1437 PETSC_EXTERN PetscErrorCode PetscMallocSetDumpLog(void);
1438 PETSC_EXTERN PetscErrorCode PetscMallocSetDumpLogThreshold(PetscLogDouble);
1439 PETSC_EXTERN PetscErrorCode PetscMallocGetDumpLog(PetscBool*);
1440 
1441 /*E
1442     PetscDataType - Used for handling different basic data types.
1443 
1444    Level: beginner
1445 
1446    Developer comment: It would be nice if we could always just use MPI Datatypes, why can we not?
1447 
1448 .seealso: PetscBinaryRead(), PetscBinaryWrite(), PetscDataTypeToMPIDataType(),
1449           PetscDataTypeGetSize()
1450 
1451 E*/
1452 typedef enum {PETSC_INT = 0,PETSC_DOUBLE = 1,PETSC_COMPLEX = 2, PETSC_LONG = 3 ,PETSC_SHORT = 4,PETSC_FLOAT = 5,
1453               PETSC_CHAR = 6,PETSC_BIT_LOGICAL = 7,PETSC_ENUM = 8,PETSC_BOOL=9, PETSC___FLOAT128 = 10,PETSC_OBJECT = 11, PETSC_FUNCTION = 12, PETSC_STRING = 13, PETSC___FP16 = 14,PETSC_STRUCT, PETSC_DATATYPE_UNKNOWN} PetscDataType;
1454 PETSC_EXTERN const char *const PetscDataTypes[];
1455 
1456 #if defined(PETSC_USE_COMPLEX)
1457 #define  PETSC_SCALAR  PETSC_COMPLEX
1458 #else
1459 #if defined(PETSC_USE_REAL_SINGLE)
1460 #define  PETSC_SCALAR  PETSC_FLOAT
1461 #elif defined(PETSC_USE_REAL___FLOAT128)
1462 #define  PETSC_SCALAR  PETSC___FLOAT128
1463 #elif defined(PETSC_USE_REAL___FP16)
1464 #define  PETSC_SCALAR  PETSC___FP16
1465 #else
1466 #define  PETSC_SCALAR  PETSC_DOUBLE
1467 #endif
1468 #endif
1469 #if defined(PETSC_USE_REAL_SINGLE)
1470 #define  PETSC_REAL  PETSC_FLOAT
1471 #elif defined(PETSC_USE_REAL___FLOAT128)
1472 #define  PETSC_REAL  PETSC___FLOAT128
1473 #elif defined(PETSC_USE_REAL___FP16)
1474 #define  PETSC_REAL  PETSC___FP16
1475 #else
1476 #define  PETSC_REAL  PETSC_DOUBLE
1477 #endif
1478 #define  PETSC_FORTRANADDR  PETSC_LONG
1479 
1480 PETSC_EXTERN PetscErrorCode PetscDataTypeToMPIDataType(PetscDataType,MPI_Datatype*);
1481 PETSC_EXTERN PetscErrorCode PetscMPIDataTypeToPetscDataType(MPI_Datatype,PetscDataType*);
1482 PETSC_EXTERN PetscErrorCode PetscDataTypeGetSize(PetscDataType,size_t*);
1483 PETSC_EXTERN PetscErrorCode PetscDataTypeFromString(const char*,PetscDataType*,PetscBool*);
1484 
1485 /*
1486     Basic memory and string operations. These are usually simple wrappers
1487    around the basic Unix system calls, but a few of them have additional
1488    functionality and/or error checking.
1489 */
1490 PETSC_EXTERN PetscErrorCode PetscBitMemcpy(void*,PetscInt,const void*,PetscInt,PetscInt,PetscDataType);
1491 PETSC_EXTERN PetscErrorCode PetscMemmove(void*,void *,size_t);
1492 PETSC_EXTERN PetscErrorCode PetscMemcmp(const void*,const void*,size_t,PetscBool  *);
1493 PETSC_EXTERN PetscErrorCode PetscStrlen(const char[],size_t*);
1494 PETSC_EXTERN PetscErrorCode PetscStrToArray(const char[],char,int*,char ***);
1495 PETSC_EXTERN PetscErrorCode PetscStrToArrayDestroy(int,char **);
1496 PETSC_EXTERN PetscErrorCode PetscStrcmp(const char[],const char[],PetscBool  *);
1497 PETSC_EXTERN PetscErrorCode PetscStrgrt(const char[],const char[],PetscBool  *);
1498 PETSC_EXTERN PetscErrorCode PetscStrcasecmp(const char[],const char[],PetscBool *);
1499 PETSC_EXTERN PetscErrorCode PetscStrncmp(const char[],const char[],size_t,PetscBool *);
1500 PETSC_EXTERN PetscErrorCode PetscStrcpy(char[],const char[]);
1501 PETSC_EXTERN PetscErrorCode PetscStrcat(char[],const char[]);
1502 PETSC_EXTERN PetscErrorCode PetscStrncat(char[],const char[],size_t);
1503 PETSC_EXTERN PetscErrorCode PetscStrncpy(char[],const char[],size_t);
1504 PETSC_EXTERN PetscErrorCode PetscStrchr(const char[],char,char *[]);
1505 PETSC_EXTERN PetscErrorCode PetscStrtolower(char[]);
1506 PETSC_EXTERN PetscErrorCode PetscStrtoupper(char[]);
1507 PETSC_EXTERN PetscErrorCode PetscStrrchr(const char[],char,char *[]);
1508 PETSC_EXTERN PetscErrorCode PetscStrstr(const char[],const char[],char *[]);
1509 PETSC_EXTERN PetscErrorCode PetscStrrstr(const char[],const char[],char *[]);
1510 PETSC_EXTERN PetscErrorCode PetscStrendswith(const char[],const char[],PetscBool*);
1511 PETSC_EXTERN PetscErrorCode PetscStrbeginswith(const char[],const char[],PetscBool*);
1512 PETSC_EXTERN PetscErrorCode PetscStrendswithwhich(const char[],const char *const*,PetscInt*);
1513 PETSC_EXTERN PetscErrorCode PetscStrallocpy(const char[],char *[]);
1514 PETSC_EXTERN PetscErrorCode PetscStrArrayallocpy(const char *const*,char***);
1515 PETSC_EXTERN PetscErrorCode PetscStrArrayDestroy(char***);
1516 PETSC_EXTERN PetscErrorCode PetscStrNArrayallocpy(PetscInt,const char *const*,char***);
1517 PETSC_EXTERN PetscErrorCode PetscStrNArrayDestroy(PetscInt,char***);
1518 PETSC_EXTERN PetscErrorCode PetscStrreplace(MPI_Comm,const char[],char[],size_t);
1519 
1520 PETSC_EXTERN void PetscStrcmpNoError(const char[],const char[],PetscBool  *);
1521 
1522 /*S
1523     PetscToken - 'Token' used for managing tokenizing strings
1524 
1525   Level: intermediate
1526 
1527 .seealso: PetscTokenCreate(), PetscTokenFind(), PetscTokenDestroy()
1528 S*/
1529 typedef struct _p_PetscToken* PetscToken;
1530 
1531 PETSC_EXTERN PetscErrorCode PetscTokenCreate(const char[],const char,PetscToken*);
1532 PETSC_EXTERN PetscErrorCode PetscTokenFind(PetscToken,char *[]);
1533 PETSC_EXTERN PetscErrorCode PetscTokenDestroy(PetscToken*);
1534 
1535 PETSC_EXTERN PetscErrorCode PetscEListFind(PetscInt,const char *const*,const char*,PetscInt*,PetscBool*);
1536 PETSC_EXTERN PetscErrorCode PetscEnumFind(const char *const*,const char*,PetscEnum*,PetscBool*);
1537 
1538 /*
1539    These are MPI operations for MPI_Allreduce() etc
1540 */
1541 PETSC_EXTERN MPI_Op MPIU_MAXSUM_OP;
1542 #if (defined(PETSC_HAVE_COMPLEX) && !defined(PETSC_HAVE_MPI_C_DOUBLE_COMPLEX)) || defined(PETSC_USE_REAL___FLOAT128) || defined(PETSC_USE_REAL___FP16)
1543 PETSC_EXTERN MPI_Op MPIU_SUM;
1544 #else
1545 #define MPIU_SUM MPI_SUM
1546 #endif
1547 #if defined(PETSC_USE_REAL___FLOAT128) || defined(PETSC_USE_REAL___FP16)
1548 PETSC_EXTERN MPI_Op MPIU_MAX;
1549 PETSC_EXTERN MPI_Op MPIU_MIN;
1550 #else
1551 #define MPIU_MAX MPI_MAX
1552 #define MPIU_MIN MPI_MIN
1553 #endif
1554 PETSC_EXTERN PetscErrorCode PetscMaxSum(MPI_Comm,const PetscInt[],PetscInt*,PetscInt*);
1555 
1556 PETSC_EXTERN PetscErrorCode MPIULong_Send(void*,PetscInt,MPI_Datatype,PetscMPIInt,PetscMPIInt,MPI_Comm);
1557 PETSC_EXTERN PetscErrorCode MPIULong_Recv(void*,PetscInt,MPI_Datatype,PetscMPIInt,PetscMPIInt,MPI_Comm);
1558 
1559 /*S
1560      PetscObject - any PETSc object, PetscViewer, Mat, Vec, KSP etc
1561 
1562    Level: beginner
1563 
1564    Note: This is the base class from which all PETSc objects are derived from.
1565 
1566 .seealso:  PetscObjectDestroy(), PetscObjectView(), PetscObjectGetName(), PetscObjectSetName(), PetscObjectReference(), PetscObjectDereference()
1567 S*/
1568 typedef struct _p_PetscObject* PetscObject;
1569 
1570 /*MC
1571     PetscObjectId - unique integer Id for a PetscObject
1572 
1573     Level: developer
1574 
1575     Notes: Unlike pointer values, object ids are never reused.
1576 
1577 .seealso: PetscObjectState, PetscObjectGetId()
1578 M*/
1579 #if defined(PETSC_USING_F90) && !defined(PETSC_USE_FORTRANKIND) /* compaq F90 */
1580 typedef int PetscObjectId;
1581 #else
1582 typedef PetscInt64 PetscObjectId;
1583 #endif
1584 
1585 /*MC
1586     PetscObjectState - integer state for a PetscObject
1587 
1588     Level: developer
1589 
1590     Notes:
1591     Object state is always-increasing and (for objects that track state) can be used to determine if an object has
1592     changed since the last time you interacted with it.  It is 64-bit so that it will not overflow for a very long time.
1593 
1594 .seealso: PetscObjectId, PetscObjectStateGet(), PetscObjectStateIncrease(), PetscObjectStateSet()
1595 M*/
1596 #if defined(PETSC_USING_F90) && !defined(PETSC_USE_FORTRANKIND) /* compaq F90 */
1597 typedef int PetscObjectState;
1598 #else
1599 typedef PetscInt64 PetscObjectState;
1600 #endif
1601 
1602 /*S
1603      PetscFunctionList - Linked list of functions, possibly stored in dynamic libraries, accessed
1604       by string name
1605 
1606    Level: advanced
1607 
1608 .seealso:  PetscFunctionListAdd(), PetscFunctionListDestroy(), PetscOpFlist
1609 S*/
1610 typedef struct _n_PetscFunctionList *PetscFunctionList;
1611 
1612 /*E
1613   PetscFileMode - Access mode for a file.
1614 
1615   Level: beginner
1616 
1617 $  FILE_MODE_READ - open a file at its beginning for reading
1618 $  FILE_MODE_WRITE - open a file at its beginning for writing (will create if the file does not exist)
1619 $  FILE_MODE_APPEND - open a file at end for writing
1620 $  FILE_MODE_UPDATE - open a file for updating, meaning for reading and writing
1621 $  FILE_MODE_APPEND_UPDATE - open a file for updating, meaning for reading and writing, at the end
1622 
1623 .seealso: PetscViewerFileSetMode()
1624 E*/
1625 typedef enum {FILE_MODE_READ, FILE_MODE_WRITE, FILE_MODE_APPEND, FILE_MODE_UPDATE, FILE_MODE_APPEND_UPDATE} PetscFileMode;
1626 extern const char *const PetscFileModes[];
1627 
1628 /*
1629     Defines PETSc error handling.
1630 */
1631 #include <petscerror.h>
1632 
1633 #define PETSC_SMALLEST_CLASSID  1211211
1634 PETSC_EXTERN PetscClassId PETSC_LARGEST_CLASSID;
1635 PETSC_EXTERN PetscClassId PETSC_OBJECT_CLASSID;
1636 PETSC_EXTERN PetscErrorCode PetscClassIdRegister(const char[],PetscClassId *);
1637 
1638 /*
1639    Routines that get memory usage information from the OS
1640 */
1641 PETSC_EXTERN PetscErrorCode PetscMemoryGetCurrentUsage(PetscLogDouble *);
1642 PETSC_EXTERN PetscErrorCode PetscMemoryGetMaximumUsage(PetscLogDouble *);
1643 PETSC_EXTERN PetscErrorCode PetscMemorySetGetMaximumUsage(void);
1644 PETSC_EXTERN PetscErrorCode PetscMemoryTrace(const char[]);
1645 
1646 PETSC_EXTERN PetscErrorCode PetscInfoAllow(PetscBool ,const char []);
1647 PETSC_EXTERN PetscErrorCode PetscSleep(PetscReal);
1648 
1649 /*
1650    Initialization of PETSc
1651 */
1652 PETSC_EXTERN PetscErrorCode PetscInitialize(int*,char***,const char[],const char[]);
1653 PETSC_EXTERN PetscErrorCode PetscInitializeNoPointers(int,char**,const char[],const char[]);
1654 PETSC_EXTERN PetscErrorCode PetscInitializeNoArguments(void);
1655 PETSC_EXTERN PetscErrorCode PetscInitialized(PetscBool *);
1656 PETSC_EXTERN PetscErrorCode PetscFinalized(PetscBool *);
1657 PETSC_EXTERN PetscErrorCode PetscFinalize(void);
1658 PETSC_EXTERN PetscErrorCode PetscInitializeFortran(void);
1659 PETSC_EXTERN PetscErrorCode PetscGetArgs(int*,char ***);
1660 PETSC_EXTERN PetscErrorCode PetscGetArguments(char ***);
1661 PETSC_EXTERN PetscErrorCode PetscFreeArguments(char **);
1662 
1663 PETSC_EXTERN PetscErrorCode PetscEnd(void);
1664 PETSC_EXTERN PetscErrorCode PetscSysInitializePackage(void);
1665 
1666 PETSC_EXTERN PetscErrorCode PetscPythonInitialize(const char[],const char[]);
1667 PETSC_EXTERN PetscErrorCode PetscPythonFinalize(void);
1668 PETSC_EXTERN PetscErrorCode PetscPythonPrintError(void);
1669 PETSC_EXTERN PetscErrorCode PetscPythonMonitorSet(PetscObject,const char[]);
1670 
1671 /*
1672      These are so that in extern C code we can caste function pointers to non-extern C
1673    function pointers. Since the regular C++ code expects its function pointers to be C++
1674 */
1675 PETSC_EXTERN_TYPEDEF typedef void (**PetscVoidStarFunction)(void);
1676 PETSC_EXTERN_TYPEDEF typedef void (*PetscVoidFunction)(void);
1677 PETSC_EXTERN_TYPEDEF typedef PetscErrorCode (*PetscErrorCodeFunction)(void);
1678 
1679 /*
1680     Functions that can act on any PETSc object.
1681 */
1682 PETSC_EXTERN PetscErrorCode PetscObjectDestroy(PetscObject*);
1683 PETSC_EXTERN PetscErrorCode PetscObjectGetComm(PetscObject,MPI_Comm *);
1684 PETSC_EXTERN PetscErrorCode PetscObjectGetClassId(PetscObject,PetscClassId *);
1685 PETSC_EXTERN PetscErrorCode PetscObjectGetClassName(PetscObject,const char *[]);
1686 PETSC_EXTERN PetscErrorCode PetscObjectSetType(PetscObject,const char []);
1687 PETSC_EXTERN PetscErrorCode PetscObjectSetPrecision(PetscObject,PetscPrecision);
1688 PETSC_EXTERN PetscErrorCode PetscObjectGetType(PetscObject,const char *[]);
1689 PETSC_EXTERN PetscErrorCode PetscObjectSetName(PetscObject,const char[]);
1690 PETSC_EXTERN PetscErrorCode PetscObjectGetName(PetscObject,const char*[]);
1691 PETSC_EXTERN PetscErrorCode PetscObjectSetTabLevel(PetscObject,PetscInt);
1692 PETSC_EXTERN PetscErrorCode PetscObjectGetTabLevel(PetscObject,PetscInt*);
1693 PETSC_EXTERN PetscErrorCode PetscObjectIncrementTabLevel(PetscObject,PetscObject,PetscInt);
1694 PETSC_EXTERN PetscErrorCode PetscObjectReference(PetscObject);
1695 PETSC_EXTERN PetscErrorCode PetscObjectGetReference(PetscObject,PetscInt*);
1696 PETSC_EXTERN PetscErrorCode PetscObjectDereference(PetscObject);
1697 PETSC_EXTERN PetscErrorCode PetscObjectGetNewTag(PetscObject,PetscMPIInt *);
1698 PETSC_EXTERN PetscErrorCode PetscObjectCompose(PetscObject,const char[],PetscObject);
1699 PETSC_EXTERN PetscErrorCode PetscObjectRemoveReference(PetscObject,const char[]);
1700 PETSC_EXTERN PetscErrorCode PetscObjectQuery(PetscObject,const char[],PetscObject *);
1701 PETSC_EXTERN PetscErrorCode PetscObjectComposeFunction_Private(PetscObject,const char[],void (*)(void));
1702 #define PetscObjectComposeFunction(a,b,d) PetscObjectComposeFunction_Private(a,b,(PetscVoidFunction)(d))
1703 PETSC_EXTERN PetscErrorCode PetscObjectSetFromOptions(PetscObject);
1704 PETSC_EXTERN PetscErrorCode PetscObjectSetUp(PetscObject);
1705 PETSC_EXTERN PetscErrorCode PetscObjectSetPrintedOptions(PetscObject);
1706 PETSC_EXTERN PetscErrorCode PetscObjectInheritPrintedOptions(PetscObject,PetscObject);
1707 PETSC_EXTERN PetscErrorCode PetscCommGetNewTag(MPI_Comm,PetscMPIInt *);
1708 
1709 #include <petscviewertypes.h>
1710 #include <petscoptions.h>
1711 
1712 PETSC_EXTERN PetscErrorCode PetscObjectsListGetGlobalNumbering(MPI_Comm,PetscInt,PetscObject*,PetscInt*,PetscInt*);
1713 
1714 PETSC_EXTERN PetscErrorCode PetscMemoryShowUsage(PetscViewer,const char[]);
1715 PETSC_EXTERN PetscErrorCode PetscMemoryView(PetscViewer,const char[]);
1716 PETSC_EXTERN PetscErrorCode PetscObjectPrintClassNamePrefixType(PetscObject,PetscViewer);
1717 PETSC_EXTERN PetscErrorCode PetscObjectView(PetscObject,PetscViewer);
1718 #define PetscObjectQueryFunction(obj,name,fptr) PetscObjectQueryFunction_Private((obj),(name),(PetscVoidFunction*)(fptr))
1719 PETSC_EXTERN PetscErrorCode PetscObjectQueryFunction_Private(PetscObject,const char[],void (**)(void));
1720 PETSC_EXTERN PetscErrorCode PetscObjectSetOptionsPrefix(PetscObject,const char[]);
1721 PETSC_EXTERN PetscErrorCode PetscObjectAppendOptionsPrefix(PetscObject,const char[]);
1722 PETSC_EXTERN PetscErrorCode PetscObjectPrependOptionsPrefix(PetscObject,const char[]);
1723 PETSC_EXTERN PetscErrorCode PetscObjectGetOptionsPrefix(PetscObject,const char*[]);
1724 PETSC_EXTERN PetscErrorCode PetscObjectChangeTypeName(PetscObject,const char[]);
1725 PETSC_EXTERN PetscErrorCode PetscObjectRegisterDestroy(PetscObject);
1726 PETSC_EXTERN PetscErrorCode PetscObjectRegisterDestroyAll(void);
1727 PETSC_EXTERN PetscErrorCode PetscObjectViewFromOptions(PetscObject,PetscObject,const char[]);
1728 PETSC_EXTERN PetscErrorCode PetscObjectName(PetscObject);
1729 PETSC_EXTERN PetscErrorCode PetscObjectTypeCompare(PetscObject,const char[],PetscBool *);
1730 PETSC_EXTERN PetscErrorCode PetscObjectTypeCompareAny(PetscObject,PetscBool*,const char[],...);
1731 PETSC_EXTERN PetscErrorCode PetscRegisterFinalize(PetscErrorCode (*)(void));
1732 PETSC_EXTERN PetscErrorCode PetscRegisterFinalizeAll(void);
1733 
1734 #if defined(PETSC_HAVE_SAWS)
1735 PETSC_EXTERN PetscErrorCode PetscSAWsBlock(void);
1736 PETSC_EXTERN PetscErrorCode PetscObjectSAWsViewOff(PetscObject);
1737 PETSC_EXTERN PetscErrorCode PetscObjectSAWsSetBlock(PetscObject,PetscBool);
1738 PETSC_EXTERN PetscErrorCode PetscObjectSAWsBlock(PetscObject);
1739 PETSC_EXTERN PetscErrorCode PetscObjectSAWsGrantAccess(PetscObject);
1740 PETSC_EXTERN PetscErrorCode PetscObjectSAWsTakeAccess(PetscObject);
1741 PETSC_EXTERN void           PetscStackSAWsGrantAccess(void);
1742 PETSC_EXTERN void           PetscStackSAWsTakeAccess(void);
1743 PETSC_EXTERN PetscErrorCode PetscStackViewSAWs(void);
1744 PETSC_EXTERN PetscErrorCode PetscStackSAWsViewOff(void);
1745 
1746 #else
1747 #define PetscSAWsBlock()                        0
1748 #define PetscObjectSAWsViewOff(obj)             0
1749 #define PetscObjectSAWsSetBlock(obj,flg)        0
1750 #define PetscObjectSAWsBlock(obj)               0
1751 #define PetscObjectSAWsGrantAccess(obj)         0
1752 #define PetscObjectSAWsTakeAccess(obj)          0
1753 #define PetscStackViewSAWs()                    0
1754 #define PetscStackSAWsViewOff()                 0
1755 #define PetscStackSAWsTakeAccess()
1756 #define PetscStackSAWsGrantAccess()
1757 
1758 #endif
1759 
1760 typedef void* PetscDLHandle;
1761 typedef enum {PETSC_DL_DECIDE=0,PETSC_DL_NOW=1,PETSC_DL_LOCAL=2} PetscDLMode;
1762 PETSC_EXTERN PetscErrorCode PetscDLOpen(const char[],PetscDLMode,PetscDLHandle *);
1763 PETSC_EXTERN PetscErrorCode PetscDLClose(PetscDLHandle *);
1764 PETSC_EXTERN PetscErrorCode PetscDLSym(PetscDLHandle,const char[],void **);
1765 
1766 #if defined(PETSC_USE_DEBUG)
1767 PETSC_EXTERN PetscErrorCode PetscMallocGetStack(void*,PetscStack**);
1768 #endif
1769 PETSC_EXTERN PetscErrorCode PetscObjectsDump(FILE*,PetscBool);
1770 
1771 /*S
1772      PetscObjectList - Linked list of PETSc objects, each accessable by string name
1773 
1774    Level: developer
1775 
1776    Notes: Used by PetscObjectCompose() and PetscObjectQuery()
1777 
1778 .seealso:  PetscObjectListAdd(), PetscObjectListDestroy(), PetscObjectListFind(), PetscObjectCompose(), PetscObjectQuery(), PetscFunctionList
1779 S*/
1780 typedef struct _n_PetscObjectList *PetscObjectList;
1781 
1782 PETSC_EXTERN PetscErrorCode PetscObjectListDestroy(PetscObjectList*);
1783 PETSC_EXTERN PetscErrorCode PetscObjectListFind(PetscObjectList,const char[],PetscObject*);
1784 PETSC_EXTERN PetscErrorCode PetscObjectListReverseFind(PetscObjectList,PetscObject,char**,PetscBool*);
1785 PETSC_EXTERN PetscErrorCode PetscObjectListAdd(PetscObjectList *,const char[],PetscObject);
1786 PETSC_EXTERN PetscErrorCode PetscObjectListRemoveReference(PetscObjectList *,const char[]);
1787 PETSC_EXTERN PetscErrorCode PetscObjectListDuplicate(PetscObjectList,PetscObjectList *);
1788 
1789 /*
1790     Dynamic library lists. Lists of names of routines in objects or in dynamic
1791   link libraries that will be loaded as needed.
1792 */
1793 
1794 #define PetscFunctionListAdd(list,name,fptr) PetscFunctionListAdd_Private((list),(name),(PetscVoidFunction)(fptr))
1795 PETSC_EXTERN PetscErrorCode PetscFunctionListAdd_Private(PetscFunctionList*,const char[],void (*)(void));
1796 PETSC_EXTERN PetscErrorCode PetscFunctionListDestroy(PetscFunctionList*);
1797 #define PetscFunctionListFind(list,name,fptr) PetscFunctionListFind_Private((list),(name),(PetscVoidFunction*)(fptr))
1798 PETSC_EXTERN PetscErrorCode PetscFunctionListFind_Private(PetscFunctionList,const char[],void (**)(void));
1799 PETSC_EXTERN PetscErrorCode PetscFunctionListPrintTypes(MPI_Comm,FILE*,const char[],const char[],const char[],const char[],PetscFunctionList,const char[]);
1800 PETSC_EXTERN PetscErrorCode PetscFunctionListDuplicate(PetscFunctionList,PetscFunctionList *);
1801 PETSC_EXTERN PetscErrorCode PetscFunctionListView(PetscFunctionList,PetscViewer);
1802 PETSC_EXTERN PetscErrorCode PetscFunctionListGet(PetscFunctionList,const char ***,int*);
1803 
1804 /*S
1805      PetscDLLibrary - Linked list of dynamics libraries to search for functions
1806 
1807    Level: advanced
1808 
1809 .seealso:  PetscDLLibraryOpen()
1810 S*/
1811 typedef struct _n_PetscDLLibrary *PetscDLLibrary;
1812 PETSC_EXTERN PetscDLLibrary  PetscDLLibrariesLoaded;
1813 PETSC_EXTERN PetscErrorCode PetscDLLibraryAppend(MPI_Comm,PetscDLLibrary *,const char[]);
1814 PETSC_EXTERN PetscErrorCode PetscDLLibraryPrepend(MPI_Comm,PetscDLLibrary *,const char[]);
1815 PETSC_EXTERN PetscErrorCode PetscDLLibrarySym(MPI_Comm,PetscDLLibrary *,const char[],const char[],void **);
1816 PETSC_EXTERN PetscErrorCode PetscDLLibraryPrintPath(PetscDLLibrary);
1817 PETSC_EXTERN PetscErrorCode PetscDLLibraryRetrieve(MPI_Comm,const char[],char *,size_t,PetscBool  *);
1818 PETSC_EXTERN PetscErrorCode PetscDLLibraryOpen(MPI_Comm,const char[],PetscDLLibrary *);
1819 PETSC_EXTERN PetscErrorCode PetscDLLibraryClose(PetscDLLibrary);
1820 
1821 /*
1822      Useful utility routines
1823 */
1824 PETSC_EXTERN PetscErrorCode PetscSplitOwnership(MPI_Comm,PetscInt*,PetscInt*);
1825 PETSC_EXTERN PetscErrorCode PetscSplitOwnershipBlock(MPI_Comm,PetscInt,PetscInt*,PetscInt*);
1826 PETSC_EXTERN PetscErrorCode PetscSequentialPhaseBegin(MPI_Comm,PetscMPIInt);
1827 PETSC_EXTERN PetscErrorCode PetscSequentialPhaseEnd(MPI_Comm,PetscMPIInt);
1828 PETSC_EXTERN PetscErrorCode PetscBarrier(PetscObject);
1829 PETSC_EXTERN PetscErrorCode PetscMPIDump(FILE*);
1830 
1831 /*
1832     PetscNot - negates a logical type value and returns result as a PetscBool
1833 
1834     Notes: This is useful in cases like
1835 $     int        *a;
1836 $     PetscBool  flag = PetscNot(a)
1837      where !a would not return a PetscBool because we cannot provide a cast from int to PetscBool in C.
1838 */
1839 #define PetscNot(a) ((a) ? PETSC_FALSE : PETSC_TRUE)
1840 
1841 /*MC
1842     PetscHelpPrintf - Prints help messages.
1843 
1844    Synopsis:
1845     #include <petscsys.h>
1846      PetscErrorCode (*PetscHelpPrintf)(const char format[],...);
1847 
1848     Not Collective
1849 
1850     Input Parameters:
1851 .   format - the usual printf() format string
1852 
1853    Level: developer
1854 
1855     Fortran Note:
1856     This routine is not supported in Fortran.
1857 
1858     Concepts: help messages^printing
1859     Concepts: printing^help messages
1860 
1861 .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscErrorPrintf()
1862 M*/
1863 PETSC_EXTERN PetscErrorCode (*PetscHelpPrintf)(MPI_Comm,const char[],...);
1864 
1865 /*
1866      Defines PETSc profiling.
1867 */
1868 #include <petsclog.h>
1869 
1870 /*
1871       Simple PETSc parallel IO for ASCII printing
1872 */
1873 PETSC_EXTERN PetscErrorCode PetscFixFilename(const char[],char[]);
1874 PETSC_EXTERN PetscErrorCode PetscFOpen(MPI_Comm,const char[],const char[],FILE**);
1875 PETSC_EXTERN PetscErrorCode PetscFClose(MPI_Comm,FILE*);
1876 PETSC_EXTERN PetscErrorCode PetscFPrintf(MPI_Comm,FILE*,const char[],...);
1877 PETSC_EXTERN PetscErrorCode PetscPrintf(MPI_Comm,const char[],...);
1878 PETSC_EXTERN PetscErrorCode PetscSNPrintf(char*,size_t,const char [],...);
1879 PETSC_EXTERN PetscErrorCode PetscSNPrintfCount(char*,size_t,const char [],size_t*,...);
1880 
1881 PETSC_EXTERN PetscErrorCode PetscErrorPrintfDefault(const char [],...);
1882 PETSC_EXTERN PetscErrorCode PetscErrorPrintfNone(const char [],...);
1883 PETSC_EXTERN PetscErrorCode PetscHelpPrintfDefault(MPI_Comm,const char [],...);
1884 
1885 #if defined(PETSC_HAVE_POPEN)
1886 PETSC_EXTERN PetscErrorCode PetscPOpen(MPI_Comm,const char[],const char[],const char[],FILE **);
1887 PETSC_EXTERN PetscErrorCode PetscPClose(MPI_Comm,FILE*,int*);
1888 PETSC_EXTERN PetscErrorCode PetscPOpenSetMachine(const char[]);
1889 #endif
1890 
1891 PETSC_EXTERN PetscErrorCode PetscSynchronizedPrintf(MPI_Comm,const char[],...);
1892 PETSC_EXTERN PetscErrorCode PetscSynchronizedFPrintf(MPI_Comm,FILE*,const char[],...);
1893 PETSC_EXTERN PetscErrorCode PetscSynchronizedFlush(MPI_Comm,FILE*);
1894 PETSC_EXTERN PetscErrorCode PetscSynchronizedFGets(MPI_Comm,FILE*,size_t,char[]);
1895 PETSC_EXTERN PetscErrorCode PetscStartMatlab(MPI_Comm,const char[],const char[],FILE**);
1896 PETSC_EXTERN PetscErrorCode PetscStartJava(MPI_Comm,const char[],const char[],FILE**);
1897 PETSC_EXTERN PetscErrorCode PetscGetPetscDir(const char*[]);
1898 
1899 PETSC_EXTERN PetscErrorCode PetscPopUpSelect(MPI_Comm,const char*,const char*,int,const char**,int*);
1900 
1901 /*S
1902      PetscContainer - Simple PETSc object that contains a pointer to any required data
1903 
1904    Level: advanced
1905 
1906 .seealso:  PetscObject, PetscContainerCreate()
1907 S*/
1908 PETSC_EXTERN PetscClassId PETSC_CONTAINER_CLASSID;
1909 typedef struct _p_PetscContainer*  PetscContainer;
1910 PETSC_EXTERN PetscErrorCode PetscContainerGetPointer(PetscContainer,void **);
1911 PETSC_EXTERN PetscErrorCode PetscContainerSetPointer(PetscContainer,void *);
1912 PETSC_EXTERN PetscErrorCode PetscContainerDestroy(PetscContainer*);
1913 PETSC_EXTERN PetscErrorCode PetscContainerCreate(MPI_Comm,PetscContainer *);
1914 PETSC_EXTERN PetscErrorCode PetscContainerSetUserDestroy(PetscContainer, PetscErrorCode (*)(void*));
1915 
1916 /*
1917    For use in debuggers
1918 */
1919 PETSC_EXTERN PetscMPIInt PetscGlobalRank;
1920 PETSC_EXTERN PetscMPIInt PetscGlobalSize;
1921 PETSC_EXTERN PetscErrorCode PetscIntView(PetscInt,const PetscInt[],PetscViewer);
1922 PETSC_EXTERN PetscErrorCode PetscRealView(PetscInt,const PetscReal[],PetscViewer);
1923 PETSC_EXTERN PetscErrorCode PetscScalarView(PetscInt,const PetscScalar[],PetscViewer);
1924 
1925 #include <stddef.h>
1926 #include <string.h>             /* for memcpy, memset */
1927 #if defined(PETSC_HAVE_STDLIB_H)
1928 #include <stdlib.h>
1929 #endif
1930 
1931 #if defined(PETSC_HAVE_XMMINTRIN_H) && !defined(__CUDACC__)
1932 #include <xmmintrin.h>
1933 #endif
1934 
1935 /*@C
1936    PetscMemcpy - Copies n bytes, beginning at location b, to the space
1937    beginning at location a. The two memory regions CANNOT overlap, use
1938    PetscMemmove() in that case.
1939 
1940    Not Collective
1941 
1942    Input Parameters:
1943 +  b - pointer to initial memory space
1944 -  n - length (in bytes) of space to copy
1945 
1946    Output Parameter:
1947 .  a - pointer to copy space
1948 
1949    Level: intermediate
1950 
1951    Compile Option:
1952     PETSC_PREFER_DCOPY_FOR_MEMCPY will cause the BLAS dcopy() routine to be used
1953                                   for memory copies on double precision values.
1954     PETSC_PREFER_COPY_FOR_MEMCPY will cause C code to be used
1955                                   for memory copies on double precision values.
1956     PETSC_PREFER_FORTRAN_FORMEMCPY will cause Fortran code to be used
1957                                   for memory copies on double precision values.
1958 
1959    Note:
1960    This routine is analogous to memcpy().
1961 
1962    Developer Note: this is inlined for fastest performance
1963 
1964   Concepts: memory^copying
1965   Concepts: copying^memory
1966 
1967 .seealso: PetscMemmove()
1968 
1969 @*/
1970 PETSC_STATIC_INLINE PetscErrorCode PetscMemcpy(void *a,const void *b,size_t n)
1971 {
1972 #if defined(PETSC_USE_DEBUG)
1973   size_t al = (size_t) a,bl = (size_t) b;
1974   size_t nl = (size_t) n;
1975   PetscFunctionBegin;
1976   if (n > 0 && !b) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Trying to copy from a null pointer");
1977   if (n > 0 && !a) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Trying to copy to a null pointer");
1978 #else
1979   PetscFunctionBegin;
1980 #endif
1981   if (a != b && n > 0) {
1982 #if defined(PETSC_USE_DEBUG)
1983     if ((al > bl && (al - bl) < nl) || (bl - al) < nl)  SETERRQ3(PETSC_COMM_SELF,PETSC_ERR_ARG_INCOMP,"Memory regions overlap: either use PetscMemmov()\n\
1984               or make sure your copy regions and lengths are correct. \n\
1985               Length (bytes) %ld first address %ld second address %ld",nl,al,bl);
1986 #endif
1987 #if (defined(PETSC_PREFER_DCOPY_FOR_MEMCPY) || defined(PETSC_PREFER_COPY_FOR_MEMCPY) || defined(PETSC_PREFER_FORTRAN_FORMEMCPY))
1988    if (!(a % sizeof(PetscScalar)) && !(n % sizeof(PetscScalar))) {
1989       size_t len = n/sizeof(PetscScalar);
1990 #if defined(PETSC_PREFER_DCOPY_FOR_MEMCPY)
1991       PetscBLASInt   one = 1,blen;
1992       PetscErrorCode ierr;
1993       ierr = PetscBLASIntCast(len,&blen);CHKERRQ(ierr);
1994       PetscStackCallBLAS("BLAScopy",BLAScopy_(&blen,(PetscScalar *)b,&one,(PetscScalar *)a,&one));
1995 #elif defined(PETSC_PREFER_FORTRAN_FORMEMCPY)
1996       fortrancopy_(&len,(PetscScalar*)b,(PetscScalar*)a);
1997 #else
1998       size_t      i;
1999       PetscScalar *x = (PetscScalar*)b, *y = (PetscScalar*)a;
2000       for (i=0; i<len; i++) y[i] = x[i];
2001 #endif
2002     } else {
2003       memcpy((char*)(a),(char*)(b),n);
2004     }
2005 #else
2006     memcpy((char*)(a),(char*)(b),n);
2007 #endif
2008   }
2009   PetscFunctionReturn(0);
2010 }
2011 
2012 /*@C
2013    PetscMemzero - Zeros the specified memory.
2014 
2015    Not Collective
2016 
2017    Input Parameters:
2018 +  a - pointer to beginning memory location
2019 -  n - length (in bytes) of memory to initialize
2020 
2021    Level: intermediate
2022 
2023    Compile Option:
2024    PETSC_PREFER_BZERO - on certain machines (the IBM RS6000) the bzero() routine happens
2025   to be faster than the memset() routine. This flag causes the bzero() routine to be used.
2026 
2027    Developer Note: this is inlined for fastest performance
2028 
2029    Concepts: memory^zeroing
2030    Concepts: zeroing^memory
2031 
2032 .seealso: PetscMemcpy()
2033 @*/
2034 PETSC_STATIC_INLINE PetscErrorCode  PetscMemzero(void *a,size_t n)
2035 {
2036   if (n > 0) {
2037 #if defined(PETSC_USE_DEBUG)
2038     if (!a) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Trying to zero at a null pointer");
2039 #endif
2040 #if defined(PETSC_PREFER_ZERO_FOR_MEMZERO)
2041     if (!(((long) a) % sizeof(PetscScalar)) && !(n % sizeof(PetscScalar))) {
2042       size_t      i,len = n/sizeof(PetscScalar);
2043       PetscScalar *x = (PetscScalar*)a;
2044       for (i=0; i<len; i++) x[i] = 0.0;
2045     } else {
2046 #elif defined(PETSC_PREFER_FORTRAN_FOR_MEMZERO)
2047     if (!(((long) a) % sizeof(PetscScalar)) && !(n % sizeof(PetscScalar))) {
2048       PetscInt len = n/sizeof(PetscScalar);
2049       fortranzero_(&len,(PetscScalar*)a);
2050     } else {
2051 #endif
2052 #if defined(PETSC_PREFER_BZERO)
2053       bzero((char *)a,n);
2054 #else
2055       memset((char*)a,0,n);
2056 #endif
2057 #if defined(PETSC_PREFER_ZERO_FOR_MEMZERO) || defined(PETSC_PREFER_FORTRAN_FOR_MEMZERO)
2058     }
2059 #endif
2060   }
2061   return 0;
2062 }
2063 
2064 /*MC
2065    PetscPrefetchBlock - Prefetches a block of memory
2066 
2067    Synopsis:
2068     #include <petscsys.h>
2069     void PetscPrefetchBlock(const anytype *a,size_t n,int rw,int t)
2070 
2071    Not Collective
2072 
2073    Input Parameters:
2074 +  a - pointer to first element to fetch (any type but usually PetscInt or PetscScalar)
2075 .  n - number of elements to fetch
2076 .  rw - 1 if the memory will be written to, otherwise 0 (ignored by many processors)
2077 -  t - temporal locality (PETSC_PREFETCH_HINT_{NTA,T0,T1,T2}), see note
2078 
2079    Level: developer
2080 
2081    Notes:
2082    The last two arguments (rw and t) must be compile-time constants.
2083 
2084    Adopting Intel's x86/x86-64 conventions, there are four levels of temporal locality.  Not all architectures offer
2085    equivalent locality hints, but the following macros are always defined to their closest analogue.
2086 +  PETSC_PREFETCH_HINT_NTA - Non-temporal.  Prefetches directly to L1, evicts to memory (skips higher level cache unless it was already there when prefetched).
2087 .  PETSC_PREFETCH_HINT_T0 - 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.
2088 .  PETSC_PREFETCH_HINT_T1 - Fetch to level 2 and higher (not L1).
2089 -  PETSC_PREFETCH_HINT_T2 - Fetch to high-level cache only.  (On many systems, T0 and T1 are equivalent.)
2090 
2091    This function does nothing on architectures that do not support prefetch and never errors (even if passed an invalid
2092    address).
2093 
2094    Concepts: memory
2095 M*/
2096 #define PetscPrefetchBlock(a,n,rw,t) do {                               \
2097     const char *_p = (const char*)(a),*_end = (const char*)((a)+(n));   \
2098     for ( ; _p < _end; _p += PETSC_LEVEL1_DCACHE_LINESIZE) PETSC_Prefetch(_p,(rw),(t)); \
2099   } while (0)
2100 
2101 /*
2102       Determine if some of the kernel computation routines use
2103    Fortran (rather than C) for the numerical calculations. On some machines
2104    and compilers (like complex numbers) the Fortran version of the routines
2105    is faster than the C/C++ versions. The flag --with-fortran-kernels
2106    should be used with ./configure to turn these on.
2107 */
2108 #if defined(PETSC_USE_FORTRAN_KERNELS)
2109 
2110 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTCRL)
2111 #define PETSC_USE_FORTRAN_KERNEL_MULTCRL
2112 #endif
2113 
2114 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJPERM)
2115 #define PETSC_USE_FORTRAN_KERNEL_MULTAIJPERM
2116 #endif
2117 
2118 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ)
2119 #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ
2120 #endif
2121 
2122 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ)
2123 #define PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ
2124 #endif
2125 
2126 #if !defined(PETSC_USE_FORTRAN_KERNEL_NORM)
2127 #define PETSC_USE_FORTRAN_KERNEL_NORM
2128 #endif
2129 
2130 #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY)
2131 #define PETSC_USE_FORTRAN_KERNEL_MAXPY
2132 #endif
2133 
2134 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ)
2135 #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ
2136 #endif
2137 
2138 #if !defined(PETSC_USE_FORTRAN_KERNEL_RELAXAIJ)
2139 #define PETSC_USE_FORTRAN_KERNEL_RELAXAIJ
2140 #endif
2141 
2142 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ)
2143 #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ
2144 #endif
2145 
2146 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ)
2147 #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ
2148 #endif
2149 
2150 #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT)
2151 #define PETSC_USE_FORTRAN_KERNEL_MDOT
2152 #endif
2153 
2154 #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY)
2155 #define PETSC_USE_FORTRAN_KERNEL_XTIMESY
2156 #endif
2157 
2158 #if !defined(PETSC_USE_FORTRAN_KERNEL_AYPX)
2159 #define PETSC_USE_FORTRAN_KERNEL_AYPX
2160 #endif
2161 
2162 #if !defined(PETSC_USE_FORTRAN_KERNEL_WAXPY)
2163 #define PETSC_USE_FORTRAN_KERNEL_WAXPY
2164 #endif
2165 
2166 #endif
2167 
2168 /*
2169     Macros for indicating code that should be compiled with a C interface,
2170    rather than a C++ interface. Any routines that are dynamically loaded
2171    (such as the PCCreate_XXX() routines) must be wrapped so that the name
2172    mangler does not change the functions symbol name. This just hides the
2173    ugly extern "C" {} wrappers.
2174 */
2175 #if defined(__cplusplus)
2176 #define EXTERN_C_BEGIN extern "C" {
2177 #define EXTERN_C_END }
2178 #else
2179 #define EXTERN_C_BEGIN
2180 #define EXTERN_C_END
2181 #endif
2182 
2183 /* --------------------------------------------------------------------*/
2184 
2185 /*MC
2186     MPI_Comm - the basic object used by MPI to determine which processes are involved in a
2187         communication
2188 
2189    Level: beginner
2190 
2191    Note: This manual page is a place-holder because MPICH does not have a manual page for MPI_Comm
2192 
2193 .seealso: PETSC_COMM_WORLD, PETSC_COMM_SELF
2194 M*/
2195 
2196 /*MC
2197     PetscScalar - PETSc type that represents either a double precision real number, a double precision
2198        complex number, a single precision real number, a long double or an int - if the code is configured
2199        with --with-scalar-type=real,complex --with-precision=single,double,__float128
2200 
2201    Level: beginner
2202 
2203 .seealso: PetscReal, MPIU_SCALAR, PetscInt, MPIU_REAL
2204 M*/
2205 
2206 /*MC
2207     PetscComplex - PETSc type that represents a complex number with precision matching that of PetscReal.
2208 
2209    Synopsis:
2210    #include <petscsys.h>
2211    PetscComplex number = 1. + 2.*PETSC_i;
2212 
2213    Level: beginner
2214 
2215    Note:
2216    Complex numbers are automatically available if PETSc was able to find a working complex implementation
2217 
2218 .seealso: PetscReal, PetscComplex, MPIU_COMPLEX, PetscInt, PETSC_i
2219 M*/
2220 
2221 /*MC
2222     PetscReal - PETSc type that represents a real number version of PetscScalar
2223 
2224    Level: beginner
2225 
2226 .seealso: PetscScalar
2227 M*/
2228 
2229 /*MC
2230     MPIU_SCALAR - MPI datatype corresponding to PetscScalar
2231 
2232    Level: beginner
2233 
2234     Note: In MPI calls that require an MPI datatype that matches a PetscScalar or array of PetscScalars
2235           pass this value
2236 
2237 .seealso: PetscReal, PetscScalar, MPIU_INT
2238 M*/
2239 
2240 #if defined(PETSC_HAVE_MPIIO)
2241 #if !defined(PETSC_WORDS_BIGENDIAN)
2242 PETSC_EXTERN PetscErrorCode MPIU_File_write_all(MPI_File,void*,PetscMPIInt,MPI_Datatype,MPI_Status*);
2243 PETSC_EXTERN PetscErrorCode MPIU_File_read_all(MPI_File,void*,PetscMPIInt,MPI_Datatype,MPI_Status*);
2244 #else
2245 #define MPIU_File_write_all(a,b,c,d,e) MPI_File_write_all(a,b,c,d,e)
2246 #define MPIU_File_read_all(a,b,c,d,e) MPI_File_read_all(a,b,c,d,e)
2247 #endif
2248 #endif
2249 
2250 /* the following petsc_static_inline require petscerror.h */
2251 
2252 /* Limit MPI to 32-bits */
2253 #define PETSC_MPI_INT_MAX  2147483647
2254 #define PETSC_MPI_INT_MIN -2147483647
2255 /* Limit BLAS to 32-bits */
2256 #define PETSC_BLAS_INT_MAX  2147483647
2257 #define PETSC_BLAS_INT_MIN -2147483647
2258 
2259 /*@C
2260     PetscBLASIntCast - casts a PetscInt (which may be 64 bits in size) to a PetscBLASInt (which may be 32 bits in size), generates an
2261          error if the PetscBLASInt is not large enough to hold the number.
2262 
2263    Not Collective
2264 
2265    Input Parameter:
2266 .     a - the PetscInt value
2267 
2268    Output Parameter:
2269 .     b - the resulting PetscBLASInt value
2270 
2271    Level: advanced
2272 
2273 .seealso: PetscBLASInt, PetscMPIInt, PetscInt, PetscMPIIntCast()
2274 @*/
2275 PETSC_STATIC_INLINE PetscErrorCode PetscBLASIntCast(PetscInt a,PetscBLASInt *b)
2276 {
2277   PetscFunctionBegin;
2278   *b =  (PetscBLASInt)(a);
2279 #if defined(PETSC_USE_64BIT_INDICES) && !defined(PETSC_HAVE_64BIT_BLAS_INDICES)
2280   if ((a) > PETSC_BLAS_INT_MAX) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Array too long for BLAS/LAPACK");
2281 #endif
2282   PetscFunctionReturn(0);
2283 }
2284 
2285 /*@C
2286     PetscMPIIntCast - casts a PetscInt (which may be 64 bits in size) to a PetscMPIInt (which may be 32 bits in size), generates an
2287          error if the PetscMPIInt is not large enough to hold the number.
2288 
2289    Not Collective
2290 
2291    Input Parameter:
2292 .     a - the PetscInt value
2293 
2294    Output Parameter:
2295 .     b - the resulting PetscMPIInt value
2296 
2297    Level: advanced
2298 
2299 .seealso: PetscBLASInt, PetscMPIInt, PetscInt, PetscBLASIntCast()
2300 @*/
2301 PETSC_STATIC_INLINE PetscErrorCode PetscMPIIntCast(PetscInt a,PetscMPIInt *b)
2302 {
2303   PetscFunctionBegin;
2304   *b =  (PetscMPIInt)(a);
2305 #if defined(PETSC_USE_64BIT_INDICES)
2306   if ((a) > PETSC_MPI_INT_MAX) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Array too long for MPI");
2307 #endif
2308   PetscFunctionReturn(0);
2309 }
2310 
2311 #define PetscInt64Mult(a,b)   ((PetscInt64)(a))*((PetscInt64)(b))
2312 
2313 /*@C
2314 
2315    PetscRealIntMultTruncate - Computes the product of a positive PetscReal and a positive PetscInt and truncates the value to slightly less than the maximal possible value
2316 
2317    Not Collective
2318 
2319    Input Parameter:
2320 +     a - the PetscReal value
2321 -     b - the second value
2322 
2323    Output Parameter:
2324 .     c - the result as a PetscInt value
2325 
2326    Use PetscInt64Mult() to compute the product of two PetscInt as a PetscInt64
2327    Use PetscIntMultTruncate() to compute the product of two positive PetscInt and truncate to fit a PetscInt
2328    Use PetscIntMultError() to compute the product of two PetscInt if you wish to generate an error if the result will not fit in a PetscInt
2329 
2330    Developers Note: We currently assume that PetscInt addition can never overflow, this is obviously wrong but requires many more checks.
2331 
2332    This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able.
2333 
2334    Level: advanced
2335 
2336 .seealso: PetscBLASInt, PetscMPIInt, PetscInt, PetscBLASIntCast(), PetscIntMult64()
2337 @*/
2338 PETSC_STATIC_INLINE PetscInt PetscRealIntMultTruncate(PetscReal a,PetscInt b)
2339 {
2340   PetscInt64 r;
2341 
2342   r  =  (PetscInt64) (a*(PetscReal)b);
2343   if (r > PETSC_MAX_INT - 100) r = PETSC_MAX_INT - 100;
2344   return (PetscInt) r;
2345 }
2346 
2347 /*@C
2348 
2349    PetscIntMultTruncate - Computes the product of two positive PetscInt and truncates the value to slightly less than the maximal possible value
2350 
2351    Not Collective
2352 
2353    Input Parameter:
2354 +     a - the PetscInt value
2355 -     b - the second value
2356 
2357    Output Parameter:
2358 .     c - the result as a PetscInt value
2359 
2360    Use PetscInt64Mult() to compute the product of two PetscInt as a PetscInt64
2361    Use PetscRealIntMultTruncate() to compute the product of a PetscReal and a PetscInt and truncate to fit a PetscInt
2362    Use PetscIntMultError() to compute the product of two PetscInt if you wish to generate an error if the result will not fit in a PetscInt
2363 
2364    Developers Note: We currently assume that PetscInt addition can never overflow, this is obviously wrong but requires many more checks.
2365 
2366    This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able.
2367 
2368    Level: advanced
2369 
2370 .seealso: PetscBLASInt, PetscMPIInt, PetscInt, PetscBLASIntCast(), PetscIntMult64()
2371 @*/
2372 PETSC_STATIC_INLINE PetscInt PetscIntMultTruncate(PetscInt a,PetscInt b)
2373 {
2374   PetscInt64 r;
2375 
2376   r  =  PetscInt64Mult(a,b);
2377   if (r > PETSC_MAX_INT - 100) r = PETSC_MAX_INT - 100;
2378   return (PetscInt) r;
2379 }
2380 
2381 /*@C
2382 
2383    PetscIntSumTruncate - Computes the sum of two positive PetscInt and truncates the value to slightly less than the maximal possible value
2384 
2385    Not Collective
2386 
2387    Input Parameter:
2388 +     a - the PetscInt value
2389 -     b - the second value
2390 
2391    Output Parameter:
2392 .     c - the result as a PetscInt value
2393 
2394    Use PetscInt64Mult() to compute the product of two PetscInt as a PetscInt64
2395    Use PetscRealIntMultTruncate() to compute the product of a PetscReal and a PetscInt and truncate to fit a PetscInt
2396    Use PetscIntMultError() to compute the product of two PetscInt if you wish to generate an error if the result will not fit in a PetscInt
2397 
2398    This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able.
2399 
2400    Level: advanced
2401 
2402 .seealso: PetscBLASInt, PetscMPIInt, PetscInt, PetscBLASIntCast(), PetscIntMult64()
2403 @*/
2404 PETSC_STATIC_INLINE PetscInt PetscIntSumTruncate(PetscInt a,PetscInt b)
2405 {
2406   PetscInt64 r;
2407 
2408   r  =  ((PetscInt64)a) + ((PetscInt64)b);
2409   if (r > PETSC_MAX_INT - 100) r = PETSC_MAX_INT - 100;
2410   return (PetscInt) r;
2411 }
2412 
2413 /*@C
2414 
2415    PetscIntMultError - Computes the product of two positive PetscInt and generates an error with overflow.
2416 
2417    Not Collective
2418 
2419    Input Parameter:
2420 +     a - the PetscInt value
2421 -     b - the second value
2422 
2423    Output Parameter:ma
2424 .     c - the result as a PetscInt value, or NULL if you do not want the result, you just want to check if it overflows
2425 
2426    Use PetscInt64Mult() to compute the product of two 32 bit PetscInt and store in a PetscInt64
2427    Use PetscIntMultTruncate() to compute the product of two PetscInt and truncate it to fit in a PetscInt
2428 
2429    Developers Note: We currently assume that PetscInt addition does not overflow, this is obviously wrong but requires many more checks.
2430 
2431    Level: advanced
2432 
2433 .seealso: PetscBLASInt, PetscMPIInt, PetscInt, PetscBLASIntCast(), PetscIntMult64(), PetscIntSumError()
2434 @*/
2435 PETSC_STATIC_INLINE PetscErrorCode PetscIntMultError(PetscInt a,PetscInt b,PetscInt *result)
2436 {
2437   PetscInt64 r;
2438 
2439   PetscFunctionBegin;
2440   r  =  PetscInt64Mult(a,b);
2441 #if !defined(PETSC_USE_64BIT_INDICES)
2442   if (r > PETSC_MAX_INT) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_SUP,"Product of two integer %d %d overflow, you must ./configure PETSc with --with-64-bit-indices for the case you are running",a,b);
2443 #endif
2444   if (result) *result = (PetscInt) r;
2445   PetscFunctionReturn(0);
2446 }
2447 
2448 /*@C
2449 
2450    PetscIntSumError - Computes the sum of two positive PetscInt and generates an error with overflow.
2451 
2452    Not Collective
2453 
2454    Input Parameter:
2455 +     a - the PetscInt value
2456 -     b - the second value
2457 
2458    Output Parameter:ma
2459 .     c - the result as a PetscInt value
2460 
2461    Use PetscInt64Mult() to compute the product of two 32 bit PetscInt and store in a PetscInt64
2462    Use PetscIntMultTruncate() to compute the product of two PetscInt and truncate it to fit in a PetscInt
2463 
2464    Level: advanced
2465 
2466 .seealso: PetscBLASInt, PetscMPIInt, PetscInt, PetscBLASIntCast(), PetscIntMult64()
2467 @*/
2468 PETSC_STATIC_INLINE PetscErrorCode PetscIntSumError(PetscInt a,PetscInt b,PetscInt *result)
2469 {
2470   PetscInt64 r;
2471 
2472   PetscFunctionBegin;
2473   r  =  ((PetscInt64)a) + ((PetscInt64)b);
2474 #if !defined(PETSC_USE_64BIT_INDICES)
2475   if (r > PETSC_MAX_INT) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_SUP,"Sum of two integer %d %d overflow, you must ./configure PETSc with --with-64-bit-indices for the case you are running",a,b);
2476 #endif
2477   if (result) *result = (PetscInt) r;
2478   PetscFunctionReturn(0);
2479 }
2480 
2481 /*
2482      The IBM include files define hz, here we hide it so that it may be used as a regular user variable.
2483 */
2484 #if defined(hz)
2485 #undef hz
2486 #endif
2487 
2488 /*  For arrays that contain filenames or paths */
2489 
2490 
2491 #if defined(PETSC_HAVE_LIMITS_H)
2492 #include <limits.h>
2493 #endif
2494 #if defined(PETSC_HAVE_SYS_PARAM_H)
2495 #include <sys/param.h>
2496 #endif
2497 #if defined(PETSC_HAVE_SYS_TYPES_H)
2498 #include <sys/types.h>
2499 #endif
2500 #if defined(MAXPATHLEN)
2501 #  define PETSC_MAX_PATH_LEN     MAXPATHLEN
2502 #elif defined(MAX_PATH)
2503 #  define PETSC_MAX_PATH_LEN     MAX_PATH
2504 #elif defined(_MAX_PATH)
2505 #  define PETSC_MAX_PATH_LEN     _MAX_PATH
2506 #else
2507 #  define PETSC_MAX_PATH_LEN     4096
2508 #endif
2509 
2510 /*MC
2511 
2512     UsingFortran - To use PETSc with Fortran you must use both PETSc include files and modules. At the beginning
2513       of every function and module definition you need something like
2514 
2515 $
2516 $#include "petsc/finclude/petscXXX.h"
2517 $         use petscXXXX
2518 
2519      You can delcare PETSc variables using either
2520 
2521 $    XXX variablename
2522 $    type(tXXX) variablename
2523 
2524     for example
2525 
2526 $#include "petsc/finclude/petscvec.h"
2527 $         use petscvec
2528 $
2529 $    Vec  A
2530 $    type(tVec) A
2531 
2532     Level: beginner
2533 
2534 M*/
2535 
2536 PETSC_EXTERN PetscErrorCode PetscGetArchType(char[],size_t);
2537 PETSC_EXTERN PetscErrorCode PetscGetHostName(char[],size_t);
2538 PETSC_EXTERN PetscErrorCode PetscGetUserName(char[],size_t);
2539 PETSC_EXTERN PetscErrorCode PetscGetProgramName(char[],size_t);
2540 PETSC_EXTERN PetscErrorCode PetscSetProgramName(const char[]);
2541 PETSC_EXTERN PetscErrorCode PetscGetDate(char[],size_t);
2542 PETSC_EXTERN PetscErrorCode PetscGetVersion(char[], size_t);
2543 PETSC_EXTERN PetscErrorCode PetscGetVersionNumber(PetscInt*,PetscInt*,PetscInt*,PetscInt*);
2544 
2545 PETSC_EXTERN PetscErrorCode PetscSortInt(PetscInt,PetscInt[]);
2546 PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsInt(PetscInt*,PetscInt[]);
2547 PETSC_EXTERN PetscErrorCode PetscFindInt(PetscInt, PetscInt, const PetscInt[], PetscInt*);
2548 PETSC_EXTERN PetscErrorCode PetscSortIntWithPermutation(PetscInt,const PetscInt[],PetscInt[]);
2549 PETSC_EXTERN PetscErrorCode PetscSortStrWithPermutation(PetscInt,const char*[],PetscInt[]);
2550 PETSC_EXTERN PetscErrorCode PetscSortIntWithArray(PetscInt,PetscInt[],PetscInt[]);
2551 PETSC_EXTERN PetscErrorCode PetscSortIntWithArrayPair(PetscInt,PetscInt[],PetscInt[],PetscInt[]);
2552 PETSC_EXTERN PetscErrorCode PetscSortMPIInt(PetscInt,PetscMPIInt[]);
2553 PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsMPIInt(PetscInt*,PetscMPIInt[]);
2554 PETSC_EXTERN PetscErrorCode PetscSortMPIIntWithArray(PetscMPIInt,PetscMPIInt[],PetscMPIInt[]);
2555 PETSC_EXTERN PetscErrorCode PetscSortIntWithScalarArray(PetscInt,PetscInt[],PetscScalar[]);
2556 PETSC_EXTERN PetscErrorCode PetscSortIntWithDataArray(PetscInt,PetscInt[],void*,size_t,void*);
2557 PETSC_EXTERN PetscErrorCode PetscSortReal(PetscInt,PetscReal[]);
2558 PETSC_EXTERN PetscErrorCode PetscSortRealWithPermutation(PetscInt,const PetscReal[],PetscInt[]);
2559 PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsReal(PetscInt*,PetscReal[]);
2560 PETSC_EXTERN PetscErrorCode PetscSortSplit(PetscInt,PetscInt,PetscScalar[],PetscInt[]);
2561 PETSC_EXTERN PetscErrorCode PetscSortSplitReal(PetscInt,PetscInt,PetscReal[],PetscInt[]);
2562 PETSC_EXTERN PetscErrorCode PetscProcessTree(PetscInt,const PetscBool [],const PetscInt[],PetscInt*,PetscInt**,PetscInt**,PetscInt**,PetscInt**);
2563 PETSC_EXTERN PetscErrorCode PetscMergeIntArrayPair(PetscInt,const PetscInt[],const PetscInt[],PetscInt,const PetscInt[],const PetscInt[],PetscInt*,PetscInt**,PetscInt**);
2564 PETSC_EXTERN PetscErrorCode PetscMergeIntArray(PetscInt,const PetscInt[],PetscInt,const PetscInt[],PetscInt*,PetscInt**);
2565 PETSC_EXTERN PetscErrorCode PetscMergeMPIIntArray(PetscInt,const PetscMPIInt[],PetscInt,const PetscMPIInt[],PetscInt*,PetscMPIInt**);
2566 
2567 PETSC_EXTERN PetscErrorCode PetscSetDisplay(void);
2568 PETSC_EXTERN PetscErrorCode PetscGetDisplay(char[],size_t);
2569 
2570 /*J
2571     PetscRandomType - String with the name of a PETSc randomizer
2572 
2573    Level: beginner
2574 
2575    Notes: to use the SPRNG you must have ./configure PETSc
2576    with the option --download-sprng
2577 
2578 .seealso: PetscRandomSetType(), PetscRandom, PetscRandomCreate()
2579 J*/
2580 typedef const char* PetscRandomType;
2581 #define PETSCRAND       "rand"
2582 #define PETSCRAND48     "rand48"
2583 #define PETSCSPRNG      "sprng"
2584 #define PETSCRANDER48   "rander48"
2585 
2586 /* Logging support */
2587 PETSC_EXTERN PetscClassId PETSC_RANDOM_CLASSID;
2588 
2589 PETSC_EXTERN PetscErrorCode PetscRandomInitializePackage(void);
2590 
2591 /*S
2592      PetscRandom - Abstract PETSc object that manages generating random numbers
2593 
2594    Level: intermediate
2595 
2596   Concepts: random numbers
2597 
2598 .seealso:  PetscRandomCreate(), PetscRandomGetValue(), PetscRandomType
2599 S*/
2600 typedef struct _p_PetscRandom*   PetscRandom;
2601 
2602 /* Dynamic creation and loading functions */
2603 PETSC_EXTERN PetscFunctionList PetscRandomList;
2604 
2605 PETSC_EXTERN PetscErrorCode PetscRandomRegister(const char[],PetscErrorCode (*)(PetscRandom));
2606 PETSC_EXTERN PetscErrorCode PetscRandomSetType(PetscRandom, PetscRandomType);
2607 PETSC_EXTERN PetscErrorCode PetscRandomSetFromOptions(PetscRandom);
2608 PETSC_EXTERN PetscErrorCode PetscRandomGetType(PetscRandom, PetscRandomType*);
2609 PETSC_STATIC_INLINE PetscErrorCode PetscRandomViewFromOptions(PetscRandom A,PetscObject obj,const char name[]) {return PetscObjectViewFromOptions((PetscObject)A,obj,name);}
2610 PETSC_EXTERN PetscErrorCode PetscRandomView(PetscRandom,PetscViewer);
2611 
2612 PETSC_EXTERN PetscErrorCode PetscRandomCreate(MPI_Comm,PetscRandom*);
2613 PETSC_EXTERN PetscErrorCode PetscRandomGetValue(PetscRandom,PetscScalar*);
2614 PETSC_EXTERN PetscErrorCode PetscRandomGetValueReal(PetscRandom,PetscReal*);
2615 PETSC_EXTERN PetscErrorCode PetscRandomGetInterval(PetscRandom,PetscScalar*,PetscScalar*);
2616 PETSC_EXTERN PetscErrorCode PetscRandomSetInterval(PetscRandom,PetscScalar,PetscScalar);
2617 PETSC_EXTERN PetscErrorCode PetscRandomSetSeed(PetscRandom,unsigned long);
2618 PETSC_EXTERN PetscErrorCode PetscRandomGetSeed(PetscRandom,unsigned long *);
2619 PETSC_EXTERN PetscErrorCode PetscRandomSeed(PetscRandom);
2620 PETSC_EXTERN PetscErrorCode PetscRandomDestroy(PetscRandom*);
2621 
2622 PETSC_EXTERN PetscErrorCode PetscGetFullPath(const char[],char[],size_t);
2623 PETSC_EXTERN PetscErrorCode PetscGetRelativePath(const char[],char[],size_t);
2624 PETSC_EXTERN PetscErrorCode PetscGetWorkingDirectory(char[],size_t);
2625 PETSC_EXTERN PetscErrorCode PetscGetRealPath(const char[],char[]);
2626 PETSC_EXTERN PetscErrorCode PetscGetHomeDirectory(char[],size_t);
2627 PETSC_EXTERN PetscErrorCode PetscTestFile(const char[],char,PetscBool *);
2628 PETSC_EXTERN PetscErrorCode PetscTestDirectory(const char[],char,PetscBool *);
2629 PETSC_EXTERN PetscErrorCode PetscMkdir(const char[]);
2630 PETSC_EXTERN PetscErrorCode PetscRMTree(const char[]);
2631 
2632 PETSC_EXTERN PetscErrorCode PetscBinaryRead(int,void*,PetscInt,PetscDataType);
2633 PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedRead(MPI_Comm,int,void*,PetscInt,PetscDataType);
2634 PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedWrite(MPI_Comm,int,void*,PetscInt,PetscDataType,PetscBool );
2635 PETSC_EXTERN PetscErrorCode PetscBinaryWrite(int,void*,PetscInt,PetscDataType,PetscBool );
2636 PETSC_EXTERN PetscErrorCode PetscBinaryOpen(const char[],PetscFileMode,int *);
2637 PETSC_EXTERN PetscErrorCode PetscBinaryClose(int);
2638 PETSC_EXTERN PetscErrorCode PetscSharedTmp(MPI_Comm,PetscBool  *);
2639 PETSC_EXTERN PetscErrorCode PetscSharedWorkingDirectory(MPI_Comm,PetscBool  *);
2640 PETSC_EXTERN PetscErrorCode PetscGetTmp(MPI_Comm,char[],size_t);
2641 PETSC_EXTERN PetscErrorCode PetscFileRetrieve(MPI_Comm,const char[],char[],size_t,PetscBool *);
2642 PETSC_EXTERN PetscErrorCode PetscLs(MPI_Comm,const char[],char[],size_t,PetscBool *);
2643 PETSC_EXTERN PetscErrorCode PetscOpenSocket(const char[],int,int*);
2644 
2645 /*
2646    In binary files variables are stored using the following lengths,
2647   regardless of how they are stored in memory on any one particular
2648   machine. Use these rather then sizeof() in computing sizes for
2649   PetscBinarySeek().
2650 */
2651 #define PETSC_BINARY_INT_SIZE   (32/8)
2652 #define PETSC_BINARY_FLOAT_SIZE  (32/8)
2653 #define PETSC_BINARY_CHAR_SIZE  (8/8)
2654 #define PETSC_BINARY_SHORT_SIZE  (16/8)
2655 #define PETSC_BINARY_DOUBLE_SIZE  (64/8)
2656 #define PETSC_BINARY_SCALAR_SIZE  sizeof(PetscScalar)
2657 
2658 /*E
2659   PetscBinarySeekType - argument to PetscBinarySeek()
2660 
2661   Level: advanced
2662 
2663 .seealso: PetscBinarySeek(), PetscBinarySynchronizedSeek()
2664 E*/
2665 typedef enum {PETSC_BINARY_SEEK_SET = 0,PETSC_BINARY_SEEK_CUR = 1,PETSC_BINARY_SEEK_END = 2} PetscBinarySeekType;
2666 PETSC_EXTERN PetscErrorCode PetscBinarySeek(int,off_t,PetscBinarySeekType,off_t*);
2667 PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedSeek(MPI_Comm,int,off_t,PetscBinarySeekType,off_t*);
2668 PETSC_EXTERN PetscErrorCode PetscByteSwap(void *,PetscDataType,PetscInt);
2669 
2670 PETSC_EXTERN PetscErrorCode PetscSetDebugTerminal(const char[]);
2671 PETSC_EXTERN PetscErrorCode PetscSetDebugger(const char[],PetscBool );
2672 PETSC_EXTERN PetscErrorCode PetscSetDefaultDebugger(void);
2673 PETSC_EXTERN PetscErrorCode PetscSetDebuggerFromString(const char*);
2674 PETSC_EXTERN PetscErrorCode PetscAttachDebugger(void);
2675 PETSC_EXTERN PetscErrorCode PetscStopForDebugger(void);
2676 
2677 PETSC_EXTERN PetscErrorCode PetscGatherNumberOfMessages(MPI_Comm,const PetscMPIInt[],const PetscMPIInt[],PetscMPIInt*);
2678 PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],PetscMPIInt**,PetscMPIInt**);
2679 PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths2(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],const PetscMPIInt[],PetscMPIInt**,PetscMPIInt**,PetscMPIInt**);
2680 PETSC_EXTERN PetscErrorCode PetscPostIrecvInt(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],const PetscMPIInt[],PetscInt***,MPI_Request**);
2681 PETSC_EXTERN PetscErrorCode PetscPostIrecvScalar(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],const PetscMPIInt[],PetscScalar***,MPI_Request**);
2682 PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSided(MPI_Comm,PetscMPIInt,MPI_Datatype,PetscMPIInt,const PetscMPIInt*,const void*,PetscMPIInt*,PetscMPIInt**,void*)
2683   PetscAttrMPIPointerWithType(6,3);
2684 PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedF(MPI_Comm,PetscMPIInt,MPI_Datatype,PetscMPIInt,const PetscMPIInt[],const void*,PetscMPIInt*,PetscMPIInt**,void*,PetscMPIInt,
2685                                                     PetscErrorCode (*send)(MPI_Comm,const PetscMPIInt[],PetscMPIInt,PetscMPIInt,void*,MPI_Request[],void*),
2686                                                     PetscErrorCode (*recv)(MPI_Comm,const PetscMPIInt[],PetscMPIInt,void*,MPI_Request[],void*),void *ctx)
2687   PetscAttrMPIPointerWithType(6,3);
2688 PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedFReq(MPI_Comm,PetscMPIInt,MPI_Datatype,PetscMPIInt,const PetscMPIInt[],const void*,PetscMPIInt*,PetscMPIInt**,void*,PetscMPIInt,
2689                                                        MPI_Request**,MPI_Request**,
2690                                                        PetscErrorCode (*send)(MPI_Comm,const PetscMPIInt[],PetscMPIInt,PetscMPIInt,void*,MPI_Request[],void*),
2691                                                        PetscErrorCode (*recv)(MPI_Comm,const PetscMPIInt[],PetscMPIInt,void*,MPI_Request[],void*),void *ctx)
2692   PetscAttrMPIPointerWithType(6,3);
2693 
2694 /*E
2695     PetscBuildTwoSidedType - algorithm for setting up two-sided communication
2696 
2697 $  PETSC_BUILDTWOSIDED_ALLREDUCE - classical algorithm using an MPI_Allreduce with
2698 $      a buffer of length equal to the communicator size. Not memory-scalable due to
2699 $      the large reduction size. Requires only MPI-1.
2700 $  PETSC_BUILDTWOSIDED_IBARRIER - nonblocking algorithm based on MPI_Issend and MPI_Ibarrier.
2701 $      Proved communication-optimal in Hoefler, Siebert, and Lumsdaine (2010). Requires MPI-3.
2702 $  PETSC_BUILDTWOSIDED_REDSCATTER - similar to above, but use more optimized function
2703 $      that only communicates the part of the reduction that is necessary.  Requires MPI-2.
2704 
2705    Level: developer
2706 
2707 .seealso: PetscCommBuildTwoSided(), PetscCommBuildTwoSidedSetType(), PetscCommBuildTwoSidedGetType()
2708 E*/
2709 typedef enum {
2710   PETSC_BUILDTWOSIDED_NOTSET = -1,
2711   PETSC_BUILDTWOSIDED_ALLREDUCE = 0,
2712   PETSC_BUILDTWOSIDED_IBARRIER = 1,
2713   PETSC_BUILDTWOSIDED_REDSCATTER = 2
2714   /* Updates here must be accompanied by updates in finclude/petscsys.h and the string array in mpits.c */
2715 } PetscBuildTwoSidedType;
2716 PETSC_EXTERN const char *const PetscBuildTwoSidedTypes[];
2717 PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedSetType(MPI_Comm,PetscBuildTwoSidedType);
2718 PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedGetType(MPI_Comm,PetscBuildTwoSidedType*);
2719 
2720 PETSC_EXTERN PetscErrorCode PetscSSEIsEnabled(MPI_Comm,PetscBool  *,PetscBool  *);
2721 
2722 /*E
2723   InsertMode - Whether entries are inserted or added into vectors or matrices
2724 
2725   Level: beginner
2726 
2727 .seealso: VecSetValues(), MatSetValues(), VecSetValue(), VecSetValuesBlocked(),
2728           VecSetValuesLocal(), VecSetValuesBlockedLocal(), MatSetValuesBlocked(),
2729           MatSetValuesBlockedLocal(), MatSetValuesLocal(), VecScatterBegin(), VecScatterEnd()
2730 E*/
2731  typedef enum {NOT_SET_VALUES, INSERT_VALUES, ADD_VALUES, MAX_VALUES, INSERT_ALL_VALUES, ADD_ALL_VALUES, INSERT_BC_VALUES, ADD_BC_VALUES} InsertMode;
2732 
2733 /*MC
2734     INSERT_VALUES - Put a value into a vector or matrix, overwrites any previous value
2735 
2736     Level: beginner
2737 
2738 .seealso: InsertMode, VecSetValues(), MatSetValues(), VecSetValue(), VecSetValuesBlocked(),
2739           VecSetValuesLocal(), VecSetValuesBlockedLocal(), MatSetValuesBlocked(), ADD_VALUES,
2740           MatSetValuesBlockedLocal(), MatSetValuesLocal(), VecScatterBegin(), VecScatterEnd(), MAX_VALUES
2741 
2742 M*/
2743 
2744 /*MC
2745     ADD_VALUES - Adds a value into a vector or matrix, if there previously was no value, just puts the
2746                 value into that location
2747 
2748     Level: beginner
2749 
2750 .seealso: InsertMode, VecSetValues(), MatSetValues(), VecSetValue(), VecSetValuesBlocked(),
2751           VecSetValuesLocal(), VecSetValuesBlockedLocal(), MatSetValuesBlocked(), INSERT_VALUES,
2752           MatSetValuesBlockedLocal(), MatSetValuesLocal(), VecScatterBegin(), VecScatterEnd(), MAX_VALUES
2753 
2754 M*/
2755 
2756 /*MC
2757     MAX_VALUES - Puts the maximum of the scattered/gathered value and the current value into each location
2758 
2759     Level: beginner
2760 
2761 .seealso: InsertMode, VecScatterBegin(), VecScatterEnd(), ADD_VALUES, INSERT_VALUES
2762 
2763 M*/
2764 
2765 PETSC_EXTERN MPI_Comm PetscObjectComm(PetscObject);
2766 
2767 typedef enum {PETSC_SUBCOMM_GENERAL=0,PETSC_SUBCOMM_CONTIGUOUS=1,PETSC_SUBCOMM_INTERLACED=2} PetscSubcommType;
2768 PETSC_EXTERN const char *const PetscSubcommTypes[];
2769 
2770 /*S
2771    PetscSubcomm - A decomposition of an MPI communicator into subcommunicators
2772 
2773    Notes: After a call to PetscSubcommSetType(), PetscSubcommSetTypeGeneral(), or PetscSubcommSetFromOptions() one may call
2774 $     PetscSubcommChild() returns the associated subcommunicator on this process
2775 $     PetscSubcommContiguousParent() returns a parent communitor but with all child of the same subcommunicator having contiguous rank
2776 
2777    Sample Usage:
2778        PetscSubcommCreate()
2779        PetscSubcommSetNumber()
2780        PetscSubcommSetType(PETSC_SUBCOMM_INTERLACED);
2781        ccomm = PetscSubcommChild()
2782        PetscSubcommDestroy()
2783 
2784    Level: advanced
2785 
2786    Concepts: communicator, create
2787 
2788    Notes:
2789 $   PETSC_SUBCOMM_GENERAL - similar to MPI_Comm_split() each process sets the new communicator (color) they will belong to and the order within that communicator
2790 $   PETSC_SUBCOMM_CONTIGUOUS - each new communicator contains a set of process with contiguous ranks in the original MPI communicator
2791 $   PETSC_SUBCOMM_INTERLACED - each new communictor contains a set of processes equally far apart in rank from the others in that new communicator
2792 
2793    Examaple: Consider a communicator with six processes split into 3 subcommunicators.
2794 $     PETSC_SUBCOMM_CONTIGUOUS - the first communicator contains rank 0,1  the second rank 2,3 and the third rank 4,5 in the original ordering of the original communicator
2795 $     PETSC_SUBCOMM_INTERLACED - the first communicator contains rank 0,3, the second 1,4 and the third 2,5
2796 
2797    Developer Notes: This is used in objects such as PCREDUNDANT() to manage the subcommunicators on which the redundant computations
2798       are performed.
2799 
2800 
2801 .seealso: PetscSubcommCreate(), PetscSubcommSetNumber(), PetscSubcommSetType(), PetscSubcommView(), PetscSubcommSetFromOptions()
2802 
2803 S*/
2804 typedef struct _n_PetscSubcomm* PetscSubcomm;
2805 
2806 struct _n_PetscSubcomm {
2807   MPI_Comm         parent;           /* parent communicator */
2808   MPI_Comm         dupparent;        /* duplicate parent communicator, under which the processors of this subcomm have contiguous rank */
2809   MPI_Comm         child;            /* the sub-communicator */
2810   PetscMPIInt      n;                /* num of subcommunicators under the parent communicator */
2811   PetscMPIInt      color;            /* color of processors belong to this communicator */
2812   PetscMPIInt      *subsize;         /* size of subcommunicator[color] */
2813   PetscSubcommType type;
2814   char             *subcommprefix;
2815 };
2816 
2817 PETSC_STATIC_INLINE MPI_Comm PetscSubcommParent(PetscSubcomm scomm) {return scomm->parent;}
2818 PETSC_STATIC_INLINE MPI_Comm PetscSubcommChild(PetscSubcomm scomm) {return scomm->child;}
2819 PETSC_STATIC_INLINE MPI_Comm PetscSubcommContiguousParent(PetscSubcomm scomm) {return scomm->dupparent;}
2820 PETSC_EXTERN PetscErrorCode PetscSubcommCreate(MPI_Comm,PetscSubcomm*);
2821 PETSC_EXTERN PetscErrorCode PetscSubcommDestroy(PetscSubcomm*);
2822 PETSC_EXTERN PetscErrorCode PetscSubcommSetNumber(PetscSubcomm,PetscInt);
2823 PETSC_EXTERN PetscErrorCode PetscSubcommSetType(PetscSubcomm,PetscSubcommType);
2824 PETSC_EXTERN PetscErrorCode PetscSubcommSetTypeGeneral(PetscSubcomm,PetscMPIInt,PetscMPIInt);
2825 PETSC_EXTERN PetscErrorCode PetscSubcommView(PetscSubcomm,PetscViewer);
2826 PETSC_EXTERN PetscErrorCode PetscSubcommSetFromOptions(PetscSubcomm);
2827 PETSC_EXTERN PetscErrorCode PetscSubcommSetOptionsPrefix(PetscSubcomm,const char[]);
2828 
2829 /*S
2830      PetscHeap - A simple class for managing heaps
2831 
2832    Level: intermediate
2833 
2834   Concepts: random numbers
2835 
2836 .seealso:  PetscHeapCreate(), PetscHeapAdd(), PetscHeapPop(), PetscHeapPeek(), PetscHeapStash(), PetscHeapUnstash(), PetscHeapView(), PetscHeapDestroy()
2837 S*/
2838 typedef struct _PetscHeap *PetscHeap;
2839 
2840 PETSC_EXTERN PetscErrorCode PetscHeapCreate(PetscInt,PetscHeap*);
2841 PETSC_EXTERN PetscErrorCode PetscHeapAdd(PetscHeap,PetscInt,PetscInt);
2842 PETSC_EXTERN PetscErrorCode PetscHeapPop(PetscHeap,PetscInt*,PetscInt*);
2843 PETSC_EXTERN PetscErrorCode PetscHeapPeek(PetscHeap,PetscInt*,PetscInt*);
2844 PETSC_EXTERN PetscErrorCode PetscHeapStash(PetscHeap,PetscInt,PetscInt);
2845 PETSC_EXTERN PetscErrorCode PetscHeapUnstash(PetscHeap);
2846 PETSC_EXTERN PetscErrorCode PetscHeapDestroy(PetscHeap*);
2847 PETSC_EXTERN PetscErrorCode PetscHeapView(PetscHeap,PetscViewer);
2848 
2849 /*S
2850    PetscSegBuffer - a segmented extendable buffer
2851 
2852    Level: developer
2853 
2854 .seealso: PetscSegBufferCreate(), PetscSegBufferGet(), PetscSegBufferExtract(), PetscSegBufferDestroy()
2855 S*/
2856 typedef struct _n_PetscSegBuffer *PetscSegBuffer;
2857 PETSC_EXTERN PetscErrorCode PetscSegBufferCreate(size_t,size_t,PetscSegBuffer*);
2858 PETSC_EXTERN PetscErrorCode PetscSegBufferDestroy(PetscSegBuffer*);
2859 PETSC_EXTERN PetscErrorCode PetscSegBufferGet(PetscSegBuffer,size_t,void*);
2860 PETSC_EXTERN PetscErrorCode PetscSegBufferExtractAlloc(PetscSegBuffer,void*);
2861 PETSC_EXTERN PetscErrorCode PetscSegBufferExtractTo(PetscSegBuffer,void*);
2862 PETSC_EXTERN PetscErrorCode PetscSegBufferExtractInPlace(PetscSegBuffer,void*);
2863 PETSC_EXTERN PetscErrorCode PetscSegBufferGetSize(PetscSegBuffer,size_t*);
2864 PETSC_EXTERN PetscErrorCode PetscSegBufferUnuse(PetscSegBuffer,size_t);
2865 
2866 /* Type-safe wrapper to encourage use of PETSC_RESTRICT. Does not use PetscFunctionBegin because the error handling
2867  * prevents the compiler from completely erasing the stub. This is called in inner loops so it has to be as fast as
2868  * possible. */
2869 PETSC_STATIC_INLINE PetscErrorCode PetscSegBufferGetInts(PetscSegBuffer seg,PetscInt count,PetscInt *PETSC_RESTRICT *slot) {return PetscSegBufferGet(seg,(size_t)count,(void**)slot);}
2870 
2871 typedef struct _n_PetscOptionsHelpPrinted *PetscOptionsHelpPrinted;
2872 extern PetscOptionsHelpPrinted PetscOptionsHelpPrintedSingleton;
2873 PETSC_EXTERN PetscErrorCode PetscOptionsHelpPrintedDestroy(PetscOptionsHelpPrinted*);
2874 PETSC_EXTERN PetscErrorCode PetscOptionsHelpPrintedCreate(PetscOptionsHelpPrinted*);
2875 PETSC_EXTERN PetscErrorCode PetscOptionsHelpPrintedCheck(PetscOptionsHelpPrinted,const char*,const char*,PetscBool*);
2876 
2877 PETSC_EXTERN PetscSegBuffer PetscCitationsList;
2878 
2879 /*@C
2880       PetscCitationsRegister - Register a bibtex item to obtain credit for an implemented algorithm used in the code.
2881 
2882      Not Collective - only what is registered on rank 0 of PETSC_COMM_WORLD will be printed
2883 
2884      Input Parameters:
2885 +      cite - the bibtex item, formated to displayed on multiple lines nicely
2886 -      set - a boolean variable initially set to PETSC_FALSE; this is used to insure only a single registration of the citation
2887 
2888    Level: intermediate
2889 
2890      Options Database:
2891 .     -citations [filename]   - print out the bibtex entries for the given computation
2892 @*/
2893 PETSC_STATIC_INLINE PetscErrorCode PetscCitationsRegister(const char cit[],PetscBool *set)
2894 {
2895   size_t         len;
2896   char           *vstring;
2897   PetscErrorCode ierr;
2898 
2899   PetscFunctionBegin;
2900   if (set && *set) PetscFunctionReturn(0);
2901   ierr = PetscStrlen(cit,&len);CHKERRQ(ierr);
2902   ierr = PetscSegBufferGet(PetscCitationsList,len,&vstring);CHKERRQ(ierr);
2903   ierr = PetscMemcpy(vstring,cit,len);CHKERRQ(ierr);
2904   if (set) *set = PETSC_TRUE;
2905   PetscFunctionReturn(0);
2906 }
2907 
2908 PETSC_EXTERN PetscErrorCode PetscURLShorten(const char[],char[],size_t);
2909 PETSC_EXTERN PetscErrorCode PetscGoogleDriveAuthorize(MPI_Comm,char[],char[],size_t);
2910 PETSC_EXTERN PetscErrorCode PetscGoogleDriveRefresh(MPI_Comm,const char[],char[],size_t);
2911 PETSC_EXTERN PetscErrorCode PetscGoogleDriveUpload(MPI_Comm,const char[],const char []);
2912 
2913 PETSC_EXTERN PetscErrorCode PetscBoxAuthorize(MPI_Comm,char[],char[],size_t);
2914 PETSC_EXTERN PetscErrorCode PetscBoxRefresh(MPI_Comm,const char[],char[],char[],size_t);
2915 
2916 PETSC_EXTERN PetscErrorCode PetscTextBelt(MPI_Comm,const char[],const char[],PetscBool*);
2917 PETSC_EXTERN PetscErrorCode PetscTellMyCell(MPI_Comm,const char[],const char[],PetscBool*);
2918 
2919 PETSC_EXTERN PetscErrorCode PetscPullJSONValue(const char[],const char[],char[],size_t,PetscBool*);
2920 PETSC_EXTERN PetscErrorCode PetscPushJSONValue(char[],const char[],const char[],size_t);
2921 
2922 
2923 #if defined(PETSC_USE_DEBUG)
2924 /*
2925    Verify that all processes in the communicator have called this from the same line of code
2926  */
2927 PETSC_EXTERN PetscErrorCode PetscAllreduceBarrierCheck(MPI_Comm,PetscMPIInt,int,const char*,const char *);
2928 
2929 /*MC
2930    MPIU_Allreduce - a PETSc replacement for MPI_Allreduce() that tries to determine if the call from all the MPI processes occur from the
2931                     same place in the PETSc code. This helps to detect bugs where different MPI processes follow different code paths
2932                     resulting in inconsistent and incorrect calls to MPI_Allreduce().
2933 
2934    Collective on MPI_Comm
2935 
2936    Synopsis:
2937      #include <petscsys.h>
2938      PetscErrorCode MPIU_Allreduce(void *indata,void *outdata,PetscMPIInt count,MPI_Datatype datatype, MPI_Op op, MPI_Comm comm);
2939 
2940    Input Parameters:
2941 +  indata - pointer to the input data to be reduced
2942 .  count - the number of MPI data items in indata and outdata
2943 .  datatype - the MPI datatype, for example MPI_INT
2944 .  op - the MPI operation, for example MPI_SUM
2945 -  comm - the MPI communicator on which the operation occurs
2946 
2947    Output Parameter:
2948 .  outdata - the reduced values
2949 
2950    Notes: In optimized mode this directly calls MPI_Allreduce()
2951 
2952    Level: developer
2953 
2954 .seealso: MPI_Allreduce()
2955 M*/
2956 #define MPIU_Allreduce(a,b,c,d,e,fcomm) (PetscAllreduceBarrierCheck(fcomm,c,__LINE__,PETSC_FUNCTION_NAME,__FILE__) || MPI_Allreduce(a,b,c,d,e,fcomm))
2957 #else
2958 #define MPIU_Allreduce(a,b,c,d,e,fcomm) MPI_Allreduce(a,b,c,d,e,fcomm)
2959 #endif
2960 
2961 #endif
2962