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