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