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