xref: /petsc/include/petscsys.h (revision 66122d6d08081cefa2d0f3b7d9c0546bcc20ae32)
1d382aafbSBarry Smith /*
2d382aafbSBarry Smith    This is the main PETSc include file (for C and C++).  It is included by all
3d382aafbSBarry Smith    other PETSc include files, so it almost never has to be specifically included.
4d382aafbSBarry Smith */
526bd1501SBarry Smith #if !defined(PETSCSYS_H)
626bd1501SBarry Smith #define PETSCSYS_H
73ca90d2dSJacob Faibussowitsch 
8d382aafbSBarry Smith /* ========================================================================== */
9d382aafbSBarry Smith /*
10d382aafbSBarry Smith    petscconf.h is contained in ${PETSC_ARCH}/include/petscconf.h it is
111c77a0c5SBarry Smith    found automatically by the compiler due to the -I${PETSC_DIR}/${PETSC_ARCH}/include that
121c77a0c5SBarry Smith    PETSc's makefiles add to the compiler rules.
131c77a0c5SBarry Smith    For --prefix installs the directory ${PETSC_ARCH} does not exist and petscconf.h is in the same
141cc8b206SBarry Smith    directory as the other PETSc include files.
15d382aafbSBarry Smith */
162c8e378dSBarry Smith #include <petscconf.h>
171c77a0c5SBarry Smith #include <petscconf_poison.h>
182c8e378dSBarry Smith #include <petscfix.h>
19bde483f2SJacob Faibussowitsch #include <petscmacros.h>
2033bb201bSJacob Faibussowitsch 
2133bb201bSJacob Faibussowitsch /* placeholder defines */
2233bb201bSJacob Faibussowitsch #if PetscHasAttribute(format)
2333bb201bSJacob Faibussowitsch #  define PETSC_ATTRIBUTE_FORMAT(strIdx,vaArgIdx)
2433bb201bSJacob Faibussowitsch #else
2533bb201bSJacob Faibussowitsch #  define PETSC_ATTRIBUTE_FORMAT(strIdx,vaArgIdx)
2633bb201bSJacob Faibussowitsch #endif
2733bb201bSJacob Faibussowitsch 
2873fca5a0SBarry Smith #if defined(PETSC_DESIRE_FEATURE_TEST_MACROS)
2973fca5a0SBarry Smith /*
3073fca5a0SBarry Smith    Feature test macros must be included before headers defined by IEEE Std 1003.1-2001
3173fca5a0SBarry Smith    We only turn these in PETSc source files that require them by setting PETSC_DESIRE_FEATURE_TEST_MACROS
3273fca5a0SBarry Smith */
33216f1ae6SBarry Smith #  if defined(PETSC__POSIX_C_SOURCE_200112L) && !defined(_POSIX_C_SOURCE)
3473fca5a0SBarry Smith #    define _POSIX_C_SOURCE 200112L
3573fca5a0SBarry Smith #  endif
36216f1ae6SBarry Smith #  if defined(PETSC__BSD_SOURCE) && !defined(_BSD_SOURCE)
3773fca5a0SBarry Smith #    define _BSD_SOURCE
3873fca5a0SBarry Smith #  endif
3907f00807SSatish Balay #  if defined(PETSC__DEFAULT_SOURCE) && !defined(_DEFAULT_SOURCE)
4007f00807SSatish Balay #    define _DEFAULT_SOURCE
4107f00807SSatish Balay #  endif
42ea0fecefSShri Abhyankar #  if defined(PETSC__GNU_SOURCE) && !defined(_GNU_SOURCE)
43ea0fecefSShri Abhyankar #    define _GNU_SOURCE
44ea0fecefSShri Abhyankar #  endif
4573fca5a0SBarry Smith #endif
4673fca5a0SBarry Smith 
47df4397b0SStefano Zampini #include <petscsystypes.h>
48df4397b0SStefano Zampini 
49d382aafbSBarry Smith /* ========================================================================== */
50d382aafbSBarry Smith 
51d382aafbSBarry Smith /*
52d382aafbSBarry Smith     Defines the interface to MPI allowing the use of all MPI functions.
53d382aafbSBarry Smith 
54d382aafbSBarry Smith     PETSc does not use the C++ binding of MPI at ALL. The following flag
55d382aafbSBarry Smith     makes sure the C++ bindings are not included. The C++ bindings REQUIRE
56d382aafbSBarry Smith     putting mpi.h before ANY C++ include files, we cannot control this
57d382aafbSBarry Smith     with all PETSc users. Users who want to use the MPI C++ bindings can include
58d382aafbSBarry Smith     mpicxx.h directly in their code
59d382aafbSBarry Smith */
60fa9e63e2SJed Brown #if !defined(MPICH_SKIP_MPICXX)
61d382aafbSBarry Smith #  define MPICH_SKIP_MPICXX 1
62fa9e63e2SJed Brown #endif
63fa9e63e2SJed Brown #if !defined(OMPI_SKIP_MPICXX)
64d382aafbSBarry Smith #  define OMPI_SKIP_MPICXX 1
65fa9e63e2SJed Brown #endif
66e771154cSJed Brown #if defined(PETSC_HAVE_MPIUNI)
67e771154cSJed Brown #  include <petsc/mpiuni/mpi.h>
68e771154cSJed Brown #else
692c8e378dSBarry Smith #  include <mpi.h>
70e771154cSJed Brown #endif
7165013866SBarry Smith 
72d382aafbSBarry Smith /*
73a7886beaSBarry Smith    Perform various sanity checks that the correct mpi.h is being included at compile time.
74a7886beaSBarry Smith    This usually happens because
75a7886beaSBarry Smith       * either an unexpected mpi.h is in the default compiler path (i.e. in /usr/include) or
76a7886beaSBarry Smith       * an extra include path -I/something (which contains the unexpected mpi.h) is being passed to the compiler
77a7886beaSBarry Smith */
78a7886beaSBarry Smith #if defined(PETSC_HAVE_MPIUNI)
79c9b973beSBarry Smith #  if !defined(MPIUNI_H)
80a7886beaSBarry Smith #    error "PETSc was configured with --with-mpi=0 but now appears to be compiling using a different mpi.h"
81a7886beaSBarry Smith #  endif
8241f4af4cSSatish Balay #elif defined(PETSC_HAVE_I_MPI_NUMVERSION)
8341f4af4cSSatish Balay #  if !defined(I_MPI_NUMVERSION)
8441f4af4cSSatish Balay #    error "PETSc was configured with I_MPI but now appears to be compiling using a non-I_MPI mpi.h"
8541f4af4cSSatish Balay #  elif I_MPI_NUMVERSION != PETSC_HAVE_I_MPI_NUMVERSION
8641f4af4cSSatish Balay #    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"
8741f4af4cSSatish Balay #  endif
8841f4af4cSSatish Balay #elif defined(PETSC_HAVE_MVAPICH2_NUMVERSION)
8941f4af4cSSatish Balay #  if !defined(MVAPICH2_NUMVERSION)
9041f4af4cSSatish Balay #    error "PETSc was configured with MVAPICH2 but now appears to be compiling using a non-MVAPICH2 mpi.h"
9141f4af4cSSatish Balay #  elif MVAPICH2_NUMVERSION != PETSC_HAVE_MVAPICH2_NUMVERSION
9241f4af4cSSatish Balay #    error "PETSc was configured with one MVAPICH2 mpi.h version but now appears to be compiling using a different MVAPICH2 mpi.h version"
9341f4af4cSSatish Balay #  endif
94a7886beaSBarry Smith #elif defined(PETSC_HAVE_MPICH_NUMVERSION)
9541f4af4cSSatish Balay #  if !defined(MPICH_NUMVERSION) || defined(MVAPICH2_NUMVERSION) || defined(I_MPI_NUMVERSION)
96a7886beaSBarry Smith #    error "PETSc was configured with MPICH but now appears to be compiling using a non-MPICH mpi.h"
97ca70f86eSJed Brown #  elif (MPICH_NUMVERSION/100000 != PETSC_HAVE_MPICH_NUMVERSION/100000) || (MPICH_NUMVERSION%100000/1000 < PETSC_HAVE_MPICH_NUMVERSION%100000/1000)
98a7886beaSBarry Smith #    error "PETSc was configured with one MPICH mpi.h version but now appears to be compiling using a different MPICH mpi.h version"
99a7886beaSBarry Smith #  endif
100a7886beaSBarry Smith #elif defined(PETSC_HAVE_OMPI_MAJOR_VERSION)
101a7886beaSBarry Smith #  if !defined(OMPI_MAJOR_VERSION)
102a7886beaSBarry Smith #    error "PETSc was configured with OpenMPI but now appears to be compiling using a non-OpenMPI mpi.h"
103ca70f86eSJed Brown #  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)
104c3ac57cfSSatish Balay #    error "PETSc was configured with one OpenMPI mpi.h version but now appears to be compiling using a different OpenMPI mpi.h version"
105a7886beaSBarry Smith #  endif
106c93fae50SJacob Faibussowitsch #  define PETSC_MPI_COMM_FMT "p"
107c93fae50SJacob Faibussowitsch #  define PETSC_MPI_WIN_FMT  "p"
108d97fd468SStefano Zampini #elif defined(PETSC_HAVE_MSMPI_VERSION)
109d97fd468SStefano Zampini #  if !defined(MSMPI_VER)
110d97fd468SStefano Zampini #    error "PETSc was configured with MSMPI but now appears to be compiling using a non-MSMPI mpi.h"
111d97fd468SStefano Zampini #  elif (MSMPI_VER != PETSC_HAVE_MSMPI_VERSION)
112d97fd468SStefano Zampini #    error "PETSc was configured with one MSMPI mpi.h version but now appears to be compiling using a different MSMPI mpi.h version"
113d97fd468SStefano Zampini #  endif
114d97fd468SStefano Zampini #elif defined(OMPI_MAJOR_VERSION) || defined(MPICH_NUMVERSION) || defined(MSMPI_VER)
115d97fd468SStefano Zampini #  error "PETSc was configured with undetermined MPI - but now appears to be compiling using any of OpenMPI, MS-MPI or a MPICH variant"
116a7886beaSBarry Smith #endif
117a7886beaSBarry Smith 
118c93fae50SJacob Faibussowitsch /* Format specifier for printing MPI_Comm (most implementations use 'int' as type) */
119c93fae50SJacob Faibussowitsch #if !defined(PETSC_MPI_COMM_FMT)
120c93fae50SJacob Faibussowitsch #  define PETSC_MPI_COMM_FMT "d"
121c93fae50SJacob Faibussowitsch #endif
122c93fae50SJacob Faibussowitsch 
123c93fae50SJacob Faibussowitsch #if !defined(PETSC_MPI_WIN_FMT)
124c93fae50SJacob Faibussowitsch #  define PETSC_MPI_WIN_FMT "d"
125c93fae50SJacob Faibussowitsch #endif
126c93fae50SJacob Faibussowitsch 
127a7886beaSBarry Smith /*
1282981ebdbSBarry Smith     Need to put stdio.h AFTER mpi.h for MPICH2 with C++ compiler
129d382aafbSBarry Smith     see the top of mpicxx.h in the MPICH2 distribution.
130d382aafbSBarry Smith */
131d382aafbSBarry Smith #include <stdio.h>
132d382aafbSBarry Smith 
133d382aafbSBarry Smith /* MSMPI on 32bit windows requires this yukky hack - that breaks MPI standard compliance */
134d382aafbSBarry Smith #if !defined(MPIAPI)
135d382aafbSBarry Smith #define MPIAPI
136d382aafbSBarry Smith #endif
137d382aafbSBarry Smith 
1381cc8b206SBarry Smith /*
1391cc8b206SBarry Smith    Support for Clang (>=3.2) matching type tag arguments with void* buffer types.
1401cc8b206SBarry Smith    This allows the compiler to detect cases where the MPI datatype argument passed to a MPI routine
1411cc8b206SBarry Smith    does not match the actual type of the argument being passed in
1421cc8b206SBarry Smith */
143c5e4d11fSDmitry Karpeev #if defined(__has_attribute) && defined(works_with_const_which_is_not_true)
144894dd566SJed Brown #  if __has_attribute(argument_with_type_tag) && __has_attribute(pointer_with_type_tag) && __has_attribute(type_tag_for_datatype)
145894dd566SJed Brown #    define PetscAttrMPIPointerWithType(bufno,typeno) __attribute__((pointer_with_type_tag(MPI,bufno,typeno)))
1468ad47952SJed Brown #    define PetscAttrMPITypeTag(type)                 __attribute__((type_tag_for_datatype(MPI,type)))
1478ad47952SJed Brown #    define PetscAttrMPITypeTagLayoutCompatible(type) __attribute__((type_tag_for_datatype(MPI,type,layout_compatible)))
148894dd566SJed Brown #  endif
149894dd566SJed Brown #endif
150894dd566SJed Brown #if !defined(PetscAttrMPIPointerWithType)
151894dd566SJed Brown #  define PetscAttrMPIPointerWithType(bufno,typeno)
1528ad47952SJed Brown #  define PetscAttrMPITypeTag(type)
1538ad47952SJed Brown #  define PetscAttrMPITypeTagLayoutCompatible(type)
154894dd566SJed Brown #endif
155b3506946SBarry Smith 
1565a576424SJed Brown PETSC_EXTERN MPI_Datatype MPIU_ENUM PetscAttrMPITypeTag(PetscEnum);
157df4397b0SStefano Zampini PETSC_EXTERN MPI_Datatype MPIU_BOOL PetscAttrMPITypeTag(PetscBool);
158e28ce29aSPatrick Sanan 
159e28ce29aSPatrick Sanan /*MC
160e28ce29aSPatrick Sanan    MPIU_INT - MPI datatype corresponding to PetscInt
161e28ce29aSPatrick Sanan 
162e28ce29aSPatrick Sanan    Notes:
163e28ce29aSPatrick Sanan    In MPI calls that require an MPI datatype that matches a PetscInt or array of PetscInt values, pass this value.
164e28ce29aSPatrick Sanan 
165e28ce29aSPatrick Sanan    Level: beginner
166e28ce29aSPatrick Sanan 
167e28ce29aSPatrick Sanan .seealso: PetscReal, PetscScalar, PetscComplex, PetscInt, MPIU_REAL, MPIU_SCALAR, MPIU_COMPLEX
168e28ce29aSPatrick Sanan M*/
169e28ce29aSPatrick Sanan 
1707cdaf61dSJed Brown PETSC_EXTERN MPI_Datatype MPIU_FORTRANADDR;
171b7b8f77aSBarry Smith 
172d382aafbSBarry Smith #if defined(PETSC_USE_64BIT_INDICES)
173bd84f1cfSSatish Balay #  define MPIU_INT MPIU_INT64
174a05e1a72SSatish Balay #  define PetscInt_FMT PetscInt64_FMT
175d382aafbSBarry Smith #else
176d382aafbSBarry Smith #  define MPIU_INT MPI_INT
177a05e1a72SSatish Balay #  define PetscInt_FMT "d"
178d382aafbSBarry Smith #endif
179d382aafbSBarry Smith 
180503cfb0cSBarry Smith /*
181503cfb0cSBarry Smith     For the rare cases when one needs to send a size_t object with MPI
182503cfb0cSBarry Smith */
183e316c87fSJed Brown PETSC_EXTERN MPI_Datatype MPIU_SIZE_T;
184d382aafbSBarry Smith 
185d382aafbSBarry Smith /*
186d382aafbSBarry Smith       You can use PETSC_STDOUT as a replacement of stdout. You can also change
187d382aafbSBarry Smith     the value of PETSC_STDOUT to redirect all standard output elsewhere
188d382aafbSBarry Smith */
189014dd563SJed Brown PETSC_EXTERN FILE* PETSC_STDOUT;
190d382aafbSBarry Smith 
191d382aafbSBarry Smith /*
192d382aafbSBarry Smith       You can use PETSC_STDERR as a replacement of stderr. You can also change
193d382aafbSBarry Smith     the value of PETSC_STDERR to redirect all standard error elsewhere
194d382aafbSBarry Smith */
195014dd563SJed Brown PETSC_EXTERN FILE* PETSC_STDERR;
196d382aafbSBarry Smith 
197c8b9133aSSatish Balay /* PetscPragmaSIMD - from CeedPragmaSIMD */
198c8b9133aSSatish Balay 
1995c993f7fSStefano Zampini #if defined(__NEC__)
2005c993f7fSStefano Zampini #  define PetscPragmaSIMD _Pragma("_NEC ivdep")
2015c993f7fSStefano Zampini #elif defined(__INTEL_COMPILER) && !defined(_WIN32)
202c8b9133aSSatish Balay #  define PetscPragmaSIMD _Pragma("vector")
2031dba8834SJose E. Roman #elif defined(__GNUC__) && __GNUC__ >= 5 && !defined(__PGI)
204c8b9133aSSatish Balay #  define PetscPragmaSIMD _Pragma("GCC ivdep")
205e5518150SSatish Balay #elif defined(_OPENMP) && _OPENMP >= 201307
206e5518150SSatish Balay #  if defined(_MSC_VER)
207160a5775SAli Reza Khaz'ali #    define PetscPragmaSIMD __pragma(omp simd)
208e5518150SSatish Balay #  else
209e5518150SSatish Balay #    define PetscPragmaSIMD _Pragma("omp simd")
210e5518150SSatish Balay #  endif
211c8b9133aSSatish Balay #elif defined(PETSC_HAVE_CRAY_VECTOR)
212c8b9133aSSatish Balay #  define PetscPragmaSIMD _Pragma("_CRI ivdep")
213c8b9133aSSatish Balay #else
214c8b9133aSSatish Balay #  define PetscPragmaSIMD
215c8b9133aSSatish Balay #endif
216c8b9133aSSatish Balay 
217d382aafbSBarry Smith /*
218d382aafbSBarry Smith     Declare extern C stuff after including external header files
219d382aafbSBarry Smith */
220d382aafbSBarry Smith 
2216a6fc655SJed Brown PETSC_EXTERN const char *const PetscBools[];
22270b3c8c7SBarry Smith 
2236edef35eSSatish Balay PETSC_EXTERN PetscBool PETSC_RUNNING_ON_VALGRIND;
2248b49ba18SBarry Smith /*
225390e1bf2SBarry Smith     Defines elementary mathematics functions and constants.
2268b49ba18SBarry Smith */
2278b49ba18SBarry Smith #include <petscmath.h>
2288b49ba18SBarry Smith 
2296a6fc655SJed Brown PETSC_EXTERN const char *const PetscCopyModes[];
230d382aafbSBarry Smith 
231d382aafbSBarry Smith /*MC
2320298fd71SBarry Smith     PETSC_IGNORE - same as NULL, means PETSc will ignore this argument
233d382aafbSBarry Smith 
234d382aafbSBarry Smith    Level: beginner
235d382aafbSBarry Smith 
236e28ce29aSPatrick Sanan    Note:
237e28ce29aSPatrick Sanan    Accepted by many PETSc functions to not set a parameter and instead use
238d382aafbSBarry Smith           some default
239d382aafbSBarry Smith 
240e28ce29aSPatrick Sanan    Fortran Notes:
241e28ce29aSPatrick Sanan    This macro does not exist in Fortran; you must use PETSC_NULL_INTEGER,
242d382aafbSBarry Smith           PETSC_NULL_DOUBLE_PRECISION etc
243d382aafbSBarry Smith 
244e28ce29aSPatrick Sanan .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_DETERMINE
245d382aafbSBarry Smith 
246d382aafbSBarry Smith M*/
2470298fd71SBarry Smith #define PETSC_IGNORE NULL
248d382aafbSBarry Smith 
249c528d872SBarry Smith /* This is deprecated */
250c528d872SBarry Smith #define PETSC_NULL NULL
251c528d872SBarry Smith 
252d382aafbSBarry Smith /*MC
253557d4da8SBarry Smith     PETSC_DECIDE - standard way of passing in integer or floating point parameter
254557d4da8SBarry Smith        where you wish PETSc to use the default.
255557d4da8SBarry Smith 
256557d4da8SBarry Smith    Level: beginner
257557d4da8SBarry Smith 
258e28ce29aSPatrick Sanan .seealso: PETSC_DEFAULT, PETSC_IGNORE, PETSC_DETERMINE
259557d4da8SBarry Smith 
260557d4da8SBarry Smith M*/
261557d4da8SBarry Smith #define PETSC_DECIDE -1
262557d4da8SBarry Smith 
263557d4da8SBarry Smith /*MC
264d382aafbSBarry Smith     PETSC_DETERMINE - standard way of passing in integer or floating point parameter
265d382aafbSBarry Smith        where you wish PETSc to compute the required value.
266d382aafbSBarry Smith 
267d382aafbSBarry Smith    Level: beginner
268d382aafbSBarry Smith 
269e28ce29aSPatrick Sanan    Developer Note:
270e28ce29aSPatrick Sanan    I would like to use const PetscInt PETSC_DETERMINE = PETSC_DECIDE; but for
271557d4da8SBarry Smith      some reason this is not allowed by the standard even though PETSC_DECIDE is a constant value.
272557d4da8SBarry Smith 
2730298fd71SBarry Smith .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_IGNORE, VecSetSizes()
274d382aafbSBarry Smith 
275d382aafbSBarry Smith M*/
276d382aafbSBarry Smith #define PETSC_DETERMINE PETSC_DECIDE
277d382aafbSBarry Smith 
278d382aafbSBarry Smith /*MC
279557d4da8SBarry Smith     PETSC_DEFAULT - standard way of passing in integer or floating point parameter
280557d4da8SBarry Smith        where you wish PETSc to use the default.
281557d4da8SBarry Smith 
282557d4da8SBarry Smith    Level: beginner
283557d4da8SBarry Smith 
284e28ce29aSPatrick Sanan    Fortran Notes:
285e28ce29aSPatrick Sanan    You need to use PETSC_DEFAULT_INTEGER or PETSC_DEFAULT_REAL.
286557d4da8SBarry Smith 
2870298fd71SBarry Smith .seealso: PETSC_DECIDE, PETSC_IGNORE, PETSC_DETERMINE
288557d4da8SBarry Smith 
289557d4da8SBarry Smith M*/
290557d4da8SBarry Smith #define PETSC_DEFAULT -2
291557d4da8SBarry Smith 
292557d4da8SBarry Smith /*MC
293d382aafbSBarry Smith     PETSC_COMM_WORLD - the equivalent of the MPI_COMM_WORLD communicator which represents
294ea8fe74dSBarry Smith            all the processes that PETSc knows about.
295d382aafbSBarry Smith 
296d382aafbSBarry Smith    Level: beginner
297d382aafbSBarry Smith 
298e28ce29aSPatrick Sanan    Notes:
299e28ce29aSPatrick Sanan    By default PETSC_COMM_WORLD and MPI_COMM_WORLD are identical unless you wish to
300d382aafbSBarry Smith           run PETSc on ONLY a subset of MPI_COMM_WORLD. In that case create your new (smaller)
301d382aafbSBarry Smith           communicator, call it, say comm, and set PETSC_COMM_WORLD = comm BEFORE calling
302a990b902SBarry Smith           PetscInitialize(), but after MPI_Init() has been called.
303a990b902SBarry Smith 
304a990b902SBarry Smith           The value of PETSC_COMM_WORLD should never be USED/accessed before PetscInitialize()
305a990b902SBarry Smith           is called because it may not have a valid value yet.
306d382aafbSBarry Smith 
307d382aafbSBarry Smith .seealso: PETSC_COMM_SELF
308d382aafbSBarry Smith 
309d382aafbSBarry Smith M*/
310014dd563SJed Brown PETSC_EXTERN MPI_Comm PETSC_COMM_WORLD;
311d382aafbSBarry Smith 
312d382aafbSBarry Smith /*MC
313503cfb0cSBarry Smith     PETSC_COMM_SELF - This is always MPI_COMM_SELF
314d382aafbSBarry Smith 
315d382aafbSBarry Smith    Level: beginner
316d382aafbSBarry Smith 
317e28ce29aSPatrick Sanan    Notes:
318e28ce29aSPatrick Sanan    Do not USE/access or set this variable before PetscInitialize() has been called.
319a990b902SBarry Smith 
320d382aafbSBarry Smith .seealso: PETSC_COMM_WORLD
321d382aafbSBarry Smith 
322d382aafbSBarry Smith M*/
323d382aafbSBarry Smith #define PETSC_COMM_SELF MPI_COMM_SELF
324d382aafbSBarry Smith 
3256de5d289SStefano Zampini /*MC
3266de5d289SStefano Zampini     PETSC_MPI_THREAD_REQUIRED - the required threading support used if PETSc initializes
3276de5d289SStefano Zampini            MPI with MPI_Init_thread.
3286de5d289SStefano Zampini 
3296de5d289SStefano Zampini    Level: beginner
3306de5d289SStefano Zampini 
3316de5d289SStefano Zampini    Notes:
3326de5d289SStefano Zampini    By default PETSC_MPI_THREAD_REQUIRED equals MPI_THREAD_FUNNELED.
3336de5d289SStefano Zampini 
3346de5d289SStefano Zampini .seealso: PetscInitialize()
3356de5d289SStefano Zampini 
3366de5d289SStefano Zampini M*/
3376de5d289SStefano Zampini PETSC_EXTERN PetscMPIInt PETSC_MPI_THREAD_REQUIRED;
3386de5d289SStefano Zampini 
339d6f2c3cbSBarry Smith PETSC_EXTERN PetscBool PetscBeganMPI;
3408ad20175SVaclav Hapla PETSC_EXTERN PetscBool PetscErrorHandlingInitialized;
341014dd563SJed Brown PETSC_EXTERN PetscBool PetscInitializeCalled;
342014dd563SJed Brown PETSC_EXTERN PetscBool PetscFinalizeCalled;
3434cf1874eSKarl Rupp PETSC_EXTERN PetscBool PetscViennaCLSynchronize;
344d382aafbSBarry Smith 
345014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetHelpVersionFunctions(PetscErrorCode (*)(MPI_Comm),PetscErrorCode (*)(MPI_Comm));
346014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommDuplicate(MPI_Comm,MPI_Comm*,int*);
347014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommDestroy(MPI_Comm*);
34857f21012SBarry Smith PETSC_EXTERN PetscErrorCode PetscCommGetComm(MPI_Comm,MPI_Comm*);
34957f21012SBarry Smith PETSC_EXTERN PetscErrorCode PetscCommRestoreComm(MPI_Comm,MPI_Comm*);
350d382aafbSBarry Smith 
35159e55d94SJunchao Zhang #if defined(PETSC_HAVE_KOKKOS)
35259e55d94SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscKokkosInitializeCheck(void);  /* Initialize Kokkos if not yet. */
35359e55d94SJunchao Zhang #endif
35459e55d94SJunchao Zhang 
35571438e86SJunchao Zhang #if defined(PETSC_HAVE_NVSHMEM)
35671438e86SJunchao Zhang PETSC_EXTERN PetscBool      PetscBeganNvshmem;
35771438e86SJunchao Zhang PETSC_EXTERN PetscBool      PetscNvshmemInitialized;
35871438e86SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscNvshmemFinalize(void);
35971438e86SJunchao Zhang #endif
36071438e86SJunchao Zhang 
361540e20f2SPierre Jolivet #if defined(PETSC_HAVE_ELEMENTAL)
362540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalInitializePackage(void);
363540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalInitialized(PetscBool*);
364540e20f2SPierre Jolivet PETSC_EXTERN PetscErrorCode PetscElementalFinalizePackage(void);
365540e20f2SPierre Jolivet #endif
366540e20f2SPierre Jolivet 
367d382aafbSBarry Smith /*MC
36895dccacaSBarry Smith    PetscMalloc - Allocates memory, One should use PetscNew(), PetscMalloc1() or PetscCalloc1() usually instead of this
369d382aafbSBarry Smith 
370eca87e8dSBarry Smith    Synopsis:
371aaa7dc30SBarry Smith     #include <petscsys.h>
372eca87e8dSBarry Smith    PetscErrorCode PetscMalloc(size_t m,void **result)
373eca87e8dSBarry Smith 
374eca87e8dSBarry Smith    Not Collective
375eca87e8dSBarry Smith 
376d382aafbSBarry Smith    Input Parameter:
377d382aafbSBarry Smith .  m - number of bytes to allocate
378d382aafbSBarry Smith 
379d382aafbSBarry Smith    Output Parameter:
380d382aafbSBarry Smith .  result - memory allocated
381d382aafbSBarry Smith 
382d382aafbSBarry Smith    Level: beginner
383d382aafbSBarry Smith 
38449d7da52SJed Brown    Notes:
38549d7da52SJed Brown    Memory is always allocated at least double aligned
386d382aafbSBarry Smith 
38749d7da52SJed Brown    It is safe to allocate size 0 and pass the resulting pointer (which may or may not be NULL) to PetscFree().
388d382aafbSBarry Smith 
389d382aafbSBarry Smith .seealso: PetscFree(), PetscNew()
390d382aafbSBarry Smith 
391d382aafbSBarry Smith M*/
392071fcb05SBarry Smith #define PetscMalloc(a,b)  ((*PetscTrMalloc)((a),PETSC_FALSE,__LINE__,PETSC_FUNCTION_NAME,__FILE__,(void**)(b)))
393d382aafbSBarry Smith 
394d382aafbSBarry Smith /*MC
3953221ece2SMatthew G. Knepley    PetscRealloc - Rellocates memory
3963221ece2SMatthew G. Knepley 
3973221ece2SMatthew G. Knepley    Synopsis:
3983221ece2SMatthew G. Knepley     #include <petscsys.h>
3993221ece2SMatthew G. Knepley    PetscErrorCode PetscRealloc(size_t m,void **result)
4003221ece2SMatthew G. Knepley 
4013221ece2SMatthew G. Knepley    Not Collective
4023221ece2SMatthew G. Knepley 
4033221ece2SMatthew G. Knepley    Input Parameters:
4043221ece2SMatthew G. Knepley +  m - number of bytes to allocate
40592f119d6SBarry Smith -  result - previous memory
4063221ece2SMatthew G. Knepley 
4073221ece2SMatthew G. Knepley    Output Parameter:
4083221ece2SMatthew G. Knepley .  result - new memory allocated
4093221ece2SMatthew G. Knepley 
4103221ece2SMatthew G. Knepley    Level: developer
4113221ece2SMatthew G. Knepley 
4123221ece2SMatthew G. Knepley    Notes:
4133221ece2SMatthew G. Knepley    Memory is always allocated at least double aligned
4143221ece2SMatthew G. Knepley 
4153221ece2SMatthew G. Knepley .seealso: PetscMalloc(), PetscFree(), PetscNew()
4163221ece2SMatthew G. Knepley 
4173221ece2SMatthew G. Knepley M*/
4183221ece2SMatthew G. Knepley #define PetscRealloc(a,b)  ((*PetscTrRealloc)((a),__LINE__,PETSC_FUNCTION_NAME,__FILE__,(void**)(b)))
4193221ece2SMatthew G. Knepley 
4203221ece2SMatthew G. Knepley /*MC
421503cfb0cSBarry Smith    PetscAddrAlign - Rounds up an address to PETSC_MEMALIGN alignment
422d382aafbSBarry Smith 
423d382aafbSBarry Smith    Synopsis:
424aaa7dc30SBarry Smith     #include <petscsys.h>
425d382aafbSBarry Smith    void *PetscAddrAlign(void *addr)
426d382aafbSBarry Smith 
427eca87e8dSBarry Smith    Not Collective
428eca87e8dSBarry Smith 
429eca87e8dSBarry Smith    Input Parameters:
430eca87e8dSBarry Smith .  addr - address to align (any pointer type)
431eca87e8dSBarry Smith 
432d382aafbSBarry Smith    Level: developer
433d382aafbSBarry Smith 
434d382aafbSBarry Smith .seealso: PetscMallocAlign()
435d382aafbSBarry Smith 
436d382aafbSBarry Smith M*/
437d382aafbSBarry Smith #define PetscAddrAlign(a) (void*)((((PETSC_UINTPTR_T)(a))+(PETSC_MEMALIGN-1)) & ~(PETSC_MEMALIGN-1))
438d382aafbSBarry Smith 
439d382aafbSBarry Smith /*MC
4408f51dc47SJunchao Zhang    PetscCalloc - Allocates a cleared (zeroed) memory region aligned to PETSC_MEMALIGN
4418f51dc47SJunchao Zhang 
4428f51dc47SJunchao Zhang    Synopsis:
4438f51dc47SJunchao Zhang     #include <petscsys.h>
4448f51dc47SJunchao Zhang    PetscErrorCode PetscCalloc(size_t m,void **result)
4458f51dc47SJunchao Zhang 
4468f51dc47SJunchao Zhang    Not Collective
4478f51dc47SJunchao Zhang 
4488f51dc47SJunchao Zhang    Input Parameter:
4498f51dc47SJunchao Zhang .  m - number of bytes to allocate
4508f51dc47SJunchao Zhang 
4518f51dc47SJunchao Zhang    Output Parameter:
4528f51dc47SJunchao Zhang .  result - memory allocated
4538f51dc47SJunchao Zhang 
4548f51dc47SJunchao Zhang    Level: beginner
4558f51dc47SJunchao Zhang 
4568f51dc47SJunchao Zhang    Notes:
4578f51dc47SJunchao Zhang    Memory is always allocated at least double aligned. This macro is useful in allocating memory pointed by void pointers
4588f51dc47SJunchao Zhang 
4598f51dc47SJunchao Zhang    It is safe to allocate size 0 and pass the resulting pointer (which may or may not be NULL) to PetscFree().
4608f51dc47SJunchao Zhang 
4618f51dc47SJunchao Zhang .seealso: PetscFree(), PetscNew()
4628f51dc47SJunchao Zhang 
4638f51dc47SJunchao Zhang M*/
464*66122d6dSBarry Smith #define PetscCalloc(m,result)  PetscMallocA(1,PETSC_TRUE,__LINE__,PETSC_FUNCTION_NAME,__FILE__,(size_t)((size_t)m),(result))
4658f51dc47SJunchao Zhang 
4668f51dc47SJunchao Zhang /*MC
467785e854fSJed Brown    PetscMalloc1 - Allocates an array of memory aligned to PETSC_MEMALIGN
468d382aafbSBarry Smith 
469eca87e8dSBarry Smith    Synopsis:
470aaa7dc30SBarry Smith     #include <petscsys.h>
471785e854fSJed Brown    PetscErrorCode PetscMalloc1(size_t m1,type **r1)
472785e854fSJed Brown 
473785e854fSJed Brown    Not Collective
474785e854fSJed Brown 
475785e854fSJed Brown    Input Parameter:
476390e1bf2SBarry Smith .  m1 - number of elements to allocate  (may be zero)
477785e854fSJed Brown 
478785e854fSJed Brown    Output Parameter:
4791fe1b817SJunchao Zhang .  r1 - memory allocated
480785e854fSJed Brown 
481e28ce29aSPatrick Sanan    Note:
482e28ce29aSPatrick Sanan    This uses the sizeof() of the memory type requested to determine the total memory to be allocated, therefore you should not
483390e1bf2SBarry Smith          multiply the number of elements requested by the sizeof() the type. For example use
484390e1bf2SBarry Smith $  PetscInt *id;
485390e1bf2SBarry Smith $  PetscMalloc1(10,&id);
486390e1bf2SBarry Smith         not
487390e1bf2SBarry Smith $  PetscInt *id;
488390e1bf2SBarry Smith $  PetscMalloc1(10*sizeof(PetscInt),&id);
489390e1bf2SBarry Smith 
4901fe1b817SJunchao Zhang         Does not zero the memory allocated, use PetscCalloc1() to obtain memory that has been zeroed.
491390e1bf2SBarry Smith 
492390e1bf2SBarry Smith    Level: beginner
493785e854fSJed Brown 
4941795a4d1SJed Brown .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscCalloc1(), PetscMalloc2()
495785e854fSJed Brown 
496785e854fSJed Brown M*/
497*66122d6dSBarry Smith #define PetscMalloc1(m1,r1) PetscMallocA(1,PETSC_FALSE,__LINE__,PETSC_FUNCTION_NAME,__FILE__,(size_t)((size_t)m1)*sizeof(**(r1)),(r1))
498785e854fSJed Brown 
499785e854fSJed Brown /*MC
5001795a4d1SJed Brown    PetscCalloc1 - Allocates a cleared (zeroed) array of memory aligned to PETSC_MEMALIGN
5011795a4d1SJed Brown 
5021795a4d1SJed Brown    Synopsis:
503aaa7dc30SBarry Smith     #include <petscsys.h>
5041795a4d1SJed Brown    PetscErrorCode PetscCalloc1(size_t m1,type **r1)
5051795a4d1SJed Brown 
5061795a4d1SJed Brown    Not Collective
5071795a4d1SJed Brown 
5081795a4d1SJed Brown    Input Parameter:
5091795a4d1SJed Brown .  m1 - number of elements to allocate in 1st chunk  (may be zero)
5101795a4d1SJed Brown 
5111795a4d1SJed Brown    Output Parameter:
5121fe1b817SJunchao Zhang .  r1 - memory allocated
5131795a4d1SJed Brown 
514e28ce29aSPatrick Sanan    Notes:
515e28ce29aSPatrick Sanan    See PetsMalloc1() for more details on usage.
516390e1bf2SBarry Smith 
517390e1bf2SBarry Smith    Level: beginner
5181795a4d1SJed Brown 
5191795a4d1SJed Brown .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc1(), PetscCalloc2()
5201795a4d1SJed Brown 
5211795a4d1SJed Brown M*/
522*66122d6dSBarry Smith #define PetscCalloc1(m1,r1) PetscMallocA(1,PETSC_TRUE,__LINE__,PETSC_FUNCTION_NAME,__FILE__,(size_t)((size_t)m1)*sizeof(**(r1)),(r1))
5231795a4d1SJed Brown 
5241795a4d1SJed Brown /*MC
525dcca6d9dSJed Brown    PetscMalloc2 - Allocates 2 arrays of memory both aligned to PETSC_MEMALIGN
526d382aafbSBarry Smith 
527eca87e8dSBarry Smith    Synopsis:
528aaa7dc30SBarry Smith     #include <petscsys.h>
529dcca6d9dSJed Brown    PetscErrorCode PetscMalloc2(size_t m1,type **r1,size_t m2,type **r2)
530eca87e8dSBarry Smith 
531eca87e8dSBarry Smith    Not Collective
532eca87e8dSBarry Smith 
533d8d19677SJose E. Roman    Input Parameters:
534d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
535dcca6d9dSJed Brown -  m2 - number of elements to allocate in 2nd chunk  (may be zero)
536d382aafbSBarry Smith 
537d8d19677SJose E. Roman    Output Parameters:
538d382aafbSBarry Smith +  r1 - memory allocated in first chunk
539d382aafbSBarry Smith -  r2 - memory allocated in second chunk
540d382aafbSBarry Smith 
541d382aafbSBarry Smith    Level: developer
542d382aafbSBarry Smith 
5431795a4d1SJed Brown .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc1(), PetscCalloc2()
544d382aafbSBarry Smith 
545d382aafbSBarry Smith M*/
546*66122d6dSBarry Smith #define PetscMalloc2(m1,r1,m2,r2) PetscMallocA(2,PETSC_FALSE,__LINE__,PETSC_FUNCTION_NAME,__FILE__,(size_t)((size_t)m1)*sizeof(**(r1)),(r1),(size_t)((size_t)m2)*sizeof(**(r2)),(r2))
547d382aafbSBarry Smith 
548d382aafbSBarry Smith /*MC
5491795a4d1SJed Brown    PetscCalloc2 - Allocates 2 cleared (zeroed) arrays of memory both aligned to PETSC_MEMALIGN
550d382aafbSBarry Smith 
551eca87e8dSBarry Smith    Synopsis:
552aaa7dc30SBarry Smith     #include <petscsys.h>
5531795a4d1SJed Brown    PetscErrorCode PetscCalloc2(size_t m1,type **r1,size_t m2,type **r2)
554eca87e8dSBarry Smith 
555eca87e8dSBarry Smith    Not Collective
556eca87e8dSBarry Smith 
557d8d19677SJose E. Roman    Input Parameters:
558d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
5591795a4d1SJed Brown -  m2 - number of elements to allocate in 2nd chunk  (may be zero)
5601795a4d1SJed Brown 
561d8d19677SJose E. Roman    Output Parameters:
5621795a4d1SJed Brown +  r1 - memory allocated in first chunk
5631795a4d1SJed Brown -  r2 - memory allocated in second chunk
5641795a4d1SJed Brown 
5651795a4d1SJed Brown    Level: developer
5661795a4d1SJed Brown 
5671795a4d1SJed Brown .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscCalloc1(), PetscMalloc2()
5681795a4d1SJed Brown 
5691795a4d1SJed Brown M*/
570*66122d6dSBarry Smith #define PetscCalloc2(m1,r1,m2,r2) PetscMallocA(2,PETSC_TRUE,__LINE__,PETSC_FUNCTION_NAME,__FILE__,(size_t)((size_t)m1)*sizeof(**(r1)),(r1),(size_t)((size_t)m2)*sizeof(**(r2)),(r2))
5711795a4d1SJed Brown 
5721795a4d1SJed Brown /*MC
573dcca6d9dSJed Brown    PetscMalloc3 - Allocates 3 arrays of memory, all aligned to PETSC_MEMALIGN
574d382aafbSBarry Smith 
575d382aafbSBarry Smith    Synopsis:
576aaa7dc30SBarry Smith     #include <petscsys.h>
577dcca6d9dSJed Brown    PetscErrorCode PetscMalloc3(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3)
578d382aafbSBarry Smith 
579d382aafbSBarry Smith    Not Collective
580d382aafbSBarry Smith 
581d8d19677SJose E. Roman    Input Parameters:
582d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
583d382aafbSBarry Smith .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
584dcca6d9dSJed Brown -  m3 - number of elements to allocate in 3rd chunk  (may be zero)
585d382aafbSBarry Smith 
586d8d19677SJose E. Roman    Output Parameters:
587d382aafbSBarry Smith +  r1 - memory allocated in first chunk
588d382aafbSBarry Smith .  r2 - memory allocated in second chunk
589d382aafbSBarry Smith -  r3 - memory allocated in third chunk
590d382aafbSBarry Smith 
591d382aafbSBarry Smith    Level: developer
592d382aafbSBarry Smith 
5931795a4d1SJed Brown .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscCalloc3(), PetscFree3()
594d382aafbSBarry Smith 
595d382aafbSBarry Smith M*/
596*66122d6dSBarry Smith #define PetscMalloc3(m1,r1,m2,r2,m3,r3) PetscMallocA(3,PETSC_FALSE,__LINE__,PETSC_FUNCTION_NAME,__FILE__,(size_t)((size_t)m1)*sizeof(**(r1)),(r1),(size_t)((size_t)m2)*sizeof(**(r2)),(r2),(size_t)((size_t)m3)*sizeof(**(r3)),(r3))
597d382aafbSBarry Smith 
598d382aafbSBarry Smith /*MC
5991795a4d1SJed Brown    PetscCalloc3 - Allocates 3 cleared (zeroed) arrays of memory, all aligned to PETSC_MEMALIGN
600d382aafbSBarry Smith 
601eca87e8dSBarry Smith    Synopsis:
602aaa7dc30SBarry Smith     #include <petscsys.h>
6031795a4d1SJed Brown    PetscErrorCode PetscCalloc3(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3)
604eca87e8dSBarry Smith 
605eca87e8dSBarry Smith    Not Collective
606eca87e8dSBarry Smith 
607d8d19677SJose E. Roman    Input Parameters:
608d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
609d382aafbSBarry Smith .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
6101795a4d1SJed Brown -  m3 - number of elements to allocate in 3rd chunk  (may be zero)
6111795a4d1SJed Brown 
612d8d19677SJose E. Roman    Output Parameters:
6131795a4d1SJed Brown +  r1 - memory allocated in first chunk
6141795a4d1SJed Brown .  r2 - memory allocated in second chunk
6151795a4d1SJed Brown -  r3 - memory allocated in third chunk
6161795a4d1SJed Brown 
6171795a4d1SJed Brown    Level: developer
6181795a4d1SJed Brown 
6191795a4d1SJed Brown .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscCalloc2(), PetscMalloc3(), PetscFree3()
6201795a4d1SJed Brown 
6211795a4d1SJed Brown M*/
622*66122d6dSBarry Smith #define PetscCalloc3(m1,r1,m2,r2,m3,r3) PetscMallocA(3,PETSC_TRUE,__LINE__,PETSC_FUNCTION_NAME,__FILE__,(size_t)((size_t)m1)*sizeof(**(r1)),(r1),(size_t)((size_t)m2)*sizeof(**(r2)),(r2),(size_t)((size_t)m3)*sizeof(**(r3)),(r3))
6231795a4d1SJed Brown 
6241795a4d1SJed Brown /*MC
625dcca6d9dSJed Brown    PetscMalloc4 - Allocates 4 arrays of memory, all aligned to PETSC_MEMALIGN
626d382aafbSBarry Smith 
627d382aafbSBarry Smith    Synopsis:
628aaa7dc30SBarry Smith     #include <petscsys.h>
629dcca6d9dSJed Brown    PetscErrorCode PetscMalloc4(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4)
630d382aafbSBarry Smith 
631d382aafbSBarry Smith    Not Collective
632d382aafbSBarry Smith 
633d8d19677SJose E. Roman    Input Parameters:
634d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
635d382aafbSBarry Smith .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
636d382aafbSBarry Smith .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
637dcca6d9dSJed Brown -  m4 - number of elements to allocate in 4th chunk  (may be zero)
638d382aafbSBarry Smith 
639d8d19677SJose E. Roman    Output Parameters:
640d382aafbSBarry Smith +  r1 - memory allocated in first chunk
641d382aafbSBarry Smith .  r2 - memory allocated in second chunk
642d382aafbSBarry Smith .  r3 - memory allocated in third chunk
643d382aafbSBarry Smith -  r4 - memory allocated in fourth chunk
644d382aafbSBarry Smith 
645d382aafbSBarry Smith    Level: developer
646d382aafbSBarry Smith 
6471795a4d1SJed Brown .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscCalloc4(), PetscFree4()
648d382aafbSBarry Smith 
649d382aafbSBarry Smith M*/
650*66122d6dSBarry Smith #define PetscMalloc4(m1,r1,m2,r2,m3,r3,m4,r4) PetscMallocA(4,PETSC_FALSE,__LINE__,PETSC_FUNCTION_NAME,__FILE__,(size_t)((size_t)m1)*sizeof(**(r1)),(r1),(size_t)((size_t)m2)*sizeof(**(r2)),(r2),(size_t)((size_t)m3)*sizeof(**(r3)),(r3),(size_t)((size_t)m4)*sizeof(**(r4)),(r4))
651d382aafbSBarry Smith 
652d382aafbSBarry Smith /*MC
6531795a4d1SJed Brown    PetscCalloc4 - Allocates 4 cleared (zeroed) arrays of memory, all aligned to PETSC_MEMALIGN
654d382aafbSBarry Smith 
655eca87e8dSBarry Smith    Synopsis:
656aaa7dc30SBarry Smith     #include <petscsys.h>
6571795a4d1SJed Brown    PetscErrorCode PetscCalloc4(size_t m1,type **r1,size_t m2,type **r2,size_t m3,type **r3,size_t m4,type **r4)
658eca87e8dSBarry Smith 
659eca87e8dSBarry Smith    Not Collective
660eca87e8dSBarry Smith 
661e28ce29aSPatrick Sanan    Input Parameters:
662d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
663d382aafbSBarry Smith .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
664d382aafbSBarry Smith .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
6651795a4d1SJed Brown -  m4 - number of elements to allocate in 4th chunk  (may be zero)
6661795a4d1SJed Brown 
667e28ce29aSPatrick Sanan    Output Parameters:
6681795a4d1SJed Brown +  r1 - memory allocated in first chunk
6691795a4d1SJed Brown .  r2 - memory allocated in second chunk
6701795a4d1SJed Brown .  r3 - memory allocated in third chunk
6711795a4d1SJed Brown -  r4 - memory allocated in fourth chunk
6721795a4d1SJed Brown 
6731795a4d1SJed Brown    Level: developer
6741795a4d1SJed Brown 
6751795a4d1SJed Brown .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscCalloc4(), PetscFree4()
6761795a4d1SJed Brown 
6771795a4d1SJed Brown M*/
678*66122d6dSBarry Smith #define PetscCalloc4(m1,r1,m2,r2,m3,r3,m4,r4) PetscMallocA(4,PETSC_TRUE,__LINE__,PETSC_FUNCTION_NAME,__FILE__,(size_t)((size_t)m1)*sizeof(**(r1)),(r1),(size_t)((size_t)m2)*sizeof(**(r2)),(r2),(size_t)((size_t)m3)*sizeof(**(r3)),(r3),(size_t)((size_t)m4)*sizeof(**(r4)),(r4))
6791795a4d1SJed Brown 
6801795a4d1SJed Brown /*MC
681dcca6d9dSJed Brown    PetscMalloc5 - Allocates 5 arrays of memory, all aligned to PETSC_MEMALIGN
682d382aafbSBarry Smith 
683d382aafbSBarry Smith    Synopsis:
684aaa7dc30SBarry Smith     #include <petscsys.h>
685dcca6d9dSJed Brown    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)
686d382aafbSBarry Smith 
687d382aafbSBarry Smith    Not Collective
688d382aafbSBarry Smith 
689e28ce29aSPatrick Sanan    Input Parameters:
690d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
691d382aafbSBarry Smith .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
692d382aafbSBarry Smith .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
693d382aafbSBarry Smith .  m4 - number of elements to allocate in 4th chunk  (may be zero)
694dcca6d9dSJed Brown -  m5 - number of elements to allocate in 5th chunk  (may be zero)
695d382aafbSBarry Smith 
696e28ce29aSPatrick Sanan    Output Parameters:
697d382aafbSBarry Smith +  r1 - memory allocated in first chunk
698d382aafbSBarry Smith .  r2 - memory allocated in second chunk
699d382aafbSBarry Smith .  r3 - memory allocated in third chunk
700d382aafbSBarry Smith .  r4 - memory allocated in fourth chunk
701d382aafbSBarry Smith -  r5 - memory allocated in fifth chunk
702d382aafbSBarry Smith 
703d382aafbSBarry Smith    Level: developer
704d382aafbSBarry Smith 
7051795a4d1SJed Brown .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscCalloc5(), PetscFree5()
706d382aafbSBarry Smith 
707d382aafbSBarry Smith M*/
708*66122d6dSBarry Smith #define PetscMalloc5(m1,r1,m2,r2,m3,r3,m4,r4,m5,r5) PetscMallocA(5,PETSC_FALSE,__LINE__,PETSC_FUNCTION_NAME,__FILE__,(size_t)((size_t)m1)*sizeof(**(r1)),(r1),(size_t)((size_t)m2)*sizeof(**(r2)),(r2),(size_t)((size_t)m3)*sizeof(**(r3)),(r3),(size_t)((size_t)m4)*sizeof(**(r4)),(r4),(size_t)((size_t)m5)*sizeof(**(r5)),(r5))
709d382aafbSBarry Smith 
710d382aafbSBarry Smith /*MC
7111795a4d1SJed Brown    PetscCalloc5 - Allocates 5 cleared (zeroed) arrays of memory, all aligned to PETSC_MEMALIGN
712d382aafbSBarry Smith 
713eca87e8dSBarry Smith    Synopsis:
714aaa7dc30SBarry Smith     #include <petscsys.h>
7151795a4d1SJed Brown    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)
716eca87e8dSBarry Smith 
717eca87e8dSBarry Smith    Not Collective
718eca87e8dSBarry Smith 
719e28ce29aSPatrick Sanan    Input Parameters:
720d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
721d382aafbSBarry Smith .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
722d382aafbSBarry Smith .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
723d382aafbSBarry Smith .  m4 - number of elements to allocate in 4th chunk  (may be zero)
7241795a4d1SJed Brown -  m5 - number of elements to allocate in 5th chunk  (may be zero)
7251795a4d1SJed Brown 
726e28ce29aSPatrick Sanan    Output Parameters:
7271795a4d1SJed Brown +  r1 - memory allocated in first chunk
7281795a4d1SJed Brown .  r2 - memory allocated in second chunk
7291795a4d1SJed Brown .  r3 - memory allocated in third chunk
7301795a4d1SJed Brown .  r4 - memory allocated in fourth chunk
7311795a4d1SJed Brown -  r5 - memory allocated in fifth chunk
7321795a4d1SJed Brown 
7331795a4d1SJed Brown    Level: developer
7341795a4d1SJed Brown 
7351795a4d1SJed Brown .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc5(), PetscFree5()
7361795a4d1SJed Brown 
7371795a4d1SJed Brown M*/
738*66122d6dSBarry Smith #define PetscCalloc5(m1,r1,m2,r2,m3,r3,m4,r4,m5,r5) PetscMallocA(5,PETSC_TRUE,__LINE__,PETSC_FUNCTION_NAME,__FILE__,(size_t)((size_t)m1)*sizeof(**(r1)),(r1),(size_t)((size_t)m2)*sizeof(**(r2)),(r2),(size_t)((size_t)m3)*sizeof(**(r3)),(r3),(size_t)((size_t)m4)*sizeof(**(r4)),(r4),(size_t)((size_t)m5)*sizeof(**(r5)),(r5))
739d382aafbSBarry Smith 
740d382aafbSBarry Smith /*MC
741dcca6d9dSJed Brown    PetscMalloc6 - Allocates 6 arrays of memory, all aligned to PETSC_MEMALIGN
742d382aafbSBarry Smith 
743d382aafbSBarry Smith    Synopsis:
744aaa7dc30SBarry Smith     #include <petscsys.h>
745dcca6d9dSJed Brown    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)
746d382aafbSBarry Smith 
747d382aafbSBarry Smith    Not Collective
748d382aafbSBarry Smith 
749e28ce29aSPatrick Sanan    Input Parameters:
750d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
751d382aafbSBarry Smith .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
752d382aafbSBarry Smith .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
753d382aafbSBarry Smith .  m4 - number of elements to allocate in 4th chunk  (may be zero)
754d382aafbSBarry Smith .  m5 - number of elements to allocate in 5th chunk  (may be zero)
755dcca6d9dSJed Brown -  m6 - number of elements to allocate in 6th chunk  (may be zero)
756d382aafbSBarry Smith 
757e28ce29aSPatrick Sanan    Output Parameteasr:
758d382aafbSBarry Smith +  r1 - memory allocated in first chunk
759d382aafbSBarry Smith .  r2 - memory allocated in second chunk
760d382aafbSBarry Smith .  r3 - memory allocated in third chunk
761d382aafbSBarry Smith .  r4 - memory allocated in fourth chunk
762d382aafbSBarry Smith .  r5 - memory allocated in fifth chunk
763d382aafbSBarry Smith -  r6 - memory allocated in sixth chunk
764d382aafbSBarry Smith 
765d382aafbSBarry Smith    Level: developer
766d382aafbSBarry Smith 
7671795a4d1SJed Brown .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscCalloc6(), PetscFree3(), PetscFree4(), PetscFree5(), PetscFree6()
768d382aafbSBarry Smith 
769d382aafbSBarry Smith M*/
770*66122d6dSBarry Smith #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)((size_t)m1)*sizeof(**(r1)),(r1),(size_t)((size_t)m2)*sizeof(**(r2)),(r2),(size_t)((size_t)m3)*sizeof(**(r3)),(r3),(size_t)((size_t)m4)*sizeof(**(r4)),(r4),(size_t)((size_t)m5)*sizeof(**(r5)),(r5),(size_t)((size_t)m6)*sizeof(**(r6)),(r6))
771d382aafbSBarry Smith 
772d382aafbSBarry Smith /*MC
7731795a4d1SJed Brown    PetscCalloc6 - Allocates 6 cleared (zeroed) arrays of memory, all aligned to PETSC_MEMALIGN
774d382aafbSBarry Smith 
775eca87e8dSBarry Smith    Synopsis:
776aaa7dc30SBarry Smith     #include <petscsys.h>
7771795a4d1SJed Brown    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)
778eca87e8dSBarry Smith 
779eca87e8dSBarry Smith    Not Collective
780eca87e8dSBarry Smith 
781e28ce29aSPatrick Sanan    Input Parameters:
782d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
783d382aafbSBarry Smith .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
784d382aafbSBarry Smith .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
785d382aafbSBarry Smith .  m4 - number of elements to allocate in 4th chunk  (may be zero)
786d382aafbSBarry Smith .  m5 - number of elements to allocate in 5th chunk  (may be zero)
7871795a4d1SJed Brown -  m6 - number of elements to allocate in 6th chunk  (may be zero)
7881795a4d1SJed Brown 
789e28ce29aSPatrick Sanan    Output Parameters:
7901795a4d1SJed Brown +  r1 - memory allocated in first chunk
7911795a4d1SJed Brown .  r2 - memory allocated in second chunk
7921795a4d1SJed Brown .  r3 - memory allocated in third chunk
7931795a4d1SJed Brown .  r4 - memory allocated in fourth chunk
7941795a4d1SJed Brown .  r5 - memory allocated in fifth chunk
7951795a4d1SJed Brown -  r6 - memory allocated in sixth chunk
7961795a4d1SJed Brown 
7971795a4d1SJed Brown    Level: developer
7981795a4d1SJed Brown 
7991795a4d1SJed Brown .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscMalloc6(), PetscFree6()
8001795a4d1SJed Brown 
8011795a4d1SJed Brown M*/
802*66122d6dSBarry Smith #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)((size_t)m1)*sizeof(**(r1)),(r1),(size_t)((size_t)m2)*sizeof(**(r2)),(r2),(size_t)((size_t)m3)*sizeof(**(r3)),(r3),(size_t)((size_t)m4)*sizeof(**(r4)),(r4),(size_t)((size_t)m5)*sizeof(**(r5)),(r5),(size_t)((size_t)m6)*sizeof(**(r6)),(r6))
8031795a4d1SJed Brown 
8041795a4d1SJed Brown /*MC
805dcca6d9dSJed Brown    PetscMalloc7 - Allocates 7 arrays of memory, all aligned to PETSC_MEMALIGN
806d382aafbSBarry Smith 
807d382aafbSBarry Smith    Synopsis:
808aaa7dc30SBarry Smith     #include <petscsys.h>
809dcca6d9dSJed Brown    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)
810d382aafbSBarry Smith 
811d382aafbSBarry Smith    Not Collective
812d382aafbSBarry Smith 
813e28ce29aSPatrick Sanan    Input Parameters:
814d382aafbSBarry Smith +  m1 - number of elements to allocate in 1st chunk  (may be zero)
815d382aafbSBarry Smith .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
816d382aafbSBarry Smith .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
817d382aafbSBarry Smith .  m4 - number of elements to allocate in 4th chunk  (may be zero)
818d382aafbSBarry Smith .  m5 - number of elements to allocate in 5th chunk  (may be zero)
819d382aafbSBarry Smith .  m6 - number of elements to allocate in 6th chunk  (may be zero)
820dcca6d9dSJed Brown -  m7 - number of elements to allocate in 7th chunk  (may be zero)
821d382aafbSBarry Smith 
822e28ce29aSPatrick Sanan    Output Parameters:
823d382aafbSBarry Smith +  r1 - memory allocated in first chunk
824d382aafbSBarry Smith .  r2 - memory allocated in second chunk
825d382aafbSBarry Smith .  r3 - memory allocated in third chunk
826d382aafbSBarry Smith .  r4 - memory allocated in fourth chunk
827d382aafbSBarry Smith .  r5 - memory allocated in fifth chunk
828d382aafbSBarry Smith .  r6 - memory allocated in sixth chunk
829eca87e8dSBarry Smith -  r7 - memory allocated in seventh chunk
830d382aafbSBarry Smith 
831d382aafbSBarry Smith    Level: developer
832d382aafbSBarry Smith 
8331795a4d1SJed Brown .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscCalloc7(), PetscFree7()
834d382aafbSBarry Smith 
835d382aafbSBarry Smith M*/
836*66122d6dSBarry Smith #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)((size_t)m1)*sizeof(**(r1)),(r1),(size_t)((size_t)m2)*sizeof(**(r2)),(r2),(size_t)((size_t)m3)*sizeof(**(r3)),(r3),(size_t)((size_t)m4)*sizeof(**(r4)),(r4),(size_t)((size_t)m5)*sizeof(**(r5)),(r5),(size_t)((size_t)m6)*sizeof(**(r6)),(r6),(size_t)((size_t)m7)*sizeof(**(r7)),(r7))
837d382aafbSBarry Smith 
838d382aafbSBarry Smith /*MC
8391795a4d1SJed Brown    PetscCalloc7 - Allocates 7 cleared (zeroed) arrays of memory, all aligned to PETSC_MEMALIGN
8401795a4d1SJed Brown 
8411795a4d1SJed Brown    Synopsis:
842aaa7dc30SBarry Smith     #include <petscsys.h>
8431795a4d1SJed Brown    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)
8441795a4d1SJed Brown 
8451795a4d1SJed Brown    Not Collective
8461795a4d1SJed Brown 
847e28ce29aSPatrick Sanan    Input Parameters:
8481795a4d1SJed Brown +  m1 - number of elements to allocate in 1st chunk  (may be zero)
8491795a4d1SJed Brown .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
8501795a4d1SJed Brown .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
8511795a4d1SJed Brown .  m4 - number of elements to allocate in 4th chunk  (may be zero)
8521795a4d1SJed Brown .  m5 - number of elements to allocate in 5th chunk  (may be zero)
8531795a4d1SJed Brown .  m6 - number of elements to allocate in 6th chunk  (may be zero)
8541795a4d1SJed Brown -  m7 - number of elements to allocate in 7th chunk  (may be zero)
8551795a4d1SJed Brown 
856e28ce29aSPatrick Sanan    Output Parameters:
8571795a4d1SJed Brown +  r1 - memory allocated in first chunk
8581795a4d1SJed Brown .  r2 - memory allocated in second chunk
8591795a4d1SJed Brown .  r3 - memory allocated in third chunk
8601795a4d1SJed Brown .  r4 - memory allocated in fourth chunk
8611795a4d1SJed Brown .  r5 - memory allocated in fifth chunk
8621795a4d1SJed Brown .  r6 - memory allocated in sixth chunk
8631795a4d1SJed Brown -  r7 - memory allocated in seventh chunk
8641795a4d1SJed Brown 
8651795a4d1SJed Brown    Level: developer
8661795a4d1SJed Brown 
8671795a4d1SJed Brown .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscMalloc7(), PetscFree7()
8681795a4d1SJed Brown 
8691795a4d1SJed Brown M*/
870*66122d6dSBarry Smith #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)((size_t)m1)*sizeof(**(r1)),(r1),(size_t)((size_t)m2)*sizeof(**(r2)),(r2),(size_t)((size_t)m3)*sizeof(**(r3)),(r3),(size_t)((size_t)m4)*sizeof(**(r4)),(r4),(size_t)((size_t)m5)*sizeof(**(r5)),(r5),(size_t)((size_t)m6)*sizeof(**(r6)),(r6),(size_t)((size_t)m7)*sizeof(**(r7)),(r7))
8711795a4d1SJed Brown 
8721795a4d1SJed Brown /*MC
873503cfb0cSBarry Smith    PetscNew - Allocates memory of a particular type, zeros the memory! Aligned to PETSC_MEMALIGN
874d382aafbSBarry Smith 
875eca87e8dSBarry Smith    Synopsis:
876aaa7dc30SBarry Smith     #include <petscsys.h>
877b00a9115SJed Brown    PetscErrorCode PetscNew(type **result)
878eca87e8dSBarry Smith 
879eca87e8dSBarry Smith    Not Collective
880eca87e8dSBarry Smith 
881d382aafbSBarry Smith    Output Parameter:
882b00a9115SJed Brown .  result - memory allocated, sized to match pointer type
883d382aafbSBarry Smith 
884d382aafbSBarry Smith    Level: beginner
885d382aafbSBarry Smith 
886390e1bf2SBarry Smith .seealso: PetscFree(), PetscMalloc(), PetscNewLog(), PetscCalloc1(), PetscMalloc1()
887d382aafbSBarry Smith 
888d382aafbSBarry Smith M*/
889b00a9115SJed Brown #define PetscNew(b)      PetscCalloc1(1,(b))
890ad0619ddSBarry Smith 
891ad0619ddSBarry Smith /*MC
892b00a9115SJed Brown    PetscNewLog - Allocates memory of a type matching pointer, zeros the memory! Aligned to PETSC_MEMALIGN. Associates the memory allocated
893ad0619ddSBarry Smith          with the given object using PetscLogObjectMemory().
894ad0619ddSBarry Smith 
895ad0619ddSBarry Smith    Synopsis:
896aaa7dc30SBarry Smith     #include <petscsys.h>
897b00a9115SJed Brown    PetscErrorCode PetscNewLog(PetscObject obj,type **result)
898ad0619ddSBarry Smith 
899ad0619ddSBarry Smith    Not Collective
900ad0619ddSBarry Smith 
901ad0619ddSBarry Smith    Input Parameter:
902b00a9115SJed Brown .  obj - object memory is logged to
903ad0619ddSBarry Smith 
904ad0619ddSBarry Smith    Output Parameter:
905b00a9115SJed Brown .  result - memory allocated, sized to match pointer type
906ad0619ddSBarry Smith 
907ad0619ddSBarry Smith    Level: developer
908ad0619ddSBarry Smith 
909390e1bf2SBarry Smith .seealso: PetscFree(), PetscMalloc(), PetscNew(), PetscLogObjectMemory(), PetscCalloc1(), PetscMalloc1()
910ad0619ddSBarry Smith 
911ad0619ddSBarry Smith M*/
912d12f57a0SLisandro Dalcin #define PetscNewLog(o,b) (PetscNew((b)) || PetscLogObjectMemory((PetscObject)o,sizeof(**(b))))
913d382aafbSBarry Smith 
914d382aafbSBarry Smith /*MC
915d382aafbSBarry Smith    PetscFree - Frees memory
916d382aafbSBarry Smith 
917eca87e8dSBarry Smith    Synopsis:
918aaa7dc30SBarry Smith     #include <petscsys.h>
919eca87e8dSBarry Smith    PetscErrorCode PetscFree(void *memory)
920eca87e8dSBarry Smith 
921eca87e8dSBarry Smith    Not Collective
922eca87e8dSBarry Smith 
923d382aafbSBarry Smith    Input Parameter:
9247f4976b7SJacob Faibussowitsch .   memory - memory to free (the pointer is ALWAYS set to NULL upon success)
925d382aafbSBarry Smith 
926d382aafbSBarry Smith    Level: beginner
927d382aafbSBarry Smith 
92849d7da52SJed Brown    Notes:
929390e1bf2SBarry Smith    Do not free memory obtained with PetscMalloc2(), PetscCalloc2() etc, they must be freed with PetscFree2() etc.
930390e1bf2SBarry Smith 
93149d7da52SJed Brown    It is safe to call PetscFree() on a NULL pointer.
932d382aafbSBarry Smith 
933390e1bf2SBarry Smith .seealso: PetscNew(), PetscMalloc(), PetscNewLog(), PetscMalloc1(), PetscCalloc1()
934d382aafbSBarry Smith 
935d382aafbSBarry Smith M*/
936ffc31a0eSLisandro Dalcin #define PetscFree(a)   ((*PetscTrFree)((void*)(a),__LINE__,PETSC_FUNCTION_NAME,__FILE__) || ((a) = NULL,0))
937d382aafbSBarry Smith 
938d382aafbSBarry Smith /*MC
939d382aafbSBarry Smith    PetscFree2 - Frees 2 chunks of memory obtained with PetscMalloc2()
940d382aafbSBarry Smith 
941eca87e8dSBarry Smith    Synopsis:
942aaa7dc30SBarry Smith     #include <petscsys.h>
943eca87e8dSBarry Smith    PetscErrorCode PetscFree2(void *memory1,void *memory2)
944eca87e8dSBarry Smith 
945eca87e8dSBarry Smith    Not Collective
946eca87e8dSBarry Smith 
947e28ce29aSPatrick Sanan    Input Parameters:
948d382aafbSBarry Smith +   memory1 - memory to free
949d382aafbSBarry Smith -   memory2 - 2nd memory to free
950d382aafbSBarry Smith 
951d382aafbSBarry Smith    Level: developer
952d382aafbSBarry Smith 
95395452b02SPatrick Sanan    Notes:
95495452b02SPatrick Sanan     Memory must have been obtained with PetscMalloc2()
955d382aafbSBarry Smith 
956d382aafbSBarry Smith .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree()
957d382aafbSBarry Smith 
958d382aafbSBarry Smith M*/
959ba282f50SJed Brown #define PetscFree2(m1,m2)   PetscFreeA(2,__LINE__,PETSC_FUNCTION_NAME,__FILE__,&(m1),&(m2))
960d382aafbSBarry Smith 
961d382aafbSBarry Smith /*MC
962d382aafbSBarry Smith    PetscFree3 - Frees 3 chunks of memory obtained with PetscMalloc3()
963d382aafbSBarry Smith 
964eca87e8dSBarry Smith    Synopsis:
965aaa7dc30SBarry Smith     #include <petscsys.h>
966eca87e8dSBarry Smith    PetscErrorCode PetscFree3(void *memory1,void *memory2,void *memory3)
967eca87e8dSBarry Smith 
968eca87e8dSBarry Smith    Not Collective
969eca87e8dSBarry Smith 
970e28ce29aSPatrick Sanan    Input Parameters:
971d382aafbSBarry Smith +   memory1 - memory to free
972d382aafbSBarry Smith .   memory2 - 2nd memory to free
973d382aafbSBarry Smith -   memory3 - 3rd memory to free
974d382aafbSBarry Smith 
975d382aafbSBarry Smith    Level: developer
976d382aafbSBarry Smith 
97795452b02SPatrick Sanan    Notes:
97895452b02SPatrick Sanan     Memory must have been obtained with PetscMalloc3()
979d382aafbSBarry Smith 
980d382aafbSBarry Smith .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3()
981d382aafbSBarry Smith 
982d382aafbSBarry Smith M*/
983ba282f50SJed Brown #define PetscFree3(m1,m2,m3)   PetscFreeA(3,__LINE__,PETSC_FUNCTION_NAME,__FILE__,&(m1),&(m2),&(m3))
984d382aafbSBarry Smith 
985d382aafbSBarry Smith /*MC
986d382aafbSBarry Smith    PetscFree4 - Frees 4 chunks of memory obtained with PetscMalloc4()
987d382aafbSBarry Smith 
988eca87e8dSBarry Smith    Synopsis:
989aaa7dc30SBarry Smith     #include <petscsys.h>
990eca87e8dSBarry Smith    PetscErrorCode PetscFree4(void *m1,void *m2,void *m3,void *m4)
991eca87e8dSBarry Smith 
992eca87e8dSBarry Smith    Not Collective
993eca87e8dSBarry Smith 
994e28ce29aSPatrick Sanan    Input Parameters:
995d382aafbSBarry Smith +   m1 - memory to free
996d382aafbSBarry Smith .   m2 - 2nd memory to free
997d382aafbSBarry Smith .   m3 - 3rd memory to free
998d382aafbSBarry Smith -   m4 - 4th memory to free
999d382aafbSBarry Smith 
1000d382aafbSBarry Smith    Level: developer
1001d382aafbSBarry Smith 
100295452b02SPatrick Sanan    Notes:
100395452b02SPatrick Sanan     Memory must have been obtained with PetscMalloc4()
1004d382aafbSBarry Smith 
1005d382aafbSBarry Smith .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4()
1006d382aafbSBarry Smith 
1007d382aafbSBarry Smith M*/
1008ba282f50SJed Brown #define PetscFree4(m1,m2,m3,m4)   PetscFreeA(4,__LINE__,PETSC_FUNCTION_NAME,__FILE__,&(m1),&(m2),&(m3),&(m4))
1009d382aafbSBarry Smith 
1010d382aafbSBarry Smith /*MC
1011d382aafbSBarry Smith    PetscFree5 - Frees 5 chunks of memory obtained with PetscMalloc5()
1012d382aafbSBarry Smith 
1013eca87e8dSBarry Smith    Synopsis:
1014aaa7dc30SBarry Smith     #include <petscsys.h>
1015eca87e8dSBarry Smith    PetscErrorCode PetscFree5(void *m1,void *m2,void *m3,void *m4,void *m5)
1016eca87e8dSBarry Smith 
1017eca87e8dSBarry Smith    Not Collective
1018eca87e8dSBarry Smith 
1019e28ce29aSPatrick Sanan    Input Parameters:
1020d382aafbSBarry Smith +   m1 - memory to free
1021d382aafbSBarry Smith .   m2 - 2nd memory to free
1022d382aafbSBarry Smith .   m3 - 3rd memory to free
1023d382aafbSBarry Smith .   m4 - 4th memory to free
1024d382aafbSBarry Smith -   m5 - 5th memory to free
1025d382aafbSBarry Smith 
1026d382aafbSBarry Smith    Level: developer
1027d382aafbSBarry Smith 
102895452b02SPatrick Sanan    Notes:
102995452b02SPatrick Sanan     Memory must have been obtained with PetscMalloc5()
1030d382aafbSBarry Smith 
1031d382aafbSBarry Smith .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5()
1032d382aafbSBarry Smith 
1033d382aafbSBarry Smith M*/
1034ba282f50SJed Brown #define PetscFree5(m1,m2,m3,m4,m5)   PetscFreeA(5,__LINE__,PETSC_FUNCTION_NAME,__FILE__,&(m1),&(m2),&(m3),&(m4),&(m5))
1035d382aafbSBarry Smith 
1036d382aafbSBarry Smith /*MC
1037d382aafbSBarry Smith    PetscFree6 - Frees 6 chunks of memory obtained with PetscMalloc6()
1038d382aafbSBarry Smith 
1039eca87e8dSBarry Smith    Synopsis:
1040aaa7dc30SBarry Smith     #include <petscsys.h>
1041eca87e8dSBarry Smith    PetscErrorCode PetscFree6(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6)
1042eca87e8dSBarry Smith 
1043eca87e8dSBarry Smith    Not Collective
1044eca87e8dSBarry Smith 
1045e28ce29aSPatrick Sanan    Input Parameters:
1046d382aafbSBarry Smith +   m1 - memory to free
1047d382aafbSBarry Smith .   m2 - 2nd memory to free
1048d382aafbSBarry Smith .   m3 - 3rd memory to free
1049d382aafbSBarry Smith .   m4 - 4th memory to free
1050d382aafbSBarry Smith .   m5 - 5th memory to free
1051d382aafbSBarry Smith -   m6 - 6th memory to free
1052d382aafbSBarry Smith 
1053d382aafbSBarry Smith    Level: developer
1054d382aafbSBarry Smith 
105595452b02SPatrick Sanan    Notes:
105695452b02SPatrick Sanan     Memory must have been obtained with PetscMalloc6()
1057d382aafbSBarry Smith 
1058d382aafbSBarry Smith .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5(), PetscMalloc6()
1059d382aafbSBarry Smith 
1060d382aafbSBarry Smith M*/
1061ba282f50SJed Brown #define PetscFree6(m1,m2,m3,m4,m5,m6)   PetscFreeA(6,__LINE__,PETSC_FUNCTION_NAME,__FILE__,&(m1),&(m2),&(m3),&(m4),&(m5),&(m6))
1062d382aafbSBarry Smith 
1063d382aafbSBarry Smith /*MC
1064d382aafbSBarry Smith    PetscFree7 - Frees 7 chunks of memory obtained with PetscMalloc7()
1065d382aafbSBarry Smith 
1066eca87e8dSBarry Smith    Synopsis:
1067aaa7dc30SBarry Smith     #include <petscsys.h>
1068eca87e8dSBarry Smith    PetscErrorCode PetscFree7(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6,void *m7)
1069eca87e8dSBarry Smith 
1070eca87e8dSBarry Smith    Not Collective
1071eca87e8dSBarry Smith 
1072e28ce29aSPatrick Sanan    Input Parameters:
1073d382aafbSBarry Smith +   m1 - memory to free
1074d382aafbSBarry Smith .   m2 - 2nd memory to free
1075d382aafbSBarry Smith .   m3 - 3rd memory to free
1076d382aafbSBarry Smith .   m4 - 4th memory to free
1077d382aafbSBarry Smith .   m5 - 5th memory to free
1078d382aafbSBarry Smith .   m6 - 6th memory to free
1079d382aafbSBarry Smith -   m7 - 7th memory to free
1080d382aafbSBarry Smith 
1081d382aafbSBarry Smith    Level: developer
1082d382aafbSBarry Smith 
108395452b02SPatrick Sanan    Notes:
108495452b02SPatrick Sanan     Memory must have been obtained with PetscMalloc7()
1085d382aafbSBarry Smith 
1086d382aafbSBarry Smith .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5(), PetscMalloc6(),
1087d382aafbSBarry Smith           PetscMalloc7()
1088d382aafbSBarry Smith 
1089d382aafbSBarry Smith M*/
1090ba282f50SJed Brown #define PetscFree7(m1,m2,m3,m4,m5,m6,m7)   PetscFreeA(7,__LINE__,PETSC_FUNCTION_NAME,__FILE__,&(m1),&(m2),&(m3),&(m4),&(m5),&(m6),&(m7))
1091d382aafbSBarry Smith 
1092ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocA(int,PetscBool,int,const char *,const char *,size_t,void *,...);
1093ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscFreeA(int,int,const char *,const char *,void *,...);
1094071fcb05SBarry Smith PETSC_EXTERN PetscErrorCode (*PetscTrMalloc)(size_t,PetscBool,int,const char[],const char[],void**);
1095efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode (*PetscTrFree)(void*,int,const char[],const char[]);
10963221ece2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode (*PetscTrRealloc)(size_t,int,const char[],const char[],void**);
1097ba282f50SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocSetCoalesce(PetscBool);
109892f119d6SBarry Smith 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 **));
1099014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocClear(void);
1100d382aafbSBarry Smith 
1101d382aafbSBarry Smith /*
1102c1706be6SHong Zhang   Unlike PetscMallocSet and PetscMallocClear which overwrite the existing settings, these two functions save the previous choice of allocator, and should be used in pair.
1103c1706be6SHong Zhang */
1104c1706be6SHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocSetDRAM(void);
1105c1706be6SHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocResetDRAM(void);
110631f06eaaSHong Zhang #if defined(PETSC_HAVE_CUDA)
110731f06eaaSHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocSetCUDAHost(void);
110831f06eaaSHong Zhang PETSC_EXTERN PetscErrorCode PetscMallocResetCUDAHost(void);
110931f06eaaSHong Zhang #endif
111059af0bd3SScott Kruger #if defined(PETSC_HAVE_HIP)
111159af0bd3SScott Kruger PETSC_EXTERN PetscErrorCode PetscMallocSetHIPHost(void);
111259af0bd3SScott Kruger PETSC_EXTERN PetscErrorCode PetscMallocResetHIPHost(void);
111359af0bd3SScott Kruger #endif
111459af0bd3SScott Kruger 
1115a5057860SBarry Smith #define MPIU_PETSCLOGDOUBLE  MPI_DOUBLE
111636763ca0SBas van 't Hof #define MPIU_2PETSCLOGDOUBLE MPI_2DOUBLE_PRECISION
1117a5057860SBarry Smith 
1118a5057860SBarry Smith /*
111966d669d6SBarry Smith    Routines for tracing memory corruption/bleeding with default PETSc memory allocation
1120d382aafbSBarry Smith */
1121014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocDump(FILE *);
112292f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocView(FILE *);
1123014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocGetCurrentUsage(PetscLogDouble *);
1124014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMallocGetMaximumUsage(PetscLogDouble *);
1125e3ed9ee7SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocPushMaximumUsage(int);
1126e3ed9ee7SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocPopMaximumUsage(int,PetscLogDouble*);
112792f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocSetDebug(PetscBool,PetscBool);
112892f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocGetDebug(PetscBool*,PetscBool*,PetscBool*);
1129efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscMallocValidate(int,const char[],const char[]);
113092f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocViewSet(PetscLogDouble);
113192f119d6SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocViewGet(PetscBool*);
1132608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocLogRequestedSizeSet(PetscBool);
1133608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocLogRequestedSizeGet(PetscBool*);
1134d382aafbSBarry Smith 
11356a6fc655SJed Brown PETSC_EXTERN const char *const PetscDataTypes[];
1136014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDataTypeToMPIDataType(PetscDataType,MPI_Datatype*);
1137014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMPIDataTypeToPetscDataType(MPI_Datatype,PetscDataType*);
1138014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDataTypeGetSize(PetscDataType,size_t*);
11398e4b2d1dSBarry Smith PETSC_EXTERN PetscErrorCode PetscDataTypeFromString(const char*,PetscDataType*,PetscBool*);
1140d382aafbSBarry Smith 
1141d382aafbSBarry Smith /*
1142d382aafbSBarry Smith     Basic memory and string operations. These are usually simple wrappers
1143d382aafbSBarry Smith    around the basic Unix system calls, but a few of them have additional
1144d382aafbSBarry Smith    functionality and/or error checking.
1145d382aafbSBarry Smith */
1146014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemcmp(const void*,const void*,size_t,PetscBool  *);
1147014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrlen(const char[],size_t*);
1148d67fe73bSBarry Smith PETSC_EXTERN PetscErrorCode PetscStrToArray(const char[],char,int*,char ***);
1149014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrToArrayDestroy(int,char **);
1150014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrcmp(const char[],const char[],PetscBool  *);
1151014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrgrt(const char[],const char[],PetscBool  *);
1152014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrcasecmp(const char[],const char[],PetscBool *);
1153014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrncmp(const char[],const char[],size_t,PetscBool *);
1154014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrcpy(char[],const char[]);
1155014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrcat(char[],const char[]);
1156a126751eSBarry Smith PETSC_EXTERN PetscErrorCode PetscStrlcat(char[],const char[],size_t);
1157014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrncpy(char[],const char[],size_t);
1158014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrchr(const char[],char,char *[]);
1159014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrtolower(char[]);
11602f234a98SBarry Smith PETSC_EXTERN PetscErrorCode PetscStrtoupper(char[]);
1161014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrrchr(const char[],char,char *[]);
1162014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrstr(const char[],const char[],char *[]);
1163014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrrstr(const char[],const char[],char *[]);
1164014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrendswith(const char[],const char[],PetscBool*);
11652c9581d2SBarry Smith PETSC_EXTERN PetscErrorCode PetscStrbeginswith(const char[],const char[],PetscBool*);
1166014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrendswithwhich(const char[],const char *const*,PetscInt*);
1167014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrallocpy(const char[],char *[]);
116847340559SBarry Smith PETSC_EXTERN PetscErrorCode PetscStrArrayallocpy(const char *const*,char***);
11696fed8037SJed Brown PETSC_EXTERN PetscErrorCode PetscStrArrayDestroy(char***);
11706991f827SBarry Smith PETSC_EXTERN PetscErrorCode PetscStrNArrayallocpy(PetscInt,const char *const*,char***);
11716991f827SBarry Smith PETSC_EXTERN PetscErrorCode PetscStrNArrayDestroy(PetscInt,char***);
1172014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStrreplace(MPI_Comm,const char[],char[],size_t);
1173d382aafbSBarry Smith 
1174573b0fb4SBarry Smith PETSC_EXTERN void PetscStrcmpNoError(const char[],const char[],PetscBool  *);
1175573b0fb4SBarry Smith 
1176014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTokenCreate(const char[],const char,PetscToken*);
1177014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTokenFind(PetscToken,char *[]);
1178014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTokenDestroy(PetscToken*);
1179d382aafbSBarry Smith 
1180e94e781bSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscStrInList(const char[],const char[],char,PetscBool*);
1181a53986e1SJed Brown PETSC_EXTERN PetscErrorCode PetscEListFind(PetscInt,const char *const*,const char*,PetscInt*,PetscBool*);
1182a53986e1SJed Brown PETSC_EXTERN PetscErrorCode PetscEnumFind(const char *const*,const char*,PetscEnum*,PetscBool*);
1183a53986e1SJed Brown 
1184d382aafbSBarry Smith /*
1185d382aafbSBarry Smith    These are MPI operations for MPI_Allreduce() etc
1186d382aafbSBarry Smith */
1187367daffbSBarry Smith PETSC_EXTERN MPI_Op MPIU_MAXSUM_OP;
1188570b7f6dSBarry Smith #if defined(PETSC_USE_REAL___FLOAT128) || defined(PETSC_USE_REAL___FP16)
1189de272c7aSSatish Balay PETSC_EXTERN MPI_Op MPIU_SUM;
1190014dd563SJed Brown PETSC_EXTERN MPI_Op MPIU_MAX;
1191014dd563SJed Brown PETSC_EXTERN MPI_Op MPIU_MIN;
1192d9822059SBarry Smith #else
1193de272c7aSSatish Balay #define MPIU_SUM MPI_SUM
1194d9822059SBarry Smith #define MPIU_MAX MPI_MAX
1195d9822059SBarry Smith #define MPIU_MIN MPI_MIN
1196d9822059SBarry Smith #endif
1197014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMaxSum(MPI_Comm,const PetscInt[],PetscInt*,PetscInt*);
1198d382aafbSBarry Smith 
1199014dd563SJed Brown PETSC_EXTERN PetscErrorCode MPIULong_Send(void*,PetscInt,MPI_Datatype,PetscMPIInt,PetscMPIInt,MPI_Comm);
1200014dd563SJed Brown PETSC_EXTERN PetscErrorCode MPIULong_Recv(void*,PetscInt,MPI_Datatype,PetscMPIInt,PetscMPIInt,MPI_Comm);
1201eb3f98d2SBarry Smith 
120295c0884eSLisandro Dalcin PETSC_EXTERN const char *const PetscFileModes[];
1203d6a4318aSJed Brown 
1204639ff905SBarry Smith /*
1205639ff905SBarry Smith     Defines PETSc error handling.
1206639ff905SBarry Smith */
1207639ff905SBarry Smith #include <petscerror.h>
1208d382aafbSBarry Smith 
12090700a824SBarry Smith #define PETSC_SMALLEST_CLASSID  1211211
1210014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_LARGEST_CLASSID;
1211014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_OBJECT_CLASSID;
1212014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscClassIdRegister(const char[],PetscClassId *);
121381256985SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscObjectGetId(PetscObject,PetscObjectId*);
121481256985SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscObjectCompareId(PetscObject,PetscObjectId,PetscBool*);
121581256985SMatthew G. Knepley 
1216d382aafbSBarry Smith /*
1217d382aafbSBarry Smith    Routines that get memory usage information from the OS
1218d382aafbSBarry Smith */
1219014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemoryGetCurrentUsage(PetscLogDouble *);
1220014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemoryGetMaximumUsage(PetscLogDouble *);
1221014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMemorySetGetMaximumUsage(void);
1222b44d5720SBarry Smith PETSC_EXTERN PetscErrorCode PetscMemoryTrace(const char[]);
1223d382aafbSBarry Smith 
1224014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSleep(PetscReal);
1225d382aafbSBarry Smith 
1226d382aafbSBarry Smith /*
1227d382aafbSBarry Smith    Initialization of PETSc
1228d382aafbSBarry Smith */
1229014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitialize(int*,char***,const char[],const char[]);
1230014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeNoPointers(int,char**,const char[],const char[]);
1231014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeNoArguments(void);
1232014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitialized(PetscBool *);
1233014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFinalized(PetscBool *);
1234014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFinalize(void);
1235014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscInitializeFortran(void);
1236014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArgs(int*,char ***);
1237014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArguments(char ***);
1238014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFreeArguments(char **);
1239d382aafbSBarry Smith 
1240014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscEnd(void);
1241607a6623SBarry Smith PETSC_EXTERN PetscErrorCode PetscSysInitializePackage(void);
1242d382aafbSBarry Smith 
1243014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonInitialize(const char[],const char[]);
1244014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonFinalize(void);
1245014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonPrintError(void);
1246014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPythonMonitorSet(PetscObject,const char[]);
1247d382aafbSBarry Smith 
1248a50e088cSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMonitorCompare(PetscErrorCode (*)(void),void *,PetscErrorCode (*)(void**),PetscErrorCode (*)(void),void *,PetscErrorCode (*)(void**),PetscBool *);
1249a50e088cSMatthew G. Knepley 
1250d382aafbSBarry Smith /*
1251d382aafbSBarry Smith      These are so that in extern C code we can caste function pointers to non-extern C
12522981ebdbSBarry Smith    function pointers. Since the regular C++ code expects its function pointers to be C++
1253d382aafbSBarry Smith */
1254638cfed1SJed Brown PETSC_EXTERN_TYPEDEF typedef void (**PetscVoidStarFunction)(void);
1255638cfed1SJed Brown PETSC_EXTERN_TYPEDEF typedef void (*PetscVoidFunction)(void);
1256638cfed1SJed Brown PETSC_EXTERN_TYPEDEF typedef PetscErrorCode (*PetscErrorCodeFunction)(void);
1257d382aafbSBarry Smith 
1258d382aafbSBarry Smith /*
1259d382aafbSBarry Smith     Functions that can act on any PETSc object.
1260d382aafbSBarry Smith */
1261014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectDestroy(PetscObject*);
1262014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetComm(PetscObject,MPI_Comm *);
1263014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetClassId(PetscObject,PetscClassId *);
1264014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetClassName(PetscObject,const char *[]);
1265014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetType(PetscObject,const char []);
1266014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetType(PetscObject,const char *[]);
1267014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetName(PetscObject,const char[]);
1268014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetName(PetscObject,const char*[]);
1269014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetTabLevel(PetscObject,PetscInt);
1270014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetTabLevel(PetscObject,PetscInt*);
1271014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectIncrementTabLevel(PetscObject,PetscObject,PetscInt);
1272014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectReference(PetscObject);
1273014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetReference(PetscObject,PetscInt*);
1274014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectDereference(PetscObject);
1275014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetNewTag(PetscObject,PetscMPIInt*);
1276014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectCompose(PetscObject,const char[],PetscObject);
1277014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRemoveReference(PetscObject,const char[]);
1278014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectQuery(PetscObject,const char[],PetscObject*);
1279bdf89e91SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectComposeFunction_Private(PetscObject,const char[],void (*)(void));
1280bdf89e91SBarry Smith #define PetscObjectComposeFunction(a,b,d) PetscObjectComposeFunction_Private(a,b,(PetscVoidFunction)(d))
1281014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetFromOptions(PetscObject);
1282014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetUp(PetscObject);
12830eb63584SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSetPrintedOptions(PetscObject);
12840eb63584SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectInheritPrintedOptions(PetscObject,PetscObject);
1285014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscCommGetNewTag(MPI_Comm,PetscMPIInt*);
1286d382aafbSBarry Smith 
1287665c2dedSJed Brown #include <petscviewertypes.h>
1288639ff905SBarry Smith #include <petscoptions.h>
1289639ff905SBarry Smith 
1290608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocTraceSet(PetscViewer,PetscBool,PetscLogDouble);
1291608c71bfSMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscMallocTraceGet(PetscBool*);
1292608c71bfSMatthew G. Knepley 
12930633abcbSJed Brown PETSC_EXTERN PetscErrorCode PetscObjectsListGetGlobalNumbering(MPI_Comm,PetscInt,PetscObject*,PetscInt*,PetscInt*);
12940633abcbSJed Brown 
1295c5e4d11fSDmitry Karpeev PETSC_EXTERN PetscErrorCode PetscMemoryView(PetscViewer,const char[]);
1296dae58748SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectPrintClassNamePrefixType(PetscObject,PetscViewer);
1297639ff905SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectView(PetscObject,PetscViewer);
12980005d66cSJed Brown #define PetscObjectQueryFunction(obj,name,fptr) PetscObjectQueryFunction_Private((obj),(name),(PetscVoidFunction*)(fptr))
12990005d66cSJed Brown PETSC_EXTERN PetscErrorCode PetscObjectQueryFunction_Private(PetscObject,const char[],void (**)(void));
1300014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectSetOptionsPrefix(PetscObject,const char[]);
1301014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectAppendOptionsPrefix(PetscObject,const char[]);
1302014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectPrependOptionsPrefix(PetscObject,const char[]);
1303014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectGetOptionsPrefix(PetscObject,const char*[]);
1304014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectChangeTypeName(PetscObject,const char[]);
1305014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRegisterDestroy(PetscObject);
1306014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectRegisterDestroyAll(void);
1307685405a1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectViewFromOptions(PetscObject,PetscObject,const char[]);
1308014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectName(PetscObject);
1309014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectTypeCompare(PetscObject,const char[],PetscBool *);
13104099cc6bSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectBaseTypeCompare(PetscObject,const char[],PetscBool *);
1311014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscObjectTypeCompareAny(PetscObject,PetscBool*,const char[],...);
1312b9e7e5c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectBaseTypeCompareAny(PetscObject,PetscBool*,const char[],...);
1313014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRegisterFinalize(PetscErrorCode (*)(void));
1314014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRegisterFinalizeAll(void);
1315d382aafbSBarry Smith 
1316e04113cfSBarry Smith #if defined(PETSC_HAVE_SAWS)
13177aab2a10SBarry Smith PETSC_EXTERN PetscErrorCode PetscSAWsBlock(void);
1318e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsViewOff(PetscObject);
1319e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsSetBlock(PetscObject,PetscBool);
1320e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsBlock(PetscObject);
1321e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsGrantAccess(PetscObject);
1322e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectSAWsTakeAccess(PetscObject);
1323e04113cfSBarry Smith PETSC_EXTERN void           PetscStackSAWsGrantAccess(void);
1324e04113cfSBarry Smith PETSC_EXTERN void           PetscStackSAWsTakeAccess(void);
1325e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscStackViewSAWs(void);
1326e04113cfSBarry Smith PETSC_EXTERN PetscErrorCode PetscStackSAWsViewOff(void);
132715681b3cSBarry Smith 
1328ec7429eaSBarry Smith #else
13297aab2a10SBarry Smith #define PetscSAWsBlock()                        0
1330e04113cfSBarry Smith #define PetscObjectSAWsViewOff(obj)             0
1331e04113cfSBarry Smith #define PetscObjectSAWsSetBlock(obj,flg)        0
1332e04113cfSBarry Smith #define PetscObjectSAWsBlock(obj)               0
1333e04113cfSBarry Smith #define PetscObjectSAWsGrantAccess(obj)         0
1334e04113cfSBarry Smith #define PetscObjectSAWsTakeAccess(obj)          0
1335e04113cfSBarry Smith #define PetscStackViewSAWs()                    0
1336e04113cfSBarry Smith #define PetscStackSAWsViewOff()                 0
1337e04113cfSBarry Smith #define PetscStackSAWsTakeAccess()
1338e04113cfSBarry Smith #define PetscStackSAWsGrantAccess()
133915681b3cSBarry Smith 
1340ec7429eaSBarry Smith #endif
1341b90c6cbeSBarry Smith 
134282b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLOpen(const char[],PetscDLMode,PetscDLHandle *);
134382b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLClose(PetscDLHandle *);
134482b97d80SJed Brown PETSC_EXTERN PetscErrorCode PetscDLSym(PetscDLHandle,const char[],void **);
1345258ec3d2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDLAddr(void (*)(void), char **);
1346258ec3d2SMatthew G. Knepley #ifdef PETSC_HAVE_CXX
1347258ec3d2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscDemangleSymbol(const char *, char **);
1348258ec3d2SMatthew G. Knepley #endif
13497d5d4d99SBarry Smith 
13505fe58b6fSBarry Smith #if defined(PETSC_USE_DEBUG)
1351a64a8e02SBarry Smith PETSC_EXTERN PetscErrorCode PetscMallocGetStack(void*,PetscStack**);
13525fe58b6fSBarry Smith #endif
13537eb1d149SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectsDump(FILE*,PetscBool);
1354a64a8e02SBarry Smith 
1355140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListDestroy(PetscObjectList*);
1356140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListFind(PetscObjectList,const char[],PetscObject*);
1357140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListReverseFind(PetscObjectList,PetscObject,char**,PetscBool*);
1358140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListAdd(PetscObjectList *,const char[],PetscObject);
1359140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListRemoveReference(PetscObjectList *,const char[]);
1360140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscObjectListDuplicate(PetscObjectList,PetscObjectList *);
1361d382aafbSBarry Smith 
1362d382aafbSBarry Smith /*
1363503cfb0cSBarry Smith     Dynamic library lists. Lists of names of routines in objects or in dynamic
1364d382aafbSBarry Smith   link libraries that will be loaded as needed.
1365d382aafbSBarry Smith */
1366a240a19fSJed Brown 
1367a240a19fSJed Brown #define PetscFunctionListAdd(list,name,fptr) PetscFunctionListAdd_Private((list),(name),(PetscVoidFunction)(fptr))
1368a240a19fSJed Brown PETSC_EXTERN PetscErrorCode PetscFunctionListAdd_Private(PetscFunctionList*,const char[],void (*)(void));
1369140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListDestroy(PetscFunctionList*);
13701c9cd337SJed Brown #define PetscFunctionListFind(list,name,fptr) PetscFunctionListFind_Private((list),(name),(PetscVoidFunction*)(fptr))
13711c9cd337SJed Brown PETSC_EXTERN PetscErrorCode PetscFunctionListFind_Private(PetscFunctionList,const char[],void (**)(void));
137244ef3d73SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListPrintTypes(MPI_Comm,FILE*,const char[],const char[],const char[],const char[],PetscFunctionList,const char[],const char[]);
1373140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListDuplicate(PetscFunctionList,PetscFunctionList *);
1374140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListView(PetscFunctionList,PetscViewer);
1375140e18c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFunctionListGet(PetscFunctionList,const char ***,int*);
1376d382aafbSBarry Smith 
1377014dd563SJed Brown PETSC_EXTERN PetscDLLibrary  PetscDLLibrariesLoaded;
1378014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryAppend(MPI_Comm,PetscDLLibrary *,const char[]);
1379014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryPrepend(MPI_Comm,PetscDLLibrary *,const char[]);
1380014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibrarySym(MPI_Comm,PetscDLLibrary *,const char[],const char[],void **);
1381014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryPrintPath(PetscDLLibrary);
1382014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryRetrieve(MPI_Comm,const char[],char *,size_t,PetscBool  *);
1383014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryOpen(MPI_Comm,const char[],PetscDLLibrary *);
1384014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscDLLibraryClose(PetscDLLibrary);
1385d382aafbSBarry Smith 
1386d382aafbSBarry Smith /*
1387d382aafbSBarry Smith      Useful utility routines
1388d382aafbSBarry Smith */
1389014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSplitOwnership(MPI_Comm,PetscInt*,PetscInt*);
1390014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSplitOwnershipBlock(MPI_Comm,PetscInt,PetscInt*,PetscInt*);
1391d24d4204SJose E. Roman PETSC_EXTERN PetscErrorCode PetscSplitOwnershipEqual(MPI_Comm,PetscInt*,PetscInt*);
1392014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSequentialPhaseBegin(MPI_Comm,PetscMPIInt);
1393014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSequentialPhaseEnd(MPI_Comm,PetscMPIInt);
1394014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBarrier(PetscObject);
1395014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscMPIDump(FILE*);
1396dd438433SSatish Balay PETSC_EXTERN PetscErrorCode PetscGlobalMinMaxInt(MPI_Comm,PetscInt[2],PetscInt[2]);
1397dd438433SSatish Balay PETSC_EXTERN PetscErrorCode PetscGlobalMinMaxReal(MPI_Comm,PetscReal[2],PetscReal[2]);
1398d382aafbSBarry Smith 
139964ac3b0dSPatrick Sanan /*MC
1400ace3abfcSBarry Smith     PetscNot - negates a logical type value and returns result as a PetscBool
1401503cfb0cSBarry Smith 
1402e28ce29aSPatrick Sanan     Notes:
1403e28ce29aSPatrick Sanan     This is useful in cases like
1404503cfb0cSBarry Smith $     int        *a;
1405ace3abfcSBarry Smith $     PetscBool  flag = PetscNot(a)
14061cc8b206SBarry Smith      where !a would not return a PetscBool because we cannot provide a cast from int to PetscBool in C.
140764ac3b0dSPatrick Sanan 
140864ac3b0dSPatrick Sanan     Level: beginner
140964ac3b0dSPatrick Sanan 
141064ac3b0dSPatrick Sanan     .seealso : PetscBool, PETSC_TRUE, PETSC_FALSE
141164ac3b0dSPatrick Sanan M*/
1412d382aafbSBarry Smith #define PetscNot(a) ((a) ? PETSC_FALSE : PETSC_TRUE)
1413503cfb0cSBarry Smith 
1414d382aafbSBarry Smith /*MC
1415d382aafbSBarry Smith     PetscHelpPrintf - Prints help messages.
1416d382aafbSBarry Smith 
1417d382aafbSBarry Smith    Synopsis:
1418aaa7dc30SBarry Smith     #include <petscsys.h>
1419659f7ba0SBarry Smith      PetscErrorCode (*PetscHelpPrintf)(MPI_Comm comm, const char format[],args);
1420d382aafbSBarry Smith 
1421659f7ba0SBarry Smith     Collective on comm
1422eca87e8dSBarry Smith 
1423d382aafbSBarry Smith     Input Parameters:
1424659f7ba0SBarry Smith +  comm - the MPI communicator over which the help message is printed
1425d382aafbSBarry Smith .  format - the usual printf() format string
1426659f7ba0SBarry Smith -  args - arguments to be printed
1427d382aafbSBarry Smith 
1428d382aafbSBarry Smith    Level: developer
1429d382aafbSBarry Smith 
1430d382aafbSBarry Smith    Fortran Note:
1431d382aafbSBarry Smith      This routine is not supported in Fortran.
1432d382aafbSBarry Smith 
1433659f7ba0SBarry Smith    Note:
1434659f7ba0SBarry Smith      You can change how help messages are printed by replacing the function pointer with a function that does not simply write to stdout.
1435659f7ba0SBarry Smith 
1436659f7ba0SBarry Smith       To use, write your own function, for example,
1437659f7ba0SBarry Smith $PetscErrorCode mypetschelpprintf(MPI_Comm comm,const char format[],....)
1438659f7ba0SBarry Smith ${
1439659f7ba0SBarry Smith $ PetscFunctionReturn(0);
1440659f7ba0SBarry Smith $}
1441659f7ba0SBarry Smith then do the assigment
1442659f7ba0SBarry Smith $    PetscHelpPrintf = mypetschelpprintf;
1443659f7ba0SBarry Smith    You can do the assignment before PetscInitialize().
1444659f7ba0SBarry Smith 
1445659f7ba0SBarry Smith   The default routine used is called PetscHelpPrintfDefault().
1446d382aafbSBarry Smith 
1447d382aafbSBarry Smith .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscErrorPrintf()
1448d382aafbSBarry Smith M*/
14493ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode (*PetscHelpPrintf)(MPI_Comm,const char[],...) PETSC_ATTRIBUTE_FORMAT(2,3);
1450d382aafbSBarry Smith 
1451fcfd50ebSBarry Smith /*
1452fcfd50ebSBarry Smith      Defines PETSc profiling.
1453fcfd50ebSBarry Smith */
14542c8e378dSBarry Smith #include <petsclog.h>
1455fcfd50ebSBarry Smith 
1456fcfd50ebSBarry Smith /*
1457fcfd50ebSBarry Smith       Simple PETSc parallel IO for ASCII printing
1458fcfd50ebSBarry Smith */
1459014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFixFilename(const char[],char[]);
1460014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFOpen(MPI_Comm,const char[],const char[],FILE**);
1461014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFClose(MPI_Comm,FILE*);
14623ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_ATTRIBUTE_FORMAT(3,4);
14633ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscPrintf(MPI_Comm,const char[],...) PETSC_ATTRIBUTE_FORMAT(2,3);
14643ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSNPrintf(char*,size_t,const char [],...) PETSC_ATTRIBUTE_FORMAT(3,4);
14653ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSNPrintfCount(char*,size_t,const char [],size_t*,...) PETSC_ATTRIBUTE_FORMAT(3,5);
14661b5687a1SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatRealArray(char[],size_t,const char*,PetscInt,const PetscReal[]);
1467fcfd50ebSBarry Smith 
14683ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscErrorPrintfDefault(const char [],...) PETSC_ATTRIBUTE_FORMAT(1,2);
14693ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscErrorPrintfNone(const char [],...) PETSC_ATTRIBUTE_FORMAT(1,2);
14703ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscHelpPrintfDefault(MPI_Comm,const char [],...) PETSC_ATTRIBUTE_FORMAT(2,3);
1471d382aafbSBarry Smith 
1472d781fa04SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatConvertGetSize(const char*,size_t*);
1473d781fa04SBarry Smith PETSC_EXTERN PetscErrorCode PetscFormatConvert(const char*,char *);
1474d781fa04SBarry Smith 
1475d382aafbSBarry Smith #if defined(PETSC_HAVE_POPEN)
1476014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPOpen(MPI_Comm,const char[],const char[],const char[],FILE **);
1477016831caSBarry Smith PETSC_EXTERN PetscErrorCode PetscPClose(MPI_Comm,FILE*);
147874ba8654SBarry Smith PETSC_EXTERN PetscErrorCode PetscPOpenSetMachine(const char[]);
1479d382aafbSBarry Smith #endif
1480d382aafbSBarry Smith 
14813ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSynchronizedPrintf(MPI_Comm,const char[],...) PETSC_ATTRIBUTE_FORMAT(2,3);
14823ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscSynchronizedFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_ATTRIBUTE_FORMAT(3,4);
14830ec8b6e3SBarry Smith PETSC_EXTERN PetscErrorCode PetscSynchronizedFlush(MPI_Comm,FILE*);
1484014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSynchronizedFGets(MPI_Comm,FILE*,size_t,char[]);
1485014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStartMatlab(MPI_Comm,const char[],const char[],FILE**);
1486014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStartJava(MPI_Comm,const char[],const char[],FILE**);
1487014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetPetscDir(const char*[]);
1488d382aafbSBarry Smith 
1489014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_CONTAINER_CLASSID;
1490014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerGetPointer(PetscContainer,void**);
1491014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerSetPointer(PetscContainer,void*);
1492014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerDestroy(PetscContainer*);
1493014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerCreate(MPI_Comm,PetscContainer*);
1494014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscContainerSetUserDestroy(PetscContainer,PetscErrorCode (*)(void*));
1495b61ba218SStefano Zampini PETSC_EXTERN PetscErrorCode PetscContainerUserDestroyDefault(void*);
1496d382aafbSBarry Smith 
1497d382aafbSBarry Smith /*
1498d382aafbSBarry Smith    For use in debuggers
1499d382aafbSBarry Smith */
1500014dd563SJed Brown PETSC_EXTERN PetscMPIInt PetscGlobalRank;
1501014dd563SJed Brown PETSC_EXTERN PetscMPIInt PetscGlobalSize;
1502014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscIntView(PetscInt,const PetscInt[],PetscViewer);
1503014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRealView(PetscInt,const PetscReal[],PetscViewer);
1504014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscScalarView(PetscInt,const PetscScalar[],PetscViewer);
1505d382aafbSBarry Smith 
1506a663daf8SBarry Smith #include <stddef.h>
1507a3aaec0aSJed Brown #include <string.h>             /* for memcpy, memset */
1508d382aafbSBarry Smith #include <stdlib.h>
15096c7e564aSBarry Smith 
15104a92a979SJed Brown #if defined(PETSC_HAVE_XMMINTRIN_H) && !defined(__CUDACC__)
1511d382aafbSBarry Smith #include <xmmintrin.h>
1512d382aafbSBarry Smith #endif
1513d382aafbSBarry Smith 
1514d382aafbSBarry Smith /*@C
1515580bdb30SBarry Smith    PetscMemmove - Copies n bytes, beginning at location b, to the space
1516580bdb30SBarry Smith    beginning at location a. Copying  between regions that overlap will
1517580bdb30SBarry Smith    take place correctly. Use PetscMemcpy() if the locations do not overlap
1518580bdb30SBarry Smith 
1519580bdb30SBarry Smith    Not Collective
1520580bdb30SBarry Smith 
1521580bdb30SBarry Smith    Input Parameters:
1522580bdb30SBarry Smith +  b - pointer to initial memory space
1523580bdb30SBarry Smith .  a - pointer to copy space
1524580bdb30SBarry Smith -  n - length (in bytes) of space to copy
1525580bdb30SBarry Smith 
1526580bdb30SBarry Smith    Level: intermediate
1527580bdb30SBarry Smith 
1528580bdb30SBarry Smith    Note:
1529857a15f1SBarry Smith    PetscArraymove() is preferred
1530580bdb30SBarry Smith    This routine is analogous to memmove().
1531580bdb30SBarry Smith 
1532580bdb30SBarry Smith    Developers Note: This is inlined for performance
1533580bdb30SBarry Smith 
1534580bdb30SBarry Smith .seealso: PetscMemcpy(), PetscMemcmp(), PetscArrayzero(), PetscMemzero(), PetscArraycmp(), PetscArraycpy(), PetscStrallocpy(),
1535580bdb30SBarry Smith           PetscArraymove()
1536580bdb30SBarry Smith @*/
1537580bdb30SBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscMemmove(void *a,const void *b,size_t n)
1538580bdb30SBarry Smith {
1539580bdb30SBarry Smith   PetscFunctionBegin;
1540580bdb30SBarry Smith   if (n > 0 && !a) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Trying to copy to null pointer");
1541580bdb30SBarry Smith   if (n > 0 && !b) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Trying to copy from a null pointer");
1542580bdb30SBarry Smith #if !defined(PETSC_HAVE_MEMMOVE)
1543580bdb30SBarry Smith   if (a < b) {
1544580bdb30SBarry Smith     if (a <= b - n) memcpy(a,b,n);
1545580bdb30SBarry Smith     else {
1546580bdb30SBarry Smith       memcpy(a,b,(int)(b - a));
1547580bdb30SBarry Smith       PetscMemmove(b,b + (int)(b - a),n - (int)(b - a));
1548580bdb30SBarry Smith     }
1549580bdb30SBarry Smith   } else {
1550580bdb30SBarry Smith     if (b <= a - n) memcpy(a,b,n);
1551580bdb30SBarry Smith     else {
1552580bdb30SBarry Smith       memcpy(b + n,b + (n - (int)(a - b)),(int)(a - b));
1553580bdb30SBarry Smith       PetscMemmove(a,b,n - (int)(a - b));
1554580bdb30SBarry Smith     }
1555580bdb30SBarry Smith   }
1556580bdb30SBarry Smith #else
1557580bdb30SBarry Smith   memmove((char*)(a),(char*)(b),n);
1558580bdb30SBarry Smith #endif
1559580bdb30SBarry Smith   PetscFunctionReturn(0);
1560580bdb30SBarry Smith }
1561580bdb30SBarry Smith 
1562d382aafbSBarry Smith /*@C
1563d382aafbSBarry Smith    PetscMemcpy - Copies n bytes, beginning at location b, to the space
1564d382aafbSBarry Smith    beginning at location a. The two memory regions CANNOT overlap, use
1565d382aafbSBarry Smith    PetscMemmove() in that case.
1566d382aafbSBarry Smith 
1567d382aafbSBarry Smith    Not Collective
1568d382aafbSBarry Smith 
1569d382aafbSBarry Smith    Input Parameters:
1570d382aafbSBarry Smith +  b - pointer to initial memory space
1571d382aafbSBarry Smith -  n - length (in bytes) of space to copy
1572d382aafbSBarry Smith 
1573d382aafbSBarry Smith    Output Parameter:
1574d382aafbSBarry Smith .  a - pointer to copy space
1575d382aafbSBarry Smith 
1576d382aafbSBarry Smith    Level: intermediate
1577d382aafbSBarry Smith 
1578d382aafbSBarry Smith    Compile Option:
1579d382aafbSBarry Smith     PETSC_PREFER_DCOPY_FOR_MEMCPY will cause the BLAS dcopy() routine to be used
1580d382aafbSBarry Smith                                   for memory copies on double precision values.
1581d382aafbSBarry Smith     PETSC_PREFER_COPY_FOR_MEMCPY will cause C code to be used
1582d382aafbSBarry Smith                                   for memory copies on double precision values.
1583d382aafbSBarry Smith     PETSC_PREFER_FORTRAN_FORMEMCPY will cause Fortran code to be used
1584d382aafbSBarry Smith                                   for memory copies on double precision values.
1585d382aafbSBarry Smith 
1586d382aafbSBarry Smith    Note:
1587580bdb30SBarry Smith    Prefer PetscArraycpy()
1588d382aafbSBarry Smith    This routine is analogous to memcpy().
15891fd49c25SBarry Smith    Not available from Fortran
15901fd49c25SBarry Smith 
1591f5f57ec0SBarry Smith    Developer Note: this is inlined for fastest performance
1592f5f57ec0SBarry Smith 
1593580bdb30SBarry Smith .seealso: PetscMemzero(), PetscMemcmp(), PetscArrayzero(), PetscArraycmp(), PetscArraycpy(), PetscMemmove(), PetscStrallocpy()
1594d382aafbSBarry Smith 
1595d382aafbSBarry Smith @*/
15967087cfbeSBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscMemcpy(void *a,const void *b,size_t n)
1597d382aafbSBarry Smith {
1598d382aafbSBarry Smith #if defined(PETSC_USE_DEBUG)
1599c5e4d11fSDmitry Karpeev   size_t al = (size_t) a,bl = (size_t) b;
1600c5e4d11fSDmitry Karpeev   size_t nl = (size_t) n;
1601a7e36092SMatthew G Knepley   PetscFunctionBegin;
1602e32f2f54SBarry Smith   if (n > 0 && !b) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Trying to copy from a null pointer");
1603e32f2f54SBarry Smith   if (n > 0 && !a) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Trying to copy to a null pointer");
1604a7e36092SMatthew G Knepley #else
1605d382aafbSBarry Smith   PetscFunctionBegin;
1606a7e36092SMatthew G Knepley #endif
1607a47a537aSLisandro Dalcin   if (a != b && n > 0) {
1608d382aafbSBarry Smith #if defined(PETSC_USE_DEBUG)
1609e47d2de2SBarry Smith     if ((al > bl && (al - bl) < nl) || (bl - al) < nl)  SETERRQ3(PETSC_COMM_SELF,PETSC_ERR_ARG_INCOMP,"Memory regions overlap: either use PetscMemmov()\n\
1610d382aafbSBarry Smith               or make sure your copy regions and lengths are correct. \n\
1611d382aafbSBarry Smith               Length (bytes) %ld first address %ld second address %ld",nl,al,bl);
1612d382aafbSBarry Smith #endif
1613d382aafbSBarry Smith #if (defined(PETSC_PREFER_DCOPY_FOR_MEMCPY) || defined(PETSC_PREFER_COPY_FOR_MEMCPY) || defined(PETSC_PREFER_FORTRAN_FORMEMCPY))
1614c5e4d11fSDmitry Karpeev    if (!(a % sizeof(PetscScalar)) && !(n % sizeof(PetscScalar))) {
1615d382aafbSBarry Smith       size_t len = n/sizeof(PetscScalar);
1616d382aafbSBarry Smith #if defined(PETSC_PREFER_DCOPY_FOR_MEMCPY)
1617c5df96a5SBarry Smith       PetscBLASInt   one = 1,blen;
1618c5df96a5SBarry Smith       PetscErrorCode ierr;
1619c5df96a5SBarry Smith       ierr = PetscBLASIntCast(len,&blen);CHKERRQ(ierr);
16208b83055fSJed Brown       PetscStackCallBLAS("BLAScopy",BLAScopy_(&blen,(PetscScalar *)b,&one,(PetscScalar *)a,&one));
1621d382aafbSBarry Smith #elif defined(PETSC_PREFER_FORTRAN_FORMEMCPY)
1622d382aafbSBarry Smith       fortrancopy_(&len,(PetscScalar*)b,(PetscScalar*)a);
1623d382aafbSBarry Smith #else
1624d382aafbSBarry Smith       size_t      i;
1625d382aafbSBarry Smith       PetscScalar *x = (PetscScalar*)b, *y = (PetscScalar*)a;
1626d382aafbSBarry Smith       for (i=0; i<len; i++) y[i] = x[i];
1627d382aafbSBarry Smith #endif
1628d382aafbSBarry Smith     } else {
1629d382aafbSBarry Smith       memcpy((char*)(a),(char*)(b),n);
1630d382aafbSBarry Smith     }
1631d382aafbSBarry Smith #else
1632d382aafbSBarry Smith     memcpy((char*)(a),(char*)(b),n);
1633d382aafbSBarry Smith #endif
1634d382aafbSBarry Smith   }
1635d382aafbSBarry Smith   PetscFunctionReturn(0);
1636d382aafbSBarry Smith }
1637d382aafbSBarry Smith 
1638d382aafbSBarry Smith /*@C
1639d382aafbSBarry Smith    PetscMemzero - Zeros the specified memory.
1640d382aafbSBarry Smith 
1641d382aafbSBarry Smith    Not Collective
1642d382aafbSBarry Smith 
1643d382aafbSBarry Smith    Input Parameters:
1644d382aafbSBarry Smith +  a - pointer to beginning memory location
1645d382aafbSBarry Smith -  n - length (in bytes) of memory to initialize
1646d382aafbSBarry Smith 
1647d382aafbSBarry Smith    Level: intermediate
1648d382aafbSBarry Smith 
1649d382aafbSBarry Smith    Compile Option:
1650d382aafbSBarry Smith    PETSC_PREFER_BZERO - on certain machines (the IBM RS6000) the bzero() routine happens
1651d382aafbSBarry Smith   to be faster than the memset() routine. This flag causes the bzero() routine to be used.
1652d382aafbSBarry Smith 
16531fd49c25SBarry Smith    Not available from Fortran
1654857a15f1SBarry Smith    Prefer PetscArrayzero()
16551fd49c25SBarry Smith 
1656503cfb0cSBarry Smith    Developer Note: this is inlined for fastest performance
1657503cfb0cSBarry Smith 
1658580bdb30SBarry Smith .seealso: PetscMemcpy(), PetscMemcmp(), PetscArrayzero(), PetscArraycmp(), PetscArraycpy(), PetscMemmove(), PetscStrallocpy()
1659d382aafbSBarry Smith @*/
16607087cfbeSBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscMemzero(void *a,size_t n)
1661d382aafbSBarry Smith {
1662d382aafbSBarry Smith   if (n > 0) {
1663d382aafbSBarry Smith #if defined(PETSC_USE_DEBUG)
166418703db9SJunchao Zhang     if (!a) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Trying to zero at a null pointer with %zu bytes",n);
1665d382aafbSBarry Smith #endif
1666d382aafbSBarry Smith #if defined(PETSC_PREFER_ZERO_FOR_MEMZERO)
1667d382aafbSBarry Smith     if (!(((long) a) % sizeof(PetscScalar)) && !(n % sizeof(PetscScalar))) {
1668d382aafbSBarry Smith       size_t      i,len = n/sizeof(PetscScalar);
1669d382aafbSBarry Smith       PetscScalar *x = (PetscScalar*)a;
1670d382aafbSBarry Smith       for (i=0; i<len; i++) x[i] = 0.0;
1671d382aafbSBarry Smith     } else {
1672d382aafbSBarry Smith #elif defined(PETSC_PREFER_FORTRAN_FOR_MEMZERO)
1673d382aafbSBarry Smith     if (!(((long) a) % sizeof(PetscScalar)) && !(n % sizeof(PetscScalar))) {
1674d382aafbSBarry Smith       PetscInt len = n/sizeof(PetscScalar);
1675d382aafbSBarry Smith       fortranzero_(&len,(PetscScalar*)a);
1676d382aafbSBarry Smith     } else {
1677d382aafbSBarry Smith #endif
1678d382aafbSBarry Smith #if defined(PETSC_PREFER_BZERO)
1679d382aafbSBarry Smith       bzero((char *)a,n);
1680d382aafbSBarry Smith #else
1681d382aafbSBarry Smith       memset((char*)a,0,n);
1682d382aafbSBarry Smith #endif
1683d382aafbSBarry Smith #if defined(PETSC_PREFER_ZERO_FOR_MEMZERO) || defined(PETSC_PREFER_FORTRAN_FOR_MEMZERO)
1684d382aafbSBarry Smith     }
1685d382aafbSBarry Smith #endif
1686d382aafbSBarry Smith   }
1687d382aafbSBarry Smith   return 0;
1688d382aafbSBarry Smith }
1689d382aafbSBarry Smith 
1690d382aafbSBarry Smith /*MC
1691580bdb30SBarry Smith    PetscArraycmp - Compares two arrays in memory.
1692580bdb30SBarry Smith 
1693580bdb30SBarry Smith    Synopsis:
1694580bdb30SBarry Smith     #include <petscsys.h>
1695580bdb30SBarry Smith     PetscErrorCode PetscArraycmp(const anytype *str1,const anytype *str2,size_t cnt,PetscBool *e)
1696580bdb30SBarry Smith 
1697580bdb30SBarry Smith    Not Collective
1698580bdb30SBarry Smith 
1699580bdb30SBarry Smith    Input Parameters:
1700580bdb30SBarry Smith +  str1 - First array
1701580bdb30SBarry Smith .  str2 - Second array
1702580bdb30SBarry Smith -  cnt  - Count of the array, not in bytes, but number of entries in the arrays
1703580bdb30SBarry Smith 
1704580bdb30SBarry Smith    Output Parameters:
1705580bdb30SBarry Smith .   e - PETSC_TRUE if equal else PETSC_FALSE.
1706580bdb30SBarry Smith 
1707580bdb30SBarry Smith    Level: intermediate
1708580bdb30SBarry Smith 
1709580bdb30SBarry Smith    Note:
1710857a15f1SBarry Smith    This routine is a preferred replacement to PetscMemcmp()
1711580bdb30SBarry Smith    The arrays must be of the same type
1712580bdb30SBarry Smith 
1713580bdb30SBarry Smith .seealso: PetscMemcpy(), PetscMemcmp(), PetscArrayzero(), PetscMemzero(), PetscArraycpy(), PetscMemmove(), PetscStrallocpy(),
1714580bdb30SBarry Smith           PetscArraymove()
1715580bdb30SBarry Smith M*/
17169e2232c7SLisandro Dalcin #define  PetscArraycmp(str1,str2,cnt,e) ((sizeof(*(str1)) != sizeof(*(str2))) || PetscMemcmp(str1,str2,(size_t)(cnt)*sizeof(*(str1)),e))
1717580bdb30SBarry Smith 
17188f8f2f0dSBarry Smith /*MC
1719580bdb30SBarry Smith    PetscArraymove - Copies from one array in memory to another, the arrays may overlap. Use PetscArraycpy() when the arrays
1720580bdb30SBarry Smith                     do not overlap
1721580bdb30SBarry Smith 
1722580bdb30SBarry Smith    Synopsis:
1723580bdb30SBarry Smith     #include <petscsys.h>
1724580bdb30SBarry Smith     PetscErrorCode PetscArraymove(anytype *str1,const anytype *str2,size_t cnt)
1725580bdb30SBarry Smith 
1726580bdb30SBarry Smith    Not Collective
1727580bdb30SBarry Smith 
1728580bdb30SBarry Smith    Input Parameters:
1729580bdb30SBarry Smith +  str1 - First array
1730580bdb30SBarry Smith .  str2 - Second array
1731580bdb30SBarry Smith -  cnt  - Count of the array, not in bytes, but number of entries in the arrays
1732580bdb30SBarry Smith 
1733580bdb30SBarry Smith    Level: intermediate
1734580bdb30SBarry Smith 
1735580bdb30SBarry Smith    Note:
1736857a15f1SBarry Smith    This routine is a preferred replacement to PetscMemmove()
1737580bdb30SBarry Smith    The arrays must be of the same type
1738580bdb30SBarry Smith 
1739580bdb30SBarry Smith .seealso: PetscMemcpy(), PetscMemcmp(), PetscArrayzero(), PetscMemzero(), PetscArraycpy(), PetscMemmove(), PetscArraycmp(), PetscStrallocpy()
1740580bdb30SBarry Smith M*/
17419e2232c7SLisandro Dalcin #define  PetscArraymove(str1,str2,cnt) ((sizeof(*(str1)) != sizeof(*(str2))) || PetscMemmove(str1,str2,(size_t)(cnt)*sizeof(*(str1))))
1742580bdb30SBarry Smith 
17438f8f2f0dSBarry Smith /*MC
1744580bdb30SBarry Smith    PetscArraycpy - Copies from one array in memory to another
1745580bdb30SBarry Smith 
1746580bdb30SBarry Smith    Synopsis:
1747580bdb30SBarry Smith     #include <petscsys.h>
1748580bdb30SBarry Smith     PetscErrorCode PetscArraycpy(anytype *str1,const anytype *str2,size_t cnt)
1749580bdb30SBarry Smith 
1750580bdb30SBarry Smith    Not Collective
1751580bdb30SBarry Smith 
1752580bdb30SBarry Smith    Input Parameters:
1753de25709eSStefano Zampini +  str1 - First array (destination)
1754de25709eSStefano Zampini .  str2 - Second array (source)
1755580bdb30SBarry Smith -  cnt  - Count of the array, not in bytes, but number of entries in the arrays
1756580bdb30SBarry Smith 
1757580bdb30SBarry Smith    Level: intermediate
1758580bdb30SBarry Smith 
1759580bdb30SBarry Smith    Note:
1760857a15f1SBarry Smith    This routine is a preferred replacement to PetscMemcpy()
1761580bdb30SBarry Smith    The arrays must be of the same type
1762580bdb30SBarry Smith 
1763580bdb30SBarry Smith .seealso: PetscMemcpy(), PetscMemcmp(), PetscArrayzero(), PetscMemzero(), PetscArraymove(), PetscMemmove(), PetscArraycmp(), PetscStrallocpy()
1764580bdb30SBarry Smith M*/
17659e2232c7SLisandro Dalcin #define  PetscArraycpy(str1,str2,cnt) ((sizeof(*(str1)) != sizeof(*(str2))) || PetscMemcpy(str1,str2,(size_t)(cnt)*sizeof(*(str1))))
1766580bdb30SBarry Smith 
17678f8f2f0dSBarry Smith /*MC
1768580bdb30SBarry Smith    PetscArrayzero - Zeros an array in memory.
1769580bdb30SBarry Smith 
1770580bdb30SBarry Smith    Synopsis:
1771580bdb30SBarry Smith     #include <petscsys.h>
1772580bdb30SBarry Smith     PetscErrorCode PetscArrayzero(anytype *str1,size_t cnt)
1773580bdb30SBarry Smith 
1774580bdb30SBarry Smith    Not Collective
1775580bdb30SBarry Smith 
1776580bdb30SBarry Smith    Input Parameters:
1777580bdb30SBarry Smith +  str1 - array
1778580bdb30SBarry Smith -  cnt  - Count of the array, not in bytes, but number of entries in the array
1779580bdb30SBarry Smith 
1780580bdb30SBarry Smith    Level: intermediate
1781580bdb30SBarry Smith 
1782580bdb30SBarry Smith    Note:
1783857a15f1SBarry Smith    This routine is a preferred replacement to PetscMemzero()
1784580bdb30SBarry Smith 
1785580bdb30SBarry Smith .seealso: PetscMemcpy(), PetscMemcmp(), PetscMemzero(), PetscArraycmp(), PetscArraycpy(), PetscMemmove(), PetscStrallocpy(), PetscArraymove()
1786580bdb30SBarry Smith M*/
17879e2232c7SLisandro Dalcin #define  PetscArrayzero(str1,cnt) PetscMemzero(str1,(size_t)(cnt)*sizeof(*(str1)))
1788580bdb30SBarry Smith 
1789d382aafbSBarry Smith /*MC
1790d382aafbSBarry Smith    PetscPrefetchBlock - Prefetches a block of memory
1791d382aafbSBarry Smith 
1792eca87e8dSBarry Smith    Synopsis:
1793aaa7dc30SBarry Smith     #include <petscsys.h>
1794eca87e8dSBarry Smith     void PetscPrefetchBlock(const anytype *a,size_t n,int rw,int t)
1795eca87e8dSBarry Smith 
1796d382aafbSBarry Smith    Not Collective
1797d382aafbSBarry Smith 
1798d382aafbSBarry Smith    Input Parameters:
1799d382aafbSBarry Smith +  a - pointer to first element to fetch (any type but usually PetscInt or PetscScalar)
1800d382aafbSBarry Smith .  n - number of elements to fetch
1801d382aafbSBarry Smith .  rw - 1 if the memory will be written to, otherwise 0 (ignored by many processors)
180250d8bf02SJed Brown -  t - temporal locality (PETSC_PREFETCH_HINT_{NTA,T0,T1,T2}), see note
1803d382aafbSBarry Smith 
1804d382aafbSBarry Smith    Level: developer
1805d382aafbSBarry Smith 
1806d382aafbSBarry Smith    Notes:
1807d382aafbSBarry Smith    The last two arguments (rw and t) must be compile-time constants.
1808d382aafbSBarry Smith 
180950d8bf02SJed Brown    Adopting Intel's x86/x86-64 conventions, there are four levels of temporal locality.  Not all architectures offer
181050d8bf02SJed Brown    equivalent locality hints, but the following macros are always defined to their closest analogue.
181150d8bf02SJed Brown +  PETSC_PREFETCH_HINT_NTA - Non-temporal.  Prefetches directly to L1, evicts to memory (skips higher level cache unless it was already there when prefetched).
181263cf1ef0SJed Brown .  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.
181363cf1ef0SJed Brown .  PETSC_PREFETCH_HINT_T1 - Fetch to level 2 and higher (not L1).
181463cf1ef0SJed Brown -  PETSC_PREFETCH_HINT_T2 - Fetch to high-level cache only.  (On many systems, T0 and T1 are equivalent.)
1815d382aafbSBarry Smith 
1816d382aafbSBarry Smith    This function does nothing on architectures that do not support prefetch and never errors (even if passed an invalid
1817d382aafbSBarry Smith    address).
1818d382aafbSBarry Smith 
1819d382aafbSBarry Smith M*/
1820d382aafbSBarry Smith #define PetscPrefetchBlock(a,n,rw,t) do {                               \
1821d382aafbSBarry Smith     const char *_p = (const char*)(a),*_end = (const char*)((a)+(n));   \
1822d382aafbSBarry Smith     for (; _p < _end; _p += PETSC_LEVEL1_DCACHE_LINESIZE) PETSC_Prefetch(_p,(rw),(t)); \
1823d382aafbSBarry Smith   } while (0)
1824d382aafbSBarry Smith 
1825d382aafbSBarry Smith /*
1826d382aafbSBarry Smith       Determine if some of the kernel computation routines use
1827d382aafbSBarry Smith    Fortran (rather than C) for the numerical calculations. On some machines
1828d382aafbSBarry Smith    and compilers (like complex numbers) the Fortran version of the routines
1829d382aafbSBarry Smith    is faster than the C/C++ versions. The flag --with-fortran-kernels
1830e2e64c6bSBarry Smith    should be used with ./configure to turn these on.
1831d382aafbSBarry Smith */
1832d382aafbSBarry Smith #if defined(PETSC_USE_FORTRAN_KERNELS)
1833d382aafbSBarry Smith 
1834d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTCRL)
1835d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTCRL
1836d382aafbSBarry Smith #endif
1837d382aafbSBarry Smith 
18385a11e1b2SBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJPERM)
18395a11e1b2SBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTAIJPERM
1840d382aafbSBarry Smith #endif
1841d382aafbSBarry Smith 
1842d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ)
1843d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ
1844d382aafbSBarry Smith #endif
1845d382aafbSBarry Smith 
1846d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ)
1847d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ
1848d382aafbSBarry Smith #endif
1849d382aafbSBarry Smith 
1850d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_NORM)
1851d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_NORM
1852d382aafbSBarry Smith #endif
1853d382aafbSBarry Smith 
1854d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY)
1855d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MAXPY
1856d382aafbSBarry Smith #endif
1857d382aafbSBarry Smith 
1858d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ)
1859d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ
1860d382aafbSBarry Smith #endif
1861d382aafbSBarry Smith 
1862d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_RELAXAIJ)
1863d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_RELAXAIJ
1864d382aafbSBarry Smith #endif
1865d382aafbSBarry Smith 
1866d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ)
1867d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ
1868d382aafbSBarry Smith #endif
1869d382aafbSBarry Smith 
1870d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ)
1871d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ
1872d382aafbSBarry Smith #endif
1873d382aafbSBarry Smith 
1874d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT)
1875d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_MDOT
1876d382aafbSBarry Smith #endif
1877d382aafbSBarry Smith 
1878d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY)
1879d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_XTIMESY
1880d382aafbSBarry Smith #endif
1881d382aafbSBarry Smith 
1882d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_AYPX)
1883d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_AYPX
1884d382aafbSBarry Smith #endif
1885d382aafbSBarry Smith 
1886d382aafbSBarry Smith #if !defined(PETSC_USE_FORTRAN_KERNEL_WAXPY)
1887d382aafbSBarry Smith #define PETSC_USE_FORTRAN_KERNEL_WAXPY
1888d382aafbSBarry Smith #endif
1889d382aafbSBarry Smith 
1890d382aafbSBarry Smith #endif
1891d382aafbSBarry Smith 
1892d382aafbSBarry Smith /*
1893d382aafbSBarry Smith     Macros for indicating code that should be compiled with a C interface,
1894d382aafbSBarry Smith    rather than a C++ interface. Any routines that are dynamically loaded
1895d382aafbSBarry Smith    (such as the PCCreate_XXX() routines) must be wrapped so that the name
1896d382aafbSBarry Smith    mangler does not change the functions symbol name. This just hides the
1897d382aafbSBarry Smith    ugly extern "C" {} wrappers.
1898d382aafbSBarry Smith */
1899d382aafbSBarry Smith #if defined(__cplusplus)
1900d382aafbSBarry Smith #  define EXTERN_C_BEGIN extern "C" {
1901d382aafbSBarry Smith #  define EXTERN_C_END }
1902d382aafbSBarry Smith #else
1903d382aafbSBarry Smith #  define EXTERN_C_BEGIN
1904d382aafbSBarry Smith #  define EXTERN_C_END
1905d382aafbSBarry Smith #endif
1906d382aafbSBarry Smith 
1907d382aafbSBarry Smith /* --------------------------------------------------------------------*/
1908d382aafbSBarry Smith 
1909d382aafbSBarry Smith /*MC
1910d382aafbSBarry Smith     MPI_Comm - the basic object used by MPI to determine which processes are involved in a
1911d382aafbSBarry Smith         communication
1912d382aafbSBarry Smith 
1913d382aafbSBarry Smith    Level: beginner
1914d382aafbSBarry Smith 
1915d382aafbSBarry Smith    Note: This manual page is a place-holder because MPICH does not have a manual page for MPI_Comm
1916d382aafbSBarry Smith 
1917d382aafbSBarry Smith .seealso: PETSC_COMM_WORLD, PETSC_COMM_SELF
1918d382aafbSBarry Smith M*/
1919d382aafbSBarry Smith 
1920d382aafbSBarry Smith #if defined(PETSC_HAVE_MPIIO)
1921014dd563SJed Brown PETSC_EXTERN PetscErrorCode MPIU_File_write_all(MPI_File,void*,PetscMPIInt,MPI_Datatype,MPI_Status*);
1922014dd563SJed Brown PETSC_EXTERN PetscErrorCode MPIU_File_read_all(MPI_File,void*,PetscMPIInt,MPI_Datatype,MPI_Status*);
1923c4e82887SLisandro Dalcin PETSC_EXTERN PetscErrorCode MPIU_File_write_at(MPI_File,MPI_Offset,void*,PetscMPIInt,MPI_Datatype,MPI_Status*);
1924c4e82887SLisandro Dalcin PETSC_EXTERN PetscErrorCode MPIU_File_read_at(MPI_File,MPI_Offset,void*,PetscMPIInt,MPI_Datatype,MPI_Status*);
1925c4e82887SLisandro Dalcin PETSC_EXTERN PetscErrorCode MPIU_File_write_at_all(MPI_File,MPI_Offset,void*,PetscMPIInt,MPI_Datatype,MPI_Status*);
1926c4e82887SLisandro Dalcin PETSC_EXTERN PetscErrorCode MPIU_File_read_at_all(MPI_File,MPI_Offset,void*,PetscMPIInt,MPI_Datatype,MPI_Status*);
1927d382aafbSBarry Smith #endif
1928d382aafbSBarry Smith 
1929d382aafbSBarry Smith /* the following petsc_static_inline require petscerror.h */
1930d382aafbSBarry Smith 
1931d382aafbSBarry Smith /* Limit MPI to 32-bits */
1932d382aafbSBarry Smith #define PETSC_MPI_INT_MAX  2147483647
1933d382aafbSBarry Smith #define PETSC_MPI_INT_MIN -2147483647
1934d382aafbSBarry Smith /* Limit BLAS to 32-bits */
1935d382aafbSBarry Smith #define PETSC_BLAS_INT_MAX  2147483647
1936d382aafbSBarry Smith #define PETSC_BLAS_INT_MIN -2147483647
1937eee0c0a6SToby Isaac #define PETSC_CUBLAS_INT_MAX  2147483647
1938d382aafbSBarry Smith 
193961b0d812SBarry Smith /*@C
1940c73702f5SBarry Smith     PetscIntCast - casts a PetscInt64 (which is 64 bits in size) to a PetscInt (which may be 32 bits in size), generates an
1941c73702f5SBarry Smith          error if the PetscInt is not large enough to hold the number.
1942c73702f5SBarry Smith 
1943c73702f5SBarry Smith    Not Collective
1944c73702f5SBarry Smith 
1945c73702f5SBarry Smith    Input Parameter:
1946c73702f5SBarry Smith .     a - the PetscInt64 value
1947c73702f5SBarry Smith 
1948c73702f5SBarry Smith    Output Parameter:
1949c73702f5SBarry Smith .     b - the resulting PetscInt value
1950c73702f5SBarry Smith 
1951c73702f5SBarry Smith    Level: advanced
1952c73702f5SBarry Smith 
1953c73702f5SBarry Smith    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
1954c73702f5SBarry Smith 
1955c73702f5SBarry Smith    Not available from Fortran
1956c73702f5SBarry Smith 
195761778c46SBarry Smith .seealso: PetscBLASInt, PetscMPIInt, PetscInt, PetscMPIIntCast(), PetscBLASIntCast(), PetscIntMultError(), PetscIntSumError()
1958c73702f5SBarry Smith @*/
1959c73702f5SBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscIntCast(PetscInt64 a,PetscInt *b)
1960c73702f5SBarry Smith {
1961c73702f5SBarry Smith   PetscFunctionBegin;
1962c73702f5SBarry Smith #if !defined(PETSC_USE_64BIT_INDICES)
19633ca90d2dSJacob Faibussowitsch   if (a > PETSC_MAX_INT) {
19643ca90d2dSJacob Faibussowitsch     *b = 0;
19653ca90d2dSJacob Faibussowitsch     SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"%" PetscInt64_FMT " is too big for PetscInt, you may need to ./configure using --with-64-bit-indices",a);
19663ca90d2dSJacob Faibussowitsch   }
1967c73702f5SBarry Smith #endif
1968c73702f5SBarry Smith   *b = (PetscInt)(a);
1969c73702f5SBarry Smith   PetscFunctionReturn(0);
1970c73702f5SBarry Smith }
1971c73702f5SBarry Smith 
1972c73702f5SBarry Smith /*@C
197361b0d812SBarry Smith     PetscBLASIntCast - casts a PetscInt (which may be 64 bits in size) to a PetscBLASInt (which may be 32 bits in size), generates an
197461b0d812SBarry Smith          error if the PetscBLASInt is not large enough to hold the number.
197561b0d812SBarry Smith 
197661b0d812SBarry Smith    Not Collective
197761b0d812SBarry Smith 
197861b0d812SBarry Smith    Input Parameter:
197961b0d812SBarry Smith .     a - the PetscInt value
198061b0d812SBarry Smith 
198161b0d812SBarry Smith    Output Parameter:
198261b0d812SBarry Smith .     b - the resulting PetscBLASInt value
198361b0d812SBarry Smith 
198461b0d812SBarry Smith    Level: advanced
198561b0d812SBarry Smith 
19860bc7d38cSBarry Smith    Notes:
19871fd49c25SBarry Smith       Not available from Fortran
1988f0b7f91aSBarry Smith       Errors if the integer is negative since PETSc calls to BLAS/LAPACK never need to cast negative integer inputs
19891fd49c25SBarry Smith 
1990c73702f5SBarry Smith .seealso: PetscBLASInt, PetscMPIInt, PetscInt, PetscMPIIntCast(), PetscIntCast()
199161b0d812SBarry Smith @*/
1992c5df96a5SBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscBLASIntCast(PetscInt a,PetscBLASInt *b)
1993c5df96a5SBarry Smith {
1994c5df96a5SBarry Smith   PetscFunctionBegin;
1995c5df96a5SBarry Smith #if defined(PETSC_USE_64BIT_INDICES) && !defined(PETSC_HAVE_64BIT_BLAS_INDICES)
19963ca90d2dSJacob Faibussowitsch   if (a > PETSC_BLAS_INT_MAX) { *b = 0; SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"%" PetscInt_FMT " 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); }
1997c5df96a5SBarry Smith #endif
1998e9e21dffSJose E. Roman   if (a < 0) { *b = 0; SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Passing negative integer to BLAS/LAPACK routine"); }
1999c73702f5SBarry Smith   *b = (PetscBLASInt)(a);
2000c5df96a5SBarry Smith   PetscFunctionReturn(0);
2001c5df96a5SBarry Smith }
2002c5df96a5SBarry Smith 
200361b0d812SBarry Smith /*@C
2004eee0c0a6SToby Isaac     PetscCuBLASIntCast - like PetscBLASIntCast(), but for PetscCuBLASInt.
2005eee0c0a6SToby Isaac 
2006eee0c0a6SToby Isaac    Not Collective
2007eee0c0a6SToby Isaac 
2008eee0c0a6SToby Isaac    Input Parameter:
2009eee0c0a6SToby Isaac .     a - the PetscInt value
2010eee0c0a6SToby Isaac 
2011eee0c0a6SToby Isaac    Output Parameter:
2012eee0c0a6SToby Isaac .     b - the resulting PetscCuBLASInt value
2013eee0c0a6SToby Isaac 
2014eee0c0a6SToby Isaac    Level: advanced
2015eee0c0a6SToby Isaac 
2016eee0c0a6SToby Isaac    Notes:
2017eee0c0a6SToby Isaac       Errors if the integer is negative since PETSc calls to cuBLAS and friends never need to cast negative integer inputs
2018eee0c0a6SToby Isaac 
2019eee0c0a6SToby Isaac .seealso: PetscCuBLASInt, PetscBLASInt, PetscMPIInt, PetscInt, PetscBLASIntCast(), PetscMPIIntCast(), PetscIntCast()
2020eee0c0a6SToby Isaac @*/
2021ae77d22fSJunchao Zhang PETSC_STATIC_INLINE PetscErrorCode PetscCuBLASIntCast(PetscInt a,PetscCuBLASInt *b)
2022eee0c0a6SToby Isaac {
2023eee0c0a6SToby Isaac   PetscFunctionBegin;
2024eee0c0a6SToby Isaac #if defined(PETSC_USE_64BIT_INDICES)
20253ca90d2dSJacob Faibussowitsch   if (a > PETSC_CUBLAS_INT_MAX) { *b = 0; SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"%" PetscInt_FMT " is too big for cuBLAS, which is restricted to 32 bit integers.",a); }
2026eee0c0a6SToby Isaac #endif
2027e9e21dffSJose E. Roman   if (a < 0) { *b = 0; SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Passing negative integer to cuBLAS routine"); }
2028eee0c0a6SToby Isaac   *b = (PetscCuBLASInt)(a);
2029eee0c0a6SToby Isaac   PetscFunctionReturn(0);
2030eee0c0a6SToby Isaac }
2031eee0c0a6SToby Isaac 
2032eee0c0a6SToby Isaac /*@C
203361b0d812SBarry Smith     PetscMPIIntCast - casts a PetscInt (which may be 64 bits in size) to a PetscMPIInt (which may be 32 bits in size), generates an
203461b0d812SBarry Smith          error if the PetscMPIInt is not large enough to hold the number.
203561b0d812SBarry Smith 
203661b0d812SBarry Smith    Not Collective
203761b0d812SBarry Smith 
203861b0d812SBarry Smith    Input Parameter:
203961b0d812SBarry Smith .     a - the PetscInt value
204061b0d812SBarry Smith 
204161b0d812SBarry Smith    Output Parameter:
204261b0d812SBarry Smith .     b - the resulting PetscMPIInt value
204361b0d812SBarry Smith 
204461b0d812SBarry Smith    Level: advanced
204561b0d812SBarry Smith 
20461fd49c25SBarry Smith    Not available from Fortran
20471fd49c25SBarry Smith 
2048c73702f5SBarry Smith .seealso: PetscBLASInt, PetscMPIInt, PetscInt, PetscBLASIntCast(), PetscIntCast()
204961b0d812SBarry Smith @*/
20504dc2109aSBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscMPIIntCast(PetscInt a,PetscMPIInt *b)
20514dc2109aSBarry Smith {
20524dc2109aSBarry Smith   PetscFunctionBegin;
20534dc2109aSBarry Smith #if defined(PETSC_USE_64BIT_INDICES)
20543ca90d2dSJacob Faibussowitsch   if (a > PETSC_MPI_INT_MAX) { *b = 0; SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"%" PetscInt_FMT " is too big for MPI buffer length. We currently only support 32 bit integers",a); }
20554dc2109aSBarry Smith #endif
2056c73702f5SBarry Smith   *b = (PetscMPIInt)(a);
20574dc2109aSBarry Smith   PetscFunctionReturn(0);
20584dc2109aSBarry Smith }
20594dc2109aSBarry Smith 
2060bafee8b4SSatish Balay #define PetscInt64Mult(a,b)   ((PetscInt64)(a))*((PetscInt64)(b))
20612f18eb33SBarry Smith 
20622f18eb33SBarry Smith /*@C
20632f18eb33SBarry Smith 
20642f18eb33SBarry Smith    PetscRealIntMultTruncate - Computes the product of a positive PetscReal and a positive PetscInt and truncates the value to slightly less than the maximal possible value
20652f18eb33SBarry Smith 
20662f18eb33SBarry Smith    Not Collective
20672f18eb33SBarry Smith 
2068d8d19677SJose E. Roman    Input Parameters:
20692f18eb33SBarry Smith +     a - the PetscReal value
20702f18eb33SBarry Smith -     b - the second value
20712f18eb33SBarry Smith 
2072390e1bf2SBarry Smith    Returns:
2073390e1bf2SBarry Smith       the result as a PetscInt value
20742f18eb33SBarry Smith 
2075bafee8b4SSatish Balay    Use PetscInt64Mult() to compute the product of two PetscInt as a PetscInt64
20762f18eb33SBarry Smith    Use PetscIntMultTruncate() to compute the product of two positive PetscInt and truncate to fit a PetscInt
20772f18eb33SBarry Smith    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
20782f18eb33SBarry Smith 
2079e28ce29aSPatrick Sanan    Developers Note:
2080e28ce29aSPatrick Sanan    We currently assume that PetscInt addition can never overflow, this is obviously wrong but requires many more checks.
20812f18eb33SBarry Smith 
20822f18eb33SBarry Smith    This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able.
20832f18eb33SBarry Smith 
20841fd49c25SBarry Smith    Not available from Fortran
20851fd49c25SBarry Smith 
20862f18eb33SBarry Smith    Level: advanced
20872f18eb33SBarry Smith 
208861778c46SBarry Smith .seealso: PetscBLASInt, PetscMPIInt, PetscInt, PetscBLASIntCast(), PetscInt64Mult(), PetscIntMultError(), PetscIntSumError()
20892f18eb33SBarry Smith @*/
20902f18eb33SBarry Smith PETSC_STATIC_INLINE PetscInt PetscRealIntMultTruncate(PetscReal a,PetscInt b)
20912f18eb33SBarry Smith {
2092bafee8b4SSatish Balay   PetscInt64 r;
20932f18eb33SBarry Smith 
2094bafee8b4SSatish Balay   r  =  (PetscInt64) (a*(PetscReal)b);
20952f18eb33SBarry Smith   if (r > PETSC_MAX_INT - 100) r = PETSC_MAX_INT - 100;
20962f18eb33SBarry Smith   return (PetscInt) r;
20972f18eb33SBarry Smith }
20982f18eb33SBarry Smith 
20992f18eb33SBarry Smith /*@C
21002f18eb33SBarry Smith 
21012f18eb33SBarry Smith    PetscIntMultTruncate - Computes the product of two positive PetscInt and truncates the value to slightly less than the maximal possible value
21022f18eb33SBarry Smith 
21032f18eb33SBarry Smith    Not Collective
21042f18eb33SBarry Smith 
2105d8d19677SJose E. Roman    Input Parameters:
21062f18eb33SBarry Smith +     a - the PetscInt value
21072f18eb33SBarry Smith -     b - the second value
21082f18eb33SBarry Smith 
2109390e1bf2SBarry Smith    Returns:
2110390e1bf2SBarry Smith       the result as a PetscInt value
21112f18eb33SBarry Smith 
2112bafee8b4SSatish Balay    Use PetscInt64Mult() to compute the product of two PetscInt as a PetscInt64
21132f18eb33SBarry Smith    Use PetscRealIntMultTruncate() to compute the product of a PetscReal and a PetscInt and truncate to fit a PetscInt
21142f18eb33SBarry Smith    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
21152f18eb33SBarry Smith 
21161fd49c25SBarry Smith    Not available from Fortran
21171fd49c25SBarry Smith 
21182f18eb33SBarry Smith    Developers Note: We currently assume that PetscInt addition can never overflow, this is obviously wrong but requires many more checks.
21192f18eb33SBarry Smith 
21202f18eb33SBarry Smith    This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able.
21212f18eb33SBarry Smith 
21222f18eb33SBarry Smith    Level: advanced
21232f18eb33SBarry Smith 
212461778c46SBarry Smith .seealso: PetscBLASInt, PetscMPIInt, PetscInt, PetscBLASIntCast(), PetscInt64Mult(), PetscIntMultError(), PetscIntSumError()
21252f18eb33SBarry Smith @*/
21262f18eb33SBarry Smith PETSC_STATIC_INLINE PetscInt PetscIntMultTruncate(PetscInt a,PetscInt b)
21272f18eb33SBarry Smith {
2128bafee8b4SSatish Balay   PetscInt64 r;
21292f18eb33SBarry Smith 
2130bafee8b4SSatish Balay   r  =  PetscInt64Mult(a,b);
21312f18eb33SBarry Smith   if (r > PETSC_MAX_INT - 100) r = PETSC_MAX_INT - 100;
21322f18eb33SBarry Smith   return (PetscInt) r;
21332f18eb33SBarry Smith }
21342f18eb33SBarry Smith 
2135f91af8c7SBarry Smith /*@C
2136f91af8c7SBarry Smith 
2137f91af8c7SBarry Smith    PetscIntSumTruncate - Computes the sum of two positive PetscInt and truncates the value to slightly less than the maximal possible value
2138f91af8c7SBarry Smith 
2139f91af8c7SBarry Smith    Not Collective
2140f91af8c7SBarry Smith 
2141d8d19677SJose E. Roman    Input Parameters:
2142f91af8c7SBarry Smith +     a - the PetscInt value
2143f91af8c7SBarry Smith -     b - the second value
2144f91af8c7SBarry Smith 
2145390e1bf2SBarry Smith    Returns:
2146390e1bf2SBarry Smith      the result as a PetscInt value
2147f91af8c7SBarry Smith 
2148bafee8b4SSatish Balay    Use PetscInt64Mult() to compute the product of two PetscInt as a PetscInt64
2149f91af8c7SBarry Smith    Use PetscRealIntMultTruncate() to compute the product of a PetscReal and a PetscInt and truncate to fit a PetscInt
2150f91af8c7SBarry Smith    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
2151f91af8c7SBarry Smith 
2152f91af8c7SBarry Smith    This is used where we compute approximate sizes for workspace and need to insure the workspace is index-able.
2153f91af8c7SBarry Smith 
2154f5f57ec0SBarry Smith    Not available from Fortran
2155f5f57ec0SBarry Smith 
2156f91af8c7SBarry Smith    Level: advanced
2157f91af8c7SBarry Smith 
215861778c46SBarry Smith .seealso: PetscBLASInt, PetscMPIInt, PetscInt, PetscBLASIntCast(), PetscInt64Mult(), PetscIntMultError()
2159f91af8c7SBarry Smith @*/
2160f91af8c7SBarry Smith PETSC_STATIC_INLINE PetscInt PetscIntSumTruncate(PetscInt a,PetscInt b)
2161f91af8c7SBarry Smith {
2162bafee8b4SSatish Balay   PetscInt64 r;
2163f91af8c7SBarry Smith 
2164bafee8b4SSatish Balay   r  =  ((PetscInt64)a) + ((PetscInt64)b);
2165f91af8c7SBarry Smith   if (r > PETSC_MAX_INT - 100) r = PETSC_MAX_INT - 100;
2166f91af8c7SBarry Smith   return (PetscInt) r;
2167f91af8c7SBarry Smith }
2168f91af8c7SBarry Smith 
21692f18eb33SBarry Smith /*@C
21702f18eb33SBarry Smith 
21712f18eb33SBarry Smith    PetscIntMultError - Computes the product of two positive PetscInt and generates an error with overflow.
21722f18eb33SBarry Smith 
21732f18eb33SBarry Smith    Not Collective
21742f18eb33SBarry Smith 
2175d8d19677SJose E. Roman    Input Parameters:
21762f18eb33SBarry Smith +     a - the PetscInt value
21772f18eb33SBarry Smith -     b - the second value
21782f18eb33SBarry Smith 
2179d8d19677SJose E. Roman    Output Parameter:
2180390e1bf2SBarry Smith .     result - the result as a PetscInt value, or NULL if you do not want the result, you just want to check if it overflows
21812f18eb33SBarry Smith 
2182bafee8b4SSatish Balay    Use PetscInt64Mult() to compute the product of two 32 bit PetscInt and store in a PetscInt64
21832f18eb33SBarry Smith    Use PetscIntMultTruncate() to compute the product of two PetscInt and truncate it to fit in a PetscInt
21842f18eb33SBarry Smith 
2185f5f57ec0SBarry Smith    Not available from Fortran
2186f5f57ec0SBarry Smith 
2187220afb94SBarry Smith    Developers Note: We currently assume that PetscInt addition does not overflow, this is obviously wrong but requires many more checks.
21882f18eb33SBarry Smith 
21892f18eb33SBarry Smith    Level: advanced
21902f18eb33SBarry Smith 
2191220afb94SBarry Smith .seealso: PetscBLASInt, PetscMPIInt, PetscInt, PetscBLASIntCast(), PetscIntMult64(), PetscIntSumError()
21922f18eb33SBarry Smith @*/
21932f18eb33SBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscIntMultError(PetscInt a,PetscInt b,PetscInt *result)
21942f18eb33SBarry Smith {
2195bafee8b4SSatish Balay   PetscInt64 r;
21962f18eb33SBarry Smith 
21972f18eb33SBarry Smith   PetscFunctionBegin;
2198bafee8b4SSatish Balay   r  =  PetscInt64Mult(a,b);
21992f18eb33SBarry Smith #if !defined(PETSC_USE_64BIT_INDICES)
220061778c46SBarry Smith   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);
22012f18eb33SBarry Smith #endif
2202f91af8c7SBarry Smith   if (result) *result = (PetscInt) r;
2203f91af8c7SBarry Smith   PetscFunctionReturn(0);
2204f91af8c7SBarry Smith }
2205f91af8c7SBarry Smith 
2206f91af8c7SBarry Smith /*@C
2207f91af8c7SBarry Smith 
2208fbfcfee5SBarry Smith    PetscIntSumError - Computes the sum of two positive PetscInt and generates an error with overflow.
2209f91af8c7SBarry Smith 
2210f91af8c7SBarry Smith    Not Collective
2211f91af8c7SBarry Smith 
2212d8d19677SJose E. Roman    Input Parameters:
2213f91af8c7SBarry Smith +     a - the PetscInt value
2214f91af8c7SBarry Smith -     b - the second value
2215f91af8c7SBarry Smith 
2216d8d19677SJose E. Roman    Output Parameter:
2217390e1bf2SBarry Smith .     c - the result as a PetscInt value,  or NULL if you do not want the result, you just want to check if it overflows
2218f91af8c7SBarry Smith 
2219bafee8b4SSatish Balay    Use PetscInt64Mult() to compute the product of two 32 bit PetscInt and store in a PetscInt64
2220f91af8c7SBarry Smith    Use PetscIntMultTruncate() to compute the product of two PetscInt and truncate it to fit in a PetscInt
2221f91af8c7SBarry Smith 
2222f5f57ec0SBarry Smith    Not available from Fortran
2223f5f57ec0SBarry Smith 
2224f91af8c7SBarry Smith    Level: advanced
2225f91af8c7SBarry Smith 
222661778c46SBarry Smith .seealso: PetscBLASInt, PetscMPIInt, PetscInt, PetscBLASIntCast(), PetscInt64Mult(), PetscIntMultError()
2227f91af8c7SBarry Smith @*/
2228f91af8c7SBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscIntSumError(PetscInt a,PetscInt b,PetscInt *result)
2229f91af8c7SBarry Smith {
2230bafee8b4SSatish Balay   PetscInt64 r;
2231f91af8c7SBarry Smith 
2232f91af8c7SBarry Smith   PetscFunctionBegin;
2233bafee8b4SSatish Balay   r  =  ((PetscInt64)a) + ((PetscInt64)b);
2234f91af8c7SBarry Smith #if !defined(PETSC_USE_64BIT_INDICES)
223561778c46SBarry Smith   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);
2236f91af8c7SBarry Smith #endif
2237f91af8c7SBarry Smith   if (result) *result = (PetscInt) r;
22382f18eb33SBarry Smith   PetscFunctionReturn(0);
22392f18eb33SBarry Smith }
2240c5df96a5SBarry Smith 
2241d382aafbSBarry Smith /*
22422981ebdbSBarry Smith      The IBM include files define hz, here we hide it so that it may be used as a regular user variable.
2243d382aafbSBarry Smith */
2244d382aafbSBarry Smith #if defined(hz)
2245d382aafbSBarry Smith #  undef hz
2246d382aafbSBarry Smith #endif
2247d382aafbSBarry Smith 
224815a5570dSLisandro Dalcin #include <limits.h>
224915a5570dSLisandro Dalcin 
225015a5570dSLisandro Dalcin /* The number of bits in a byte */
225115a5570dSLisandro Dalcin 
225215a5570dSLisandro Dalcin #define PETSC_BITS_PER_BYTE CHAR_BIT
225315a5570dSLisandro Dalcin 
2254d382aafbSBarry Smith #if defined(PETSC_HAVE_SYS_TYPES_H)
2255d382aafbSBarry Smith #  include <sys/types.h>
2256d382aafbSBarry Smith #endif
2257d382aafbSBarry Smith 
2258d382aafbSBarry Smith /*MC
2259d382aafbSBarry Smith 
226066d79e26SBarry Smith     PETSC_VERSION - This manual page provides information about how PETSc documents and uses its version information. This information is available to both C/C++
226166d79e26SBarry Smith                     and Fortran compilers when petscsys.h is included.
226266d79e26SBarry Smith 
226366d79e26SBarry Smith     The current PETSc version and the API for accessing it are defined in petscversion.h
226466d79e26SBarry Smith 
226566d79e26SBarry Smith     The complete version number is given as the triple  PETSC_VERSION_MAJOR.PETSC_VERSION_MINOR.PETSC_VERSION_SUBMINOR (in short hand x.y.z)
226666d79e26SBarry Smith 
226766d79e26SBarry Smith     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
226866d79e26SBarry Smith     where only a change in the major version number (x) indicates a change in the API.
226966d79e26SBarry Smith 
227066d79e26SBarry Smith     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
227166d79e26SBarry Smith 
227266d79e26SBarry Smith     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),
227366d79e26SBarry Smith     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
227466d79e26SBarry Smith     version number (x.y.z).
227566d79e26SBarry Smith 
227666d79e26SBarry Smith     PETSC_RELEASE_DATE is the date the x.y version was released (i.e. the version before any patch releases)
227766d79e26SBarry Smith 
227866d79e26SBarry Smith     PETSC_VERSION_DATE is the date the x.y.z version was released
227966d79e26SBarry Smith 
228066d79e26SBarry Smith     PETSC_VERSION_GIT is the last git commit to the repository given in the form vx.y.z-wwwww
228166d79e26SBarry Smith 
228266d79e26SBarry Smith     PETSC_VERSION_DATE_GIT is the date of the last git commit to the repository
228366d79e26SBarry Smith 
2284cbc12506SBarry Smith     PETSC_VERSION_() is deprecated and will eventually be removed.
228566d79e26SBarry Smith 
2286cbc12506SBarry Smith     Level: intermediate
228766d79e26SBarry Smith 
228866d79e26SBarry Smith M*/
228966d79e26SBarry Smith 
2290014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetArchType(char[],size_t);
2291014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetHostName(char[],size_t);
2292014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetUserName(char[],size_t);
2293014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetProgramName(char[],size_t);
2294014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetProgramName(const char[]);
2295014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetDate(char[],size_t);
229627710113SBarry Smith PETSC_EXTERN PetscErrorCode PetscGetVersion(char[], size_t);
22975f309d01SBarry Smith PETSC_EXTERN PetscErrorCode PetscGetVersionNumber(PetscInt*,PetscInt*,PetscInt*,PetscInt*);
2298d382aafbSBarry Smith 
22996a7c706bSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscSortedInt(PetscInt,const PetscInt[],PetscBool*);
23006a7c706bSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscSortedMPIInt(PetscInt,const PetscMPIInt[],PetscBool*);
23016a7c706bSVaclav Hapla PETSC_EXTERN PetscErrorCode PetscSortedReal(PetscInt,const PetscReal[],PetscBool*);
2302014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortInt(PetscInt,PetscInt[]);
2303ce605777SToby Isaac PETSC_EXTERN PetscErrorCode PetscSortReverseInt(PetscInt,PetscInt[]);
230422ab5688SLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscSortedRemoveDupsInt(PetscInt*,PetscInt[]);
2305014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsInt(PetscInt*,PetscInt[]);
2306f1cab4e1SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscCheckDupsInt(PetscInt,const PetscInt[],PetscBool*);
230760e03357SMatthew G Knepley PETSC_EXTERN PetscErrorCode PetscFindInt(PetscInt, PetscInt, const PetscInt[], PetscInt*);
2308d2aeb606SJed Brown PETSC_EXTERN PetscErrorCode PetscFindMPIInt(PetscMPIInt, PetscInt, const PetscMPIInt[], PetscInt*);
2309014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortIntWithPermutation(PetscInt,const PetscInt[],PetscInt[]);
2310014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortStrWithPermutation(PetscInt,const char*[],PetscInt[]);
2311014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortIntWithArray(PetscInt,PetscInt[],PetscInt[]);
23126c2863d0SBarry Smith PETSC_EXTERN PetscErrorCode PetscSortIntWithArrayPair(PetscInt,PetscInt[],PetscInt[],PetscInt[]);
231317d7d925SStefano Zampini PETSC_EXTERN PetscErrorCode PetscSortMPIInt(PetscInt,PetscMPIInt[]);
231417d7d925SStefano Zampini PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsMPIInt(PetscInt*,PetscMPIInt[]);
2315014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortMPIIntWithArray(PetscMPIInt,PetscMPIInt[],PetscMPIInt[]);
23165569a785SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscSortMPIIntWithIntArray(PetscMPIInt,PetscMPIInt[],PetscInt[]);
2317014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortIntWithScalarArray(PetscInt,PetscInt[],PetscScalar[]);
231817df18f2SToby Isaac PETSC_EXTERN PetscErrorCode PetscSortIntWithDataArray(PetscInt,PetscInt[],void*,size_t,void*);
2319014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortReal(PetscInt,PetscReal[]);
232039f41f7fSStefano Zampini PETSC_EXTERN PetscErrorCode PetscSortRealWithArrayInt(PetscInt,PetscReal[],PetscInt[]);
2321014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortRealWithPermutation(PetscInt,const PetscReal[],PetscInt[]);
2322745b41b2SMatthew G. Knepley PETSC_EXTERN PetscErrorCode PetscSortRemoveDupsReal(PetscInt*,PetscReal[]);
232339f41f7fSStefano Zampini PETSC_EXTERN PetscErrorCode PetscFindReal(PetscReal,PetscInt,const PetscReal[],PetscReal,PetscInt*);
2324014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortSplit(PetscInt,PetscInt,PetscScalar[],PetscInt[]);
2325014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSortSplitReal(PetscInt,PetscInt,PetscReal[],PetscInt[]);
2326014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscProcessTree(PetscInt,const PetscBool [],const PetscInt[],PetscInt*,PetscInt**,PetscInt**,PetscInt**,PetscInt**);
23276c2863d0SBarry Smith PETSC_EXTERN PetscErrorCode PetscMergeIntArrayPair(PetscInt,const PetscInt[],const PetscInt[],PetscInt,const PetscInt[],const PetscInt[],PetscInt*,PetscInt**,PetscInt**);
23286c2863d0SBarry Smith PETSC_EXTERN PetscErrorCode PetscMergeIntArray(PetscInt,const PetscInt[],PetscInt,const PetscInt[],PetscInt*,PetscInt**);
2329e498c390SJed Brown PETSC_EXTERN PetscErrorCode PetscMergeMPIIntArray(PetscInt,const PetscMPIInt[],PetscInt,const PetscMPIInt[],PetscInt*,PetscMPIInt**);
2330ce605777SToby Isaac PETSC_EXTERN PetscErrorCode PetscParallelSortedInt(MPI_Comm, PetscInt, const PetscInt[], PetscBool *);
2331ce605777SToby Isaac 
23324d3610e3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscTimSort(PetscInt,void*,size_t,int(*)(const void*,const void*,void*),void*);
2333676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscIntSortSemiOrdered(PetscInt,PetscInt[]);
2334676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscMPIIntSortSemiOrdered(PetscInt,PetscMPIInt[]);
2335676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscRealSortSemiOrdered(PetscInt,PetscReal[]);
23364d3610e3SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscTimSortWithArray(PetscInt,void*,size_t,void*,size_t,int(*)(const void*,const void*,void*),void*);
2337676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscIntSortSemiOrderedWithArray(PetscInt,PetscInt[],PetscInt[]);
2338676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscMPIIntSortSemiOrderedWithArray(PetscInt,PetscMPIInt[],PetscMPIInt[]);
2339676f2a66SJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscRealSortSemiOrderedWithArrayInt(PetscInt,PetscReal[],PetscInt[]);
2340676f2a66SJacob Faibussowitsch 
2341014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDisplay(void);
2342014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetDisplay(char[],size_t);
2343d382aafbSBarry Smith 
234476bdecfbSBarry Smith /*J
2345d382aafbSBarry Smith     PetscRandomType - String with the name of a PETSc randomizer
2346d382aafbSBarry Smith 
2347d382aafbSBarry Smith    Level: beginner
2348d382aafbSBarry Smith 
2349e28ce29aSPatrick Sanan    Notes:
2350e28ce29aSPatrick Sanan    To use SPRNG or RANDOM123 you must have ./configure PETSc
235125ccb61fSToby Isaac    with the option --download-sprng or --download-random123
2352d382aafbSBarry Smith 
23538f6c3df8SBarry Smith .seealso: PetscRandomSetType(), PetscRandom, PetscRandomCreate()
235476bdecfbSBarry Smith J*/
235519fd82e9SBarry Smith typedef const char* PetscRandomType;
2356d382aafbSBarry Smith #define PETSCRAND       "rand"
2357d382aafbSBarry Smith #define PETSCRAND48     "rand48"
2358d382aafbSBarry Smith #define PETSCSPRNG      "sprng"
2359c5e4d11fSDmitry Karpeev #define PETSCRANDER48   "rander48"
236025ccb61fSToby Isaac #define PETSCRANDOM123  "random123"
2361808ba619SStefano Zampini #define PETSCCURAND     "curand"
2362d382aafbSBarry Smith 
2363d382aafbSBarry Smith /* Logging support */
2364014dd563SJed Brown PETSC_EXTERN PetscClassId PETSC_RANDOM_CLASSID;
2365d382aafbSBarry Smith 
2366607a6623SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomInitializePackage(void);
2367d382aafbSBarry Smith 
2368d382aafbSBarry Smith /* Dynamic creation and loading functions */
2369140e18c1SBarry Smith PETSC_EXTERN PetscFunctionList PetscRandomList;
2370d382aafbSBarry Smith 
2371bdf89e91SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomRegister(const char[],PetscErrorCode (*)(PetscRandom));
237219fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomSetType(PetscRandom,PetscRandomType);
2373014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetFromOptions(PetscRandom);
237419fd82e9SBarry Smith PETSC_EXTERN PetscErrorCode PetscRandomGetType(PetscRandom,PetscRandomType*);
2375fe2efc57SMark PETSC_EXTERN PetscErrorCode PetscRandomViewFromOptions(PetscRandom,PetscObject,const char[]);
2376014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomView(PetscRandom,PetscViewer);
2377d382aafbSBarry Smith 
2378014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomCreate(MPI_Comm,PetscRandom*);
2379014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetValue(PetscRandom,PetscScalar*);
2380014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetValueReal(PetscRandom,PetscReal*);
2381808ba619SStefano Zampini PETSC_EXTERN PetscErrorCode PetscRandomGetValues(PetscRandom,PetscInt,PetscScalar*);
2382808ba619SStefano Zampini PETSC_EXTERN PetscErrorCode PetscRandomGetValuesReal(PetscRandom,PetscInt,PetscReal*);
2383014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetInterval(PetscRandom,PetscScalar*,PetscScalar*);
2384014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetInterval(PetscRandom,PetscScalar,PetscScalar);
2385014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSetSeed(PetscRandom,unsigned long);
2386014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomGetSeed(PetscRandom,unsigned long *);
2387014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomSeed(PetscRandom);
2388014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscRandomDestroy(PetscRandom*);
2389d382aafbSBarry Smith 
2390014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetFullPath(const char[],char[],size_t);
2391014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetRelativePath(const char[],char[],size_t);
2392014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetWorkingDirectory(char[],size_t);
2393014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetRealPath(const char[],char[]);
2394014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetHomeDirectory(char[],size_t);
2395014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTestFile(const char[],char,PetscBool *);
2396014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscTestDirectory(const char[],char,PetscBool *);
239797540f07SSatish Balay PETSC_EXTERN PetscErrorCode PetscMkdir(const char[]);
23988a10d460SHong Zhang PETSC_EXTERN PetscErrorCode PetscMkdtemp(char[]);
239997540f07SSatish Balay PETSC_EXTERN PetscErrorCode PetscRMTree(const char[]);
2400d382aafbSBarry Smith 
240130815ce0SLisandro Dalcin PETSC_STATIC_INLINE PetscBool PetscBinaryBigEndian(void) {long _petsc_v = 1; return ((char*)&_petsc_v)[0] ? PETSC_FALSE : PETSC_TRUE;}
240230815ce0SLisandro Dalcin 
24039860990eSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinaryRead(int,void*,PetscInt,PetscInt*,PetscDataType);
24049860990eSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedRead(MPI_Comm,int,void*,PetscInt,PetscInt*,PetscDataType);
2405f253e43cSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinaryWrite(int,const void*,PetscInt,PetscDataType);
2406f253e43cSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedWrite(MPI_Comm,int,const void*,PetscInt,PetscDataType);
2407014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinaryOpen(const char[],PetscFileMode,int *);
2408014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinaryClose(int);
2409014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSharedTmp(MPI_Comm,PetscBool  *);
2410014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSharedWorkingDirectory(MPI_Comm,PetscBool  *);
2411014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGetTmp(MPI_Comm,char[],size_t);
2412014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFileRetrieve(MPI_Comm,const char[],char[],size_t,PetscBool *);
2413014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscLs(MPI_Comm,const char[],char[],size_t,PetscBool *);
2414c891a504SStefano Zampini #if defined(PETSC_USE_SOCKET_VIEWER)
2415e2fc02c1SBarry Smith PETSC_EXTERN PetscErrorCode PetscOpenSocket(const char[],int,int*);
2416c891a504SStefano Zampini #endif
2417d382aafbSBarry Smith 
2418014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinarySeek(int,off_t,PetscBinarySeekType,off_t*);
2419014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscBinarySynchronizedSeek(MPI_Comm,int,off_t,PetscBinarySeekType,off_t*);
2420014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscByteSwap(void *,PetscDataType,PetscInt);
2421d382aafbSBarry Smith 
2422014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebugTerminal(const char[]);
2423014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebugger(const char[],PetscBool);
2424014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDefaultDebugger(void);
2425014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetDebuggerFromString(const char*);
2426014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscAttachDebugger(void);
2427014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStopForDebugger(void);
24282a2a2941SBarry Smith PETSC_EXTERN PetscErrorCode PetscWaitOnError(void);
2429d382aafbSBarry Smith 
2430014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGatherNumberOfMessages(MPI_Comm,const PetscMPIInt[],const PetscMPIInt[],PetscMPIInt*);
2431014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],PetscMPIInt**,PetscMPIInt**);
2432014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscGatherMessageLengths2(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],const PetscMPIInt[],PetscMPIInt**,PetscMPIInt**,PetscMPIInt**);
2433014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPostIrecvInt(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],const PetscMPIInt[],PetscInt***,MPI_Request**);
2434014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPostIrecvScalar(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],const PetscMPIInt[],PetscScalar***,MPI_Request**);
2435cf4b5b4fSJed Brown PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSided(MPI_Comm,PetscMPIInt,MPI_Datatype,PetscMPIInt,const PetscMPIInt*,const void*,PetscMPIInt*,PetscMPIInt**,void*)
2436cf4b5b4fSJed Brown   PetscAttrMPIPointerWithType(6,3);
2437d815da10SJed Brown PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedF(MPI_Comm,PetscMPIInt,MPI_Datatype,PetscMPIInt,const PetscMPIInt[],const void*,PetscMPIInt*,PetscMPIInt**,void*,PetscMPIInt,
2438d815da10SJed Brown                                                     PetscErrorCode (*send)(MPI_Comm,const PetscMPIInt[],PetscMPIInt,PetscMPIInt,void*,MPI_Request[],void*),
2439d815da10SJed Brown                                                     PetscErrorCode (*recv)(MPI_Comm,const PetscMPIInt[],PetscMPIInt,void*,MPI_Request[],void*),void *ctx)
2440d815da10SJed Brown   PetscAttrMPIPointerWithType(6,3);
24416afbe7ddSJed Brown PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedFReq(MPI_Comm,PetscMPIInt,MPI_Datatype,PetscMPIInt,const PetscMPIInt[],const void*,PetscMPIInt*,PetscMPIInt**,void*,PetscMPIInt,
24426afbe7ddSJed Brown                                                        MPI_Request**,MPI_Request**,
24436afbe7ddSJed Brown                                                        PetscErrorCode (*send)(MPI_Comm,const PetscMPIInt[],PetscMPIInt,PetscMPIInt,void*,MPI_Request[],void*),
24446afbe7ddSJed Brown                                                        PetscErrorCode (*recv)(MPI_Comm,const PetscMPIInt[],PetscMPIInt,void*,MPI_Request[],void*),void *ctx)
24456afbe7ddSJed Brown   PetscAttrMPIPointerWithType(6,3);
2446d382aafbSBarry Smith 
24476145cd65SJed Brown PETSC_EXTERN const char *const PetscBuildTwoSidedTypes[];
24486145cd65SJed Brown PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedSetType(MPI_Comm,PetscBuildTwoSidedType);
24496145cd65SJed Brown PETSC_EXTERN PetscErrorCode PetscCommBuildTwoSidedGetType(MPI_Comm,PetscBuildTwoSidedType*);
24506145cd65SJed Brown 
2451014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSSEIsEnabled(MPI_Comm,PetscBool*,PetscBool*);
2452d382aafbSBarry Smith 
2453ce94432eSBarry Smith PETSC_EXTERN MPI_Comm PetscObjectComm(PetscObject);
2454ce94432eSBarry Smith 
245545487dadSJed Brown PETSC_EXTERN const char *const PetscSubcommTypes[];
245645487dadSJed Brown 
2457d382aafbSBarry Smith struct _n_PetscSubcomm {
2458d382aafbSBarry Smith   MPI_Comm         parent;           /* parent communicator */
2459d382aafbSBarry Smith   MPI_Comm         dupparent;        /* duplicate parent communicator, under which the processors of this subcomm have contiguous rank */
2460306c2d5bSBarry Smith   MPI_Comm         child;            /* the sub-communicator */
246145487dadSJed Brown   PetscMPIInt      n;                /* num of subcommunicators under the parent communicator */
246245487dadSJed Brown   PetscMPIInt      color;            /* color of processors belong to this communicator */
2463708d824cSJed Brown   PetscMPIInt      *subsize;         /* size of subcommunicator[color] */
246445487dadSJed Brown   PetscSubcommType type;
2465e5acf8a4SHong Zhang   char             *subcommprefix;
2466d382aafbSBarry Smith };
2467d382aafbSBarry Smith 
2468c5e4d11fSDmitry Karpeev PETSC_STATIC_INLINE MPI_Comm PetscSubcommParent(PetscSubcomm scomm) {return scomm->parent;}
2469306c2d5bSBarry Smith PETSC_STATIC_INLINE MPI_Comm PetscSubcommChild(PetscSubcomm scomm) {return scomm->child;}
247036be1a5eSBarry Smith PETSC_STATIC_INLINE MPI_Comm PetscSubcommContiguousParent(PetscSubcomm scomm) {return scomm->dupparent;}
2471014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommCreate(MPI_Comm,PetscSubcomm*);
2472014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommDestroy(PetscSubcomm*);
2473014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommSetNumber(PetscSubcomm,PetscInt);
2474014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSubcommSetType(PetscSubcomm,PetscSubcommType);
247565d9b8f1SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetTypeGeneral(PetscSubcomm,PetscMPIInt,PetscMPIInt);
2476053d1c95SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommView(PetscSubcomm,PetscViewer);
2477f68be91cSHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetFromOptions(PetscSubcomm);
2478e5acf8a4SHong Zhang PETSC_EXTERN PetscErrorCode PetscSubcommSetOptionsPrefix(PetscSubcomm,const char[]);
2479a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetParent(PetscSubcomm,MPI_Comm*);
2480a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetContiguousParent(PetscSubcomm,MPI_Comm*);
2481a530d236SBarry Smith PETSC_EXTERN PetscErrorCode PetscSubcommGetChild(PetscSubcomm,MPI_Comm*);
2482d382aafbSBarry Smith 
24839962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapCreate(PetscInt,PetscHeap*);
24849962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapAdd(PetscHeap,PetscInt,PetscInt);
24859962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapPop(PetscHeap,PetscInt*,PetscInt*);
24869962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapPeek(PetscHeap,PetscInt*,PetscInt*);
24879962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapStash(PetscHeap,PetscInt,PetscInt);
24889962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapUnstash(PetscHeap);
24899962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapDestroy(PetscHeap*);
24909962606eSBarry Smith PETSC_EXTERN PetscErrorCode PetscHeapView(PetscHeap,PetscViewer);
24919962606eSBarry Smith 
24925e71baefSBarry Smith PETSC_EXTERN PetscErrorCode PetscProcessPlacementView(PetscViewer);
24935f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGet(MPI_Comm,PetscShmComm*);
24945f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGlobalToLocal(PetscShmComm,PetscMPIInt,PetscMPIInt*);
24955f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommLocalToGlobal(PetscShmComm,PetscMPIInt,PetscMPIInt*);
24965f7487a0SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscShmCommGetMpiShmComm(PetscShmComm,MPI_Comm*);
24975e71baefSBarry Smith 
2498a32e93adSJunchao Zhang /* routines to better support OpenMP multithreading needs of some PETSc third party libraries */
2499a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlCreate(MPI_Comm,PetscInt,PetscOmpCtrl*);
2500a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlGetOmpComms(PetscOmpCtrl,MPI_Comm*,MPI_Comm*,PetscBool*);
2501a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlDestroy(PetscOmpCtrl*);
2502a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlBarrier(PetscOmpCtrl);
2503a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlOmpRegionOnMasterBegin(PetscOmpCtrl);
2504a32e93adSJunchao Zhang PETSC_EXTERN PetscErrorCode PetscOmpCtrlOmpRegionOnMasterEnd(PetscOmpCtrl);
2505a32e93adSJunchao Zhang 
250613e3f751SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferCreate(size_t,size_t,PetscSegBuffer*);
25070f453b92SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferDestroy(PetscSegBuffer*);
250813e3f751SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferGet(PetscSegBuffer,size_t,void*);
2509137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractAlloc(PetscSegBuffer,void*);
2510137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractTo(PetscSegBuffer,void*);
2511137cf7b6SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferExtractInPlace(PetscSegBuffer,void*);
251213e3f751SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferGetSize(PetscSegBuffer,size_t*);
251313e3f751SJed Brown PETSC_EXTERN PetscErrorCode PetscSegBufferUnuse(PetscSegBuffer,size_t);
25140f453b92SJed Brown 
2515471ecdacSJed Brown /* Type-safe wrapper to encourage use of PETSC_RESTRICT. Does not use PetscFunctionBegin because the error handling
2516471ecdacSJed Brown  * prevents the compiler from completely erasing the stub. This is called in inner loops so it has to be as fast as
2517471ecdacSJed Brown  * possible. */
25186a11cab8SBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscSegBufferGetInts(PetscSegBuffer seg,size_t count,PetscInt *PETSC_RESTRICT *slot) {return PetscSegBufferGet(seg,count,(void**)slot);}
2519d382aafbSBarry Smith 
25209de0f6ecSBarry Smith extern PetscOptionsHelpPrinted PetscOptionsHelpPrintedSingleton;
25219de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode PetscOptionsHelpPrintedDestroy(PetscOptionsHelpPrinted*);
25229de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode PetscOptionsHelpPrintedCreate(PetscOptionsHelpPrinted*);
25239de0f6ecSBarry Smith PETSC_EXTERN PetscErrorCode PetscOptionsHelpPrintedCheck(PetscOptionsHelpPrinted,const char*,const char*,PetscBool*);
25249de0f6ecSBarry Smith 
2525ace2fbaeSBarry Smith #include <stdarg.h>
2526ace2fbaeSBarry Smith PETSC_EXTERN PetscErrorCode PetscVSNPrintf(char*,size_t,const char[],size_t*,va_list);
2527ace2fbaeSBarry Smith PETSC_EXTERN PetscErrorCode (*PetscVFPrintf)(FILE*,const char[],va_list);
2528ace2fbaeSBarry Smith 
2529268b0dfdSSatish Balay PETSC_EXTERN PetscSegBuffer PetscCitationsList;
2530fbfcfee5SBarry Smith 
25311f817a21SBarry Smith /*@C
25321f817a21SBarry Smith       PetscCitationsRegister - Register a bibtex item to obtain credit for an implemented algorithm used in the code.
25331f817a21SBarry Smith 
25341f817a21SBarry Smith      Not Collective - only what is registered on rank 0 of PETSC_COMM_WORLD will be printed
25351f817a21SBarry Smith 
25361f817a21SBarry Smith      Input Parameters:
25371f817a21SBarry Smith +      cite - the bibtex item, formated to displayed on multiple lines nicely
25381f817a21SBarry Smith -      set - a boolean variable initially set to PETSC_FALSE; this is used to insure only a single registration of the citation
25391f817a21SBarry Smith 
2540850545d0SSatish Balay    Level: intermediate
2541850545d0SSatish Balay 
2542f5f57ec0SBarry Smith    Not available from Fortran
2543f5f57ec0SBarry Smith 
25441f817a21SBarry Smith      Options Database:
2545063414e0SPatrick Sanan .     -citations [filename]   - print out the bibtex entries for the given computation
25461f817a21SBarry Smith @*/
2547dff31646SBarry Smith PETSC_STATIC_INLINE PetscErrorCode PetscCitationsRegister(const char cit[],PetscBool *set)
2548dff31646SBarry Smith {
2549dff31646SBarry Smith   size_t         len;
2550dff31646SBarry Smith   char           *vstring;
2551dff31646SBarry Smith   PetscErrorCode ierr;
2552dff31646SBarry Smith 
25531f817a21SBarry Smith   PetscFunctionBegin;
25548d3683fcSBarry Smith   if (set && *set) PetscFunctionReturn(0);
2555dff31646SBarry Smith   ierr = PetscStrlen(cit,&len);CHKERRQ(ierr);
255635005c2bSLisandro Dalcin   ierr = PetscSegBufferGet(PetscCitationsList,len,&vstring);CHKERRQ(ierr);
2557580bdb30SBarry Smith   ierr = PetscArraycpy(vstring,cit,len);CHKERRQ(ierr);
2558dff31646SBarry Smith   if (set) *set = PETSC_TRUE;
25591f817a21SBarry Smith   PetscFunctionReturn(0);
2560dff31646SBarry Smith }
2561dff31646SBarry Smith 
2562b967cddfSBarry Smith PETSC_EXTERN PetscErrorCode PetscURLShorten(const char[],char[],size_t);
2563fe278a28SBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveAuthorize(MPI_Comm,char[],char[],size_t);
2564fe278a28SBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveRefresh(MPI_Comm,const char[],char[],size_t);
2565f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscGoogleDriveUpload(MPI_Comm,const char[],const char []);
2566fe278a28SBarry Smith 
2567f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscBoxAuthorize(MPI_Comm,char[],char[],size_t);
2568f044a08eSBarry Smith PETSC_EXTERN PetscErrorCode PetscBoxRefresh(MPI_Comm,const char[],char[],char[],size_t);
2569b967cddfSBarry Smith 
25709f4d3c52SBarry Smith PETSC_EXTERN PetscErrorCode PetscGlobusGetTransfers(MPI_Comm,const char[],char[],size_t);
25719f4d3c52SBarry Smith 
257204102261SBarry Smith PETSC_EXTERN PetscErrorCode PetscTextBelt(MPI_Comm,const char[],const char[],PetscBool*);
2573763ec7b1SBarry Smith PETSC_EXTERN PetscErrorCode PetscTellMyCell(MPI_Comm,const char[],const char[],PetscBool*);
2574dff31646SBarry Smith 
257568e69593SBarry Smith PETSC_EXTERN PetscErrorCode PetscPullJSONValue(const char[],const char[],char[],size_t,PetscBool*);
25765dc0f0a4SBarry Smith PETSC_EXTERN PetscErrorCode PetscPushJSONValue(char[],const char[],const char[],size_t);
2577d382aafbSBarry Smith 
2578b2566f29SBarry Smith #if defined(PETSC_USE_DEBUG)
2579503e1a2cSLisandro Dalcin PETSC_STATIC_INLINE unsigned int PetscStrHash(const char *str)
2580df05ca09SBarry Smith {
2581df05ca09SBarry Smith   unsigned int c,hash = 5381;
2582df05ca09SBarry Smith 
2583503e1a2cSLisandro Dalcin   while ((c = (unsigned int)*str++)) hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
2584df05ca09SBarry Smith   return hash;
2585df05ca09SBarry Smith }
258677a5e07dSBarry Smith 
258777a5e07dSBarry Smith /*MC
258877a5e07dSBarry Smith    MPIU_Allreduce - a PETSc replacement for MPI_Allreduce() that tries to determine if the call from all the MPI processes occur from the
258977a5e07dSBarry Smith                     same place in the PETSc code. This helps to detect bugs where different MPI processes follow different code paths
259077a5e07dSBarry Smith                     resulting in inconsistent and incorrect calls to MPI_Allreduce().
259177a5e07dSBarry Smith 
2592d083f849SBarry Smith    Collective
259377a5e07dSBarry Smith 
259477a5e07dSBarry Smith    Synopsis:
259577a5e07dSBarry Smith      #include <petscsys.h>
259677a5e07dSBarry Smith      PetscErrorCode MPIU_Allreduce(void *indata,void *outdata,PetscMPIInt count,MPI_Datatype datatype, MPI_Op op, MPI_Comm comm);
259777a5e07dSBarry Smith 
259877a5e07dSBarry Smith    Input Parameters:
2599df05ca09SBarry Smith +  a - pointer to the input data to be reduced
2600df05ca09SBarry Smith .  c - the number of MPI data items in a and b
2601df05ca09SBarry Smith .  d - the MPI datatype, for example MPI_INT
2602df05ca09SBarry Smith .  e - the MPI operation, for example MPI_SUM
2603df05ca09SBarry Smith -  fcomm - the MPI communicator on which the operation occurs
260477a5e07dSBarry Smith 
260577a5e07dSBarry Smith    Output Parameter:
2606df05ca09SBarry Smith .  b - the reduced values
260777a5e07dSBarry Smith 
2608e28ce29aSPatrick Sanan    Notes:
2609e28ce29aSPatrick Sanan      In optimized mode this directly calls MPI_Allreduce()
261077a5e07dSBarry Smith 
2611df05ca09SBarry Smith      This is defined as a macro that can return error codes internally so it cannot be used in a subroutine that returns void.
2612df05ca09SBarry Smith 
2613df05ca09SBarry Smith      The error code this returns should be checked with CHKERRMPI()
2614df05ca09SBarry Smith 
261577a5e07dSBarry Smith    Level: developer
261677a5e07dSBarry Smith 
261777a5e07dSBarry Smith .seealso: MPI_Allreduce()
261877a5e07dSBarry Smith M*/
2619df05ca09SBarry Smith #define MPIU_Allreduce(a,b,c,d,e,fcomm) MPI_SUCCESS; do {               \
2620df05ca09SBarry Smith   PetscErrorCode _4_ierr;                                               \
2621df05ca09SBarry Smith   PetscMPIInt    a_b1[6],a_b2[6];                                       \
26223ca90d2dSJacob Faibussowitsch   int            _mpiu_allreduce_c_int = (int)c;                        \
2623df05ca09SBarry Smith   a_b1[0] = -(PetscMPIInt)__LINE__;                          a_b1[1] = -a_b1[0];\
2624df05ca09SBarry Smith   a_b1[2] = -(PetscMPIInt)PetscStrHash(PETSC_FUNCTION_NAME); a_b1[3] = -a_b1[2];\
2625df05ca09SBarry Smith   a_b1[4] = -(PetscMPIInt)(c);                               a_b1[5] = -a_b1[4];\
2626df05ca09SBarry Smith   _4_ierr = MPI_Allreduce(a_b1,a_b2,6,MPI_INT,MPI_MAX,fcomm);CHKERRMPI(_4_ierr);\
2627df05ca09SBarry Smith   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");\
2628df05ca09SBarry Smith   if (-a_b2[2] != a_b2[3]) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_PLIB,"MPI_Allreduce() called in different locations (functions) on different processors");\
26293ca90d2dSJacob Faibussowitsch   if (-a_b2[4] != a_b2[5]) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_PLIB,"MPI_Allreduce() called with different counts %d on different processors",_mpiu_allreduce_c_int); \
2630df05ca09SBarry Smith   _4_ierr = MPI_Allreduce((a),(b),(c),d,e,(fcomm));CHKERRMPI(_4_ierr);\
2631df05ca09SBarry Smith   } while (0)
2632b2566f29SBarry Smith #else
2633df05ca09SBarry Smith #define MPIU_Allreduce(a,b,c,d,e,fcomm) MPI_Allreduce((a),(b),(c),d,e,(fcomm))
2634b2566f29SBarry Smith #endif
2635b2566f29SBarry Smith 
2636b674149eSJunchao Zhang #if defined(PETSC_HAVE_MPI_PROCESS_SHARED_MEMORY)
26378198064fSBarry Smith PETSC_EXTERN PetscErrorCode MPIU_Win_allocate_shared(MPI_Aint,PetscMPIInt,MPI_Info,MPI_Comm,void*,MPI_Win*);
26388198064fSBarry Smith PETSC_EXTERN PetscErrorCode MPIU_Win_shared_query(MPI_Win,PetscMPIInt,MPI_Aint*,PetscMPIInt*,void*);
26392f065d89SBarry Smith #endif
26408198064fSBarry Smith 
2641cd88fca5SStefano Zampini /* this is a vile hack */
2642cd88fca5SStefano Zampini #if defined(PETSC_HAVE_NECMPI)
2643961fb248SStefano Zampini #if !defined(PETSC_NECMPI_VERSION_MAJOR) ||                              \
2644961fb248SStefano Zampini     !defined(PETSC_NECMPI_VERSION_MINOR) ||                              \
2645961fb248SStefano Zampini     PETSC_NECMPI_VERSION_MAJOR < 2       ||                              \
2646961fb248SStefano Zampini     (PETSC_NECMPI_VERSION_MAJOR == 2 && PETSC_NECMPI_VERSION_MINOR < 18)
2647cd88fca5SStefano Zampini #define MPI_Type_free(a) (*(a) = MPI_DATATYPE_NULL,0);
2648cd88fca5SStefano Zampini #endif
2649961fb248SStefano Zampini #endif
2650cd88fca5SStefano Zampini 
265112801b39SBarry Smith /*
265260fbe2beSVaclav Hapla     List of external packages and queries on it
265360fbe2beSVaclav Hapla */
265460fbe2beSVaclav Hapla PETSC_EXTERN PetscErrorCode  PetscHasExternalPackage(const char[],PetscBool*);
265560fbe2beSVaclav Hapla 
2656a52b435bSMark Adams /*
2657a52b435bSMark Adams  OpenMP support
2658a52b435bSMark Adams */
2659a52b435bSMark Adams #if defined(_OPENMP)
2660a52b435bSMark Adams #define PetscPragmaOMP(...) _Pragma(PetscStringize(omp __VA_ARGS__))
2661a52b435bSMark Adams #else // no OpenMP so no threads
2662a52b435bSMark Adams #define PetscPragmaOMP(...)
2663a52b435bSMark Adams #endif
2664a52b435bSMark Adams 
2665d382aafbSBarry Smith #endif
2666