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