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