xref: /petsc/include/petsc.h (revision b3e33450d23fd45ce20f9e98a251b5850ba1a57f)
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_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. Not currently used.
653 */
654 #define PetscPublishAll(v)           0
655 #define PetscObjectTakeAccess(obj)   0
656 #define PetscObjectGrantAccess(obj)  0
657 #define PetscObjectDepublish(obj)    0
658 
659 
660 
661 /*
662       This code allows one to pass a MPI communicator between
663     C and Fortran. MPI 2.0 defines a standard API for doing this.
664     The code here is provided to allow PETSc to work with MPI 1.1
665     standard MPI libraries.
666 */
667 EXTERN PetscErrorCode  MPICCommToFortranComm(MPI_Comm,int *);
668 EXTERN PetscErrorCode  MPIFortranCommToCComm(int,MPI_Comm*);
669 
670 /*
671       Simple PETSc parallel IO for ASCII printing
672 */
673 EXTERN PetscErrorCode  PetscFixFilename(const char[],char[]);
674 EXTERN PetscErrorCode  PetscFOpen(MPI_Comm,const char[],const char[],FILE**);
675 EXTERN PetscErrorCode  PetscFClose(MPI_Comm,FILE*);
676 EXTERN PetscErrorCode  PetscFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4);
677 EXTERN PetscErrorCode  PetscPrintf(MPI_Comm,const char[],...)  PETSC_PRINTF_FORMAT_CHECK(2,3);
678 
679 /* These are used internally by PETSc ASCII IO routines*/
680 #include <stdarg.h>
681 EXTERN PetscErrorCode  PetscVSNPrintf(char*,size_t,const char*,va_list);
682 EXTERN PetscErrorCode  PetscVFPrintf(FILE*,const char*,va_list);
683 
684 /*MC
685     PetscErrorPrintf - Prints error messages.
686 
687     Not Collective
688 
689    Synopsis:
690      PetscErrorCode (*PetscErrorPrintf)(const char format[],...);
691 
692     Input Parameters:
693 .   format - the usual printf() format string
694 
695    Options Database Keys:
696 .    -error_output_stderr - cause error messages to be printed to stderr instead of the
697          (default) stdout
698 
699 
700    Level: developer
701 
702     Fortran Note:
703     This routine is not supported in Fortran.
704 
705     Concepts: error messages^printing
706     Concepts: printing^error messages
707 
708 .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf()
709 M*/
710 EXTERN PetscErrorCode  (*PetscErrorPrintf)(const char[],...);
711 
712 /*MC
713     PetscHelpPrintf - Prints help messages.
714 
715     Not Collective
716 
717    Synopsis:
718      PetscErrorCode (*PetscHelpPrintf)(const char format[],...);
719 
720     Input Parameters:
721 .   format - the usual printf() format string
722 
723    Level: developer
724 
725     Fortran Note:
726     This routine is not supported in Fortran.
727 
728     Concepts: help messages^printing
729     Concepts: printing^help messages
730 
731 .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscErrorPrintf()
732 M*/
733 EXTERN PetscErrorCode  (*PetscHelpPrintf)(MPI_Comm,const char[],...);
734 
735 EXTERN PetscErrorCode  PetscPOpen(MPI_Comm,const char[],const char[],const char[],FILE **);
736 EXTERN PetscErrorCode  PetscPClose(MPI_Comm,FILE*);
737 EXTERN PetscErrorCode  PetscSynchronizedPrintf(MPI_Comm,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3);
738 EXTERN PetscErrorCode  PetscSynchronizedFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4);
739 EXTERN PetscErrorCode  PetscSynchronizedFlush(MPI_Comm);
740 EXTERN PetscErrorCode  PetscSynchronizedFGets(MPI_Comm,FILE*,size_t,char[]);
741 EXTERN PetscErrorCode  PetscStartMatlab(MPI_Comm,const char[],const char[],FILE**);
742 EXTERN PetscErrorCode  PetscStartJava(MPI_Comm,const char[],const char[],FILE**);
743 EXTERN PetscErrorCode  PetscGetPetscDir(const char*[]);
744 
745 EXTERN PetscErrorCode  PetscPopUpSelect(MPI_Comm,char*,char*,int,char**,int*);
746 /*S
747      PetscObjectContainer - Simple PETSc object that contains a pointer to any required data
748 
749    Level: advanced
750 
751 .seealso:  PetscObject, PetscObjectContainerCreate()
752 S*/
753 typedef struct _p_PetscObjectContainer*  PetscObjectContainer;
754 EXTERN PetscErrorCode PetscObjectContainerGetPointer(PetscObjectContainer,void **);
755 EXTERN PetscErrorCode PetscObjectContainerSetPointer(PetscObjectContainer,void *);
756 EXTERN PetscErrorCode PetscObjectContainerDestroy(PetscObjectContainer);
757 EXTERN PetscErrorCode PetscObjectContainerCreate(MPI_Comm comm,PetscObjectContainer *);
758 
759 /*
760    For incremental debugging
761 */
762 extern PetscTruth PetscCompare;
763 EXTERN PetscErrorCode        PetscCompareDouble(double);
764 EXTERN PetscErrorCode        PetscCompareScalar(PetscScalar);
765 EXTERN PetscErrorCode        PetscCompareInt(PetscInt);
766 
767 /*
768    For use in debuggers
769 */
770 extern int PetscGlobalRank,PetscGlobalSize;
771 EXTERN PetscErrorCode PetscIntView(PetscInt,PetscInt[],PetscViewer);
772 EXTERN PetscErrorCode PetscRealView(PetscInt,PetscReal[],PetscViewer);
773 EXTERN PetscErrorCode PetscScalarView(PetscInt,PetscScalar[],PetscViewer);
774 
775 /*
776     Allows accessing Matlab Engine
777 */
778 #include "petscmatlab.h"
779 
780 /*
781     C code optimization is often enhanced by telling the compiler
782   that certain pointer arguments to functions are not aliased to
783   to other arguments. This is not yet ANSI C standard so we define
784   the macro "restrict" to indicate that the variable is not aliased
785   to any other argument.
786 */
787 #if defined(PETSC_HAVE_RESTRICT) && !defined(__cplusplus)
788 #define restrict _Restrict
789 #else
790 #if defined(restrict)
791 #undef restrict
792 #endif
793 #define restrict
794 #endif
795 
796 /*
797       Determine if some of the kernel computation routines use
798    Fortran (rather than C) for the numerical calculations. On some machines
799    and compilers (like complex numbers) the Fortran version of the routines
800    is faster than the C/C++ versions. The flag PETSC_USE_FORTRAN_KERNELS
801    would be set in the petscconf.h file
802 */
803 #if defined(PETSC_USE_FORTRAN_KERNELS)
804 
805 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ)
806 #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ
807 #endif
808 
809 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ)
810 #define PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ
811 #endif
812 
813 #if !defined(PETSC_USE_FORTRAN_KERNEL_NORM)
814 #define PETSC_USE_FORTRAN_KERNEL_NORM
815 #endif
816 
817 #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY)
818 #define PETSC_USE_FORTRAN_KERNEL_MAXPY
819 #endif
820 
821 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ)
822 #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ
823 #endif
824 
825 #if !defined(PETSC_USE_FORTRAN_KERNEL_RELAXAIJ)
826 #define PETSC_USE_FORTRAN_KERNEL_RELAXAIJ
827 #endif
828 
829 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ)
830 #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ
831 #endif
832 
833 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ)
834 #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ
835 #endif
836 
837 #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT)
838 #define PETSC_USE_FORTRAN_KERNEL_MDOT
839 #endif
840 
841 #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY)
842 #define PETSC_USE_FORTRAN_KERNEL_XTIMESY
843 #endif
844 
845 #if !defined(PETSC_USE_FORTRAN_KERNEL_AYPX)
846 #define PETSC_USE_FORTRAN_KERNEL_AYPX
847 #endif
848 
849 #if !defined(PETSC_USE_FORTRAN_KERNEL_WAXPY)
850 #define PETSC_USE_FORTRAN_KERNEL_WAXPY
851 #endif
852 
853 #endif
854 
855 /*
856     Macros for indicating code that should be compiled with a C interface,
857    rather than a C++ interface. Any routines that are dynamically loaded
858    (such as the PCCreate_XXX() routines) must be wrapped so that the name
859    mangler does not change the functions symbol name. This just hides the
860    ugly extern "C" {} wrappers.
861 */
862 #if defined(__cplusplus)
863 #define EXTERN_C_BEGIN extern "C" {
864 #define EXTERN_C_END }
865 #else
866 #define EXTERN_C_BEGIN
867 #define EXTERN_C_END
868 #endif
869 
870 /* --------------------------------------------------------------------*/
871 
872 /*M
873     size - integer variable used to contain the number of processors in
874            the relevent MPI_Comm
875 
876    Level: beginner
877 
878 .seealso: rank, comm
879 M*/
880 
881 /*M
882     rank - integer variable used to contain the number of this processor relative
883            to all in the relevent MPI_Comm
884 
885    Level: beginner
886 
887 .seealso: size, comm
888 M*/
889 
890 /*M
891     comm - MPI_Comm used in the current routine or object
892 
893    Level: beginner
894 
895 .seealso: size, rank
896 M*/
897 
898 /*M
899     MPI_Comm - the basic object used by MPI to determine which processes are involved in a
900         communication
901 
902    Level: beginner
903 
904    Note: This manual page is a place-holder because MPICH does not have a manual page for MPI_Comm
905 
906 .seealso: size, rank, comm, PETSC_COMM_WORLD, PETSC_COMM_SELF
907 M*/
908 
909 /*M
910     PetscScalar - PETSc type that represents either a double precision real number or
911        a double precision complex number if the code is compiled with BOPT=g_complex or O_complex
912 
913    Level: beginner
914 
915 .seealso: PetscReal, PassiveReal, PassiveScalar
916 M*/
917 
918 /*M
919     PetscReal - PETSc type that represents a double precision real number
920 
921    Level: beginner
922 
923 .seealso: PetscScalar, PassiveReal, PassiveScalar
924 M*/
925 
926 /*M
927     PassiveScalar - PETSc type that represents either a double precision real number or
928        a double precision complex number if the code is compiled with BOPT=g_complex or O_complex
929 
930    Level: beginner
931 
932     This is the same as a PetscScalar except in code that is automatically differentiated it is
933    treated as a constant (not an indendent or dependent variable)
934 
935 .seealso: PetscReal, PassiveReal, PetscScalar
936 M*/
937 
938 /*M
939     PassiveReal - PETSc type that represents a double precision real number
940 
941    Level: beginner
942 
943     This is the same as a PetscReal except in code that is automatically differentiated it is
944    treated as a constant (not an indendent or dependent variable)
945 
946 .seealso: PetscScalar, PetscReal, PassiveScalar
947 M*/
948 
949 /*M
950     MPIU_SCALAR - MPI datatype corresponding to PetscScalar
951 
952    Level: beginner
953 
954     Note: In MPI calls that require an MPI datatype that matches a PetscScalar or array of PetscScalars
955           pass this value
956 
957 .seealso: PetscReal, PassiveReal, PassiveScalar, PetscScalar
958 M*/
959 
960 /*
961      The IBM include files define hz, here we hide it so that it may be used
962    as a regular user variable.
963 */
964 #if defined(hz)
965 #undef hz
966 #endif
967 
968 /*  For arrays that contain filenames or paths */
969 
970 
971 #if defined(PETSC_HAVE_LIMITS_H)
972 #include <limits.h>
973 #endif
974 #if defined(PETSC_HAVE_SYS_PARAM_H)
975 #include <sys/param.h>
976 #endif
977 
978 #if defined(MAXPATHLEN)
979 #  define PETSC_MAX_PATH_LEN     MAXPATHLEN
980 #elif defined(MAX_PATH)
981 #  define PETSC_MAX_PATH_LEN     MAX_PATH
982 #elif defined(_MAX_PATH)
983 #  define PETSC_MAX_PATH_LEN     _MAX_PATH
984 #else
985 #  define PETSC_MAX_PATH_LEN     4096
986 #endif
987 
988 PETSC_EXTERN_CXX_END
989 #endif
990 
991 
992