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