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