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