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