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