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