xref: /petsc/include/petsc.h (revision ccd8e176670fb05caf832f9e3bb0ac26438b82ab)
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 /*
34    Currently cannot check formatting for PETSc print statements because we have our
35    own format %D
36 */
37 #undef  PETSC_PRINTF_FORMAT_CHECK
38 #define PETSC_PRINTF_FORMAT_CHECK(a,b)
39 #undef  PETSC_FPRINTF_FORMAT_CHECK
40 #define PETSC_FPRINTF_FORMAT_CHECK(a,b)
41 
42 /*
43    Fixes for configure time choices which impact our interface. Currently only
44    calling conventions and extra compiler checking falls under this category.
45 */
46 #if !defined (PETSC_STDCALL)
47 #define PETSC_STDCALL
48 #endif
49 #if !defined (PETSC_TEMPLATE)
50 #define PETSC_TEMPLATE
51 #endif
52 
53 /* ========================================================================== */
54 
55 #include <stdio.h>
56 /*
57     Defines the interface to MPI allowing the use of all MPI functions.
58 */
59 #include "mpi.h"
60 
61 /*
62     All PETSc C functions return this error code, it is the final argument of
63    all Fortran subroutines
64 */
65 typedef int PetscErrorCode;
66 typedef int PetscCookie;
67 typedef int PetscEvent;
68 typedef int PetscBLASInt;
69 typedef int PetscMPIInt;
70 
71 #if defined(PETSC_USE_64BIT_INT)
72 typedef long long PetscInt;
73 #define MPIU_INT MPI_LONG_LONG_INT
74 #else
75 typedef int PetscInt;
76 #define MPIU_INT MPI_INT
77 #endif
78 
79 /*
80     Declare extern C stuff after incuding external header files
81 */
82 
83 PETSC_EXTERN_CXX_BEGIN
84 
85 /*
86     EXTERN indicates a PETSc function defined elsewhere
87 */
88 #if !defined(EXTERN)
89 #define EXTERN extern
90 #endif
91 
92 /*
93     Defines some elementary mathematics functions and constants.
94 */
95 #include "petscmath.h"
96 
97 /*
98        Basic PETSc constants
99 */
100 
101 /*E
102     PetscTruth - Logical variable. Actually an integer
103 
104    Level: beginner
105 
106 E*/
107 typedef enum { PETSC_FALSE,PETSC_TRUE } PetscTruth;
108 
109 /*M
110     PETSC_FALSE - False value of PetscTruth
111 
112     Level: beginner
113 
114     Note: Zero integer
115 
116 .seealso: PetscTruth
117 M*/
118 
119 /*M
120     PETSC_TRUE - True value of PetscTruth
121 
122     Level: beginner
123 
124     Note: Nonzero integer
125 
126 .seealso: PetscTruth
127 M*/
128 
129 /*M
130     PETSC_YES - Alias for PETSC_TRUE
131 
132     Level: beginner
133 
134     Note: Zero integer
135 
136 .seealso: PetscTruth
137 M*/
138 
139 /*M
140     PETSC_NO - Alias for PETSC_FALSE
141 
142     Level: beginner
143 
144     Note: Nonzero integer
145 
146 .seealso: PetscTruth
147 M*/
148 
149 /*M
150     PETSC_NULL - standard way of passing in a null or array or pointer
151 
152    Level: beginner
153 
154    Notes: accepted by many PETSc functions to not set a parameter and instead use
155           some default
156 
157           This macro does not exist in Fortran; you must use PETSC_NULL_INTEGER,
158           PETSC_NULL_DOUBLE_PRECISION etc
159 
160 .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_IGNORE, PETSC_DETERMINE
161 
162 M*/
163 #define PETSC_NULL           0
164 
165 /*M
166     PETSC_DECIDE - standard way of passing in integer or floating point parameter
167        where you wish PETSc to use the default.
168 
169    Level: beginner
170 
171 .seealso: PETSC_NULL, PETSC_DEFAULT, PETSC_IGNORE, PETSC_DETERMINE
172 
173 M*/
174 #define PETSC_DECIDE         -1
175 
176 /*M
177     PETSC_DEFAULT - standard way of passing in integer or floating point parameter
178        where you wish PETSc to use the default.
179 
180    Level: beginner
181 
182 .seealso: PETSC_DECIDE, PETSC_NULL, PETSC_IGNORE, PETSC_DETERMINE
183 
184 M*/
185 #define PETSC_DEFAULT        -2
186 
187 #define PETSC_YES            PETSC_TRUE
188 #define PETSC_NO             PETSC_FALSE
189 
190 /*M
191     PETSC_IGNORE - same as PETSC_NULL, means PETSc will ignore this argument
192 
193    Level: beginner
194 
195    Notes: accepted by many PETSc functions to not set a parameter and instead use
196           some default
197 
198           This macro does not exist in Fortran; you must use PETSC_NULL_INTEGER,
199           PETSC_NULL_DOUBLE_PRECISION etc
200 
201 .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_NULL, PETSC_DETERMINE
202 
203 M*/
204 #define PETSC_IGNORE         PETSC_NULL
205 
206 /*M
207     PETSC_DETERMINE - standard way of passing in integer or floating point parameter
208        where you wish PETSc to compute the required value.
209 
210    Level: beginner
211 
212 .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_IGNORE, PETSC_NULL, VecSetSizes()
213 
214 M*/
215 #define PETSC_DETERMINE      PETSC_DECIDE
216 
217 /*M
218     PETSC_COMM_WORLD - a duplicate of the MPI_COMM_WORLD communicator which represents
219            all the processs
220 
221    Level: beginner
222 
223    Notes: PETSC_COMM_WORLD and MPI_COMM_WORLD are equivalent except that passing MPI_COMM_WORLD
224           into PETSc object constructors will result in using more MPI resources since an MPI_Comm_dup()
225           will be done on it internally. We recommend always using PETSC_COMM_WORLD
226 
227 .seealso: PETSC_COMM_SELF
228 
229 M*/
230 extern MPI_Comm   PETSC_COMM_WORLD;
231 
232 /*M
233     PETSC_COMM_SELF - a duplicate of the MPI_COMM_SELF communicator which represents
234            the current process
235 
236    Level: beginner
237 
238    Notes: PETSC_COMM_SELF and MPI_COMM_SELF are equivalent except that passint MPI_COMM_SELF
239           into PETSc object constructors will result in using more MPI resources since an MPI_Comm_dup()
240           will be done on it internally. We recommend always using PETSC_COMM_SELF
241 
242 .seealso: PETSC_COMM_WORLD
243 
244 M*/
245 extern MPI_Comm   PETSC_COMM_SELF;
246 
247 extern PetscTruth PetscInitializeCalled;
248 EXTERN PetscErrorCode        PetscSetCommWorld(MPI_Comm);
249 EXTERN PetscErrorCode        PetscSetHelpVersionFunctions(PetscErrorCode (*)(MPI_Comm),PetscErrorCode (*)(MPI_Comm));
250 EXTERN PetscErrorCode        PetscCommDuplicate(MPI_Comm,MPI_Comm*,int*);
251 EXTERN PetscErrorCode        PetscCommDestroy(MPI_Comm*);
252 
253 /*MC
254    PetscMalloc - Allocates memory
255 
256    Input Parameter:
257 .  m - number of bytes to allocate
258 
259    Output Parameter:
260 .  result - memory allocated
261 
262    Synopsis:
263    PetscErrorCode PetscMalloc(size_t m,void **result)
264 
265    Level: beginner
266 
267    Notes: Memory is always allocated at least double aligned
268 
269 .seealso: PetscFree(), PetscNew()
270 
271   Concepts: memory allocation
272 
273 M*/
274 #define PetscMalloc(a,b)     (*PetscTrMalloc)((a),__LINE__,__FUNCT__,__FILE__,__SDIR__,(void**)(b))
275 /*MC
276    PetscNew - Allocates memory of a particular type
277 
278    Input Parameter:
279 . type - structure name of space to be allocated. Memory of size sizeof(type) is allocated
280 
281    Output Parameter:
282 .  result - memory allocated
283 
284    Synopsis:
285    PetscErrorCode PetscNew(struct type,((type *))result)
286 
287    Level: beginner
288 
289 .seealso: PetscFree(), PetscMalloc()
290 
291   Concepts: memory allocation
292 
293 M*/
294 #define PetscNew(A,b)        PetscMalloc(sizeof(A),(b))
295 /*MC
296    PetscFree - Frees memory
297 
298    Input Parameter:
299 .   memory - memory to free
300 
301    Synopsis:
302    PetscErrorCode PetscFree(void *memory)
303 
304    Level: beginner
305 
306    Notes: Memory must have been obtained with PetscNew() or PetscMalloc()
307 
308 .seealso: PetscNew(), PetscMalloc()
309 
310   Concepts: memory allocation
311 
312 M*/
313 #define PetscFree(a)   ((*PetscTrFree)((a),__LINE__,__FUNCT__,__FILE__,__SDIR__) || ((a = 0),0))
314 EXTERN PetscErrorCode  (*PetscTrMalloc)(size_t,int,const char[],const char[],const char[],void**);
315 EXTERN PetscErrorCode  (*PetscTrFree)(void*,int,const char[],const char[],const char[]);
316 EXTERN PetscErrorCode  PetscSetMalloc(PetscErrorCode (*)(size_t,int,const char[],const char[],const char[],void**),PetscErrorCode (*)(void*,int,const char[],const char[],const char[]));
317 EXTERN PetscErrorCode  PetscClearMalloc(void);
318 
319 /*
320    Routines for tracing memory corruption/bleeding with default PETSc
321    memory allocation
322 */
323 EXTERN PetscErrorCode   PetscTrDump(FILE *);
324 EXTERN PetscErrorCode   PetscTrSpace(PetscLogDouble *,PetscLogDouble *,PetscLogDouble *);
325 EXTERN PetscErrorCode   PetscTrValid(int,const char[],const char[],const char[]);
326 EXTERN PetscErrorCode   PetscTrDebug(PetscTruth);
327 EXTERN PetscErrorCode   PetscTrLog(void);
328 EXTERN PetscErrorCode   PetscTrLogDump(FILE *);
329 EXTERN PetscErrorCode   PetscGetResidentSetSize(PetscLogDouble *);
330 
331 /*
332     Variable type where we stash PETSc object pointers in Fortran.
333     Assumes that sizeof(long) == sizeof(void*)which is true on
334     all machines that we know.
335 */
336 #define PetscFortranAddr   long
337 
338 /*E
339     PetscDataType - Used for handling different basic data types.
340 
341    Level: beginner
342 
343 .seealso: PetscBinaryRead(), PetscBinaryWrite(), PetscDataTypeToMPIDataType(),
344           PetscDataTypeGetSize(), PetscDataTypeGetName()
345 
346 E*/
347 typedef enum {PETSC_INT = 0,PETSC_DOUBLE = 1,PETSC_COMPLEX = 2,
348               PETSC_LONG =3 ,PETSC_SHORT = 4,PETSC_FLOAT = 5,
349               PETSC_CHAR = 6,PETSC_LOGICAL = 7} PetscDataType;
350 #if defined(PETSC_USE_COMPLEX)
351 #define PETSC_SCALAR PETSC_COMPLEX
352 #else
353 #if defined(PETSC_USE_SINGLE)
354 #define PETSC_SCALAR PETSC_FLOAT
355 #else
356 #define PETSC_SCALAR PETSC_DOUBLE
357 #endif
358 #endif
359 #if defined(PETSC_USE_SINGLE)
360 #define PETSC_REAL PETSC_FLOAT
361 #else
362 #define PETSC_REAL PETSC_DOUBLE
363 #endif
364 #define PETSC_FORTRANADDR PETSC_LONG
365 
366 EXTERN PetscErrorCode PetscDataTypeToMPIDataType(PetscDataType,MPI_Datatype*);
367 EXTERN PetscErrorCode PetscDataTypeGetSize(PetscDataType,int*);
368 EXTERN PetscErrorCode PetscDataTypeGetName(PetscDataType,const char*[]);
369 
370 /*
371     Basic memory and string operations. These are usually simple wrappers
372    around the basic Unix system calls, but a few of them have additional
373    functionality and/or error checking.
374 */
375 EXTERN PetscErrorCode   PetscMemcpy(void*,const void *,size_t);
376 EXTERN PetscErrorCode   PetscBitMemcpy(void*,int,const void*,int,int,PetscDataType);
377 EXTERN PetscErrorCode   PetscMemmove(void*,void *,size_t);
378 EXTERN PetscErrorCode   PetscMemzero(void*,size_t);
379 EXTERN PetscErrorCode   PetscMemcmp(const void*,const void*,size_t,PetscTruth *);
380 EXTERN PetscErrorCode   PetscStrlen(const char[],size_t*);
381 EXTERN PetscErrorCode   PetscStrcmp(const char[],const char[],PetscTruth *);
382 EXTERN PetscErrorCode   PetscStrgrt(const char[],const char[],PetscTruth *);
383 EXTERN PetscErrorCode   PetscStrcasecmp(const char[],const char[],PetscTruth*);
384 EXTERN PetscErrorCode   PetscStrncmp(const char[],const char[],size_t,PetscTruth*);
385 EXTERN PetscErrorCode   PetscStrcpy(char[],const char[]);
386 EXTERN PetscErrorCode   PetscStrcat(char[],const char[]);
387 EXTERN PetscErrorCode   PetscStrncat(char[],const char[],size_t);
388 EXTERN PetscErrorCode   PetscStrncpy(char[],const char[],size_t);
389 EXTERN PetscErrorCode   PetscStrchr(const char[],char,char *[]);
390 EXTERN PetscErrorCode   PetscStrtolower(char[]);
391 EXTERN PetscErrorCode   PetscStrrchr(const char[],char,char *[]);
392 EXTERN PetscErrorCode   PetscStrstr(const char[],const char[],char *[]);
393 EXTERN PetscErrorCode   PetscStrallocpy(const char[],char *[]);
394 EXTERN PetscErrorCode   PetscStrreplace(MPI_Comm,const char[],char[],size_t);
395 #define      PetscStrfree(a) ((a) ? PetscFree(a) : 0)
396 /*S
397     PetscToken - 'Token' used for managing tokenizing strings
398 
399   Level: intermediate
400 
401 .seealso: PetscTokenCreate(), PetscTokenFind(), PetscTokenDestroy()
402 S*/
403 typedef struct {char token;char *array;char *current;} PetscToken;
404 
405 EXTERN PetscErrorCode   PetscTokenCreate(const char[],const char,PetscToken**);
406 EXTERN PetscErrorCode   PetscTokenFind(PetscToken*,char *[]);
407 EXTERN PetscErrorCode   PetscTokenDestroy(PetscToken*);
408 
409 /*
410    These are  MPI operations for MPI_Allreduce() etc
411 */
412 EXTERN MPI_Op PetscMaxSum_Op;
413 #if defined(PETSC_USE_COMPLEX)
414 EXTERN MPI_Op PetscSum_Op;
415 #else
416 #define PetscSum_Op MPI_SUM
417 #endif
418 EXTERN PetscErrorCode PetscMaxSum(MPI_Comm,const PetscInt[],PetscInt*,PetscInt*);
419 
420 /*S
421      PetscObject - any PETSc object, PetscViewer, Mat, Vec, KSP etc
422 
423    Level: beginner
424 
425    Note: This is the base class from which all objects appear.
426 
427 .seealso:  PetscObjectDestroy(), PetscObjectView(), PetscObjectGetName(), PetscObjectSetName()
428 S*/
429 typedef struct _p_PetscObject* PetscObject;
430 
431 /*S
432      PetscFList - Linked list of functions, possibly stored in dynamic libraries, accessed
433       by string name
434 
435    Level: advanced
436 
437 .seealso:  PetscFListAdd(), PetscFListDestroy()
438 S*/
439 typedef struct _PetscFList *PetscFList;
440 
441 #include "petscviewer.h"
442 #include "petscoptions.h"
443 
444 EXTERN PetscErrorCode PetscLogInfoAllow(PetscTruth,const char []);
445 EXTERN PetscErrorCode PetscShowMemoryUsage(PetscViewer,const char[]);
446 EXTERN PetscErrorCode PetscGetTime(PetscLogDouble*);
447 EXTERN PetscErrorCode PetscGetCPUTime(PetscLogDouble*);
448 EXTERN PetscErrorCode PetscSleep(int);
449 
450 /*
451     Initialization of PETSc
452 */
453 EXTERN PetscErrorCode  PetscInitialize(int*,char***,const char[],const char[]);
454 EXTERN PetscErrorCode  PetscInitializeNoArguments(void);
455 EXTERN PetscErrorCode  PetscInitialized(PetscTruth *);
456 EXTERN PetscErrorCode  PetscFinalize(void);
457 EXTERN PetscErrorCode  PetscInitializeFortran(void);
458 EXTERN PetscErrorCode  PetscGetArgs(int*,char ***);
459 EXTERN PetscErrorCode  PetscEnd(void);
460 
461 typedef void (**PetscVoidFunction)(void);
462 
463 /*
464    PetscTryMethod - Queries an object for a method, if it exists then calls it.
465               These are intended to be used only inside PETSc functions.
466 */
467 #define  PetscTryMethod(obj,A,B,C) \
468   0;{ PetscErrorCode (*f)B, __ierr; \
469     __ierr = PetscObjectQueryFunction((PetscObject)obj,#A,(PetscVoidFunction)&f);CHKERRQ(__ierr); \
470     if (f) {__ierr = (*f)C;CHKERRQ(__ierr);}\
471   }
472 #define  PetscUseMethod(obj,A,B,C) \
473   0;{ PetscErrorCode (*f)B, __ierr; \
474     __ierr = PetscObjectQueryFunction((PetscObject)obj,A,(PetscVoidFunction)&f);CHKERRQ(__ierr); \
475     if (f) {__ierr = (*f)C;CHKERRQ(__ierr);}\
476     else {SETERRQ1(PETSC_ERR_SUP,"Cannot locate function %s in object",A);} \
477   }
478 /*
479     Functions that can act on any PETSc object.
480 */
481 EXTERN PetscErrorCode PetscObjectDestroy(PetscObject);
482 EXTERN PetscErrorCode PetscObjectExists(PetscObject,PetscTruth*);
483 EXTERN PetscErrorCode PetscObjectGetComm(PetscObject,MPI_Comm *);
484 EXTERN PetscErrorCode PetscObjectGetCookie(PetscObject,int *);
485 EXTERN PetscErrorCode PetscObjectGetType(PetscObject,int *);
486 EXTERN PetscErrorCode PetscObjectSetName(PetscObject,const char[]);
487 EXTERN PetscErrorCode PetscObjectGetName(PetscObject,char*[]);
488 EXTERN PetscErrorCode PetscObjectReference(PetscObject);
489 EXTERN PetscErrorCode PetscObjectGetReference(PetscObject,int*);
490 EXTERN PetscErrorCode PetscObjectDereference(PetscObject);
491 EXTERN PetscErrorCode PetscObjectGetNewTag(PetscObject,PetscMPIInt *);
492 EXTERN PetscErrorCode PetscCommGetNewTag(MPI_Comm,PetscMPIInt *);
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     PetscErrorCode 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. Not currently used.
649 */
650 #define PetscPublishAll(v)           0
651 #define PetscObjectTakeAccess(obj)   0
652 #define PetscObjectGrantAccess(obj)  0
653 #define PetscObjectDepublish(obj)    0
654 
655 
656 
657 /*
658       This code allows one to pass a MPI communicator between
659     C and Fortran. MPI 2.0 defines a standard API for doing this.
660     The code here is provided to allow PETSc to work with MPI 1.1
661     standard MPI libraries.
662 */
663 EXTERN PetscErrorCode  MPICCommToFortranComm(MPI_Comm,int *);
664 EXTERN PetscErrorCode  MPIFortranCommToCComm(int,MPI_Comm*);
665 
666 /*
667       Simple PETSc parallel IO for ASCII printing
668 */
669 EXTERN PetscErrorCode  PetscFixFilename(const char[],char[]);
670 EXTERN PetscErrorCode  PetscFOpen(MPI_Comm,const char[],const char[],FILE**);
671 EXTERN PetscErrorCode  PetscFClose(MPI_Comm,FILE*);
672 EXTERN PetscErrorCode  PetscFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4);
673 EXTERN PetscErrorCode  PetscPrintf(MPI_Comm,const char[],...)  PETSC_PRINTF_FORMAT_CHECK(2,3);
674 
675 /* These are used internally by PETSc ASCII IO routines*/
676 #include <stdarg.h>
677 EXTERN PetscErrorCode  PetscVSNPrintf(char*,size_t,const char*,va_list);
678 EXTERN PetscErrorCode  PetscVFPrintf(FILE*,const char*,va_list);
679 
680 /*MC
681     PetscErrorPrintf - Prints error messages.
682 
683     Not Collective
684 
685    Synopsis:
686      PetscErrorCode (*PetscErrorPrintf)(const char format[],...);
687 
688     Input Parameters:
689 .   format - the usual printf() format string
690 
691    Options Database Keys:
692 .    -error_output_stderr - cause error messages to be printed to stderr instead of the
693          (default) stdout
694 
695 
696    Level: developer
697 
698     Fortran Note:
699     This routine is not supported in Fortran.
700 
701     Concepts: error messages^printing
702     Concepts: printing^error messages
703 
704 .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf()
705 M*/
706 EXTERN PetscErrorCode  (*PetscErrorPrintf)(const char[],...);
707 
708 /*MC
709     PetscHelpPrintf - Prints help messages.
710 
711     Not Collective
712 
713    Synopsis:
714      PetscErrorCode (*PetscHelpPrintf)(const char format[],...);
715 
716     Input Parameters:
717 .   format - the usual printf() format string
718 
719    Level: developer
720 
721     Fortran Note:
722     This routine is not supported in Fortran.
723 
724     Concepts: help messages^printing
725     Concepts: printing^help messages
726 
727 .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscErrorPrintf()
728 M*/
729 EXTERN PetscErrorCode  (*PetscHelpPrintf)(MPI_Comm,const char[],...);
730 
731 EXTERN PetscErrorCode  PetscPOpen(MPI_Comm,const char[],const char[],const char[],FILE **);
732 EXTERN PetscErrorCode  PetscPClose(MPI_Comm,FILE*);
733 EXTERN PetscErrorCode  PetscSynchronizedPrintf(MPI_Comm,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3);
734 EXTERN PetscErrorCode  PetscSynchronizedFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4);
735 EXTERN PetscErrorCode  PetscSynchronizedFlush(MPI_Comm);
736 EXTERN PetscErrorCode  PetscSynchronizedFGets(MPI_Comm,FILE*,size_t,char[]);
737 EXTERN PetscErrorCode  PetscStartMatlab(MPI_Comm,const char[],const char[],FILE**);
738 EXTERN PetscErrorCode  PetscStartJava(MPI_Comm,const char[],const char[],FILE**);
739 EXTERN PetscErrorCode  PetscGetPetscDir(const char*[]);
740 
741 EXTERN PetscErrorCode  PetscPopUpSelect(MPI_Comm,char*,char*,int,char**,int*);
742 /*S
743      PetscObjectContainer - Simple PETSc object that contains a pointer to any required data
744 
745    Level: advanced
746 
747 .seealso:  PetscObject, PetscObjectContainerCreate()
748 S*/
749 typedef struct _p_PetscObjectContainer*  PetscObjectContainer;
750 EXTERN PetscErrorCode PetscObjectContainerGetPointer(PetscObjectContainer,void **);
751 EXTERN PetscErrorCode PetscObjectContainerSetPointer(PetscObjectContainer,void *);
752 EXTERN PetscErrorCode PetscObjectContainerDestroy(PetscObjectContainer);
753 EXTERN PetscErrorCode PetscObjectContainerCreate(MPI_Comm comm,PetscObjectContainer *);
754 
755 /*
756    For incremental debugging
757 */
758 extern PetscTruth PetscCompare;
759 EXTERN PetscErrorCode        PetscCompareDouble(double);
760 EXTERN PetscErrorCode        PetscCompareScalar(PetscScalar);
761 EXTERN PetscErrorCode        PetscCompareInt(PetscInt);
762 
763 /*
764    For use in debuggers
765 */
766 extern int PetscGlobalRank,PetscGlobalSize;
767 EXTERN PetscErrorCode PetscIntView(PetscInt,PetscInt[],PetscViewer);
768 EXTERN PetscErrorCode PetscRealView(PetscInt,PetscReal[],PetscViewer);
769 EXTERN PetscErrorCode PetscScalarView(PetscInt,PetscScalar[],PetscViewer);
770 
771 /*
772     Allows accessing Matlab Engine
773 */
774 #include "petscmatlab.h"
775 
776 /*
777     C code optimization is often enhanced by telling the compiler
778   that certain pointer arguments to functions are not aliased to
779   to other arguments. This is not yet ANSI C standard so we define
780   the macro "restrict" to indicate that the variable is not aliased
781   to any other argument.
782 */
783 #if defined(PETSC_HAVE_RESTRICT) && !defined(__cplusplus)
784 #define restrict _Restrict
785 #else
786 #if defined(restrict)
787 #undef restrict
788 #endif
789 #define restrict
790 #endif
791 
792 /*
793       Determine if some of the kernel computation routines use
794    Fortran (rather than C) for the numerical calculations. On some machines
795    and compilers (like complex numbers) the Fortran version of the routines
796    is faster than the C/C++ versions. The flag PETSC_USE_FORTRAN_KERNELS
797    would be set in the petscconf.h file
798 */
799 #if defined(PETSC_USE_FORTRAN_KERNELS)
800 
801 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ)
802 #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ
803 #endif
804 
805 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ)
806 #define PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ
807 #endif
808 
809 #if !defined(PETSC_USE_FORTRAN_KERNEL_NORM)
810 #define PETSC_USE_FORTRAN_KERNEL_NORM
811 #endif
812 
813 #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY)
814 #define PETSC_USE_FORTRAN_KERNEL_MAXPY
815 #endif
816 
817 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ)
818 #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ
819 #endif
820 
821 #if !defined(PETSC_USE_FORTRAN_KERNEL_RELAXAIJ)
822 #define PETSC_USE_FORTRAN_KERNEL_RELAXAIJ
823 #endif
824 
825 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ)
826 #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ
827 #endif
828 
829 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ)
830 #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ
831 #endif
832 
833 #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT)
834 #define PETSC_USE_FORTRAN_KERNEL_MDOT
835 #endif
836 
837 #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY)
838 #define PETSC_USE_FORTRAN_KERNEL_XTIMESY
839 #endif
840 
841 #if !defined(PETSC_USE_FORTRAN_KERNEL_AYPX)
842 #define PETSC_USE_FORTRAN_KERNEL_AYPX
843 #endif
844 
845 #if !defined(PETSC_USE_FORTRAN_KERNEL_WAXPY)
846 #define PETSC_USE_FORTRAN_KERNEL_WAXPY
847 #endif
848 
849 #endif
850 
851 /*
852     Macros for indicating code that should be compiled with a C interface,
853    rather than a C++ interface. Any routines that are dynamically loaded
854    (such as the PCCreate_XXX() routines) must be wrapped so that the name
855    mangler does not change the functions symbol name. This just hides the
856    ugly extern "C" {} wrappers.
857 */
858 #if defined(__cplusplus)
859 #define EXTERN_C_BEGIN extern "C" {
860 #define EXTERN_C_END }
861 #else
862 #define EXTERN_C_BEGIN
863 #define EXTERN_C_END
864 #endif
865 
866 /* --------------------------------------------------------------------*/
867 
868 /*M
869     size - integer variable used to contain the number of processors in
870            the relevent MPI_Comm
871 
872    Level: beginner
873 
874 .seealso: rank, comm
875 M*/
876 
877 /*M
878     rank - integer variable used to contain the number of this processor relative
879            to all in the relevent MPI_Comm
880 
881    Level: beginner
882 
883 .seealso: size, comm
884 M*/
885 
886 /*M
887     comm - MPI_Comm used in the current routine or object
888 
889    Level: beginner
890 
891 .seealso: size, rank
892 M*/
893 
894 /*M
895     MPI_Comm - the basic object used by MPI to determine which processes are involved in a
896         communication
897 
898    Level: beginner
899 
900    Note: This manual page is a place-holder because MPICH does not have a manual page for MPI_Comm
901 
902 .seealso: size, rank, comm, PETSC_COMM_WORLD, PETSC_COMM_SELF
903 M*/
904 
905 /*M
906     PetscScalar - PETSc type that represents either a double precision real number or
907        a double precision complex number if the code is compiled with BOPT=g_complex or O_complex
908 
909    Level: beginner
910 
911 .seealso: PetscReal, PassiveReal, PassiveScalar
912 M*/
913 
914 /*M
915     PetscReal - PETSc type that represents a double precision real number
916 
917    Level: beginner
918 
919 .seealso: PetscScalar, PassiveReal, PassiveScalar
920 M*/
921 
922 /*M
923     PassiveScalar - 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     This is the same as a PetscScalar except in code that is automatically differentiated it is
929    treated as a constant (not an indendent or dependent variable)
930 
931 .seealso: PetscReal, PassiveReal, PetscScalar
932 M*/
933 
934 /*M
935     PassiveReal - PETSc type that represents a double precision real number
936 
937    Level: beginner
938 
939     This is the same as a PetscReal except in code that is automatically differentiated it is
940    treated as a constant (not an indendent or dependent variable)
941 
942 .seealso: PetscScalar, PetscReal, PassiveScalar
943 M*/
944 
945 /*M
946     MPIU_SCALAR - MPI datatype corresponding to PetscScalar
947 
948    Level: beginner
949 
950     Note: In MPI calls that require an MPI datatype that matches a PetscScalar or array of PetscScalars
951           pass this value
952 
953 .seealso: PetscReal, PassiveReal, PassiveScalar, PetscScalar
954 M*/
955 
956 /*
957      The IBM include files define hz, here we hide it so that it may be used
958    as a regular user variable.
959 */
960 #if defined(hz)
961 #undef hz
962 #endif
963 
964 /*  For arrays that contain filenames or paths */
965 
966 
967 #if defined(PETSC_HAVE_LIMITS_H)
968 #include <limits.h>
969 #endif
970 #if defined(PETSC_HAVE_SYS_PARAM_H)
971 #include <sys/param.h>
972 #endif
973 #if defined(PETSC_HAVE_SYS_TYPES_H)
974 #include <sys/types.h>
975 #endif
976 #if defined(MAXPATHLEN)
977 #  define PETSC_MAX_PATH_LEN     MAXPATHLEN
978 #elif defined(MAX_PATH)
979 #  define PETSC_MAX_PATH_LEN     MAX_PATH
980 #elif defined(_MAX_PATH)
981 #  define PETSC_MAX_PATH_LEN     _MAX_PATH
982 #else
983 #  define PETSC_MAX_PATH_LEN     4096
984 #endif
985 
986 PETSC_EXTERN_CXX_END
987 #endif
988 
989 
990