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