xref: /petsc/include/petsc.h (revision c3d102fe2dfc19c1832704c537829f04ceb136a2)
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 /*
56     Defines the interface to MPI allowing the use of all MPI functions.
57 */
58 #include "mpi.h"
59 /*
60     Yuck, we need to put stdio.h AFTER mpi.h for MPICH2 with C++ compiler
61     see the top of mpicxx.h
62 
63     The MPI STANDARD HAS TO BE CHANGED to prevent this nonsense.
64 */
65 #include <stdio.h>
66 
67 /*
68     All PETSc C functions return this error code, it is the final argument of
69    all Fortran subroutines
70 */
71 typedef int PetscErrorCode;
72 typedef int PetscCookie;
73 typedef int PetscEvent;
74 typedef int PetscBLASInt;
75 typedef int PetscMPIInt;
76 
77 #if defined(PETSC_USE_64BIT_INT)
78 typedef long long PetscInt;
79 #define MPIU_INT MPI_LONG_LONG_INT
80 #else
81 typedef int PetscInt;
82 #define MPIU_INT MPI_INT
83 #endif
84 
85 /*
86     Allows defining simple C++ polymorphic functions that remove certain
87    optional arguments for a simplier user interface.
88 */
89 #if defined(__cplusplus)
90 #define PetscPolymorphicSubroutine(A,B,C) inline PetscErrorCode A B {return A C;}
91 #else
92 #define PetscPolymorphicSubroutine(A,B,C)
93 #endif
94 
95 /*
96     Declare extern C stuff after incuding external header files
97 */
98 
99 PETSC_EXTERN_CXX_BEGIN
100 
101 /*
102     EXTERN indicates a PETSc function defined elsewhere
103 */
104 #if !defined(EXTERN)
105 #define EXTERN extern
106 #endif
107 
108 /*
109     Defines some elementary mathematics functions and constants.
110 */
111 #include "petscmath.h"
112 
113 /*
114        Basic PETSc constants
115 */
116 
117 /*E
118     PetscTruth - Logical variable. Actually an integer
119 
120    Level: beginner
121 
122 E*/
123 typedef enum { PETSC_FALSE,PETSC_TRUE } PetscTruth;
124 
125 /*M
126     PETSC_FALSE - False value of PetscTruth
127 
128     Level: beginner
129 
130     Note: Zero integer
131 
132 .seealso: PetscTruth
133 M*/
134 
135 /*M
136     PETSC_TRUE - True value of PetscTruth
137 
138     Level: beginner
139 
140     Note: Nonzero integer
141 
142 .seealso: PetscTruth
143 M*/
144 
145 /*M
146     PETSC_YES - Alias for PETSC_TRUE
147 
148     Level: beginner
149 
150     Note: Zero integer
151 
152 .seealso: PetscTruth
153 M*/
154 
155 /*M
156     PETSC_NO - Alias for PETSC_FALSE
157 
158     Level: beginner
159 
160     Note: Nonzero integer
161 
162 .seealso: PetscTruth
163 M*/
164 
165 /*M
166     PETSC_NULL - standard way of passing in a null or array or pointer
167 
168    Level: beginner
169 
170    Notes: accepted by many PETSc functions to not set a parameter and instead use
171           some default
172 
173           This macro does not exist in Fortran; you must use PETSC_NULL_INTEGER,
174           PETSC_NULL_DOUBLE_PRECISION etc
175 
176 .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_IGNORE, PETSC_DETERMINE
177 
178 M*/
179 #define PETSC_NULL           0
180 
181 /*M
182     PETSC_DECIDE - standard way of passing in integer or floating point parameter
183        where you wish PETSc to use the default.
184 
185    Level: beginner
186 
187 .seealso: PETSC_NULL, PETSC_DEFAULT, PETSC_IGNORE, PETSC_DETERMINE
188 
189 M*/
190 #define PETSC_DECIDE         -1
191 
192 /*M
193     PETSC_DEFAULT - standard way of passing in integer or floating point parameter
194        where you wish PETSc to use the default.
195 
196    Level: beginner
197 
198 .seealso: PETSC_DECIDE, PETSC_NULL, PETSC_IGNORE, PETSC_DETERMINE
199 
200 M*/
201 #define PETSC_DEFAULT        -2
202 
203 #define PETSC_YES            PETSC_TRUE
204 #define PETSC_NO             PETSC_FALSE
205 
206 /*M
207     PETSC_IGNORE - same as PETSC_NULL, means PETSc will ignore this argument
208 
209    Level: beginner
210 
211    Notes: accepted by many PETSc functions to not set a parameter and instead use
212           some default
213 
214           This macro does not exist in Fortran; you must use PETSC_NULL_INTEGER,
215           PETSC_NULL_DOUBLE_PRECISION etc
216 
217 .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_NULL, PETSC_DETERMINE
218 
219 M*/
220 #define PETSC_IGNORE         PETSC_NULL
221 
222 /*M
223     PETSC_DETERMINE - standard way of passing in integer or floating point parameter
224        where you wish PETSc to compute the required value.
225 
226    Level: beginner
227 
228 .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_IGNORE, PETSC_NULL, VecSetSizes()
229 
230 M*/
231 #define PETSC_DETERMINE      PETSC_DECIDE
232 
233 /*M
234     PETSC_COMM_WORLD - a duplicate of the MPI_COMM_WORLD communicator which represents
235            all the processs
236 
237    Level: beginner
238 
239    Notes: PETSC_COMM_WORLD and MPI_COMM_WORLD are equivalent except that passing MPI_COMM_WORLD
240           into PETSc object constructors will result in using more MPI resources since an MPI_Comm_dup()
241           will be done on it internally. We recommend always using PETSC_COMM_WORLD
242 
243 .seealso: PETSC_COMM_SELF
244 
245 M*/
246 extern MPI_Comm   PETSC_COMM_WORLD;
247 
248 /*M
249     PETSC_COMM_SELF - a duplicate of the MPI_COMM_SELF communicator which represents
250            the current process
251 
252    Level: beginner
253 
254    Notes: PETSC_COMM_SELF and MPI_COMM_SELF are equivalent except that passint MPI_COMM_SELF
255           into PETSc object constructors will result in using more MPI resources since an MPI_Comm_dup()
256           will be done on it internally. We recommend always using PETSC_COMM_SELF
257 
258 .seealso: PETSC_COMM_WORLD
259 
260 M*/
261 extern MPI_Comm   PETSC_COMM_SELF;
262 
263 extern PetscTruth PetscInitializeCalled;
264 extern PetscTruth PetscFinalizeCalled;
265 EXTERN PetscErrorCode        PetscSetCommWorld(MPI_Comm);
266 EXTERN PetscErrorCode        PetscSetHelpVersionFunctions(PetscErrorCode (*)(MPI_Comm),PetscErrorCode (*)(MPI_Comm));
267 EXTERN PetscErrorCode        PetscCommDuplicate(MPI_Comm,MPI_Comm*,int*);
268 EXTERN PetscErrorCode        PetscCommDestroy(MPI_Comm*);
269 
270 /*MC
271    PetscMalloc - Allocates memory
272 
273    Input Parameter:
274 .  m - number of bytes to allocate
275 
276    Output Parameter:
277 .  result - memory allocated
278 
279    Synopsis:
280    PetscErrorCode PetscMalloc(size_t m,void **result)
281 
282    Level: beginner
283 
284    Notes: Memory is always allocated at least double aligned
285 
286           If you request memory of zero size it will allocate no space and assign the pointer to 0; PetscFree() will
287           properly handle not freeing the null pointer.
288 
289 .seealso: PetscFree(), PetscNew()
290 
291   Concepts: memory allocation
292 
293 M*/
294 #define PetscMalloc(a,b)  ((a != 0) ? (*PetscTrMalloc)((a),__LINE__,__FUNCT__,__FILE__,__SDIR__,(void**)(b)) : (*(b) = 0,0) )
295 
296 /*MC
297    PetscMalloc2 - Allocates 2 chunks of  memory
298 
299    Input Parameter:
300 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
301 .  t1 - type of first memory elements
302 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
303 -  t2 - type of second memory elements
304 
305    Output Parameter:
306 +  r1 - memory allocated in first chunk
307 -  r2 - memory allocated in second chunk
308 
309    Synopsis:
310    PetscErrorCode PetscMalloc2(size_t m1,type, t1,void **r1,size_t m2,type t2,void **r2)
311 
312    Level: developer
313 
314    Notes: Memory of first chunk is always allocated at least double aligned
315 
316 .seealso: PetscFree(), PetscNew(), PetscMalloc()
317 
318   Concepts: memory allocation
319 
320 M*/
321 #if defined(PETSC_USE_DEBUG)
322 #define PetscMalloc2(m1,t1,r1,m2,t2,r2) (PetscMalloc((m1)*sizeof(t1),r1) || PetscMalloc((m2)*sizeof(t2),r2))
323 #else
324 #define PetscMalloc2(m1,t1,r1,m2,t2,r2) (PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2),r1) || (*(r2) = (t2*)(*(r1)+m1),0))
325 #endif
326 
327 /*MC
328    PetscMalloc3 - Allocates 3 chunks of  memory
329 
330    Input Parameter:
331 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
332 .  t1 - type of first memory elements
333 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
334 .  t2 - type of second memory elements
335 .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
336 -  t3 - type of third memory elements
337 
338    Output Parameter:
339 +  r1 - memory allocated in first chunk
340 .  r2 - memory allocated in second chunk
341 -  r3 - memory allocated in third chunk
342 
343    Synopsis:
344    PetscErrorCode PetscMalloc3(size_t m1,type, t1,void **r1,size_t m2,type t2,void **r2,size_t m3,type t3,void **r3)
345 
346    Level: developer
347 
348    Notes: Memory of first chunk is always allocated at least double aligned
349 
350 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3()
351 
352   Concepts: memory allocation
353 
354 M*/
355 #if defined(PETSC_USE_DEBUG)
356 #define PetscMalloc3(m1,t1,r1,m2,t2,r2,m3,t3,r3) (PetscMalloc((m1)*sizeof(t1),r1) || PetscMalloc((m2)*sizeof(t2),r2) || PetscMalloc((m3)*sizeof(t3),r3))
357 #else
358 #define PetscMalloc3(m1,t1,r1,m2,t2,r2,m3,t3,r3) (PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3),r1) || (*(r2) = (t2*)(*(r1)+m1),*(r3) = (t3*)(*(r2)+m2),0))
359 #endif
360 
361 /*MC
362    PetscMalloc4 - Allocates 4 chunks of  memory
363 
364    Input Parameter:
365 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
366 .  t1 - type of first memory elements
367 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
368 .  t2 - type of second memory elements
369 .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
370 .  t3 - type of third memory elements
371 .  m4 - number of elements to allocate in 4th chunk  (may be zero)
372 -  t4 - type of fourth memory elements
373 
374    Output Parameter:
375 +  r1 - memory allocated in first chunk
376 .  r2 - memory allocated in second chunk
377 .  r3 - memory allocated in third chunk
378 -  r4 - memory allocated in fourth chunk
379 
380    Synopsis:
381    PetscErrorCode PetscMalloc4(size_t m1,type, t1,void **r1,size_t m2,type t2,void **r2,size_t m3,type t3,void **r3,size_t m4,type t4,void **r4)
382 
383    Level: developer
384 
385    Notes: Memory of first chunk is always allocated at least double aligned
386 
387 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4()
388 
389   Concepts: memory allocation
390 
391 M*/
392 #if defined(PETSC_USE_DEBUG)
393 #define PetscMalloc4(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4) (PetscMalloc((m1)*sizeof(t1),r1) || PetscMalloc((m2)*sizeof(t2),r2) || PetscMalloc((m3)*sizeof(t3),r3) || PetscMalloc((m4)*sizeof(t4),r4))
394 #else
395 #define PetscMalloc4(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4) (PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3)+(m4)*sizeof(t4),r1) || (*(r2) = (t2*)(*(r1)+m1),*(r3) = (t3*)(*(r2)+m2),*(r4) = (t4*)(*(r3)+m3),0))
396 #endif
397 
398 /*MC
399    PetscMalloc5 - Allocates 5 chunks of  memory
400 
401    Input Parameter:
402 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
403 .  t1 - type of first memory elements
404 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
405 .  t2 - type of second memory elements
406 .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
407 .  t3 - type of third memory elements
408 .  m4 - number of elements to allocate in 4th chunk  (may be zero)
409 .  t4 - type of fourth memory elements
410 .  m5 - number of elements to allocate in 5th chunk  (may be zero)
411 -  t5 - type of fifth memory elements
412 
413    Output Parameter:
414 +  r1 - memory allocated in first chunk
415 .  r2 - memory allocated in second chunk
416 .  r3 - memory allocated in third chunk
417 .  r4 - memory allocated in fourth chunk
418 -  r5 - memory allocated in fifth chunk
419 
420    Synopsis:
421    PetscErrorCode PetscMalloc5(size_t m1,type, t1,void **r1,size_t m2,type t2,void **r2,size_t m3,type t3,void **r3,size_t m4,type t4,void **r4,size_t m5,type t5,void **r5)
422 
423    Level: developer
424 
425    Notes: Memory of first chunk is always allocated at least double aligned
426 
427 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4(), PetscFree5()
428 
429   Concepts: memory allocation
430 
431 M*/
432 #if defined(PETSC_USE_DEBUG)
433 #define PetscMalloc5(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4,m5,t5,r5) (PetscMalloc((m1)*sizeof(t1),r1) || PetscMalloc((m2)*sizeof(t2),r2) || PetscMalloc((m3)*sizeof(t3),r3) || PetscMalloc((m4)*sizeof(t4),r4) || PetscMalloc((m5)*sizeof(t5),r5))
434 #else
435 #define PetscMalloc5(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4,m5,t5,r5) (PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3)+(m4)*sizeof(t4)+(m5)*sizeof(t5),r1) || (*(r2) = (t2*)(*(r1)+m1),*(r3) = (t3*)(*(r2)+m2),*(r4) = (t4*)(*(r3)+m3),*(r5) = (t5*)(*(r4)+m4),0))
436 #endif
437 
438 
439 /*MC
440    PetscMalloc6 - Allocates 6 chunks of  memory
441 
442    Input Parameter:
443 +  m1 - number of elements to allocate in 1st chunk  (may be zero)
444 .  t1 - type of first memory elements
445 .  m2 - number of elements to allocate in 2nd chunk  (may be zero)
446 .  t2 - type of second memory elements
447 .  m3 - number of elements to allocate in 3rd chunk  (may be zero)
448 .  t3 - type of third memory elements
449 .  m4 - number of elements to allocate in 4th chunk  (may be zero)
450 .  t4 - type of fourth memory elements
451 .  m5 - number of elements to allocate in 5th chunk  (may be zero)
452 .  t5 - type of fifth memory elements
453 .  m6 - number of elements to allocate in 6th chunk  (may be zero)
454 -  t6 - type of sixth memory elements
455 
456    Output Parameter:
457 +  r1 - memory allocated in first chunk
458 .  r2 - memory allocated in second chunk
459 .  r3 - memory allocated in third chunk
460 .  r4 - memory allocated in fourth chunk
461 .  r5 - memory allocated in fifth chunk
462 -  r6 - memory allocated in sixth chunk
463 
464    Synopsis:
465    PetscErrorCode PetscMalloc6(size_t m1,type, t1,void **r1,size_t m2,type t2,void **r2,size_t m3,type t3,void **r3,size_t m4,type t4,void **r4,size_t m5,type t5,void **r5,size_t m6,type t6,void **r6)
466 
467    Level: developer
468 
469    Notes: Memory of first chunk is always allocated at least double aligned
470 
471 .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4(), PetscFree5(), PetscFree6()
472 
473   Concepts: memory allocation
474 
475 M*/
476 #if defined(PETSC_USE_DEBUG)
477 #define PetscMalloc6(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4,m5,t5,r5,m6,t6,r6) (PetscMalloc((m1)*sizeof(t1),r1) || PetscMalloc((m2)*sizeof(t2),r2) || PetscMalloc((m3)*sizeof(t3),r3) || PetscMalloc((m4)*sizeof(t4),r4) || PetscMalloc((m5)*sizeof(t5),r5) || PetscMalloc((m6)*sizeof(t6),r6))
478 #else
479 #define PetscMalloc6(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4,m5,t5,r5,m6,t6,r6) (PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3)+(m4)*sizeof(t4)+(m5)*sizeof(t5)+(m6)*sizeof(t6),r1) || (*(r2) = (t2*)(*(r1)+m1),*(r3) = (t3*)(*(r2)+m2),*(r4) = (t4*)(*(r3)+m3),*(r5) = (t5*)(*(r4)+m4),*(r6) = (t6*)(*(r5)+m5),0))
480 #endif
481 
482 /*MC
483    PetscNew - Allocates memory of a particular type, Zeros the memory!
484 
485    Input Parameter:
486 . type - structure name of space to be allocated. Memory of size sizeof(type) is allocated
487 
488    Output Parameter:
489 .  result - memory allocated
490 
491    Synopsis:
492    PetscErrorCode PetscNew(struct type,((type *))result)
493 
494    Level: beginner
495 
496 .seealso: PetscFree(), PetscMalloc()
497 
498   Concepts: memory allocation
499 
500 M*/
501 #define PetscNew(A,b)        (PetscMalloc(sizeof(A),(b)) || PetscMemzero(*(b),sizeof(A)))
502 
503 /*MC
504    PetscFree - Frees memory
505 
506    Input Parameter:
507 .   memory - memory to free
508 
509    Synopsis:
510    PetscErrorCode PetscFree(void *memory)
511 
512    Level: beginner
513 
514    Notes: Memory must have been obtained with PetscNew() or PetscMalloc()
515 
516 .seealso: PetscNew(), PetscMalloc()
517 
518   Concepts: memory allocation
519 
520 M*/
521 #define PetscFree(a)   ((a) ? ((*PetscTrFree)((a),__LINE__,__FUNCT__,__FILE__,__SDIR__) || ((a = 0),0)) : 0)
522 
523 /*MC
524    PetscFree2 - Frees 2 chunks of memory obtained with PetscMalloc2()
525 
526    Input Parameter:
527 +   memory1 - memory to free
528 -   memory2 - 2nd memory to free
529 
530 
531    Synopsis:
532    PetscErrorCode PetscFree2(void *memory1,void *memory2)
533 
534    Level: developer
535 
536    Notes: Memory must have been obtained with PetscMalloc2()
537 
538 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree()
539 
540   Concepts: memory allocation
541 
542 M*/
543 #if defined(PETSC_USE_DEBUG)
544 #define PetscFree2(m1,m2)   (PetscFree(m2) || PetscFree(m1))
545 #else
546 #define PetscFree2(m1,m2)   (PetscFree(m1))
547 #endif
548 
549 /*MC
550    PetscFree3 - Frees 3 chunks of memory obtained with PetscMalloc3()
551 
552    Input Parameter:
553 +   memory1 - memory to free
554 .   memory2 - 2nd memory to free
555 -   memory3 - 3rd memory to free
556 
557 
558    Synopsis:
559    PetscErrorCode PetscFree3(void *memory1,void *memory2,void *memory3)
560 
561    Level: developer
562 
563    Notes: Memory must have been obtained with PetscMalloc3()
564 
565 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3()
566 
567   Concepts: memory allocation
568 
569 M*/
570 #if defined(PETSC_USE_DEBUG)
571 #define PetscFree3(m1,m2,m3)   (PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
572 #else
573 #define PetscFree3(m1,m2,m3)   (PetscFree(m1))
574 #endif
575 
576 /*MC
577    PetscFree4 - Frees 4 chunks of memory obtained with PetscMalloc4()
578 
579    Input Parameter:
580 +   m1 - memory to free
581 .   m2 - 2nd memory to free
582 .   m3 - 3rd memory to free
583 -   m4 - 4th memory to free
584 
585 
586    Synopsis:
587    PetscErrorCode PetscFree4(void *m1,void *m2,void *m3,void *m4)
588 
589    Level: developer
590 
591    Notes: Memory must have been obtained with PetscMalloc4()
592 
593 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4()
594 
595   Concepts: memory allocation
596 
597 M*/
598 #if defined(PETSC_USE_DEBUG)
599 #define PetscFree4(m1,m2,m3,m4)   (PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
600 #else
601 #define PetscFree4(m1,m2,m3,m4)   (PetscFree(m1))
602 #endif
603 
604 /*MC
605    PetscFree5 - Frees 5 chunks of memory obtained with PetscMalloc5()
606 
607    Input Parameter:
608 +   m1 - memory to free
609 .   m2 - 2nd memory to free
610 .   m3 - 3rd memory to free
611 .   m4 - 4th memory to free
612 -   m5 - 5th memory to free
613 
614 
615    Synopsis:
616    PetscErrorCode PetscFree5(void *m1,void *m2,void *m3,void *m4,void *m5)
617 
618    Level: developer
619 
620    Notes: Memory must have been obtained with PetscMalloc5()
621 
622 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5()
623 
624   Concepts: memory allocation
625 
626 M*/
627 #if defined(PETSC_USE_DEBUG)
628 #define PetscFree5(m1,m2,m3,m4,m5)   (PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
629 #else
630 #define PetscFree5(m1,m2,m3,m4,m5)   (PetscFree(m1))
631 #endif
632 
633 
634 /*MC
635    PetscFree6 - Frees 6 chunks of memory obtained with PetscMalloc6()
636 
637    Input Parameter:
638 +   m1 - memory to free
639 .   m2 - 2nd memory to free
640 .   m3 - 3rd memory to free
641 .   m4 - 4th memory to free
642 .   m5 - 5th memory to free
643 -   m6 - 6th memory to free
644 
645 
646    Synopsis:
647    PetscErrorCode PetscFree6(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6)
648 
649    Level: developer
650 
651    Notes: Memory must have been obtained with PetscMalloc6()
652 
653 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5(), PetscMalloc6()
654 
655   Concepts: memory allocation
656 
657 M*/
658 #if defined(PETSC_USE_DEBUG)
659 #define PetscFree6(m1,m2,m3,m4,m5,m6)   (PetscFree(m6) || PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
660 #else
661 #define PetscFree6(m1,m2,m3,m4,m5,m6)   (PetscFree(m1))
662 #endif
663 
664 EXTERN PetscErrorCode  (*PetscTrMalloc)(size_t,int,const char[],const char[],const char[],void**);
665 EXTERN PetscErrorCode  (*PetscTrFree)(void*,int,const char[],const char[],const char[]);
666 EXTERN PetscErrorCode  PetscSetMalloc(PetscErrorCode (*)(size_t,int,const char[],const char[],const char[],void**),PetscErrorCode (*)(void*,int,const char[],const char[],const char[]));
667 EXTERN PetscErrorCode  PetscClearMalloc(void);
668 
669 /*
670    Routines for tracing memory corruption/bleeding with default PETSc
671    memory allocation
672 */
673 EXTERN PetscErrorCode   PetscMallocDump(FILE *);
674 EXTERN PetscErrorCode   PetscMallocDumpLog(FILE *);
675 EXTERN PetscErrorCode   PetscMallocGetCurrentUsage(PetscLogDouble *);
676 EXTERN PetscErrorCode   PetscMallocGetMaximumUsage(PetscLogDouble *);
677 EXTERN PetscErrorCode   PetscMallocDebug(PetscTruth);
678 EXTERN PetscErrorCode   PetscMallocValidate(int,const char[],const char[],const char[]);
679 EXTERN PetscErrorCode   PetscMallocSetDumpLog(void);
680 
681 
682 /*
683     Variable type where we stash PETSc object pointers in Fortran.
684     Assumes that sizeof(long) == sizeof(void*)which is true on
685     all machines that we know.
686 */
687 #define PetscFortranAddr   long
688 
689 /*E
690     PetscDataType - Used for handling different basic data types.
691 
692    Level: beginner
693 
694 .seealso: PetscBinaryRead(), PetscBinaryWrite(), PetscDataTypeToMPIDataType(),
695           PetscDataTypeGetSize(), PetscDataTypeGetName()
696 
697 E*/
698 typedef enum {PETSC_INT = 0,PETSC_DOUBLE = 1,PETSC_COMPLEX = 2,
699               PETSC_LONG = 3 ,PETSC_SHORT = 4,PETSC_FLOAT = 5,
700               PETSC_CHAR = 6,PETSC_LOGICAL = 7} PetscDataType;
701 #if defined(PETSC_USE_COMPLEX)
702 #define PETSC_SCALAR PETSC_COMPLEX
703 #else
704 #if defined(PETSC_USE_SINGLE)
705 #define PETSC_SCALAR PETSC_FLOAT
706 #else
707 #define PETSC_SCALAR PETSC_DOUBLE
708 #endif
709 #endif
710 #if defined(PETSC_USE_SINGLE)
711 #define PETSC_REAL PETSC_FLOAT
712 #else
713 #define PETSC_REAL PETSC_DOUBLE
714 #endif
715 #define PETSC_FORTRANADDR PETSC_LONG
716 
717 EXTERN PetscErrorCode PetscDataTypeToMPIDataType(PetscDataType,MPI_Datatype*);
718 EXTERN PetscErrorCode PetscDataTypeGetSize(PetscDataType,PetscInt*);
719 EXTERN PetscErrorCode PetscDataTypeGetName(PetscDataType,const char*[]);
720 
721 /*
722     Basic memory and string operations. These are usually simple wrappers
723    around the basic Unix system calls, but a few of them have additional
724    functionality and/or error checking.
725 */
726 EXTERN PetscErrorCode   PetscMemcpy(void*,const void *,size_t);
727 EXTERN PetscErrorCode   PetscBitMemcpy(void*,PetscInt,const void*,PetscInt,PetscInt,PetscDataType);
728 EXTERN PetscErrorCode   PetscMemmove(void*,void *,size_t);
729 EXTERN PetscErrorCode   PetscMemzero(void*,size_t);
730 EXTERN PetscErrorCode   PetscMemcmp(const void*,const void*,size_t,PetscTruth *);
731 EXTERN PetscErrorCode   PetscStrlen(const char[],size_t*);
732 EXTERN PetscErrorCode   PetscStrcmp(const char[],const char[],PetscTruth *);
733 EXTERN PetscErrorCode   PetscStrgrt(const char[],const char[],PetscTruth *);
734 EXTERN PetscErrorCode   PetscStrcasecmp(const char[],const char[],PetscTruth*);
735 EXTERN PetscErrorCode   PetscStrncmp(const char[],const char[],size_t,PetscTruth*);
736 EXTERN PetscErrorCode   PetscStrcpy(char[],const char[]);
737 EXTERN PetscErrorCode   PetscStrcat(char[],const char[]);
738 EXTERN PetscErrorCode   PetscStrncat(char[],const char[],size_t);
739 EXTERN PetscErrorCode   PetscStrncpy(char[],const char[],size_t);
740 EXTERN PetscErrorCode   PetscStrchr(const char[],char,char *[]);
741 EXTERN PetscErrorCode   PetscStrtolower(char[]);
742 EXTERN PetscErrorCode   PetscStrrchr(const char[],char,char *[]);
743 EXTERN PetscErrorCode   PetscStrstr(const char[],const char[],char *[]);
744 EXTERN PetscErrorCode   PetscStrallocpy(const char[],char *[]);
745 EXTERN PetscErrorCode   PetscStrreplace(MPI_Comm,const char[],char[],size_t);
746 #define      PetscStrfree(a) ((a) ? PetscFree(a) : 0)
747 /*S
748     PetscToken - 'Token' used for managing tokenizing strings
749 
750   Level: intermediate
751 
752 .seealso: PetscTokenCreate(), PetscTokenFind(), PetscTokenDestroy()
753 S*/
754 typedef struct {char token;char *array;char *current;} PetscToken;
755 
756 EXTERN PetscErrorCode   PetscTokenCreate(const char[],const char,PetscToken**);
757 EXTERN PetscErrorCode   PetscTokenFind(PetscToken*,char *[]);
758 EXTERN PetscErrorCode   PetscTokenDestroy(PetscToken*);
759 
760 /*
761    These are  MPI operations for MPI_Allreduce() etc
762 */
763 EXTERN MPI_Op PetscMaxSum_Op;
764 #if defined(PETSC_USE_COMPLEX)
765 EXTERN MPI_Op PetscSum_Op;
766 #else
767 #define PetscSum_Op MPI_SUM
768 #endif
769 EXTERN PetscErrorCode PetscMaxSum(MPI_Comm,const PetscInt[],PetscInt*,PetscInt*);
770 
771 /*S
772      PetscObject - any PETSc object, PetscViewer, Mat, Vec, KSP etc
773 
774    Level: beginner
775 
776    Note: This is the base class from which all objects appear.
777 
778 .seealso:  PetscObjectDestroy(), PetscObjectView(), PetscObjectGetName(), PetscObjectSetName()
779 S*/
780 typedef struct _p_PetscObject* PetscObject;
781 
782 /*S
783      PetscFList - Linked list of functions, possibly stored in dynamic libraries, accessed
784       by string name
785 
786    Level: advanced
787 
788 .seealso:  PetscFListAdd(), PetscFListDestroy()
789 S*/
790 typedef struct _PetscFList *PetscFList;
791 
792 #include "petscviewer.h"
793 #include "petscoptions.h"
794 
795 /*
796    Routines that get memory usage information from the OS
797 */
798 EXTERN PetscErrorCode PetscMemoryGetCurrentUsage(PetscLogDouble *);
799 EXTERN PetscErrorCode PetscMemoryGetMaximumUsage(PetscLogDouble *);
800 EXTERN PetscErrorCode PetscMemorySetGetMaximumUsage(void);
801 EXTERN PetscErrorCode PetscMemoryShowUsage(PetscViewer,const char[]);
802 
803 EXTERN PetscErrorCode PetscLogInfoAllow(PetscTruth,const char []);
804 EXTERN PetscErrorCode PetscGetTime(PetscLogDouble*);
805 EXTERN PetscErrorCode PetscGetCPUTime(PetscLogDouble*);
806 EXTERN PetscErrorCode PetscSleep(int);
807 
808 /*
809     Initialization of PETSc
810 */
811 EXTERN PetscErrorCode  PetscInitialize(int*,char***,const char[],const char[]);
812 PetscPolymorphicSubroutine(PetscInitialize,(int *argc,char ***args),(argc,args,PETSC_NULL,PETSC_NULL))
813 EXTERN PetscErrorCode  PetscInitializeNoArguments(void);
814 EXTERN PetscErrorCode  PetscInitialized(PetscTruth *);
815 EXTERN PetscErrorCode  PetscFinalized(PetscTruth *);
816 EXTERN PetscErrorCode  PetscFinalize(void);
817 EXTERN PetscErrorCode  PetscInitializeFortran(void);
818 EXTERN PetscErrorCode  PetscGetArgs(int*,char ***);
819 EXTERN PetscErrorCode  PetscEnd(void);
820 
821 typedef void (**PetscVoidFunction)(void);
822 
823 /*
824    PetscTryMethod - Queries an object for a method, if it exists then calls it.
825               These are intended to be used only inside PETSc functions.
826 */
827 #define  PetscTryMethod(obj,A,B,C) \
828   0;{ PetscErrorCode (*f)B, __ierr; \
829     __ierr = PetscObjectQueryFunction((PetscObject)obj,#A,(PetscVoidFunction)&f);CHKERRQ(__ierr); \
830     if (f) {__ierr = (*f)C;CHKERRQ(__ierr);}\
831   }
832 #define  PetscUseMethod(obj,A,B,C) \
833   0;{ PetscErrorCode (*f)B, __ierr; \
834     __ierr = PetscObjectQueryFunction((PetscObject)obj,A,(PetscVoidFunction)&f);CHKERRQ(__ierr); \
835     if (f) {__ierr = (*f)C;CHKERRQ(__ierr);}\
836     else {SETERRQ1(PETSC_ERR_SUP,"Cannot locate function %s in object",A);} \
837   }
838 /*
839     Functions that can act on any PETSc object.
840 */
841 EXTERN PetscErrorCode PetscObjectDestroy(PetscObject);
842 EXTERN PetscErrorCode PetscObjectExists(PetscObject,PetscTruth*);
843 EXTERN PetscErrorCode PetscObjectGetComm(PetscObject,MPI_Comm *);
844 EXTERN PetscErrorCode PetscObjectGetCookie(PetscObject,int *);
845 EXTERN PetscErrorCode PetscObjectGetType(PetscObject,int *);
846 EXTERN PetscErrorCode PetscObjectSetName(PetscObject,const char[]);
847 EXTERN PetscErrorCode PetscObjectGetName(PetscObject,char*[]);
848 EXTERN PetscErrorCode PetscObjectReference(PetscObject);
849 EXTERN PetscErrorCode PetscObjectGetReference(PetscObject,PetscInt*);
850 EXTERN PetscErrorCode PetscObjectDereference(PetscObject);
851 EXTERN PetscErrorCode PetscObjectGetNewTag(PetscObject,PetscMPIInt *);
852 EXTERN PetscErrorCode PetscCommGetNewTag(MPI_Comm,PetscMPIInt *);
853 EXTERN PetscErrorCode PetscObjectView(PetscObject,PetscViewer);
854 EXTERN PetscErrorCode PetscObjectCompose(PetscObject,const char[],PetscObject);
855 EXTERN PetscErrorCode PetscObjectQuery(PetscObject,const char[],PetscObject *);
856 EXTERN PetscErrorCode PetscObjectComposeFunction(PetscObject,const char[],const char[],void (*)(void));
857 
858 typedef void (*FCNVOID)(void); /* cast in next macro should never be extern C */
859 typedef PetscErrorCode (*FCNINTVOID)(void); /* used in casts to make sure they are not extern C */
860 /*MC
861    PetscObjectComposeFunctionDynamic - Associates a function with a given PETSc object.
862 
863    Collective on PetscObject
864 
865    Input Parameters:
866 +  obj - the PETSc object; this must be cast with a (PetscObject), for example,
867          PetscObjectCompose((PetscObject)mat,...);
868 .  name - name associated with the child function
869 .  fname - name of the function
870 -  ptr - function pointer (or PETSC_NULL if using dynamic libraries)
871 
872    Level: advanced
873 
874     Synopsis:
875     PetscErrorCode PetscObjectComposeFunctionDynamic(PetscObject obj,const char name[],const char fname[],void *ptr)
876 
877    Notes:
878    To remove a registered routine, pass in a PETSC_NULL rname and fnc().
879 
880    PetscObjectComposeFunctionDynamic() can be used with any PETSc object (such as
881    Mat, Vec, KSP, SNES, etc.) or any user-provided object.
882 
883    The composed function must be wrapped in a EXTERN_C_BEGIN/END for this to
884    work in C++/complex with dynamic link libraries (PETSC_USE_DYNAMIC_LIBRARIES)
885    enabled.
886 
887    Concepts: objects^composing functions
888    Concepts: composing functions
889    Concepts: functions^querying
890    Concepts: objects^querying
891    Concepts: querying objects
892 
893 .seealso: PetscObjectQueryFunction()
894 M*/
895 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
896 #define PetscObjectComposeFunctionDynamic(a,b,c,d) PetscObjectComposeFunction(a,b,c,0)
897 #else
898 #define PetscObjectComposeFunctionDynamic(a,b,c,d) PetscObjectComposeFunction(a,b,c,(FCNVOID)(d))
899 #endif
900 
901 EXTERN PetscErrorCode PetscObjectQueryFunction(PetscObject,const char[],void (**)(void));
902 EXTERN PetscErrorCode PetscObjectSetOptionsPrefix(PetscObject,const char[]);
903 EXTERN PetscErrorCode PetscObjectAppendOptionsPrefix(PetscObject,const char[]);
904 EXTERN PetscErrorCode PetscObjectPrependOptionsPrefix(PetscObject,const char[]);
905 EXTERN PetscErrorCode PetscObjectGetOptionsPrefix(PetscObject,char*[]);
906 EXTERN PetscErrorCode PetscObjectPublish(PetscObject);
907 EXTERN PetscErrorCode PetscObjectChangeTypeName(PetscObject,const char[]);
908 EXTERN PetscErrorCode PetscObjectRegisterDestroy(PetscObject);
909 EXTERN PetscErrorCode PetscObjectRegisterDestroyAll(void);
910 EXTERN PetscErrorCode PetscObjectName(PetscObject);
911 EXTERN PetscErrorCode PetscTypeCompare(PetscObject,const char[],PetscTruth*);
912 
913 /*
914     Defines PETSc error handling.
915 */
916 #include "petscerror.h"
917 
918 /*S
919      PetscOList - Linked list of PETSc objects, accessable by string name
920 
921    Level: advanced
922 
923 .seealso:  PetscOListAdd(), PetscOListDestroy(), PetscOListFind()
924 S*/
925 typedef struct _PetscOList *PetscOList;
926 
927 EXTERN PetscErrorCode PetscOListDestroy(PetscOList *);
928 EXTERN PetscErrorCode PetscOListFind(PetscOList,const char[],PetscObject*);
929 EXTERN PetscErrorCode PetscOListReverseFind(PetscOList,PetscObject,char**);
930 EXTERN PetscErrorCode PetscOListAdd(PetscOList *,const char[],PetscObject);
931 EXTERN PetscErrorCode PetscOListDuplicate(PetscOList,PetscOList *);
932 
933 /*
934     Dynamic library lists. Lists of names of routines in dynamic
935   link libraries that will be loaded as needed.
936 */
937 EXTERN PetscErrorCode PetscFListAdd(PetscFList*,const char[],const char[],void (*)(void));
938 EXTERN PetscErrorCode PetscFListDestroy(PetscFList*);
939 EXTERN PetscErrorCode PetscFListFind(MPI_Comm,PetscFList,const char[],void (**)(void));
940 EXTERN PetscErrorCode PetscFListPrintTypes(MPI_Comm,FILE*,const char[],const char[],const char[],const char[],PetscFList);
941 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
942 #define    PetscFListAddDynamic(a,b,p,c) PetscFListAdd(a,b,p,0)
943 #else
944 #define    PetscFListAddDynamic(a,b,p,c) PetscFListAdd(a,b,p,(void (*)(void))c)
945 #endif
946 EXTERN PetscErrorCode PetscFListDuplicate(PetscFList,PetscFList *);
947 EXTERN PetscErrorCode PetscFListView(PetscFList,PetscViewer);
948 EXTERN PetscErrorCode PetscFListConcat(const char [],const char [],char []);
949 EXTERN PetscErrorCode PetscFListGet(PetscFList,char ***,int*);
950 
951 /*S
952      PetscDLLibraryList - Linked list of dynamics libraries to search for functions
953 
954    Level: advanced
955 
956    PETSC_USE_DYNAMIC_LIBRARIES must be defined in petscconf.h to use dynamic libraries
957 
958 .seealso:  PetscDLLibraryOpen()
959 S*/
960 typedef struct _PetscDLLibraryList *PetscDLLibraryList;
961 extern PetscDLLibraryList DLLibrariesLoaded;
962 EXTERN PetscErrorCode PetscDLLibraryRetrieve(MPI_Comm,const char[],char *,int,PetscTruth *);
963 EXTERN PetscErrorCode PetscDLLibraryOpen(MPI_Comm,const char[],void **);
964 EXTERN PetscErrorCode PetscDLLibrarySym(MPI_Comm,PetscDLLibraryList *,const char[],const char[],void **);
965 EXTERN PetscErrorCode PetscDLLibraryAppend(MPI_Comm,PetscDLLibraryList *,const char[]);
966 EXTERN PetscErrorCode PetscDLLibraryPrepend(MPI_Comm,PetscDLLibraryList *,const char[]);
967 EXTERN PetscErrorCode PetscDLLibraryClose(PetscDLLibraryList);
968 EXTERN PetscErrorCode PetscDLLibraryPrintPath(void);
969 EXTERN PetscErrorCode PetscDLLibraryGetInfo(void*,const char[],const char *[]);
970 
971 /*
972     Mechanism for translating PETSc object representations between languages
973     Not currently used.
974 */
975 typedef enum {PETSC_LANGUAGE_C,PETSC_LANGUAGE_CXX} PetscLanguage;
976 #define PETSC_LANGUAGE_F77 PETSC_LANGUAGE_C
977 EXTERN PetscErrorCode PetscObjectComposeLanguage(PetscObject,PetscLanguage,void *);
978 EXTERN PetscErrorCode PetscObjectQueryLanguage(PetscObject,PetscLanguage,void **);
979 
980 /*
981      Useful utility routines
982 */
983 EXTERN PetscErrorCode PetscSplitOwnership(MPI_Comm,PetscInt*,PetscInt*);
984 EXTERN PetscErrorCode PetscSplitOwnershipBlock(MPI_Comm,PetscInt,PetscInt*,PetscInt*);
985 EXTERN PetscErrorCode PetscSequentialPhaseBegin(MPI_Comm,PetscMPIInt);
986 PetscPolymorphicSubroutine(PetscSequentialPhaseBegin,(MPI_Comm comm),(comm,1))
987 PetscPolymorphicSubroutine(PetscSequentialPhaseBegin,(void),(PETSC_COMM_WORLD,1))
988 EXTERN PetscErrorCode PetscSequentialPhaseEnd(MPI_Comm,PetscMPIInt);
989 PetscPolymorphicSubroutine(PetscSequentialPhaseEnd,(MPI_Comm comm),(comm,1))
990 PetscPolymorphicSubroutine(PetscSequentialPhaseEnd,(void),(PETSC_COMM_WORLD,1))
991 EXTERN PetscErrorCode PetscBarrier(PetscObject);
992 EXTERN PetscErrorCode PetscMPIDump(FILE*);
993 
994 #define PetscNot(a) ((a) ? PETSC_FALSE : PETSC_TRUE)
995 /*
996     Defines basic graphics available from PETSc.
997 */
998 #include "petscdraw.h"
999 
1000 /*
1001     Defines the base data structures for all PETSc objects
1002 */
1003 #include "petschead.h"
1004 
1005 /*
1006      Defines PETSc profiling.
1007 */
1008 #include "petsclog.h"
1009 
1010 /*
1011           For locking, unlocking and destroying AMS memories associated with
1012     PETSc objects. Not currently used.
1013 */
1014 #define PetscPublishAll(v)           0
1015 #define PetscObjectTakeAccess(obj)   0
1016 #define PetscObjectGrantAccess(obj)  0
1017 #define PetscObjectDepublish(obj)    0
1018 
1019 
1020 
1021 /*
1022       This code allows one to pass a MPI communicator between
1023     C and Fortran. MPI 2.0 defines a standard API for doing this.
1024     The code here is provided to allow PETSc to work with MPI 1.1
1025     standard MPI libraries.
1026 */
1027 EXTERN PetscErrorCode  MPICCommToFortranComm(MPI_Comm,int *);
1028 EXTERN PetscErrorCode  MPIFortranCommToCComm(int,MPI_Comm*);
1029 
1030 /*
1031       Simple PETSc parallel IO for ASCII printing
1032 */
1033 EXTERN PetscErrorCode  PetscFixFilename(const char[],char[]);
1034 EXTERN PetscErrorCode  PetscFOpen(MPI_Comm,const char[],const char[],FILE**);
1035 EXTERN PetscErrorCode  PetscFClose(MPI_Comm,FILE*);
1036 EXTERN PetscErrorCode  PetscFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4);
1037 EXTERN PetscErrorCode  PetscPrintf(MPI_Comm,const char[],...)  PETSC_PRINTF_FORMAT_CHECK(2,3);
1038 
1039 /* These are used internally by PETSc ASCII IO routines*/
1040 #include <stdarg.h>
1041 EXTERN PetscErrorCode  PetscVSNPrintf(char*,size_t,const char*,va_list);
1042 EXTERN PetscErrorCode  PetscVFPrintf(FILE*,const char*,va_list);
1043 
1044 /*MC
1045     PetscErrorPrintf - Prints error messages.
1046 
1047     Not Collective
1048 
1049    Synopsis:
1050      PetscErrorCode (*PetscErrorPrintf)(const char format[],...);
1051 
1052     Input Parameters:
1053 .   format - the usual printf() format string
1054 
1055    Options Database Keys:
1056 .    -error_output_stderr - cause error messages to be printed to stderr instead of the
1057          (default) stdout
1058 
1059 
1060    Level: developer
1061 
1062     Fortran Note:
1063     This routine is not supported in Fortran.
1064 
1065     Concepts: error messages^printing
1066     Concepts: printing^error messages
1067 
1068 .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf()
1069 M*/
1070 EXTERN PetscErrorCode  (*PetscErrorPrintf)(const char[],...);
1071 
1072 /*MC
1073     PetscHelpPrintf - Prints help messages.
1074 
1075     Not Collective
1076 
1077    Synopsis:
1078      PetscErrorCode (*PetscHelpPrintf)(const char format[],...);
1079 
1080     Input Parameters:
1081 .   format - the usual printf() format string
1082 
1083    Level: developer
1084 
1085     Fortran Note:
1086     This routine is not supported in Fortran.
1087 
1088     Concepts: help messages^printing
1089     Concepts: printing^help messages
1090 
1091 .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscErrorPrintf()
1092 M*/
1093 EXTERN PetscErrorCode  (*PetscHelpPrintf)(MPI_Comm,const char[],...);
1094 
1095 EXTERN PetscErrorCode  PetscPOpen(MPI_Comm,const char[],const char[],const char[],FILE **);
1096 EXTERN PetscErrorCode  PetscPClose(MPI_Comm,FILE*);
1097 EXTERN PetscErrorCode  PetscSynchronizedPrintf(MPI_Comm,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3);
1098 EXTERN PetscErrorCode  PetscSynchronizedFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4);
1099 EXTERN PetscErrorCode  PetscSynchronizedFlush(MPI_Comm);
1100 EXTERN PetscErrorCode  PetscSynchronizedFGets(MPI_Comm,FILE*,size_t,char[]);
1101 EXTERN PetscErrorCode  PetscStartMatlab(MPI_Comm,const char[],const char[],FILE**);
1102 EXTERN PetscErrorCode  PetscStartJava(MPI_Comm,const char[],const char[],FILE**);
1103 EXTERN PetscErrorCode  PetscGetPetscDir(const char*[]);
1104 
1105 EXTERN PetscErrorCode  PetscPopUpSelect(MPI_Comm,char*,char*,int,char**,int*);
1106 /*S
1107      PetscObjectContainer - Simple PETSc object that contains a pointer to any required data
1108 
1109    Level: advanced
1110 
1111 .seealso:  PetscObject, PetscObjectContainerCreate()
1112 S*/
1113 typedef struct _p_PetscObjectContainer*  PetscObjectContainer;
1114 EXTERN PetscErrorCode PetscObjectContainerGetPointer(PetscObjectContainer,void **);
1115 EXTERN PetscErrorCode PetscObjectContainerSetPointer(PetscObjectContainer,void *);
1116 EXTERN PetscErrorCode PetscObjectContainerDestroy(PetscObjectContainer);
1117 EXTERN PetscErrorCode PetscObjectContainerCreate(MPI_Comm comm,PetscObjectContainer *);
1118 EXTERN PetscErrorCode PetscObjectContainerSetUserDestroy(PetscObjectContainer, PetscErrorCode (*)(void*));
1119 
1120 /*
1121    For incremental debugging
1122 */
1123 extern PetscTruth PetscCompare;
1124 EXTERN PetscErrorCode        PetscCompareDouble(double);
1125 EXTERN PetscErrorCode        PetscCompareScalar(PetscScalar);
1126 EXTERN PetscErrorCode        PetscCompareInt(PetscInt);
1127 
1128 /*
1129    For use in debuggers
1130 */
1131 extern int PetscGlobalRank,PetscGlobalSize;
1132 EXTERN PetscErrorCode PetscIntView(PetscInt,PetscInt[],PetscViewer);
1133 EXTERN PetscErrorCode PetscRealView(PetscInt,PetscReal[],PetscViewer);
1134 EXTERN PetscErrorCode PetscScalarView(PetscInt,PetscScalar[],PetscViewer);
1135 
1136 /*
1137     Allows accessing Matlab Engine
1138 */
1139 #include "petscmatlab.h"
1140 
1141 /*
1142     C code optimization is often enhanced by telling the compiler
1143   that certain pointer arguments to functions are not aliased to
1144   to other arguments. This is not yet ANSI C standard so we define
1145   the macro "restrict" to indicate that the variable is not aliased
1146   to any other argument.
1147 */
1148 #if defined(PETSC_HAVE_RESTRICT) && !defined(__cplusplus)
1149 #define restrict _Restrict
1150 #else
1151 #if defined(restrict)
1152 #undef restrict
1153 #endif
1154 #define restrict
1155 #endif
1156 
1157 /*
1158       Determine if some of the kernel computation routines use
1159    Fortran (rather than C) for the numerical calculations. On some machines
1160    and compilers (like complex numbers) the Fortran version of the routines
1161    is faster than the C/C++ versions. The flag PETSC_USE_FORTRAN_KERNELS
1162    would be set in the petscconf.h file
1163 */
1164 #if defined(PETSC_USE_FORTRAN_KERNELS)
1165 
1166 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ)
1167 #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ
1168 #endif
1169 
1170 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ)
1171 #define PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ
1172 #endif
1173 
1174 #if !defined(PETSC_USE_FORTRAN_KERNEL_NORM)
1175 #define PETSC_USE_FORTRAN_KERNEL_NORM
1176 #endif
1177 
1178 #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY)
1179 #define PETSC_USE_FORTRAN_KERNEL_MAXPY
1180 #endif
1181 
1182 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ)
1183 #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ
1184 #endif
1185 
1186 #if !defined(PETSC_USE_FORTRAN_KERNEL_RELAXAIJ)
1187 #define PETSC_USE_FORTRAN_KERNEL_RELAXAIJ
1188 #endif
1189 
1190 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ)
1191 #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ
1192 #endif
1193 
1194 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ)
1195 #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ
1196 #endif
1197 
1198 #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT)
1199 #define PETSC_USE_FORTRAN_KERNEL_MDOT
1200 #endif
1201 
1202 #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY)
1203 #define PETSC_USE_FORTRAN_KERNEL_XTIMESY
1204 #endif
1205 
1206 #if !defined(PETSC_USE_FORTRAN_KERNEL_AYPX)
1207 #define PETSC_USE_FORTRAN_KERNEL_AYPX
1208 #endif
1209 
1210 #if !defined(PETSC_USE_FORTRAN_KERNEL_WAXPY)
1211 #define PETSC_USE_FORTRAN_KERNEL_WAXPY
1212 #endif
1213 
1214 #endif
1215 
1216 /*
1217     Macros for indicating code that should be compiled with a C interface,
1218    rather than a C++ interface. Any routines that are dynamically loaded
1219    (such as the PCCreate_XXX() routines) must be wrapped so that the name
1220    mangler does not change the functions symbol name. This just hides the
1221    ugly extern "C" {} wrappers.
1222 */
1223 #if defined(__cplusplus)
1224 #define EXTERN_C_BEGIN extern "C" {
1225 #define EXTERN_C_END }
1226 #else
1227 #define EXTERN_C_BEGIN
1228 #define EXTERN_C_END
1229 #endif
1230 
1231 /* --------------------------------------------------------------------*/
1232 
1233 /*M
1234     size - integer variable used to contain the number of processors in
1235            the relevent MPI_Comm
1236 
1237    Level: beginner
1238 
1239 .seealso: rank, comm
1240 M*/
1241 
1242 /*M
1243     rank - integer variable used to contain the number of this processor relative
1244            to all in the relevent MPI_Comm
1245 
1246    Level: beginner
1247 
1248 .seealso: size, comm
1249 M*/
1250 
1251 /*M
1252     comm - MPI_Comm used in the current routine or object
1253 
1254    Level: beginner
1255 
1256 .seealso: size, rank
1257 M*/
1258 
1259 /*M
1260     MPI_Comm - the basic object used by MPI to determine which processes are involved in a
1261         communication
1262 
1263    Level: beginner
1264 
1265    Note: This manual page is a place-holder because MPICH does not have a manual page for MPI_Comm
1266 
1267 .seealso: size, rank, comm, PETSC_COMM_WORLD, PETSC_COMM_SELF
1268 M*/
1269 
1270 /*M
1271     PetscScalar - PETSc type that represents either a double precision real number or
1272        a double precision complex number if the code is configured with --with-scalar-type=complex
1273 
1274    Level: beginner
1275 
1276 .seealso: PetscReal, PassiveReal, PassiveScalar
1277 M*/
1278 
1279 /*M
1280     PetscReal - PETSc type that represents a double precision real number
1281 
1282    Level: beginner
1283 
1284 .seealso: PetscScalar, PassiveReal, PassiveScalar
1285 M*/
1286 
1287 /*M
1288     PassiveScalar - PETSc type that represents either a double precision real number or
1289        a double precision complex number if the code is  code is configured with --with-scalar-type=complex
1290 
1291    Level: beginner
1292 
1293     This is the same as a PetscScalar except in code that is automatically differentiated it is
1294    treated as a constant (not an indendent or dependent variable)
1295 
1296 .seealso: PetscReal, PassiveReal, PetscScalar
1297 M*/
1298 
1299 /*M
1300     PassiveReal - PETSc type that represents a double precision real number
1301 
1302    Level: beginner
1303 
1304     This is the same as a PetscReal except in code that is automatically differentiated it is
1305    treated as a constant (not an indendent or dependent variable)
1306 
1307 .seealso: PetscScalar, PetscReal, PassiveScalar
1308 M*/
1309 
1310 /*M
1311     MPIU_SCALAR - MPI datatype corresponding to PetscScalar
1312 
1313    Level: beginner
1314 
1315     Note: In MPI calls that require an MPI datatype that matches a PetscScalar or array of PetscScalars
1316           pass this value
1317 
1318 .seealso: PetscReal, PassiveReal, PassiveScalar, PetscScalar
1319 M*/
1320 
1321 /*
1322      The IBM include files define hz, here we hide it so that it may be used
1323    as a regular user variable.
1324 */
1325 #if defined(hz)
1326 #undef hz
1327 #endif
1328 
1329 /*  For arrays that contain filenames or paths */
1330 
1331 
1332 #if defined(PETSC_HAVE_LIMITS_H)
1333 #include <limits.h>
1334 #endif
1335 #if defined(PETSC_HAVE_SYS_PARAM_H)
1336 #include <sys/param.h>
1337 #endif
1338 #if defined(PETSC_HAVE_SYS_TYPES_H)
1339 #include <sys/types.h>
1340 #endif
1341 #if defined(MAXPATHLEN)
1342 #  define PETSC_MAX_PATH_LEN     MAXPATHLEN
1343 #elif defined(MAX_PATH)
1344 #  define PETSC_MAX_PATH_LEN     MAX_PATH
1345 #elif defined(_MAX_PATH)
1346 #  define PETSC_MAX_PATH_LEN     _MAX_PATH
1347 #else
1348 #  define PETSC_MAX_PATH_LEN     4096
1349 #endif
1350 
1351 PETSC_EXTERN_CXX_END
1352 #endif
1353 
1354 
1355