xref: /petsc/include/petsc.h (revision 6f69ff64820919ebe18fb76bd64afac7cb45e7be)
1 /*
2    This is the main PETSc include file (for C and C++).  It is included by all
3    other PETSc include files, so it almost never has to be specifically included.
4 */
5 #if !defined(__PETSC_H)
6 #define __PETSC_H
7 /* ========================================================================== */
8 /*
9    This facilitates using C version of PETSc from C++
10 */
11 
12 #if defined(PETSC_USE_EXTERN_CXX) && defined(__cplusplus)
13 #define PETSC_EXTERN_CXX_BEGIN extern "C" {
14 #define PETSC_EXTERN_CXX_END  }
15 #else
16 #define PETSC_EXTERN_CXX_BEGIN
17 #define PETSC_EXTERN_CXX_END
18 #endif
19 /* ========================================================================== */
20 /*
21    Current PETSc version number and release date
22 */
23 #include "petscversion.h"
24 
25 /* ========================================================================== */
26 /*
27    petscconf.h is contained in bmake/${PETSC_ARCH}/petscconf.h it is
28    found automatically by the compiler due to the -I${PETSC_DIR}/bmake/${PETSC_ARCH}
29    in the bmake/common_variables definition of PETSC_INCLUDE
30 */
31 #include "petscconf.h"
32 /*
33    Fixes for configure time choices which impact our interface. Currently only
34    calling conventions and extra compiler checking falls under this category.
35 */
36 #if !defined(PETSC_PRINTF_FORMAT_CHECK)
37 #define PETSC_PRINTF_FORMAT_CHECK(a,b)
38 #endif
39 #if !defined (PETSC_STDCALL)
40 #define PETSC_STDCALL
41 #endif
42 #if !defined (PETSC_TEMPLATE)
43 #define PETSC_TEMPLATE
44 #endif
45 
46 /* ========================================================================== */
47 
48 #include <stdio.h>
49 /*
50     Defines the interface to MPI allowing the use of all MPI functions.
51 */
52 #include "mpi.h"
53 
54 /*
55     All PETSc C functions return this error code, it is the final argument of
56    all Fortran subroutines
57 */
58 typedef int PetscErrorCode;
59 typedef int PetscCookie;
60 typedef int PetscEvent;
61 typedef int PetscBLASInt;
62 typedef int PetscMPIInt;
63 
64 #if defined(PETSC_USE_64BIT_INT)
65 typedef long long PetscInt;
66 #define MPIU_INT MPI_LONG_LONG_INT
67 #undef  PETSC_PRINTF_FORMAT_CHECK
68 #define PETSC_PRINTF_FORMAT_CHECK(a,b)
69 #undef  PETSC_FPRINTF_FORMAT_CHECK
70 #define PETSC_FPRINTF_FORMAT_CHECK(a,b)
71 #else
72 typedef int PetscInt;
73 #define MPIU_INT MPI_INT
74 #endif
75 
76 /*
77     Declare extern C stuff after incuding external header files
78 */
79 
80 PETSC_EXTERN_CXX_BEGIN
81 
82 /*
83     EXTERN indicates a PETSc function defined elsewhere
84 */
85 #if !defined(EXTERN)
86 #define EXTERN extern
87 #endif
88 
89 /*
90     Defines some elementary mathematics functions and constants.
91 */
92 #include "petscmath.h"
93 
94 /*
95        Basic PETSc constants
96 */
97 
98 /*E
99     PetscTruth - Logical variable. Actually an integer
100 
101    Level: beginner
102 
103 E*/
104 typedef enum { PETSC_FALSE,PETSC_TRUE } PetscTruth;
105 
106 /*M
107     PETSC_FALSE - False value of PetscTruth
108 
109     Level: beginner
110 
111     Note: Zero integer
112 
113 .seealso: PetscTruth
114 M*/
115 
116 /*M
117     PETSC_TRUE - True value of PetscTruth
118 
119     Level: beginner
120 
121     Note: Nonzero integer
122 
123 .seealso: PetscTruth
124 M*/
125 
126 /*M
127     PETSC_YES - Alias for PETSC_TRUE
128 
129     Level: beginner
130 
131     Note: Zero integer
132 
133 .seealso: PetscTruth
134 M*/
135 
136 /*M
137     PETSC_NO - Alias for PETSC_FALSE
138 
139     Level: beginner
140 
141     Note: Nonzero integer
142 
143 .seealso: PetscTruth
144 M*/
145 
146 /*M
147     PETSC_NULL - standard way of passing in a null or array or pointer
148 
149    Level: beginner
150 
151    Notes: accepted by many PETSc functions to not set a parameter and instead use
152           some default
153 
154           This macro does not exist in Fortran; you must use PETSC_NULL_INTEGER,
155           PETSC_NULL_DOUBLE_PRECISION etc
156 
157 .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_IGNORE, PETSC_DETERMINE
158 
159 M*/
160 #define PETSC_NULL           0
161 
162 /*M
163     PETSC_DECIDE - standard way of passing in integer or floating point parameter
164        where you wish PETSc to use the default.
165 
166    Level: beginner
167 
168 .seealso: PETSC_NULL, PETSC_DEFAULT, PETSC_IGNORE, PETSC_DETERMINE
169 
170 M*/
171 #define PETSC_DECIDE         -1
172 
173 /*M
174     PETSC_DEFAULT - standard way of passing in integer or floating point parameter
175        where you wish PETSc to use the default.
176 
177    Level: beginner
178 
179 .seealso: PETSC_DECIDE, PETSC_NULL, PETSC_IGNORE, PETSC_DETERMINE
180 
181 M*/
182 #define PETSC_DEFAULT        -2
183 
184 #define PETSC_YES            PETSC_TRUE
185 #define PETSC_NO             PETSC_FALSE
186 
187 /*M
188     PETSC_IGNORE - same as PETSC_NULL, means PETSc will ignore this argument
189 
190    Level: beginner
191 
192    Notes: accepted by many PETSc functions to not set a parameter and instead use
193           some default
194 
195           This macro does not exist in Fortran; you must use PETSC_NULL_INTEGER,
196           PETSC_NULL_DOUBLE_PRECISION etc
197 
198 .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_NULL, PETSC_DETERMINE
199 
200 M*/
201 #define PETSC_IGNORE         PETSC_NULL
202 
203 /*M
204     PETSC_DETERMINE - standard way of passing in integer or floating point parameter
205        where you wish PETSc to compute the required value.
206 
207    Level: beginner
208 
209 .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_IGNORE, PETSC_NULL, VecSetSizes()
210 
211 M*/
212 #define PETSC_DETERMINE      PETSC_DECIDE
213 
214 /*M
215     PETSC_COMM_WORLD - a duplicate of the MPI_COMM_WORLD communicator which represents
216            all the processs
217 
218    Level: beginner
219 
220    Notes: PETSC_COMM_WORLD and MPI_COMM_WORLD are equivalent except that passing MPI_COMM_WORLD
221           into PETSc object constructors will result in using more MPI resources since an MPI_Comm_dup()
222           will be done on it internally. We recommend always using PETSC_COMM_WORLD
223 
224 .seealso: PETSC_COMM_SELF
225 
226 M*/
227 extern MPI_Comm   PETSC_COMM_WORLD;
228 
229 /*M
230     PETSC_COMM_SELF - a duplicate of the MPI_COMM_SELF communicator which represents
231            the current process
232 
233    Level: beginner
234 
235    Notes: PETSC_COMM_SELF and MPI_COMM_SELF are equivalent except that passint MPI_COMM_SELF
236           into PETSc object constructors will result in using more MPI resources since an MPI_Comm_dup()
237           will be done on it internally. We recommend always using PETSC_COMM_SELF
238 
239 .seealso: PETSC_COMM_WORLD
240 
241 M*/
242 extern MPI_Comm   PETSC_COMM_SELF;
243 
244 extern PetscTruth PetscInitializeCalled;
245 EXTERN PetscErrorCode        PetscSetCommWorld(MPI_Comm);
246 EXTERN PetscErrorCode        PetscSetHelpVersionFunctions(PetscErrorCode (*)(MPI_Comm),PetscErrorCode (*)(MPI_Comm));
247 EXTERN PetscErrorCode        PetscCommDuplicate(MPI_Comm,MPI_Comm*,int*);
248 EXTERN PetscErrorCode        PetscCommDestroy(MPI_Comm*);
249 
250 /*MC
251    PetscMalloc - Allocates memory
252 
253    Input Parameter:
254 .  m - number of bytes to allocate
255 
256    Output Parameter:
257 .  result - memory allocated
258 
259    Synopsis:
260    PetscErrorCode PetscMalloc(size_t m,void **result)
261 
262    Level: beginner
263 
264    Notes: Memory is always allocated at least double aligned
265 
266 .seealso: PetscFree(), PetscNew()
267 
268   Concepts: memory allocation
269 
270 M*/
271 #define PetscMalloc(a,b)     (*PetscTrMalloc)((a),__LINE__,__FUNCT__,__FILE__,__SDIR__,(void**)(b))
272 /*MC
273    PetscNew - Allocates memory of a particular type
274 
275    Input Parameter:
276 . type - structure name of space to be allocated. Memory of size sizeof(type) is allocated
277 
278    Output Parameter:
279 .  result - memory allocated
280 
281    Synopsis:
282    PetscErrorCode PetscNew(struct type,((type *))result)
283 
284    Level: beginner
285 
286 .seealso: PetscFree(), PetscMalloc()
287 
288   Concepts: memory allocation
289 
290 M*/
291 #define PetscNew(A,b)        PetscMalloc(sizeof(A),(b))
292 /*MC
293    PetscFree - Frees memory
294 
295    Input Parameter:
296 .   memory - memory to free
297 
298    Synopsis:
299    PetscErrorCode PetscFree(void *memory)
300 
301    Level: beginner
302 
303    Notes: Memory must have been obtained with PetscNew() or PetscMalloc()
304 
305 .seealso: PetscNew(), PetscMalloc()
306 
307   Concepts: memory allocation
308 
309 M*/
310 #define PetscFree(a)         (*PetscTrFree)((a),__LINE__,__FUNCT__,__FILE__,__SDIR__)
311 EXTERN PetscErrorCode  (*PetscTrMalloc)(size_t,int,const char[],const char[],const char[],void**);
312 EXTERN PetscErrorCode  (*PetscTrFree)(void*,int,const char[],const char[],const char[]);
313 EXTERN PetscErrorCode  PetscSetMalloc(PetscErrorCode (*)(size_t,int,const char[],const char[],const char[],void**),PetscErrorCode (*)(void*,int,const char[],const char[],const char[]));
314 EXTERN PetscErrorCode  PetscClearMalloc(void);
315 
316 /*
317    Routines for tracing memory corruption/bleeding with default PETSc
318    memory allocation
319 */
320 EXTERN PetscErrorCode   PetscTrDump(FILE *);
321 EXTERN PetscErrorCode   PetscTrSpace(PetscLogDouble *,PetscLogDouble *,PetscLogDouble *);
322 EXTERN PetscErrorCode   PetscTrValid(int,const char[],const char[],const char[]);
323 EXTERN PetscErrorCode   PetscTrDebug(PetscTruth);
324 EXTERN PetscErrorCode   PetscTrLog(void);
325 EXTERN PetscErrorCode   PetscTrLogDump(FILE *);
326 EXTERN PetscErrorCode   PetscGetResidentSetSize(PetscLogDouble *);
327 
328 /*
329     Variable type where we stash PETSc object pointers in Fortran.
330     Assumes that sizeof(long) == sizeof(void*)which is true on
331     all machines that we know.
332 */
333 #define PetscFortranAddr   long
334 
335 /*E
336     PetscDataType - Used for handling different basic data types.
337 
338    Level: beginner
339 
340 .seealso: PetscBinaryRead(), PetscBinaryWrite(), PetscDataTypeToMPIDataType(),
341           PetscDataTypeGetSize(), PetscDataTypeGetName()
342 
343 E*/
344 typedef enum {PETSC_INT = 0,PETSC_DOUBLE = 1,PETSC_COMPLEX = 2,
345               PETSC_LONG =3 ,PETSC_SHORT = 4,PETSC_FLOAT = 5,
346               PETSC_CHAR = 6,PETSC_LOGICAL = 7} PetscDataType;
347 #if defined(PETSC_USE_COMPLEX)
348 #define PETSC_SCALAR PETSC_COMPLEX
349 #else
350 #if defined(PETSC_USE_SINGLE)
351 #define PETSC_SCALAR PETSC_FLOAT
352 #else
353 #define PETSC_SCALAR PETSC_DOUBLE
354 #endif
355 #endif
356 #if defined(PETSC_USE_SINGLE)
357 #define PETSC_REAL PETSC_FLOAT
358 #else
359 #define PETSC_REAL PETSC_DOUBLE
360 #endif
361 #define PETSC_FORTRANADDR PETSC_LONG
362 
363 EXTERN PetscErrorCode PetscDataTypeToMPIDataType(PetscDataType,MPI_Datatype*);
364 EXTERN PetscErrorCode PetscDataTypeGetSize(PetscDataType,int*);
365 EXTERN PetscErrorCode PetscDataTypeGetName(PetscDataType,const char*[]);
366 
367 /*
368     Basic memory and string operations. These are usually simple wrappers
369    around the basic Unix system calls, but a few of them have additional
370    functionality and/or error checking.
371 */
372 EXTERN PetscErrorCode   PetscMemcpy(void*,const void *,size_t);
373 EXTERN PetscErrorCode   PetscBitMemcpy(void*,int,const void*,int,int,PetscDataType);
374 EXTERN PetscErrorCode   PetscMemmove(void*,void *,size_t);
375 EXTERN PetscErrorCode   PetscMemzero(void*,size_t);
376 EXTERN PetscErrorCode   PetscMemcmp(const void*,const void*,size_t,PetscTruth *);
377 EXTERN PetscErrorCode   PetscStrlen(const char[],size_t*);
378 EXTERN PetscErrorCode   PetscStrcmp(const char[],const char[],PetscTruth *);
379 EXTERN PetscErrorCode   PetscStrgrt(const char[],const char[],PetscTruth *);
380 EXTERN PetscErrorCode   PetscStrcasecmp(const char[],const char[],PetscTruth*);
381 EXTERN PetscErrorCode   PetscStrncmp(const char[],const char[],size_t,PetscTruth*);
382 EXTERN PetscErrorCode   PetscStrcpy(char[],const char[]);
383 EXTERN PetscErrorCode   PetscStrcat(char[],const char[]);
384 EXTERN PetscErrorCode   PetscStrncat(char[],const char[],size_t);
385 EXTERN PetscErrorCode   PetscStrncpy(char[],const char[],size_t);
386 EXTERN PetscErrorCode   PetscStrchr(const char[],char,char *[]);
387 EXTERN PetscErrorCode   PetscStrtolower(char[]);
388 EXTERN PetscErrorCode   PetscStrrchr(const char[],char,char *[]);
389 EXTERN PetscErrorCode   PetscStrstr(const char[],const char[],char *[]);
390 EXTERN PetscErrorCode   PetscStrallocpy(const char[],char *[]);
391 EXTERN PetscErrorCode   PetscStrreplace(MPI_Comm,const char[],char[],size_t);
392 #define      PetscStrfree(a) ((a) ? PetscFree(a) : 0)
393 /*S
394     PetscToken - 'Token' used for managing tokenizing strings
395 
396   Level: intermediate
397 
398 .seealso: PetscTokenCreate(), PetscTokenFind(), PetscTokenDestroy()
399 S*/
400 typedef struct {char token;char *array;char *current;} PetscToken;
401 
402 EXTERN PetscErrorCode   PetscTokenCreate(const char[],const char,PetscToken**);
403 EXTERN PetscErrorCode   PetscTokenFind(PetscToken*,char *[]);
404 EXTERN PetscErrorCode   PetscTokenDestroy(PetscToken*);
405 
406 /*
407    These are  MPI operations for MPI_Allreduce() etc
408 */
409 EXTERN MPI_Op PetscMaxSum_Op;
410 #if defined(PETSC_USE_COMPLEX)
411 EXTERN MPI_Op PetscSum_Op;
412 #else
413 #define PetscSum_Op MPI_SUM
414 #endif
415 EXTERN PetscErrorCode PetscMaxSum(MPI_Comm,const PetscInt[],PetscInt*,PetscInt*);
416 
417 /*S
418      PetscObject - any PETSc object, PetscViewer, Mat, Vec, KSP etc
419 
420    Level: beginner
421 
422    Note: This is the base class from which all objects appear.
423 
424 .seealso:  PetscObjectDestroy(), PetscObjectView(), PetscObjectGetName(), PetscObjectSetName()
425 S*/
426 typedef struct _p_PetscObject* PetscObject;
427 
428 /*S
429      PetscFList - Linked list of functions, possibly stored in dynamic libraries, accessed
430       by string name
431 
432    Level: advanced
433 
434 .seealso:  PetscFListAdd(), PetscFListDestroy()
435 S*/
436 typedef struct _PetscFList *PetscFList;
437 
438 #include "petscviewer.h"
439 #include "petscoptions.h"
440 
441 EXTERN PetscErrorCode PetscShowMemoryUsage(PetscViewer,const char[]);
442 EXTERN PetscErrorCode PetscGetTime(PetscLogDouble*);
443 EXTERN PetscErrorCode PetscGetCPUTime(PetscLogDouble*);
444 EXTERN PetscErrorCode PetscSleep(int);
445 
446 /*
447     Initialization of PETSc
448 */
449 EXTERN PetscErrorCode  PetscInitialize(int*,char***,const char[],const char[]);
450 EXTERN PetscErrorCode  PetscInitializeNoArguments(void);
451 EXTERN PetscErrorCode  PetscInitialized(PetscTruth *);
452 EXTERN PetscErrorCode  PetscFinalize(void);
453 EXTERN PetscErrorCode  PetscInitializeFortran(void);
454 EXTERN PetscErrorCode  PetscGetArgs(int*,char ***);
455 EXTERN PetscErrorCode  PetscEnd(void);
456 
457 /*
458    ParameterDict is an abstraction for arguments to interface mechanisms
459 */
460 extern PetscCookie DICT_COOKIE;
461 typedef struct _p_Dict *ParameterDict;
462 
463 typedef void (**PetscVoidFunction)(void);
464 
465 /*
466    PetscTryMethod - Queries an object for a method, if it exists then calls it.
467               These are intended to be used only inside PETSc functions.
468 */
469 #define  PetscTryMethod(obj,A,B,C) \
470   0;{ PetscErrorCode (*f)B, __ierr; \
471     __ierr = PetscObjectQueryFunction((PetscObject)obj,#A,(PetscVoidFunction)&f);CHKERRQ(__ierr); \
472     if (f) {__ierr = (*f)C;CHKERRQ(__ierr);}\
473   }
474 #define  PetscUseMethod(obj,A,B,C) \
475   0;{ PetscErrorCode (*f)B, __ierr; \
476     __ierr = PetscObjectQueryFunction((PetscObject)obj,A,(PetscVoidFunction)&f);CHKERRQ(__ierr); \
477     if (f) {__ierr = (*f)C;CHKERRQ(__ierr);}\
478     else {SETERRQ1(1,"Cannot locate function %s in object",A);} \
479   }
480 /*
481     Functions that can act on any PETSc object.
482 */
483 EXTERN PetscErrorCode PetscObjectDestroy(PetscObject);
484 EXTERN PetscErrorCode PetscObjectExists(PetscObject,PetscTruth*);
485 EXTERN PetscErrorCode PetscObjectGetComm(PetscObject,MPI_Comm *);
486 EXTERN PetscErrorCode PetscObjectGetCookie(PetscObject,int *);
487 EXTERN PetscErrorCode PetscObjectGetType(PetscObject,int *);
488 EXTERN PetscErrorCode PetscObjectSetName(PetscObject,const char[]);
489 EXTERN PetscErrorCode PetscObjectGetName(PetscObject,char*[]);
490 EXTERN PetscErrorCode PetscObjectReference(PetscObject);
491 EXTERN PetscErrorCode PetscObjectGetReference(PetscObject,int*);
492 EXTERN PetscErrorCode PetscObjectDereference(PetscObject);
493 EXTERN PetscErrorCode PetscObjectGetNewTag(PetscObject,int *);
494 EXTERN PetscErrorCode PetscObjectSetParameterDict(PetscObject,ParameterDict);
495 EXTERN PetscErrorCode PetscObjectGetParameterDict(PetscObject,ParameterDict*);
496 EXTERN PetscErrorCode PetscCommGetNewTag(MPI_Comm,int *);
497 EXTERN PetscErrorCode PetscObjectView(PetscObject,PetscViewer);
498 EXTERN PetscErrorCode PetscObjectCompose(PetscObject,const char[],PetscObject);
499 EXTERN PetscErrorCode PetscObjectQuery(PetscObject,const char[],PetscObject *);
500 EXTERN PetscErrorCode PetscObjectComposeFunction(PetscObject,const char[],const char[],void (*)(void));
501 
502 typedef void (*FCNVOID)(void); /* cast in next macro should never be extern C */
503 typedef PetscErrorCode (*FCNINTVOID)(void); /* used in casts to make sure they are not extern C */
504 /*MC
505    PetscObjectComposeFunctionDynamic - Associates a function with a given PETSc object.
506 
507    Collective on PetscObject
508 
509    Input Parameters:
510 +  obj - the PETSc object; this must be cast with a (PetscObject), for example,
511          PetscObjectCompose((PetscObject)mat,...);
512 .  name - name associated with the child function
513 .  fname - name of the function
514 -  ptr - function pointer (or PETSC_NULL if using dynamic libraries)
515 
516    Level: advanced
517 
518     Synopsis:
519     int PetscObjectComposeFunctionDynamic(PetscObject obj,const char name[],const char fname[],void *ptr)
520 
521    Notes:
522    To remove a registered routine, pass in a PETSC_NULL rname and fnc().
523 
524    PetscObjectComposeFunctionDynamic() can be used with any PETSc object (such as
525    Mat, Vec, KSP, SNES, etc.) or any user-provided object.
526 
527    The composed function must be wrapped in a EXTERN_C_BEGIN/END for this to
528    work in C++/complex with dynamic link libraries (PETSC_USE_DYNAMIC_LIBRARIES)
529    enabled.
530 
531    Concepts: objects^composing functions
532    Concepts: composing functions
533    Concepts: functions^querying
534    Concepts: objects^querying
535    Concepts: querying objects
536 
537 .seealso: PetscObjectQueryFunction()
538 M*/
539 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
540 #define PetscObjectComposeFunctionDynamic(a,b,c,d) PetscObjectComposeFunction(a,b,c,0)
541 #else
542 #define PetscObjectComposeFunctionDynamic(a,b,c,d) PetscObjectComposeFunction(a,b,c,(FCNVOID)(d))
543 #endif
544 
545 EXTERN PetscErrorCode PetscObjectQueryFunction(PetscObject,const char[],void (**)(void));
546 EXTERN PetscErrorCode PetscObjectSetOptionsPrefix(PetscObject,const char[]);
547 EXTERN PetscErrorCode PetscObjectAppendOptionsPrefix(PetscObject,const char[]);
548 EXTERN PetscErrorCode PetscObjectPrependOptionsPrefix(PetscObject,const char[]);
549 EXTERN PetscErrorCode PetscObjectGetOptionsPrefix(PetscObject,char*[]);
550 EXTERN PetscErrorCode PetscObjectPublish(PetscObject);
551 EXTERN PetscErrorCode PetscObjectChangeTypeName(PetscObject,const char[]);
552 EXTERN PetscErrorCode PetscObjectRegisterDestroy(PetscObject);
553 EXTERN PetscErrorCode PetscObjectRegisterDestroyAll(void);
554 EXTERN PetscErrorCode PetscObjectName(PetscObject);
555 EXTERN PetscErrorCode PetscTypeCompare(PetscObject,const char[],PetscTruth*);
556 
557 /*
558     Defines PETSc error handling.
559 */
560 #include "petscerror.h"
561 
562 /*S
563      PetscOList - Linked list of PETSc objects, accessable by string name
564 
565    Level: advanced
566 
567 .seealso:  PetscOListAdd(), PetscOListDestroy(), PetscOListFind()
568 S*/
569 typedef struct _PetscOList *PetscOList;
570 
571 EXTERN PetscErrorCode PetscOListDestroy(PetscOList *);
572 EXTERN PetscErrorCode PetscOListFind(PetscOList,const char[],PetscObject*);
573 EXTERN PetscErrorCode PetscOListReverseFind(PetscOList,PetscObject,char**);
574 EXTERN PetscErrorCode PetscOListAdd(PetscOList *,const char[],PetscObject);
575 EXTERN PetscErrorCode PetscOListDuplicate(PetscOList,PetscOList *);
576 
577 /*
578     Dynamic library lists. Lists of names of routines in dynamic
579   link libraries that will be loaded as needed.
580 */
581 EXTERN PetscErrorCode PetscFListAdd(PetscFList*,const char[],const char[],void (*)(void));
582 EXTERN PetscErrorCode PetscFListDestroy(PetscFList*);
583 EXTERN PetscErrorCode PetscFListFind(MPI_Comm,PetscFList,const char[],void (**)(void));
584 EXTERN PetscErrorCode PetscFListPrintTypes(MPI_Comm,FILE*,const char[],const char[],const char[],const char[],PetscFList);
585 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
586 #define    PetscFListAddDynamic(a,b,p,c) PetscFListAdd(a,b,p,0)
587 #else
588 #define    PetscFListAddDynamic(a,b,p,c) PetscFListAdd(a,b,p,(void (*)(void))c)
589 #endif
590 EXTERN PetscErrorCode PetscFListDuplicate(PetscFList,PetscFList *);
591 EXTERN PetscErrorCode PetscFListView(PetscFList,PetscViewer);
592 EXTERN PetscErrorCode PetscFListConcat(const char [],const char [],char []);
593 EXTERN PetscErrorCode PetscFListGet(PetscFList,char ***,int*);
594 
595 /*S
596      PetscDLLibraryList - Linked list of dynamics libraries to search for functions
597 
598    Level: advanced
599 
600    PETSC_USE_DYNAMIC_LIBRARIES must be defined in petscconf.h to use dynamic libraries
601 
602 .seealso:  PetscDLLibraryOpen()
603 S*/
604 typedef struct _PetscDLLibraryList *PetscDLLibraryList;
605 extern PetscDLLibraryList DLLibrariesLoaded;
606 EXTERN PetscErrorCode PetscDLLibraryRetrieve(MPI_Comm,const char[],char *,int,PetscTruth *);
607 EXTERN PetscErrorCode PetscDLLibraryOpen(MPI_Comm,const char[],void **);
608 EXTERN PetscErrorCode PetscDLLibrarySym(MPI_Comm,PetscDLLibraryList *,const char[],const char[],void **);
609 EXTERN PetscErrorCode PetscDLLibraryAppend(MPI_Comm,PetscDLLibraryList *,const char[]);
610 EXTERN PetscErrorCode PetscDLLibraryPrepend(MPI_Comm,PetscDLLibraryList *,const char[]);
611 EXTERN PetscErrorCode PetscDLLibraryClose(PetscDLLibraryList);
612 EXTERN PetscErrorCode PetscDLLibraryPrintPath(void);
613 EXTERN PetscErrorCode PetscDLLibraryGetInfo(void*,const char[],const char *[]);
614 
615 /*
616     Mechanism for translating PETSc object representations between languages
617     Not currently used.
618 */
619 typedef enum {PETSC_LANGUAGE_C,PETSC_LANGUAGE_CPP} PetscLanguage;
620 #define PETSC_LANGUAGE_F77 PETSC_LANGUAGE_C
621 EXTERN PetscErrorCode PetscObjectComposeLanguage(PetscObject,PetscLanguage,void *);
622 EXTERN PetscErrorCode PetscObjectQueryLanguage(PetscObject,PetscLanguage,void **);
623 
624 /*
625      Useful utility routines
626 */
627 EXTERN PetscErrorCode PetscSplitOwnership(MPI_Comm,PetscInt*,PetscInt*);
628 EXTERN PetscErrorCode PetscSplitOwnershipBlock(MPI_Comm,PetscInt,PetscInt*,PetscInt*);
629 EXTERN PetscErrorCode PetscSequentialPhaseBegin(MPI_Comm,PetscMPIInt);
630 EXTERN PetscErrorCode PetscSequentialPhaseEnd(MPI_Comm,PetscMPIInt);
631 EXTERN PetscErrorCode PetscBarrier(PetscObject);
632 EXTERN PetscErrorCode PetscMPIDump(FILE*);
633 
634 #define PetscNot(a) ((a) ? PETSC_FALSE : PETSC_TRUE)
635 /*
636     Defines basic graphics available from PETSc.
637 */
638 #include "petscdraw.h"
639 
640 /*
641     Defines the base data structures for all PETSc objects
642 */
643 #include "petschead.h"
644 
645 /*
646      Defines PETSc profiling.
647 */
648 #include "petsclog.h"
649 
650 /*
651           For locking, unlocking and destroying AMS memories associated with
652     PETSc objects
653 */
654 #if defined(PETSC_HAVE_AMS)
655 
656 extern PetscTruth PetscAMSPublishAll;
657 #define PetscPublishAll(v) (PetscAMSPublishAll ? PetscObjectPublish((PetscObject)v) : 0)
658 #define PetscObjectTakeAccess(obj)  ((((PetscObject)(obj))->amem == -1) ? 0 : AMS_Memory_take_access(((PetscObject)(obj))->amem))
659 #define PetscObjectGrantAccess(obj) ((((PetscObject)(obj))->amem == -1) ? 0 : AMS_Memory_grant_access(((PetscObject)(obj))->amem))
660 #define PetscObjectDepublish(obj)   ((((PetscObject)(obj))->amem == -1) ? 0 : AMS_Memory_destroy(((PetscObject)(obj))->amem)); \
661     ((PetscObject)(obj))->amem = -1;
662 
663 #else
664 
665 #define PetscPublishAll(v)           0
666 #define PetscObjectTakeAccess(obj)   0
667 #define PetscObjectGrantAccess(obj)  0
668 #define PetscObjectDepublish(obj)      0
669 
670 #endif
671 
672 
673 
674 /*
675       This code allows one to pass a MPI communicator between
676     C and Fortran. MPI 2.0 defines a standard API for doing this.
677     The code here is provided to allow PETSc to work with MPI 1.1
678     standard MPI libraries.
679 */
680 EXTERN PetscErrorCode  MPICCommToFortranComm(MPI_Comm,int *);
681 EXTERN PetscErrorCode  MPIFortranCommToCComm(int,MPI_Comm*);
682 
683 /*
684       Simple PETSc parallel IO for ASCII printing
685 */
686 EXTERN PetscErrorCode  PetscFixFilename(const char[],char[]);
687 EXTERN PetscErrorCode  PetscFOpen(MPI_Comm,const char[],const char[],FILE**);
688 EXTERN PetscErrorCode  PetscFClose(MPI_Comm,FILE*);
689 EXTERN PetscErrorCode  PetscFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4);
690 EXTERN PetscErrorCode  PetscPrintf(MPI_Comm,const char[],...)  PETSC_PRINTF_FORMAT_CHECK(2,3);
691 
692 /* These are used internally by PETSc ASCII IO routines*/
693 #include <stdarg.h>
694 EXTERN PetscErrorCode  PetscVSNPrintf(char*,size_t,const char*,va_list);
695 EXTERN PetscErrorCode  PetscVFPrintf(FILE*,const char*,va_list);
696 
697 /*MC
698     PetscErrorPrintf - Prints error messages.
699 
700     Not Collective
701 
702    Synopsis:
703      PetscErrorCode (*PetscErrorPrintf)(const char format[],...);
704 
705     Input Parameters:
706 .   format - the usual printf() format string
707 
708    Options Database Keys:
709 .    -error_output_stderr - cause error messages to be printed to stderr instead of the
710          (default) stdout
711 
712 
713    Level: developer
714 
715     Fortran Note:
716     This routine is not supported in Fortran.
717 
718     Concepts: error messages^printing
719     Concepts: printing^error messages
720 
721 .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf()
722 M*/
723 EXTERN PetscErrorCode  (*PetscErrorPrintf)(const char[],...);
724 
725 /*MC
726     PetscHelpPrintf - Prints help messages.
727 
728     Not Collective
729 
730    Synopsis:
731      PetscErrorCode (*PetscHelpPrintf)(const char format[],...);
732 
733     Input Parameters:
734 .   format - the usual printf() format string
735 
736    Level: developer
737 
738     Fortran Note:
739     This routine is not supported in Fortran.
740 
741     Concepts: help messages^printing
742     Concepts: printing^help messages
743 
744 .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscErrorPrintf()
745 M*/
746 EXTERN PetscErrorCode  (*PetscHelpPrintf)(MPI_Comm,const char[],...);
747 
748 EXTERN PetscErrorCode  PetscPOpen(MPI_Comm,const char[],const char[],const char[],FILE **);
749 EXTERN PetscErrorCode  PetscPClose(MPI_Comm,FILE*);
750 EXTERN PetscErrorCode  PetscSynchronizedPrintf(MPI_Comm,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3);
751 EXTERN PetscErrorCode  PetscSynchronizedFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4);
752 EXTERN PetscErrorCode  PetscSynchronizedFlush(MPI_Comm);
753 EXTERN PetscErrorCode  PetscSynchronizedFGets(MPI_Comm,FILE*,int,char[]);
754 EXTERN PetscErrorCode  PetscStartMatlab(MPI_Comm,const char[],const char[],FILE**);
755 EXTERN PetscErrorCode  PetscStartJava(MPI_Comm,const char[],const char[],FILE**);
756 EXTERN PetscErrorCode  PetscGetPetscDir(const char*[]);
757 
758 EXTERN PetscErrorCode  PetscPopUpSelect(MPI_Comm,char*,char*,int,char**,int*);
759 /*S
760      PetscObjectContainer - Simple PETSc object that contains a pointer to any required data
761 
762    Level: advanced
763 
764 .seealso:  PetscObject, PetscObjectContainerCreate()
765 S*/
766 typedef struct _p_PetscObjectContainer*  PetscObjectContainer;
767 EXTERN PetscErrorCode PetscObjectContainerGetPointer(PetscObjectContainer,void **);
768 EXTERN PetscErrorCode PetscObjectContainerSetPointer(PetscObjectContainer,void *);
769 EXTERN PetscErrorCode PetscObjectContainerDestroy(PetscObjectContainer);
770 EXTERN PetscErrorCode PetscObjectContainerCreate(MPI_Comm comm,PetscObjectContainer *);
771 
772 /*
773    For incremental debugging
774 */
775 extern PetscTruth PetscCompare;
776 EXTERN PetscErrorCode        PetscCompareDouble(double);
777 EXTERN PetscErrorCode        PetscCompareScalar(PetscScalar);
778 EXTERN PetscErrorCode        PetscCompareInt(int);
779 
780 /*
781    For use in debuggers
782 */
783 extern int PetscGlobalRank,PetscGlobalSize;
784 EXTERN PetscErrorCode PetscIntView(PetscInt,PetscInt[],PetscViewer);
785 EXTERN PetscErrorCode PetscRealView(PetscInt,PetscReal[],PetscViewer);
786 EXTERN PetscErrorCode PetscScalarView(PetscInt,PetscScalar[],PetscViewer);
787 
788 /*
789     Allows accessing Matlab Engine
790 */
791 #include "petscmatlab.h"
792 
793 /*
794     C code optimization is often enhanced by telling the compiler
795   that certain pointer arguments to functions are not aliased to
796   to other arguments. This is not yet ANSI C standard so we define
797   the macro "restrict" to indicate that the variable is not aliased
798   to any other argument.
799 */
800 #if defined(PETSC_HAVE_RESTRICT) && !defined(__cplusplus)
801 #define restrict _Restrict
802 #else
803 #if defined(restrict)
804 #undef restrict
805 #endif
806 #define restrict
807 #endif
808 
809 /*
810       Determine if some of the kernel computation routines use
811    Fortran (rather than C) for the numerical calculations. On some machines
812    and compilers (like complex numbers) the Fortran version of the routines
813    is faster than the C/C++ versions. The flag PETSC_USE_FORTRAN_KERNELS
814    would be set in the petscconf.h file
815 */
816 #if defined(PETSC_USE_FORTRAN_KERNELS)
817 
818 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ)
819 #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ
820 #endif
821 
822 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ)
823 #define PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ
824 #endif
825 
826 #if !defined(PETSC_USE_FORTRAN_KERNEL_NORM)
827 #define PETSC_USE_FORTRAN_KERNEL_NORM
828 #endif
829 
830 #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY)
831 #define PETSC_USE_FORTRAN_KERNEL_MAXPY
832 #endif
833 
834 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ)
835 #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ
836 #endif
837 
838 #if !defined(PETSC_USE_FORTRAN_KERNEL_RELAXAIJ)
839 #define PETSC_USE_FORTRAN_KERNEL_RELAXAIJ
840 #endif
841 
842 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ)
843 #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ
844 #endif
845 
846 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ)
847 #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ
848 #endif
849 
850 #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT)
851 #define PETSC_USE_FORTRAN_KERNEL_MDOT
852 #endif
853 
854 #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY)
855 #define PETSC_USE_FORTRAN_KERNEL_XTIMESY
856 #endif
857 
858 #if !defined(PETSC_USE_FORTRAN_KERNEL_AYPX)
859 #define PETSC_USE_FORTRAN_KERNEL_AYPX
860 #endif
861 
862 #if !defined(PETSC_USE_FORTRAN_KERNEL_WAXPY)
863 #define PETSC_USE_FORTRAN_KERNEL_WAXPY
864 #endif
865 
866 #endif
867 
868 /*
869     Macros for indicating code that should be compiled with a C interface,
870    rather than a C++ interface. Any routines that are dynamically loaded
871    (such as the PCCreate_XXX() routines) must be wrapped so that the name
872    mangler does not change the functions symbol name. This just hides the
873    ugly extern "C" {} wrappers.
874 */
875 #if defined(__cplusplus)
876 #define EXTERN_C_BEGIN extern "C" {
877 #define EXTERN_C_END }
878 #else
879 #define EXTERN_C_BEGIN
880 #define EXTERN_C_END
881 #endif
882 
883 /* --------------------------------------------------------------------*/
884 
885 /*M
886     size - integer variable used to contain the number of processors in
887            the relevent MPI_Comm
888 
889    Level: beginner
890 
891 .seealso: rank, comm
892 M*/
893 
894 /*M
895     rank - integer variable used to contain the number of this processor relative
896            to all in the relevent MPI_Comm
897 
898    Level: beginner
899 
900 .seealso: size, comm
901 M*/
902 
903 /*M
904     comm - MPI_Comm used in the current routine or object
905 
906    Level: beginner
907 
908 .seealso: size, rank
909 M*/
910 
911 /*M
912     MPI_Comm - the basic object used by MPI to determine which processes are involved in a
913         communication
914 
915    Level: beginner
916 
917    Note: This manual page is a place-holder because MPICH does not have a manual page for MPI_Comm
918 
919 .seealso: size, rank, comm, PETSC_COMM_WORLD, PETSC_COMM_SELF
920 M*/
921 
922 /*M
923     PetscScalar - PETSc type that represents either a double precision real number or
924        a double precision complex number if the code is compiled with BOPT=g_complex or O_complex
925 
926    Level: beginner
927 
928 .seealso: PetscReal, PassiveReal, PassiveScalar
929 M*/
930 
931 /*M
932     PetscReal - PETSc type that represents a double precision real number
933 
934    Level: beginner
935 
936 .seealso: PetscScalar, PassiveReal, PassiveScalar
937 M*/
938 
939 /*M
940     PassiveScalar - PETSc type that represents either a double precision real number or
941        a double precision complex number if the code is compiled with BOPT=g_complex or O_complex
942 
943    Level: beginner
944 
945     This is the same as a PetscScalar except in code that is automatically differentiated it is
946    treated as a constant (not an indendent or dependent variable)
947 
948 .seealso: PetscReal, PassiveReal, PetscScalar
949 M*/
950 
951 /*M
952     PassiveReal - PETSc type that represents a double precision real number
953 
954    Level: beginner
955 
956     This is the same as a PetscReal except in code that is automatically differentiated it is
957    treated as a constant (not an indendent or dependent variable)
958 
959 .seealso: PetscScalar, PetscReal, PassiveScalar
960 M*/
961 
962 /*M
963     MPIU_SCALAR - MPI datatype corresponding to PetscScalar
964 
965    Level: beginner
966 
967     Note: In MPI calls that require an MPI datatype that matches a PetscScalar or array of PetscScalars
968           pass this value
969 
970 .seealso: PetscReal, PassiveReal, PassiveScalar, PetscScalar
971 M*/
972 
973 /*
974      The IBM include files define hz, here we hide it so that it may be used
975    as a regular user variable.
976 */
977 #if defined(hz)
978 #undef hz
979 #endif
980 
981 /*  For arrays that contain filenames or paths */
982 
983 
984 #if defined(PETSC_HAVE_LIMITS_H)
985 #include <limits.h>
986 #endif
987 #if defined(PETSC_HAVE_SYS_PARAM_H)
988 #include <sys/param.h>
989 #endif
990 
991 #if defined(MAXPATHLEN)
992 #  define PETSC_MAX_PATH_LEN     MAXPATHLEN
993 #elif defined(MAX_PATH)
994 #  define PETSC_MAX_PATH_LEN     MAX_PATH
995 #elif defined(_MAX_PATH)
996 #  define PETSC_MAX_PATH_LEN     _MAX_PATH
997 #else
998 #  define PETSC_MAX_PATH_LEN     4096
999 #endif
1000 
1001 PETSC_EXTERN_CXX_END
1002 #endif
1003 
1004 
1005