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