xref: /petsc/include/petsc.h (revision be29d3c6887e35e9e43a4f137c8657ac14f8b020)
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    PetscNew - Allocates memory of a particular type, Zeros the memory!
519 
520    Input Parameter:
521 . type - structure name of space to be allocated. Memory of size sizeof(type) is allocated
522 
523    Output Parameter:
524 .  result - memory allocated
525 
526    Synopsis:
527    PetscErrorCode PetscNew(struct type,((type *))result)
528 
529    Level: beginner
530 
531 .seealso: PetscFree(), PetscMalloc()
532 
533   Concepts: memory allocation
534 
535 M*/
536 #define PetscNew(A,b)        (PetscMalloc(sizeof(A),(b)) || PetscMemzero(*(b),sizeof(A)))
537 
538 /*MC
539    PetscFree - Frees memory
540 
541    Input Parameter:
542 .   memory - memory to free
543 
544    Synopsis:
545    PetscErrorCode PetscFree(void *memory)
546 
547    Level: beginner
548 
549    Notes: Memory must have been obtained with PetscNew() or PetscMalloc()
550 
551 .seealso: PetscNew(), PetscMalloc()
552 
553   Concepts: memory allocation
554 
555 M*/
556 #define PetscFree(a)   ((a) ? ((*PetscTrFree)((a),__LINE__,__FUNCT__,__FILE__,__SDIR__) || ((a = 0),0)) : 0)
557 
558 /*MC
559    PetscFree2 - Frees 2 chunks of memory obtained with PetscMalloc2()
560 
561    Input Parameter:
562 +   memory1 - memory to free
563 -   memory2 - 2nd memory to free
564 
565 
566    Synopsis:
567    PetscErrorCode PetscFree2(void *memory1,void *memory2)
568 
569    Level: developer
570 
571    Notes: Memory must have been obtained with PetscMalloc2()
572 
573 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree()
574 
575   Concepts: memory allocation
576 
577 M*/
578 #if defined(PETSC_USE_DEBUG)
579 #define PetscFree2(m1,m2)   (PetscFree(m2) || PetscFree(m1))
580 #else
581 #define PetscFree2(m1,m2)   (PetscFree(m1))
582 #endif
583 
584 /*MC
585    PetscFree3 - Frees 3 chunks of memory obtained with PetscMalloc3()
586 
587    Input Parameter:
588 +   memory1 - memory to free
589 .   memory2 - 2nd memory to free
590 -   memory3 - 3rd memory to free
591 
592 
593    Synopsis:
594    PetscErrorCode PetscFree3(void *memory1,void *memory2,void *memory3)
595 
596    Level: developer
597 
598    Notes: Memory must have been obtained with PetscMalloc3()
599 
600 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3()
601 
602   Concepts: memory allocation
603 
604 M*/
605 #if defined(PETSC_USE_DEBUG)
606 #define PetscFree3(m1,m2,m3)   (PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
607 #else
608 #define PetscFree3(m1,m2,m3)   (PetscFree(m1))
609 #endif
610 
611 /*MC
612    PetscFree4 - Frees 4 chunks of memory obtained with PetscMalloc4()
613 
614    Input Parameter:
615 +   m1 - memory to free
616 .   m2 - 2nd memory to free
617 .   m3 - 3rd memory to free
618 -   m4 - 4th memory to free
619 
620 
621    Synopsis:
622    PetscErrorCode PetscFree4(void *m1,void *m2,void *m3,void *m4)
623 
624    Level: developer
625 
626    Notes: Memory must have been obtained with PetscMalloc4()
627 
628 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4()
629 
630   Concepts: memory allocation
631 
632 M*/
633 #if defined(PETSC_USE_DEBUG)
634 #define PetscFree4(m1,m2,m3,m4)   (PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
635 #else
636 #define PetscFree4(m1,m2,m3,m4)   (PetscFree(m1))
637 #endif
638 
639 /*MC
640    PetscFree5 - Frees 5 chunks of memory obtained with PetscMalloc5()
641 
642    Input Parameter:
643 +   m1 - memory to free
644 .   m2 - 2nd memory to free
645 .   m3 - 3rd memory to free
646 .   m4 - 4th memory to free
647 -   m5 - 5th memory to free
648 
649 
650    Synopsis:
651    PetscErrorCode PetscFree5(void *m1,void *m2,void *m3,void *m4,void *m5)
652 
653    Level: developer
654 
655    Notes: Memory must have been obtained with PetscMalloc5()
656 
657 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5()
658 
659   Concepts: memory allocation
660 
661 M*/
662 #if defined(PETSC_USE_DEBUG)
663 #define PetscFree5(m1,m2,m3,m4,m5)   (PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
664 #else
665 #define PetscFree5(m1,m2,m3,m4,m5)   (PetscFree(m1))
666 #endif
667 
668 
669 /*MC
670    PetscFree6 - Frees 6 chunks of memory obtained with PetscMalloc6()
671 
672    Input Parameter:
673 +   m1 - memory to free
674 .   m2 - 2nd memory to free
675 .   m3 - 3rd memory to free
676 .   m4 - 4th memory to free
677 .   m5 - 5th memory to free
678 -   m6 - 6th memory to free
679 
680 
681    Synopsis:
682    PetscErrorCode PetscFree6(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6)
683 
684    Level: developer
685 
686    Notes: Memory must have been obtained with PetscMalloc6()
687 
688 .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5(), PetscMalloc6()
689 
690   Concepts: memory allocation
691 
692 M*/
693 #if defined(PETSC_USE_DEBUG)
694 #define PetscFree6(m1,m2,m3,m4,m5,m6)   (PetscFree(m6) || PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
695 #else
696 #define PetscFree6(m1,m2,m3,m4,m5,m6)   (PetscFree(m1))
697 #endif
698 
699 EXTERN PETSC_DLLEXPORT PetscErrorCode (*PetscTrMalloc)(size_t,int,const char[],const char[],const char[],void**);
700 EXTERN PETSC_DLLEXPORT PetscErrorCode (*PetscTrFree)(void*,int,const char[],const char[],const char[]);
701 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[]));
702 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscClearMalloc(void);
703 
704 /*
705    Routines for tracing memory corruption/bleeding with default PETSc
706    memory allocation
707 */
708 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMallocDump(FILE *);
709 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMallocDumpLog(FILE *);
710 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMallocGetCurrentUsage(PetscLogDouble *);
711 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMallocGetMaximumUsage(PetscLogDouble *);
712 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMallocDebug(PetscTruth);
713 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMallocValidate(int,const char[],const char[],const char[]);
714 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMallocSetDumpLog(void);
715 
716 
717 /*
718     Variable type where we stash PETSc object pointers in Fortran.
719     Assumes that sizeof(long) == sizeof(void*)which is true on
720     all machines that we know.
721 */
722 #define PetscFortranAddr   long
723 
724 /*E
725     PetscDataType - Used for handling different basic data types.
726 
727    Level: beginner
728 
729 .seealso: PetscBinaryRead(), PetscBinaryWrite(), PetscDataTypeToMPIDataType(),
730           PetscDataTypeGetSize(), PetscDataTypeGetName()
731 
732 E*/
733 typedef enum {PETSC_INT = 0,PETSC_DOUBLE = 1,PETSC_COMPLEX = 2,
734               PETSC_LONG = 3 ,PETSC_SHORT = 4,PETSC_FLOAT = 5,
735               PETSC_CHAR = 6,PETSC_LOGICAL = 7} PetscDataType;
736 #if defined(PETSC_USE_COMPLEX)
737 #define PETSC_SCALAR PETSC_COMPLEX
738 #else
739 #if defined(PETSC_USE_SINGLE)
740 #define PETSC_SCALAR PETSC_FLOAT
741 #else
742 #define PETSC_SCALAR PETSC_DOUBLE
743 #endif
744 #endif
745 #if defined(PETSC_USE_SINGLE)
746 #define PETSC_REAL PETSC_FLOAT
747 #else
748 #define PETSC_REAL PETSC_DOUBLE
749 #endif
750 #define PETSC_FORTRANADDR PETSC_LONG
751 
752 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDataTypeToMPIDataType(PetscDataType,MPI_Datatype*);
753 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDataTypeGetSize(PetscDataType,PetscInt*);
754 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDataTypeGetName(PetscDataType,const char*[]);
755 
756 /*
757     Basic memory and string operations. These are usually simple wrappers
758    around the basic Unix system calls, but a few of them have additional
759    functionality and/or error checking.
760 */
761 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMemcpy(void*,const void *,size_t);
762 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscBitMemcpy(void*,PetscInt,const void*,PetscInt,PetscInt,PetscDataType);
763 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMemmove(void*,void *,size_t);
764 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMemzero(void*,size_t);
765 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscMemcmp(const void*,const void*,size_t,PetscTruth *);
766 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrlen(const char[],size_t*);
767 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrcmp(const char[],const char[],PetscTruth *);
768 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrgrt(const char[],const char[],PetscTruth *);
769 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrcasecmp(const char[],const char[],PetscTruth*);
770 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrncmp(const char[],const char[],size_t,PetscTruth*);
771 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrcpy(char[],const char[]);
772 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrcat(char[],const char[]);
773 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrncat(char[],const char[],size_t);
774 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrncpy(char[],const char[],size_t);
775 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrchr(const char[],char,char *[]);
776 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrtolower(char[]);
777 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrrchr(const char[],char,char *[]);
778 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrstr(const char[],const char[],char *[]);
779 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrallocpy(const char[],char *[]);
780 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscStrreplace(MPI_Comm,const char[],char[],size_t);
781 #define      PetscStrfree(a) ((a) ? PetscFree(a) : 0)
782 /*S
783     PetscToken - 'Token' used for managing tokenizing strings
784 
785   Level: intermediate
786 
787 .seealso: PetscTokenCreate(), PetscTokenFind(), PetscTokenDestroy()
788 S*/
789 typedef struct {char token;char *array;char *current;} PetscToken;
790 
791 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscTokenCreate(const char[],const char,PetscToken**);
792 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscTokenFind(PetscToken*,char *[]);
793 EXTERN PetscErrorCode PETSC_DLLEXPORT   PetscTokenDestroy(PetscToken*);
794 
795 /*
796    These are  MPI operations for MPI_Allreduce() etc
797 */
798 EXTERN PETSC_DLLEXPORT MPI_Op PetscMaxSum_Op;
799 #if defined(PETSC_USE_COMPLEX)
800 EXTERN PETSC_DLLEXPORT MPI_Op PetscSum_Op;
801 #else
802 #define PetscSum_Op MPI_SUM
803 #endif
804 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMaxSum(MPI_Comm,const PetscInt[],PetscInt*,PetscInt*);
805 
806 /*S
807      PetscObject - any PETSc object, PetscViewer, Mat, Vec, KSP etc
808 
809    Level: beginner
810 
811    Note: This is the base class from which all objects appear.
812 
813 .seealso:  PetscObjectDestroy(), PetscObjectView(), PetscObjectGetName(), PetscObjectSetName()
814 S*/
815 typedef struct _p_PetscObject* PetscObject;
816 
817 /*S
818      PetscFList - Linked list of functions, possibly stored in dynamic libraries, accessed
819       by string name
820 
821    Level: advanced
822 
823 .seealso:  PetscFListAdd(), PetscFListDestroy()
824 S*/
825 typedef struct _PetscFList *PetscFList;
826 
827 #include "petscviewer.h"
828 #include "petscoptions.h"
829 
830 /*
831    Routines that get memory usage information from the OS
832 */
833 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemoryGetCurrentUsage(PetscLogDouble *);
834 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemoryGetMaximumUsage(PetscLogDouble *);
835 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemorySetGetMaximumUsage(void);
836 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMemoryShowUsage(PetscViewer,const char[]);
837 
838 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscLogInfoAllow(PetscTruth,const char []);
839 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetTime(PetscLogDouble*);
840 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetCPUTime(PetscLogDouble*);
841 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSleep(int);
842 
843 /*
844     Initialization of PETSc
845 */
846 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscInitialize(int*,char***,const char[],const char[]);
847 PetscPolymorphicSubroutine(PetscInitialize,(int *argc,char ***args),(argc,args,PETSC_NULL,PETSC_NULL))
848 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscInitializeNoArguments(void);
849 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscInitialized(PetscTruth *);
850 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFinalized(PetscTruth *);
851 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFinalize(void);
852 EXTERN PetscErrorCode PetscInitializeFortran(void);
853 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscGetArgs(int*,char ***);
854 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscEnd(void);
855 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscInitializePackage(char *);
856 typedef void (**PetscVoidFunction)(void);
857 
858 /*
859    PetscTryMethod - Queries an object for a method, if it exists then calls it.
860               These are intended to be used only inside PETSc functions.
861 */
862 #define  PetscTryMethod(obj,A,B,C) \
863   0;{ PetscErrorCode (*f)B, __ierr; \
864     __ierr = PetscObjectQueryFunction((PetscObject)obj,#A,(PetscVoidFunction)&f);CHKERRQ(__ierr); \
865     if (f) {__ierr = (*f)C;CHKERRQ(__ierr);}\
866   }
867 #define  PetscUseMethod(obj,A,B,C) \
868   0;{ PetscErrorCode (*f)B, __ierr; \
869     __ierr = PetscObjectQueryFunction((PetscObject)obj,A,(PetscVoidFunction)&f);CHKERRQ(__ierr); \
870     if (f) {__ierr = (*f)C;CHKERRQ(__ierr);}\
871     else {SETERRQ1(PETSC_ERR_SUP,"Cannot locate function %s in object",A);} \
872   }
873 /*
874     Functions that can act on any PETSc object.
875 */
876 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectDestroy(PetscObject);
877 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectExists(PetscObject,PetscTruth*);
878 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetComm(PetscObject,MPI_Comm *);
879 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetCookie(PetscObject,int *);
880 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetType(PetscObject,int *);
881 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectSetName(PetscObject,const char[]);
882 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetName(PetscObject,char*[]);
883 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectReference(PetscObject);
884 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetReference(PetscObject,PetscInt*);
885 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectDereference(PetscObject);
886 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetNewTag(PetscObject,PetscMPIInt *);
887 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscCommGetNewTag(MPI_Comm,PetscMPIInt *);
888 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectView(PetscObject,PetscViewer);
889 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectCompose(PetscObject,const char[],PetscObject);
890 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectQuery(PetscObject,const char[],PetscObject *);
891 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectComposeFunction(PetscObject,const char[],const char[],void (*)(void));
892 
893 typedef void (*FCNVOID)(void); /* cast in next macro should never be extern C */
894 typedef PetscErrorCode (*FCNINTVOID)(void); /* used in casts to make sure they are not extern C */
895 /*MC
896    PetscObjectComposeFunctionDynamic - Associates a function with a given PETSc object.
897 
898    Collective on PetscObject
899 
900    Input Parameters:
901 +  obj - the PETSc object; this must be cast with a (PetscObject), for example,
902          PetscObjectCompose((PetscObject)mat,...);
903 .  name - name associated with the child function
904 .  fname - name of the function
905 -  ptr - function pointer (or PETSC_NULL if using dynamic libraries)
906 
907    Level: advanced
908 
909     Synopsis:
910     PetscErrorCode PetscObjectComposeFunctionDynamic(PetscObject obj,const char name[],const char fname[],void *ptr)
911 
912    Notes:
913    To remove a registered routine, pass in a PETSC_NULL rname and fnc().
914 
915    PetscObjectComposeFunctionDynamic() can be used with any PETSc object (such as
916    Mat, Vec, KSP, SNES, etc.) or any user-provided object.
917 
918    The composed function must be wrapped in a EXTERN_C_BEGIN/END for this to
919    work in C++/complex with dynamic link libraries (PETSC_USE_DYNAMIC_LIBRARIES)
920    enabled.
921 
922    Concepts: objects^composing functions
923    Concepts: composing functions
924    Concepts: functions^querying
925    Concepts: objects^querying
926    Concepts: querying objects
927 
928 .seealso: PetscObjectQueryFunction()
929 M*/
930 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
931 #define PetscObjectComposeFunctionDynamic(a,b,c,d) PetscObjectComposeFunction(a,b,c,0)
932 #else
933 #define PetscObjectComposeFunctionDynamic(a,b,c,d) PetscObjectComposeFunction(a,b,c,(FCNVOID)(d))
934 #endif
935 
936 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectQueryFunction(PetscObject,const char[],void (**)(void));
937 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectSetOptionsPrefix(PetscObject,const char[]);
938 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectAppendOptionsPrefix(PetscObject,const char[]);
939 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectPrependOptionsPrefix(PetscObject,const char[]);
940 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectGetOptionsPrefix(PetscObject,char*[]);
941 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectPublish(PetscObject);
942 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectChangeTypeName(PetscObject,const char[]);
943 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectRegisterDestroy(PetscObject);
944 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectRegisterDestroyAll(void);
945 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectName(PetscObject);
946 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscTypeCompare(PetscObject,const char[],PetscTruth*);
947 
948 /*
949     Defines PETSc error handling.
950 */
951 #include "petscerror.h"
952 
953 /*S
954      PetscOList - Linked list of PETSc objects, accessable by string name
955 
956    Level: advanced
957 
958 .seealso:  PetscOListAdd(), PetscOListDestroy(), PetscOListFind()
959 S*/
960 typedef struct _PetscOList *PetscOList;
961 
962 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOListDestroy(PetscOList *);
963 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOListFind(PetscOList,const char[],PetscObject*);
964 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOListReverseFind(PetscOList,PetscObject,char**);
965 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOListAdd(PetscOList *,const char[],PetscObject);
966 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscOListDuplicate(PetscOList,PetscOList *);
967 
968 /*
969     Dynamic library lists. Lists of names of routines in dynamic
970   link libraries that will be loaded as needed.
971 */
972 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListAdd(PetscFList*,const char[],const char[],void (*)(void));
973 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListDestroy(PetscFList*);
974 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListFind(MPI_Comm,PetscFList,const char[],void (**)(void));
975 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListPrintTypes(MPI_Comm,FILE*,const char[],const char[],const char[],const char[],PetscFList);
976 #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
977 #define    PetscFListAddDynamic(a,b,p,c) PetscFListAdd(a,b,p,0)
978 #else
979 #define    PetscFListAddDynamic(a,b,p,c) PetscFListAdd(a,b,p,(void (*)(void))c)
980 #endif
981 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListDuplicate(PetscFList,PetscFList *);
982 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListView(PetscFList,PetscViewer);
983 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListConcat(const char [],const char [],char []);
984 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscFListGet(PetscFList,char ***,int*);
985 
986 /*S
987      PetscDLLibraryList - Linked list of dynamics libraries to search for functions
988 
989    Level: advanced
990 
991    PETSC_USE_DYNAMIC_LIBRARIES must be defined in petscconf.h to use dynamic libraries
992 
993 .seealso:  PetscDLLibraryOpen()
994 S*/
995 typedef struct _PetscDLLibraryList *PetscDLLibraryList;
996 extern PetscDLLibraryList DLLibrariesLoaded;
997 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryRetrieve(MPI_Comm,const char[],char *,int,PetscTruth *);
998 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryOpen(MPI_Comm,const char[],void **);
999 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibrarySym(MPI_Comm,PetscDLLibraryList *,const char[],const char[],void **);
1000 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryAppend(MPI_Comm,PetscDLLibraryList *,const char[]);
1001 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryPrepend(MPI_Comm,PetscDLLibraryList *,const char[]);
1002 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryClose(PetscDLLibraryList);
1003 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryPrintPath(void);
1004 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscDLLibraryGetInfo(void*,const char[],const char *[]);
1005 
1006 /*
1007     Mechanism for translating PETSc object representations between languages
1008     Not currently used.
1009 */
1010 typedef enum {PETSC_LANGUAGE_C,PETSC_LANGUAGE_CXX} PetscLanguage;
1011 #define PETSC_LANGUAGE_F77 PETSC_LANGUAGE_C
1012 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectComposeLanguage(PetscObject,PetscLanguage,void *);
1013 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectQueryLanguage(PetscObject,PetscLanguage,void **);
1014 
1015 /*
1016      Useful utility routines
1017 */
1018 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSplitOwnership(MPI_Comm,PetscInt*,PetscInt*);
1019 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSplitOwnershipBlock(MPI_Comm,PetscInt,PetscInt*,PetscInt*);
1020 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSequentialPhaseBegin(MPI_Comm,PetscMPIInt);
1021 PetscPolymorphicSubroutine(PetscSequentialPhaseBegin,(MPI_Comm comm),(comm,1))
1022 PetscPolymorphicSubroutine(PetscSequentialPhaseBegin,(void),(PETSC_COMM_WORLD,1))
1023 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscSequentialPhaseEnd(MPI_Comm,PetscMPIInt);
1024 PetscPolymorphicSubroutine(PetscSequentialPhaseEnd,(MPI_Comm comm),(comm,1))
1025 PetscPolymorphicSubroutine(PetscSequentialPhaseEnd,(void),(PETSC_COMM_WORLD,1))
1026 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscBarrier(PetscObject);
1027 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscMPIDump(FILE*);
1028 
1029 #define PetscNot(a) ((a) ? PETSC_FALSE : PETSC_TRUE)
1030 /*
1031     Defines basic graphics available from PETSc.
1032 */
1033 #include "petscdraw.h"
1034 
1035 /*
1036     Defines the base data structures for all PETSc objects
1037 */
1038 #include "petschead.h"
1039 
1040 /*
1041      Defines PETSc profiling.
1042 */
1043 #include "petsclog.h"
1044 
1045 /*
1046           For locking, unlocking and destroying AMS memories associated with
1047     PETSc objects. Not currently used.
1048 */
1049 #define PetscPublishAll(v)           0
1050 #define PetscObjectTakeAccess(obj)   0
1051 #define PetscObjectGrantAccess(obj)  0
1052 #define PetscObjectDepublish(obj)    0
1053 
1054 
1055 
1056 /*
1057       This code allows one to pass a MPI communicator between
1058     C and Fortran. MPI 2.0 defines a standard API for doing this.
1059     The code here is provided to allow PETSc to work with MPI 1.1
1060     standard MPI libraries.
1061 */
1062 EXTERN PetscErrorCode MPICCommToFortranComm(MPI_Comm,int *);
1063 EXTERN PetscErrorCode MPIFortranCommToCComm(int,MPI_Comm*);
1064 
1065 /*
1066       Simple PETSc parallel IO for ASCII printing
1067 */
1068 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscFixFilename(const char[],char[]);
1069 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscFOpen(MPI_Comm,const char[],const char[],FILE**);
1070 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscFClose(MPI_Comm,FILE*);
1071 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4);
1072 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscPrintf(MPI_Comm,const char[],...)  PETSC_PRINTF_FORMAT_CHECK(2,3);
1073 
1074 /* These are used internally by PETSc ASCII IO routines*/
1075 #include <stdarg.h>
1076 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscVSNPrintf(char*,size_t,const char*,va_list);
1077 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscVFPrintf(FILE*,const char*,va_list);
1078 
1079 /*MC
1080     PetscErrorPrintf - Prints error messages.
1081 
1082     Not Collective
1083 
1084    Synopsis:
1085      PetscErrorCode (*PetscErrorPrintf)(const char format[],...);
1086 
1087     Input Parameters:
1088 .   format - the usual printf() format string
1089 
1090    Options Database Keys:
1091 .    -error_output_stderr - cause error messages to be printed to stderr instead of the
1092          (default) stdout
1093 
1094 
1095    Level: developer
1096 
1097     Fortran Note:
1098     This routine is not supported in Fortran.
1099 
1100     Concepts: error messages^printing
1101     Concepts: printing^error messages
1102 
1103 .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf()
1104 M*/
1105 EXTERN PETSC_DLLEXPORT PetscErrorCode (*PetscErrorPrintf)(const char[],...);
1106 
1107 /*MC
1108     PetscHelpPrintf - Prints help messages.
1109 
1110     Not Collective
1111 
1112    Synopsis:
1113      PetscErrorCode (*PetscHelpPrintf)(const char format[],...);
1114 
1115     Input Parameters:
1116 .   format - the usual printf() format string
1117 
1118    Level: developer
1119 
1120     Fortran Note:
1121     This routine is not supported in Fortran.
1122 
1123     Concepts: help messages^printing
1124     Concepts: printing^help messages
1125 
1126 .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscErrorPrintf()
1127 M*/
1128 EXTERN PETSC_DLLEXPORT PetscErrorCode  (*PetscHelpPrintf)(MPI_Comm,const char[],...);
1129 
1130 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscPOpen(MPI_Comm,const char[],const char[],const char[],FILE **);
1131 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscPClose(MPI_Comm,FILE*);
1132 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscSynchronizedPrintf(MPI_Comm,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3);
1133 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscSynchronizedFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4);
1134 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscSynchronizedFlush(MPI_Comm);
1135 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscSynchronizedFGets(MPI_Comm,FILE*,size_t,char[]);
1136 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscStartMatlab(MPI_Comm,const char[],const char[],FILE**);
1137 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscStartJava(MPI_Comm,const char[],const char[],FILE**);
1138 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscGetPetscDir(const char*[]);
1139 
1140 EXTERN PetscErrorCode PETSC_DLLEXPORT  PetscPopUpSelect(MPI_Comm,char*,char*,int,char**,int*);
1141 /*S
1142      PetscObjectContainer - Simple PETSc object that contains a pointer to any required data
1143 
1144    Level: advanced
1145 
1146 .seealso:  PetscObject, PetscObjectContainerCreate()
1147 S*/
1148 typedef struct _p_PetscObjectContainer*  PetscObjectContainer;
1149 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectContainerGetPointer(PetscObjectContainer,void **);
1150 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectContainerSetPointer(PetscObjectContainer,void *);
1151 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectContainerDestroy(PetscObjectContainer);
1152 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectContainerCreate(MPI_Comm comm,PetscObjectContainer *);
1153 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscObjectContainerSetUserDestroy(PetscObjectContainer, PetscErrorCode (*)(void*));
1154 
1155 /*
1156    For use in debuggers
1157 */
1158 extern PETSC_DLLEXPORT int PetscGlobalRank;
1159 extern PETSC_DLLEXPORT int PetscGlobalSize;
1160 
1161 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscIntView(PetscInt,PetscInt[],PetscViewer);
1162 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscRealView(PetscInt,PetscReal[],PetscViewer);
1163 EXTERN PetscErrorCode PETSC_DLLEXPORT PetscScalarView(PetscInt,PetscScalar[],PetscViewer);
1164 
1165 /*
1166     Allows accessing Matlab Engine
1167 */
1168 #include "petscmatlab.h"
1169 
1170 /*
1171     C code optimization is often enhanced by telling the compiler
1172   that certain pointer arguments to functions are not aliased to
1173   to other arguments. This is not yet ANSI C standard so we define
1174   the macro "restrict" to indicate that the variable is not aliased
1175   to any other argument.
1176 */
1177 #if defined(PETSC_HAVE_RESTRICT) && !defined(__cplusplus)
1178 #define restrict _Restrict
1179 #else
1180 #if defined(restrict)
1181 #undef restrict
1182 #endif
1183 #define restrict
1184 #endif
1185 
1186 /*
1187       Determine if some of the kernel computation routines use
1188    Fortran (rather than C) for the numerical calculations. On some machines
1189    and compilers (like complex numbers) the Fortran version of the routines
1190    is faster than the C/C++ versions. The flag PETSC_USE_FORTRAN_KERNELS
1191    would be set in the petscconf.h file
1192 */
1193 #if defined(PETSC_USE_FORTRAN_KERNELS)
1194 
1195 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ)
1196 #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ
1197 #endif
1198 
1199 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ)
1200 #define PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ
1201 #endif
1202 
1203 #if !defined(PETSC_USE_FORTRAN_KERNEL_NORM)
1204 #define PETSC_USE_FORTRAN_KERNEL_NORM
1205 #endif
1206 
1207 #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY)
1208 #define PETSC_USE_FORTRAN_KERNEL_MAXPY
1209 #endif
1210 
1211 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ)
1212 #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ
1213 #endif
1214 
1215 #if !defined(PETSC_USE_FORTRAN_KERNEL_RELAXAIJ)
1216 #define PETSC_USE_FORTRAN_KERNEL_RELAXAIJ
1217 #endif
1218 
1219 #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ)
1220 #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ
1221 #endif
1222 
1223 #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ)
1224 #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ
1225 #endif
1226 
1227 #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT)
1228 #define PETSC_USE_FORTRAN_KERNEL_MDOT
1229 #endif
1230 
1231 #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY)
1232 #define PETSC_USE_FORTRAN_KERNEL_XTIMESY
1233 #endif
1234 
1235 #if !defined(PETSC_USE_FORTRAN_KERNEL_AYPX)
1236 #define PETSC_USE_FORTRAN_KERNEL_AYPX
1237 #endif
1238 
1239 #if !defined(PETSC_USE_FORTRAN_KERNEL_WAXPY)
1240 #define PETSC_USE_FORTRAN_KERNEL_WAXPY
1241 #endif
1242 
1243 #endif
1244 
1245 /*
1246     Macros for indicating code that should be compiled with a C interface,
1247    rather than a C++ interface. Any routines that are dynamically loaded
1248    (such as the PCCreate_XXX() routines) must be wrapped so that the name
1249    mangler does not change the functions symbol name. This just hides the
1250    ugly extern "C" {} wrappers.
1251 */
1252 #if defined(__cplusplus)
1253 #define EXTERN_C_BEGIN extern "C" {
1254 #define EXTERN_C_END }
1255 #else
1256 #define EXTERN_C_BEGIN
1257 #define EXTERN_C_END
1258 #endif
1259 
1260 /* --------------------------------------------------------------------*/
1261 
1262 /*M
1263     size - integer variable used to contain the number of processors in
1264            the relevent MPI_Comm
1265 
1266    Level: beginner
1267 
1268 .seealso: rank, comm
1269 M*/
1270 
1271 /*M
1272     rank - integer variable used to contain the number of this processor relative
1273            to all in the relevent MPI_Comm
1274 
1275    Level: beginner
1276 
1277 .seealso: size, comm
1278 M*/
1279 
1280 /*M
1281     comm - MPI_Comm used in the current routine or object
1282 
1283    Level: beginner
1284 
1285 .seealso: size, rank
1286 M*/
1287 
1288 /*M
1289     MPI_Comm - the basic object used by MPI to determine which processes are involved in a
1290         communication
1291 
1292    Level: beginner
1293 
1294    Note: This manual page is a place-holder because MPICH does not have a manual page for MPI_Comm
1295 
1296 .seealso: size, rank, comm, PETSC_COMM_WORLD, PETSC_COMM_SELF
1297 M*/
1298 
1299 /*M
1300     PetscScalar - PETSc type that represents either a double precision real number or
1301        a double precision complex number if the code is configured with --with-scalar-type=complex
1302 
1303    Level: beginner
1304 
1305 .seealso: PetscReal, PassiveReal, PassiveScalar
1306 M*/
1307 
1308 /*M
1309     PetscReal - PETSc type that represents a double precision real number
1310 
1311    Level: beginner
1312 
1313 .seealso: PetscScalar, PassiveReal, PassiveScalar
1314 M*/
1315 
1316 /*M
1317     PassiveScalar - PETSc type that represents either a double precision real number or
1318        a double precision complex number if the code is  code is configured with --with-scalar-type=complex
1319 
1320    Level: beginner
1321 
1322     This is the same as a PetscScalar except in code that is automatically differentiated it is
1323    treated as a constant (not an indendent or dependent variable)
1324 
1325 .seealso: PetscReal, PassiveReal, PetscScalar
1326 M*/
1327 
1328 /*M
1329     PassiveReal - PETSc type that represents a double precision real number
1330 
1331    Level: beginner
1332 
1333     This is the same as a PetscReal except in code that is automatically differentiated it is
1334    treated as a constant (not an indendent or dependent variable)
1335 
1336 .seealso: PetscScalar, PetscReal, PassiveScalar
1337 M*/
1338 
1339 /*M
1340     MPIU_SCALAR - MPI datatype corresponding to PetscScalar
1341 
1342    Level: beginner
1343 
1344     Note: In MPI calls that require an MPI datatype that matches a PetscScalar or array of PetscScalars
1345           pass this value
1346 
1347 .seealso: PetscReal, PassiveReal, PassiveScalar, PetscScalar
1348 M*/
1349 
1350 /*
1351      The IBM include files define hz, here we hide it so that it may be used
1352    as a regular user variable.
1353 */
1354 #if defined(hz)
1355 #undef hz
1356 #endif
1357 
1358 /*  For arrays that contain filenames or paths */
1359 
1360 
1361 #if defined(PETSC_HAVE_LIMITS_H)
1362 #include <limits.h>
1363 #endif
1364 #if defined(PETSC_HAVE_SYS_PARAM_H)
1365 #include <sys/param.h>
1366 #endif
1367 #if defined(PETSC_HAVE_SYS_TYPES_H)
1368 #include <sys/types.h>
1369 #endif
1370 #if defined(MAXPATHLEN)
1371 #  define PETSC_MAX_PATH_LEN     MAXPATHLEN
1372 #elif defined(MAX_PATH)
1373 #  define PETSC_MAX_PATH_LEN     MAX_PATH
1374 #elif defined(_MAX_PATH)
1375 #  define PETSC_MAX_PATH_LEN     _MAX_PATH
1376 #else
1377 #  define PETSC_MAX_PATH_LEN     4096
1378 #endif
1379 
1380 PETSC_EXTERN_CXX_END
1381 #endif
1382 
1383 
1384