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