xref: /petsc/include/petsc.h (revision 9dcbbd2be7d6c63d58f4f57b80657b56043f6042)
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(PETSC_USE_EXTERN_CXX) && 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 extern const char *PetscTruths[];
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 extern const char *PetscDataTypes[];
811 
812 #if defined(PETSC_USE_COMPLEX)
813 #define PETSC_SCALAR PETSC_COMPLEX
814 #else
815 #if defined(PETSC_USE_SINGLE)
816 #define PETSC_SCALAR PETSC_FLOAT
817 #else
818 #define PETSC_SCALAR PETSC_DOUBLE
819 #endif
820 #endif
821 #if defined(PETSC_USE_SINGLE)
822 #define PETSC_REAL PETSC_FLOAT
823 #else
824 #define PETSC_REAL PETSC_DOUBLE
825 #endif
826 #define PETSC_FORTRANADDR PETSC_LONG
827 
828 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDataTypeToMPIDataType(PetscDataType,MPI_Datatype*);
829 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDataTypeGetSize(PetscDataType,PetscInt*);
830 
831 /*
832     Basic memory and string operations. These are usually simple wrappers
833    around the basic Unix system calls, but a few of them have additional
834    functionality and/or error checking.
835 */
836 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMemcpy(void*,const void *,size_t);
837 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscBitMemcpy(void*,PetscInt,const void*,PetscInt,PetscInt,PetscDataType);
838 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMemmove(void*,void *,size_t);
839 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMemzero(void*,size_t);
840 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMemcmp(const void*,const void*,size_t,PetscTruth *);
841 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrlen(const char[],size_t*);
842 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrcmp(const char[],const char[],PetscTruth *);
843 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrgrt(const char[],const char[],PetscTruth *);
844 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrcasecmp(const char[],const char[],PetscTruth*);
845 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrncmp(const char[],const char[],size_t,PetscTruth*);
846 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrcpy(char[],const char[]);
847 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrcat(char[],const char[]);
848 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrncat(char[],const char[],size_t);
849 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrncpy(char[],const char[],size_t);
850 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrchr(const char[],char,char *[]);
851 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrtolower(char[]);
852 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrrchr(const char[],char,char *[]);
853 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrstr(const char[],const char[],char *[]);
854 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrallocpy(const char[],char *[]);
855 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrreplace(MPI_Comm,const char[],char[],size_t);
856 #define      PetscStrfree(a) ((a) ? PetscFree(a) : 0)
857 /*S
858     PetscToken - 'Token' used for managing tokenizing strings
859 
860   Level: intermediate
861 
862 .seealso: PetscTokenCreate(), PetscTokenFind(), PetscTokenDestroy()
863 S*/
864 typedef struct {char token;char *array;char *current;} PetscToken;
865 
866 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscTokenCreate(const char[],const char,PetscToken**);
867 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscTokenFind(PetscToken*,char *[]);
868 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscTokenDestroy(PetscToken*);
869 
870 /*
871    These are  MPI operations for MPI_Allreduce() etc
872 */
873 EXTERN PETSC_DLLEXPORT MPI_Op PetscMaxSum_Op;
874 #if defined(PETSC_USE_COMPLEX)
875 EXTERN PETSC_DLLEXPORT MPI_Op PetscSum_Op;
876 #else
877 #define PetscSum_Op MPI_SUM
878 #endif
879 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMaxSum(MPI_Comm,const PetscInt[],PetscInt*,PetscInt*);
880 
881 /*S
882      PetscObject - any PETSc object, PetscViewer, Mat, Vec, KSP etc
883 
884    Level: beginner
885 
886    Note: This is the base class from which all objects appear.
887 
888 .seealso:  PetscObjectDestroy(), PetscObjectView(), PetscObjectGetName(), PetscObjectSetName()
889 S*/
890 typedef struct _p_PetscObject* PetscObject;
891 
892 /*S
893      PetscFList - Linked list of functions, possibly stored in dynamic libraries, accessed
894       by string name
895 
896    Level: advanced
897 
898 .seealso:  PetscFListAdd(), PetscFListDestroy()
899 S*/
900 typedef struct _PetscFList *PetscFList;
901 
902 #include "petscviewer.h"
903 #include "petscoptions.h"
904 
905 /*
906    Routines that get memory usage information from the OS
907 */
908 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemoryGetCurrentUsage(PetscLogDouble *);
909 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemoryGetMaximumUsage(PetscLogDouble *);
910 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemorySetGetMaximumUsage(void);
911 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemoryShowUsage(PetscViewer,const char[]);
912 
913 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscLogInfoAllow(PetscTruth,const char []);
914 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetTime(PetscLogDouble*);
915 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetCPUTime(PetscLogDouble*);
916 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSleep(int);
917 
918 /*
919     Initialization of PETSc
920 */
921 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscInitialize(int*,char***,const char[],const char[]);
922 PetscPolymorphicSubroutine(PetscInitialize,(int *argc,char ***args),(argc,args,PETSC_NULL,PETSC_NULL))
923 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscInitializeNoArguments(void);
924 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscInitialized(PetscTruth *);
925 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFinalized(PetscTruth *);
926 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFinalize(void);
927 EXTERN PetscErrorCode PetscInitializeFortran(void);
928 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetArgs(int*,char ***);
929 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscEnd(void);
930 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscInitializePackage(char *);
931 typedef void (**PetscVoidFunction)(void);
932 
933 /*
934    PetscTryMethod - Queries an object for a method, if it exists then calls it.
935               These are intended to be used only inside PETSc functions.
936 */
937 #define  PetscTryMethod(obj,A,B,C) \
938   0;{ PetscErrorCode (*f)B, __ierr; \
939     __ierr = PetscObjectQueryFunction((PetscObject)obj,#A,(PetscVoidFunction)&f);CHKERRQ(__ierr); \
940     if (f) {__ierr = (*f)C;CHKERRQ(__ierr);}\
941   }
942 #define  PetscUseMethod(obj,A,B,C) \
943   0;{ PetscErrorCode (*f)B, __ierr; \
944     __ierr = PetscObjectQueryFunction((PetscObject)obj,A,(PetscVoidFunction)&f);CHKERRQ(__ierr); \
945     if (f) {__ierr = (*f)C;CHKERRQ(__ierr);}\
946     else {SETERRQ1(PETSC_ERR_SUP,"Cannot locate function %s in object",A);} \
947   }
948 /*
949     Functions that can act on any PETSc object.
950 */
951 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectDestroy(PetscObject);
952 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectExists(PetscObject,PetscTruth*);
953 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetComm(PetscObject,MPI_Comm *);
954 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetCookie(PetscObject,int *);
955 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetType(PetscObject,int *);
956 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectSetName(PetscObject,const char[]);
957 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetName(PetscObject,char*[]);
958 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectReference(PetscObject);
959 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetReference(PetscObject,PetscInt*);
960 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectDereference(PetscObject);
961 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetNewTag(PetscObject,PetscMPIInt *);
962 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscCommGetNewTag(MPI_Comm,PetscMPIInt *);
963 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectView(PetscObject,PetscViewer);
964 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectCompose(PetscObject,const char[],PetscObject);
965 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectQuery(PetscObject,const char[],PetscObject *);
966 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectComposeFunction(PetscObject,const char[],const char[],void (*)(void));
967 
968 typedef void (*FCNVOID)(void); /* cast in next macro should never be extern C */
969 typedef PetscErrorCode (*FCNINTVOID)(void); /* used in casts to make sure they are not extern C */
970 /*MC
971    PetscObjectComposeFunctionDynamic - Associates a function with a given PETSc object.
972 
973    Collective on PetscObject
974 
975    Input Parameters:
976 +  obj - the PETSc object; this must be cast with a (PetscObject), for example,
977          PetscObjectCompose((PetscObject)mat,...);
978 .  name - name associated with the child function
979 .  fname - name of the function
980 -  ptr - function pointer (or PETSC_NULL if using dynamic libraries)
981 
982    Level: advanced
983 
984     Synopsis:
985     PetscErrorCode PetscObjectComposeFunctionDynamic(PetscObject obj,const char name[],const char fname[],void *ptr)
986 
987    Notes:
988    To remove a registered routine, pass in a PETSC_NULL rname and fnc().
989 
990    PetscObjectComposeFunctionDynamic() can be used with any PETSc object (such as
991    Mat, Vec, KSP, SNES, etc.) or any user-provided object.
992 
993    The composed function must be wrapped in a EXTERN_C_BEGIN/END for this to
994    work in C++/complex with dynamic link libraries (PETSC_USE_DYNAMIC_LIBRARIES)
995    enabled.
996 
997    Concepts: objects^composing functions
998    Concepts: composing functions
999    Concepts: functions^querying
1000    Concepts: objects^querying
1001    Concepts: querying objects
1002 
1003 .seealso: PetscObjectQueryFunction()
1004 M*/
1005 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
1006 #define PetscObjectComposeFunctionDynamic(a,b,c,d) PetscObjectComposeFunction(a,b,c,0)
1007 #else
1008 #define PetscObjectComposeFunctionDynamic(a,b,c,d) PetscObjectComposeFunction(a,b,c,(FCNVOID)(d))
1009 #endif
1010 
1011 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectQueryFunction(PetscObject,const char[],void (**)(void));
1012 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectSetOptionsPrefix(PetscObject,const char[]);
1013 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectAppendOptionsPrefix(PetscObject,const char[]);
1014 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectPrependOptionsPrefix(PetscObject,const char[]);
1015 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetOptionsPrefix(PetscObject,char*[]);
1016 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectPublish(PetscObject);
1017 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectChangeTypeName(PetscObject,const char[]);
1018 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectRegisterDestroy(PetscObject);
1019 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectRegisterDestroyAll(void);
1020 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectName(PetscObject);
1021 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscTypeCompare(PetscObject,const char[],PetscTruth*);
1022 
1023 /*
1024     Defines PETSc error handling.
1025 */
1026 #include "petscerror.h"
1027 
1028 /*S
1029      PetscOList - Linked list of PETSc objects, accessable by string name
1030 
1031    Level: advanced
1032 
1033 .seealso:  PetscOListAdd(), PetscOListDestroy(), PetscOListFind()
1034 S*/
1035 typedef struct _PetscOList *PetscOList;
1036 
1037 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOListDestroy(PetscOList *);
1038 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOListFind(PetscOList,const char[],PetscObject*);
1039 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOListReverseFind(PetscOList,PetscObject,char**);
1040 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOListAdd(PetscOList *,const char[],PetscObject);
1041 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOListDuplicate(PetscOList,PetscOList *);
1042 
1043 /*
1044     Dynamic library lists. Lists of names of routines in dynamic
1045   link libraries that will be loaded as needed.
1046 */
1047 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListAdd(PetscFList*,const char[],const char[],void (*)(void));
1048 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListDestroy(PetscFList*);
1049 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListFind(MPI_Comm,PetscFList,const char[],void (**)(void));
1050 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListPrintTypes(MPI_Comm,FILE*,const char[],const char[],const char[],const char[],PetscFList);
1051 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
1052 #define    PetscFListAddDynamic(a,b,p,c) PetscFListAdd(a,b,p,0)
1053 #else
1054 #define    PetscFListAddDynamic(a,b,p,c) PetscFListAdd(a,b,p,(void (*)(void))c)
1055 #endif
1056 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListDuplicate(PetscFList,PetscFList *);
1057 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListView(PetscFList,PetscViewer);
1058 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListConcat(const char [],const char [],char []);
1059 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListGet(PetscFList,char ***,int*);
1060 
1061 /*S
1062      PetscDLLibraryList - Linked list of dynamics libraries to search for functions
1063 
1064    Level: advanced
1065 
1066    PETSC_USE_DYNAMIC_LIBRARIES must be defined in petscconf.h to use dynamic libraries
1067 
1068 .seealso:  PetscDLLibraryOpen()
1069 S*/
1070 typedef struct _PetscDLLibraryList *PetscDLLibraryList;
1071 extern PetscDLLibraryList DLLibrariesLoaded;
1072 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryRetrieve(MPI_Comm,const char[],char *,int,PetscTruth *);
1073 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryOpen(MPI_Comm,const char[],void **);
1074 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibrarySym(MPI_Comm,PetscDLLibraryList *,const char[],const char[],void **);
1075 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryAppend(MPI_Comm,PetscDLLibraryList *,const char[]);
1076 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryPrepend(MPI_Comm,PetscDLLibraryList *,const char[]);
1077 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryClose(PetscDLLibraryList);
1078 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryPrintPath(void);
1079 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryGetInfo(void*,const char[],const char *[]);
1080 
1081 /*
1082     Mechanism for translating PETSc object representations between languages
1083     Not currently used.
1084 */
1085 typedef enum {PETSC_LANGUAGE_C,PETSC_LANGUAGE_CXX} PetscLanguage;
1086 #define PETSC_LANGUAGE_F77 PETSC_LANGUAGE_C
1087 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectComposeLanguage(PetscObject,PetscLanguage,void *);
1088 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectQueryLanguage(PetscObject,PetscLanguage,void **);
1089 
1090 /*
1091      Useful utility routines
1092 */
1093 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSplitOwnership(MPI_Comm,PetscInt*,PetscInt*);
1094 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSplitOwnershipBlock(MPI_Comm,PetscInt,PetscInt*,PetscInt*);
1095 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSequentialPhaseBegin(MPI_Comm,PetscMPIInt);
1096 PetscPolymorphicSubroutine(PetscSequentialPhaseBegin,(MPI_Comm comm),(comm,1))
1097 PetscPolymorphicSubroutine(PetscSequentialPhaseBegin,(void),(PETSC_COMM_WORLD,1))
1098 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSequentialPhaseEnd(MPI_Comm,PetscMPIInt);
1099 PetscPolymorphicSubroutine(PetscSequentialPhaseEnd,(MPI_Comm comm),(comm,1))
1100 PetscPolymorphicSubroutine(PetscSequentialPhaseEnd,(void),(PETSC_COMM_WORLD,1))
1101 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscBarrier(PetscObject);
1102 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMPIDump(FILE*);
1103 
1104 #define PetscNot(a) ((a) ? PETSC_FALSE : PETSC_TRUE)
1105 /*
1106     Defines basic graphics available from PETSc.
1107 */
1108 #include "petscdraw.h"
1109 
1110 /*
1111     Defines the base data structures for all PETSc objects
1112 */
1113 #include "petschead.h"
1114 
1115 /*
1116      Defines PETSc profiling.
1117 */
1118 #include "petsclog.h"
1119 
1120 /*
1121           For locking, unlocking and destroying AMS memories associated with
1122     PETSc objects. Not currently used.
1123 */
1124 #define PetscPublishAll(v)           0
1125 #define PetscObjectTakeAccess(obj)   0
1126 #define PetscObjectGrantAccess(obj)  0
1127 #define PetscObjectDepublish(obj)    0
1128 
1129 
1130 
1131 /*
1132       This code allows one to pass a MPI communicator between
1133     C and Fortran. MPI 2.0 defines a standard API for doing this.
1134     The code here is provided to allow PETSc to work with MPI 1.1
1135     standard MPI libraries.
1136 */
1137 EXTERN PetscErrorCode MPICCommToFortranComm(MPI_Comm,int *);
1138 EXTERN PetscErrorCode MPIFortranCommToCComm(int,MPI_Comm*);
1139 
1140 /*
1141       Simple PETSc parallel IO for ASCII printing
1142 */
1143 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscFixFilename(const char[],char[]);
1144 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscFOpen(MPI_Comm,const char[],const char[],FILE**);
1145 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscFClose(MPI_Comm,FILE*);
1146 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4);
1147 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscPrintf(MPI_Comm,const char[],...)  PETSC_PRINTF_FORMAT_CHECK(2,3);
1148 
1149 /* These are used internally by PETSc ASCII IO routines*/
1150 #include <stdarg.h>
1151 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscVSNPrintf(char*,size_t,const char*,va_list);
1152 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscVFPrintf(FILE*,const char*,va_list);
1153 
1154 /*MC
1155     PetscErrorPrintf - Prints error messages.
1156 
1157     Not Collective
1158 
1159    Synopsis:
1160      PetscErrorCode (*PetscErrorPrintf)(const char format[],...);
1161 
1162     Input Parameters:
1163 .   format - the usual printf() format string
1164 
1165    Options Database Keys:
1166 .    -error_output_stderr - cause error messages to be printed to stderr instead of the
1167          (default) stdout
1168 
1169 
1170    Level: developer
1171 
1172     Fortran Note:
1173     This routine is not supported in Fortran.
1174 
1175     Concepts: error messages^printing
1176     Concepts: printing^error messages
1177 
1178 .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf()
1179 M*/
1180 EXTERN PETSC_DLLEXPORT PetscErrorCode (*PetscErrorPrintf)(const char[],...);
1181 
1182 /*MC
1183     PetscHelpPrintf - Prints help messages.
1184 
1185     Not Collective
1186 
1187    Synopsis:
1188      PetscErrorCode (*PetscHelpPrintf)(const char format[],...);
1189 
1190     Input Parameters:
1191 .   format - the usual printf() format string
1192 
1193    Level: developer
1194 
1195     Fortran Note:
1196     This routine is not supported in Fortran.
1197 
1198     Concepts: help messages^printing
1199     Concepts: printing^help messages
1200 
1201 .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscErrorPrintf()
1202 M*/
1203 EXTERN PETSC_DLLEXPORT PetscErrorCode  (*PetscHelpPrintf)(MPI_Comm,const char[],...);
1204 
1205 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscPOpen(MPI_Comm,const char[],const char[],const char[],FILE **);
1206 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscPClose(MPI_Comm,FILE*);
1207 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscSynchronizedPrintf(MPI_Comm,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3);
1208 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscSynchronizedFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4);
1209 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscSynchronizedFlush(MPI_Comm);
1210 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscSynchronizedFGets(MPI_Comm,FILE*,size_t,char[]);
1211 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscStartMatlab(MPI_Comm,const char[],const char[],FILE**);
1212 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscStartJava(MPI_Comm,const char[],const char[],FILE**);
1213 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscGetPetscDir(const char*[]);
1214 
1215 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscPopUpSelect(MPI_Comm,char*,char*,int,char**,int*);
1216 /*S
1217      PetscObjectContainer - Simple PETSc object that contains a pointer to any required data
1218 
1219    Level: advanced
1220 
1221 .seealso:  PetscObject, PetscObjectContainerCreate()
1222 S*/
1223 typedef struct _p_PetscObjectContainer*  PetscObjectContainer;
1224 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectContainerGetPointer(PetscObjectContainer,void **);
1225 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectContainerSetPointer(PetscObjectContainer,void *);
1226 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectContainerDestroy(PetscObjectContainer);
1227 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectContainerCreate(MPI_Comm comm,PetscObjectContainer *);
1228 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectContainerSetUserDestroy(PetscObjectContainer, PetscErrorCode (*)(void*));
1229 
1230 /*
1231    For use in debuggers
1232 */
1233 extern PETSC_DLLEXPORT PetscMPIInt PetscGlobalRank;
1234 extern PETSC_DLLEXPORT PetscMPIInt PetscGlobalSize;
1235 
1236 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscIntView(PetscInt,PetscInt[],PetscViewer);
1237 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRealView(PetscInt,PetscReal[],PetscViewer);
1238 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscScalarView(PetscInt,PetscScalar[],PetscViewer);
1239 
1240 /*
1241     Allows accessing Matlab Engine
1242 */
1243 #include "petscmatlab.h"
1244 
1245 /*
1246     C code optimization is often enhanced by telling the compiler
1247   that certain pointer arguments to functions are not aliased to
1248   to other arguments. This is not yet ANSI C standard so we define
1249   the macro "restrict" to indicate that the variable is not aliased
1250   to any other argument.
1251 */
1252 #if defined(PETSC_HAVE_RESTRICT) && !defined(__cplusplus)
1253 #define restrict _Restrict
1254 #else
1255 #if defined(restrict)
1256 #undef restrict
1257 #endif
1258 #define restrict
1259 #endif
1260 
1261 /*
1262       Determine if some of the kernel computation routines use
1263    Fortran (rather than C) for the numerical calculations. On some machines
1264    and compilers (like complex numbers) the Fortran version of the routines
1265    is faster than the C/C++ versions. The flag PETSC_USE_FORTRAN_KERNELS
1266    would be set in the petscconf.h file
1267 */
1268 #if defined(PETSC_USE_FORTRAN_KERNELS)
1269 
1270 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ)
1271 #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ
1272 #endif
1273 
1274 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ)
1275 #define PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ
1276 #endif
1277 
1278 #if !defined(PETSC_USE_FORTRAN_KERNEL_NORM)
1279 #define PETSC_USE_FORTRAN_KERNEL_NORM
1280 #endif
1281 
1282 #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY)
1283 #define PETSC_USE_FORTRAN_KERNEL_MAXPY
1284 #endif
1285 
1286 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ)
1287 #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ
1288 #endif
1289 
1290 #if !defined(PETSC_USE_FORTRAN_KERNEL_RELAXAIJ)
1291 #define PETSC_USE_FORTRAN_KERNEL_RELAXAIJ
1292 #endif
1293 
1294 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ)
1295 #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ
1296 #endif
1297 
1298 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ)
1299 #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ
1300 #endif
1301 
1302 #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT)
1303 #define PETSC_USE_FORTRAN_KERNEL_MDOT
1304 #endif
1305 
1306 #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY)
1307 #define PETSC_USE_FORTRAN_KERNEL_XTIMESY
1308 #endif
1309 
1310 #if !defined(PETSC_USE_FORTRAN_KERNEL_AYPX)
1311 #define PETSC_USE_FORTRAN_KERNEL_AYPX
1312 #endif
1313 
1314 #if !defined(PETSC_USE_FORTRAN_KERNEL_WAXPY)
1315 #define PETSC_USE_FORTRAN_KERNEL_WAXPY
1316 #endif
1317 
1318 #endif
1319 
1320 /*
1321     Macros for indicating code that should be compiled with a C interface,
1322    rather than a C++ interface. Any routines that are dynamically loaded
1323    (such as the PCCreate_XXX() routines) must be wrapped so that the name
1324    mangler does not change the functions symbol name. This just hides the
1325    ugly extern "C" {} wrappers.
1326 */
1327 #if defined(__cplusplus)
1328 #define EXTERN_C_BEGIN extern "C" {
1329 #define EXTERN_C_END }
1330 #else
1331 #define EXTERN_C_BEGIN
1332 #define EXTERN_C_END
1333 #endif
1334 
1335 /* --------------------------------------------------------------------*/
1336 
1337 /*M
1338     size - integer variable used to contain the number of processors in
1339            the relevent MPI_Comm
1340 
1341    Level: beginner
1342 
1343 .seealso: rank, comm
1344 M*/
1345 
1346 /*M
1347     rank - integer variable used to contain the number of this processor relative
1348            to all in the relevent MPI_Comm
1349 
1350    Level: beginner
1351 
1352 .seealso: size, comm
1353 M*/
1354 
1355 /*M
1356     comm - MPI_Comm used in the current routine or object
1357 
1358    Level: beginner
1359 
1360 .seealso: size, rank
1361 M*/
1362 
1363 /*M
1364     MPI_Comm - the basic object used by MPI to determine which processes are involved in a
1365         communication
1366 
1367    Level: beginner
1368 
1369    Note: This manual page is a place-holder because MPICH does not have a manual page for MPI_Comm
1370 
1371 .seealso: size, rank, comm, PETSC_COMM_WORLD, PETSC_COMM_SELF
1372 M*/
1373 
1374 /*M
1375     PetscScalar - PETSc type that represents either a double precision real number or
1376        a double precision complex number if the code is configured with --with-scalar-type=complex
1377 
1378    Level: beginner
1379 
1380 .seealso: PetscReal, PassiveReal, PassiveScalar
1381 M*/
1382 
1383 /*M
1384     PetscReal - PETSc type that represents a double precision real number
1385 
1386    Level: beginner
1387 
1388 .seealso: PetscScalar, PassiveReal, PassiveScalar
1389 M*/
1390 
1391 /*M
1392     PassiveScalar - PETSc type that represents either a double precision real number or
1393        a double precision complex number if the code is  code is configured with --with-scalar-type=complex
1394 
1395    Level: beginner
1396 
1397     This is the same as a PetscScalar except in code that is automatically differentiated it is
1398    treated as a constant (not an indendent or dependent variable)
1399 
1400 .seealso: PetscReal, PassiveReal, PetscScalar
1401 M*/
1402 
1403 /*M
1404     PassiveReal - PETSc type that represents a double precision real number
1405 
1406    Level: beginner
1407 
1408     This is the same as a PetscReal except in code that is automatically differentiated it is
1409    treated as a constant (not an indendent or dependent variable)
1410 
1411 .seealso: PetscScalar, PetscReal, PassiveScalar
1412 M*/
1413 
1414 /*M
1415     MPIU_SCALAR - MPI datatype corresponding to PetscScalar
1416 
1417    Level: beginner
1418 
1419     Note: In MPI calls that require an MPI datatype that matches a PetscScalar or array of PetscScalars
1420           pass this value
1421 
1422 .seealso: PetscReal, PassiveReal, PassiveScalar, PetscScalar
1423 M*/
1424 
1425 /*
1426      The IBM include files define hz, here we hide it so that it may be used
1427    as a regular user variable.
1428 */
1429 #if defined(hz)
1430 #undef hz
1431 #endif
1432 
1433 /*  For arrays that contain filenames or paths */
1434 
1435 
1436 #if defined(PETSC_HAVE_LIMITS_H)
1437 #include <limits.h>
1438 #endif
1439 #if defined(PETSC_HAVE_SYS_PARAM_H)
1440 #include <sys/param.h>
1441 #endif
1442 #if defined(PETSC_HAVE_SYS_TYPES_H)
1443 #include <sys/types.h>
1444 #endif
1445 #if defined(MAXPATHLEN)
1446 #  define PETSC_MAX_PATH_LEN     MAXPATHLEN
1447 #elif defined(MAX_PATH)
1448 #  define PETSC_MAX_PATH_LEN     MAX_PATH
1449 #elif defined(_MAX_PATH)
1450 #  define PETSC_MAX_PATH_LEN     _MAX_PATH
1451 #else
1452 #  define PETSC_MAX_PATH_LEN     4096
1453 #endif
1454 
1455 PETSC_EXTERN_CXX_END
1456 #endif
1457 
1458 
1459