Actual source code: petsc.h
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: */
7: /* ========================================================================== */
8: /*
9: petscconf.h is contained in bmake/${PETSC_ARCH}/petscconf.h it is
10: found automatically by the compiler due to the -I${PETSC_DIR}/bmake/${PETSC_ARCH}
11: in the bmake/common/variables definition of PETSC_INCLUDE
12: */
13: #include "petscconf.h"
15: /* ========================================================================== */
16: /*
17: This facilitates using C version of PETSc from C++ and
18: C++ version from C. Use --with-c-support --with-clanguage=c++ with config/configure.py for the latter)
19: */
21: #error "PETSc configured with --with-clanguage=c++ and NOT --with-c-support - it can be used only with a C++ compiler"
22: #endif
27: #else
30: #endif
31: /* ========================================================================== */
32: /*
33: Current PETSc version number and release date. Also listed in
34: Web page
35: src/docs/tex/manual/intro.tex,
36: src/docs/tex/manual/manual.tex.
37: src/docs/website/index.html.
38: */
39: #include petscversion.h
40: #define PETSC_AUTHOR_INFO "\
41: The PETSc Team\n\
42: petsc-maint@mcs.anl.gov\n\
43: http://www.mcs.anl.gov/petsc/\n"
44: #if (PETSC_VERSION_RELEASE == 1)
45: #define PetscGetVersion(version,len) (PetscSNPrintf(*(version),len,"Petsc Release Version %d.%d.%d, Patch %d, ", \
46: PETSC_VERSION_MAJOR,PETSC_VERSION_MINOR, PETSC_VERSION_SUBMINOR, \
47: PETSC_VERSION_PATCH),PetscStrcat(*(version),PETSC_VERSION_PATCH_DATE), \
48: PetscStrcat(*(version)," HG revision: "),PetscStrcat(*(version),PETSC_VERSION_HG),0)
49: #else
50: #define PetscGetVersion(version,len) (PetscSNPrintf(*(version),len,"Petsc Development Version %d.%d.%d, Patch %d, ", \
51: PETSC_VERSION_MAJOR,PETSC_VERSION_MINOR, PETSC_VERSION_SUBMINOR, \
52: PETSC_VERSION_PATCH),PetscStrcat(*(version),PETSC_VERSION_PATCH_DATE), \
53: PetscStrcat(*(version)," HG revision: "),PetscStrcat(*(version),PETSC_VERSION_HG),0)
54: #endif
56: /*MC
57: PetscGetVersion - Gets the Petsc Version information in a string.
59: Output Parameter:
60: . version - version string
62: Input Parameter:
63: . len - length of the string
65: Level: developer
67: Usage:
68: char version[256];
69: PetscGetVersion(&version,256);
71: Fortran Note:
72: This routine is not supported in Fortran.
74: .seealso: PetscGetProgramName()
76: M*/
78: /* ========================================================================== */
80: /*
81: Currently cannot check formatting for PETSc print statements because we have our
82: own format %D and %G
83: */
84: #undef PETSC_PRINTF_FORMAT_CHECK
85: #define PETSC_PRINTF_FORMAT_CHECK(a,b)
86: #undef PETSC_FPRINTF_FORMAT_CHECK
87: #define PETSC_FPRINTF_FORMAT_CHECK(a,b)
89: /*
90: Fixes for configure time choices which impact our interface. Currently only
91: calling conventions and extra compiler checking falls under this category.
92: */
93: #if !defined(PETSC_STDCALL)
94: #define PETSC_STDCALL
95: #endif
96: #if !defined(PETSC_TEMPLATE)
97: #define PETSC_TEMPLATE
98: #endif
99: #if !defined(PETSC_HAVE_DLL_EXPORT)
100: #define PETSC_DLL_EXPORT
101: #define PETSC_DLL_IMPORT
102: #endif
103: #if !defined()
104: #define
105: #endif
106: #if !defined()
107: #define
108: #endif
109: #if !defined()
110: #define
111: #endif
112: #if !defined()
113: #define
114: #endif
115: #if !defined()
116: #define
117: #endif
118: #if !defined()
119: #define
120: #endif
121: #if !defined()
122: #define
123: #endif
124: #if !defined()
125: #define
126: #endif
127: /* ========================================================================== */
129: /*
130: Defines the interface to MPI allowing the use of all MPI functions.
132: PETSc does not use the C++ binding of MPI at ALL. The following flag
133: makes sure the C++ bindings are not included. The C++ bindings REQUIRE
134: putting mpi.h before ANY C++ include files, we cannot control this
135: with all PETSc users.
136: */
137: #define MPICH_SKIP_MPICXX 1
138: #include "mpi.h"
139: /*
140: Yuck, we need to put stdio.h AFTER mpi.h for MPICH2 with C++ compiler
141: see the top of mpicxx.h
143: The MPI STANDARD HAS TO BE CHANGED to prevent this nonsense.
144: */
145: #include <stdio.h>
147: /*MC
148: PetscErrorCode - datatype used for return error code from all PETSc functions
150: Level: beginner
152: .seealso: CHKERRQ, SETERRQ
153: M*/
154: typedef int PetscErrorCode;
156: /*MC
158: PetscCookie - A unique id used to identify each PETSc object.
159: (internal integer in the data structure used for error
160: checking). These are all defined by an offset from the lowest
161: one, PETSC_SMALLEST_COOKIE.
163: Level: advanced
166: M*/
167: typedef int PetscCookie;
169: /*MC
170: PetscEvent - id used to identify PETSc or user events - primarily for logging
172: Level: intermediate
175: M*/
176: typedef int PetscEvent;
178: /*MC
179: PetscBLASInt - datatype used to represent 'int' parameters to blas functions.
181: Level: intermediate
182: M*/
183: typedef int PetscBLASInt;
185: /*MC
186: PetscMPIInt - datatype used to represent 'int' parameters to MPI functions.
188: Level: intermediate
189: M*/
190: typedef int PetscMPIInt;
192: /*MC
193: PetscEnum - datatype used to pass enum types within PETSc functions.
195: Level: intermediate
197: .seealso: PetscOptionsGetEnum(), PetscOptionsEnum(), PetscBagRegisterEnum()
198: M*/
199: typedef enum { ENUM_DUMMY } PetscEnum;
201: /*MC
202: PetscInt - PETSc type that represents integer - used primarily to
203: represent size of objects. Its size can be configured with the option
204: --with-64-bit-indices - to be either 32bit or 64bit [default 32 bit ints]
206: Level: intermediate
208: .seealso: PetscScalar
209: M*/
210: #if defined(PETSC_USE_64BIT_INDICES)
211: typedef long long PetscInt;
212: #define MPIU_INT MPI_LONG_LONG_INT
213: #else
214: typedef int PetscInt;
215: #define MPIU_INT MPI_INT
216: #endif
218: /*
219: You can use PETSC_STDOUT as a replacement of stdout. You can also change
220: the value of PETSC_STDOUT to redirect all standard output elsewhere
221: */
224: /*
225: You can use PETSC_STDERR as a replacement of stderr. You can also change
226: the value of PETSC_STDERR to redirect all standard error elsewhere
227: */
231: /*MC
232: PetscPolymorphicSubroutine - allows defining a C++ polymorphic version of
233: a PETSc function that remove certain optional arguments for a simplier user interface
235: Not collective
237: Synopsis:
238: PetscPolymorphicSubroutine(Functionname,(arguments of C++ function),(arguments of C function))
239:
240: Level: developer
242: Example:
243: PetscPolymorphicSubroutine(VecNorm,(Vec x,PetscReal *r),(x,NORM_2,r)) generates the new routine
244: PetscErrorCode VecNorm(Vec x,PetscReal *r) = VecNorm(x,NORM_2,r)
246: .seealso: PetscPolymorphicFunction()
248: M*/
249: #define PetscPolymorphicSubroutine(A,B,C) PETSC_STATIC_INLINE PetscErrorCode A B {return A C;}
251: /*MC
252: PetscPolymorphicScalar - allows defining a C++ polymorphic version of
253: a PETSc function that replaces a PetscScalar * argument with a PetscScalar argument
255: Not collective
257: Synopsis:
258: PetscPolymorphicScalar(Functionname,(arguments of C++ function),(arguments of C function))
259:
260: Level: developer
262: Example:
263: PetscPolymorphicScalar(VecAXPY,(PetscScalar _val,Vec x,Vec y),(&_Val,x,y)) generates the new routine
264: PetscErrorCode VecAXPY(PetscScalar _val,Vec x,Vec y) = {PetscScalar _Val = _val; return VecAXPY(&_Val,x,y);}
266: .seealso: PetscPolymorphicFunction(),PetscPolymorphicSubroutine()
268: M*/
269: #define PetscPolymorphicScalar(A,B,C) PETSC_STATIC_INLINE PetscErrorCode A B {PetscScalar _Val = _val; return A C;}
271: /*MC
272: PetscPolymorphicFunction - allows defining a C++ polymorphic version of
273: a PETSc function that remove certain optional arguments for a simplier user interface
274: and returns the computed value (istead of an error code)
276: Not collective
278: Synopsis:
279: PetscPolymorphicFunction(Functionname,(arguments of C++ function),(arguments of C function),return type,return variable name)
280:
281: Level: developer
283: Example:
284: PetscPolymorphicFunction(VecNorm,(Vec x,NormType t),(x,t,&r),PetscReal,r) generates the new routine
285: PetscReal VecNorm(Vec x,NormType t) = {PetscReal r; VecNorm(x,t,&r); return r;}
287: .seealso: PetscPolymorphicSubroutine()
289: M*/
290: #define PetscPolymorphicFunction(A,B,C,D,E) PETSC_STATIC_INLINE D A B {D E; A C;return E;}
292: #else
293: #define PetscPolymorphicSubroutine(A,B,C)
294: #define PetscPolymorphicScalar(A,B,C)
295: #define PetscPolymorphicFunction(A,B,C,D,E)
296: #endif
298: /*
299: Extern indicates a PETSc function defined elsewhere
300: */
301: #if !defined(EXTERN)
302: #define EXTERN extern
303: #endif
305: /*
306: Defines some elementary mathematics functions and constants.
307: */
308: #include petscmath.h
310: /*
312: */
316: /*
317: Basic PETSc constants
318: */
320: /*E
321: PetscTruth - Logical variable. Actually an integer
323: Level: beginner
325: E*/
326: typedef enum { PETSC_FALSE,PETSC_TRUE } PetscTruth;
329: /*MC
330: PETSC_FALSE - False value of PetscTruth
332: Level: beginner
334: Note: Zero integer
336: .seealso: PetscTruth, PETSC_TRUE
337: M*/
339: /*MC
340: PETSC_TRUE - True value of PetscTruth
342: Level: beginner
344: Note: Nonzero integer
346: .seealso: PetscTruth, PETSC_FALSE
347: M*/
349: /*MC
350: PETSC_YES - Alias for PETSC_TRUE
352: Level: beginner
354: Note: Zero integer
356: .seealso: PetscTruth, PETSC_TRUE, PETSC_FALSE, PETSC_NO
357: M*/
358: #define PETSC_YES PETSC_TRUE
360: /*MC
361: PETSC_NO - Alias for PETSC_FALSE
363: Level: beginner
365: Note: Nonzero integer
367: .seealso: PetscTruth, PETSC_TRUE, PETSC_FALSE, PETSC_YES
368: M*/
369: #define PETSC_NO PETSC_FALSE
371: /*MC
372: PETSC_NULL - standard way of passing in a null or array or pointer
374: Level: beginner
376: Notes: accepted by many PETSc functions to not set a parameter and instead use
377: some default
379: This macro does not exist in Fortran; you must use PETSC_NULL_INTEGER,
380: PETSC_NULL_DOUBLE_PRECISION etc
382: .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_IGNORE, PETSC_DETERMINE
384: M*/
385: #define PETSC_NULL 0
387: /*MC
388: PETSC_DECIDE - standard way of passing in integer or floating point parameter
389: where you wish PETSc to use the default.
391: Level: beginner
393: .seealso: PETSC_NULL, PETSC_DEFAULT, PETSC_IGNORE, PETSC_DETERMINE
395: M*/
396: #define PETSC_DECIDE -1
398: /*MC
399: PETSC_DEFAULT - standard way of passing in integer or floating point parameter
400: where you wish PETSc to use the default.
402: Level: beginner
404: .seealso: PETSC_DECIDE, PETSC_NULL, PETSC_IGNORE, PETSC_DETERMINE
406: M*/
407: #define PETSC_DEFAULT -2
410: /*MC
411: PETSC_IGNORE - same as PETSC_NULL, means PETSc will ignore this argument
413: Level: beginner
415: Notes: accepted by many PETSc functions to not set a parameter and instead use
416: some default
418: This macro does not exist in Fortran; you must use PETSC_NULL_INTEGER,
419: PETSC_NULL_DOUBLE_PRECISION etc
421: .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_NULL, PETSC_DETERMINE
423: M*/
424: #define PETSC_IGNORE PETSC_NULL
426: /*MC
427: PETSC_DETERMINE - standard way of passing in integer or floating point parameter
428: where you wish PETSc to compute the required value.
430: Level: beginner
432: .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_IGNORE, PETSC_NULL, VecSetSizes()
434: M*/
435: #define PETSC_DETERMINE PETSC_DECIDE
437: /*MC
438: PETSC_COMM_WORLD - the equivalent of the MPI_COMM_WORLD communicator which represents
439: all the processs that PETSc knows about.
441: Level: beginner
443: Notes: By default PETSC_COMM_WORLD and MPI_COMM_WORLD are identical unless you wish to
444: run PETSc on ONLY a subset of MPI_COMM_WORLD. In that case create your new (smaller)
445: communicator, call it, say comm, and set PETSC_COMM_WORLD = comm BEFORE calling
446: PetscInitialize()
448: .seealso: PETSC_COMM_SELF
450: M*/
453: /*MC
454: PETSC_COMM_SELF - a duplicate of the MPI_COMM_SELF communicator which represents
455: the current process
457: Level: beginner
459: Notes: PETSC_COMM_SELF and MPI_COMM_SELF are equivalent.
461: .seealso: PETSC_COMM_WORLD
463: M*/
464: #define PETSC_COMM_SELF MPI_COMM_SELF
469: EXTERN PetscErrorCode PetscSetHelpVersionFunctions(PetscErrorCode (*)(MPI_Comm),PetscErrorCode (*)(MPI_Comm));
470: EXTERN PetscErrorCode PetscCommDuplicate(MPI_Comm,MPI_Comm*,int*);
471: EXTERN PetscErrorCode PetscCommDestroy(MPI_Comm*);
473: /*MC
474: PetscMalloc - Allocates memory
476: Input Parameter:
477: . m - number of bytes to allocate
479: Output Parameter:
480: . result - memory allocated
482: Synopsis:
483: PetscErrorCode PetscMalloc(size_t m,void **result)
485: Level: beginner
487: Notes: Memory is always allocated at least double aligned
489: If you request memory of zero size it will allocate no space and assign the pointer to 0; PetscFree() will
490: properly handle not freeing the null pointer.
492: .seealso: PetscFree(), PetscNew()
494: Concepts: memory allocation
496: M*/
497: #define PetscMalloc(a,b) ((a != 0) ? (*PetscTrMalloc)((a),__LINE__,__FUNCT__,__FILE__,__SDIR__,(void**)(b)) : (*(b) = 0,0) )
499: /*MC
500: PetscMalloc2 - Allocates 2 chunks of memory
502: Input Parameter:
503: + m1 - number of elements to allocate in 1st chunk (may be zero)
504: . t1 - type of first memory elements
505: . m2 - number of elements to allocate in 2nd chunk (may be zero)
506: - t2 - type of second memory elements
508: Output Parameter:
509: + r1 - memory allocated in first chunk
510: - r2 - memory allocated in second chunk
512: Synopsis:
513: PetscErrorCode PetscMalloc2(size_t m1,type, t1,void **r1,size_t m2,type t2,void **r2)
515: Level: developer
517: Notes: Memory of first chunk is always allocated at least double aligned
519: .seealso: PetscFree(), PetscNew(), PetscMalloc()
521: Concepts: memory allocation
523: M*/
524: #if defined(PETSC_USE_DEBUG)
525: #define PetscMalloc2(m1,t1,r1,m2,t2,r2) (PetscMalloc((m1)*sizeof(t1),r1) || PetscMalloc((m2)*sizeof(t2),r2))
526: #else
527: #define PetscMalloc2(m1,t1,r1,m2,t2,r2) (PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2),r1) || (*(r2) = (t2*)(*(r1)+m1),0))
528: #endif
530: /*MC
531: PetscMalloc3 - Allocates 3 chunks of memory
533: Input Parameter:
534: + m1 - number of elements to allocate in 1st chunk (may be zero)
535: . t1 - type of first memory elements
536: . m2 - number of elements to allocate in 2nd chunk (may be zero)
537: . t2 - type of second memory elements
538: . m3 - number of elements to allocate in 3rd chunk (may be zero)
539: - t3 - type of third memory elements
541: Output Parameter:
542: + r1 - memory allocated in first chunk
543: . r2 - memory allocated in second chunk
544: - r3 - memory allocated in third chunk
546: Synopsis:
547: PetscErrorCode PetscMalloc3(size_t m1,type, t1,void **r1,size_t m2,type t2,void **r2,size_t m3,type t3,void **r3)
549: Level: developer
551: Notes: Memory of first chunk is always allocated at least double aligned
553: .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3()
555: Concepts: memory allocation
557: M*/
558: #if defined(PETSC_USE_DEBUG)
559: #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))
560: #else
561: #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))
562: #endif
564: /*MC
565: PetscMalloc4 - Allocates 4 chunks of memory
567: Input Parameter:
568: + m1 - number of elements to allocate in 1st chunk (may be zero)
569: . t1 - type of first memory elements
570: . m2 - number of elements to allocate in 2nd chunk (may be zero)
571: . t2 - type of second memory elements
572: . m3 - number of elements to allocate in 3rd chunk (may be zero)
573: . t3 - type of third memory elements
574: . m4 - number of elements to allocate in 4th chunk (may be zero)
575: - t4 - type of fourth memory elements
577: Output Parameter:
578: + r1 - memory allocated in first chunk
579: . r2 - memory allocated in second chunk
580: . r3 - memory allocated in third chunk
581: - r4 - memory allocated in fourth chunk
583: Synopsis:
584: 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)
586: Level: developer
588: Notes: Memory of first chunk is always allocated at least double aligned
590: .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4()
592: Concepts: memory allocation
594: M*/
595: #if defined(PETSC_USE_DEBUG)
596: #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))
597: #else
598: #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))
599: #endif
601: /*MC
602: PetscMalloc5 - Allocates 5 chunks of memory
604: Input Parameter:
605: + m1 - number of elements to allocate in 1st chunk (may be zero)
606: . t1 - type of first memory elements
607: . m2 - number of elements to allocate in 2nd chunk (may be zero)
608: . t2 - type of second memory elements
609: . m3 - number of elements to allocate in 3rd chunk (may be zero)
610: . t3 - type of third memory elements
611: . m4 - number of elements to allocate in 4th chunk (may be zero)
612: . t4 - type of fourth memory elements
613: . m5 - number of elements to allocate in 5th chunk (may be zero)
614: - t5 - type of fifth memory elements
616: Output Parameter:
617: + r1 - memory allocated in first chunk
618: . r2 - memory allocated in second chunk
619: . r3 - memory allocated in third chunk
620: . r4 - memory allocated in fourth chunk
621: - r5 - memory allocated in fifth chunk
623: Synopsis:
624: 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)
626: Level: developer
628: Notes: Memory of first chunk is always allocated at least double aligned
630: .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4(), PetscFree5()
632: Concepts: memory allocation
634: M*/
635: #if defined(PETSC_USE_DEBUG)
636: #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))
637: #else
638: #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))
639: #endif
642: /*MC
643: PetscMalloc6 - Allocates 6 chunks of memory
645: Input Parameter:
646: + m1 - number of elements to allocate in 1st chunk (may be zero)
647: . t1 - type of first memory elements
648: . m2 - number of elements to allocate in 2nd chunk (may be zero)
649: . t2 - type of second memory elements
650: . m3 - number of elements to allocate in 3rd chunk (may be zero)
651: . t3 - type of third memory elements
652: . m4 - number of elements to allocate in 4th chunk (may be zero)
653: . t4 - type of fourth memory elements
654: . m5 - number of elements to allocate in 5th chunk (may be zero)
655: . t5 - type of fifth memory elements
656: . m6 - number of elements to allocate in 6th chunk (may be zero)
657: - t6 - type of sixth memory elements
659: Output Parameter:
660: + r1 - memory allocated in first chunk
661: . r2 - memory allocated in second chunk
662: . r3 - memory allocated in third chunk
663: . r4 - memory allocated in fourth chunk
664: . r5 - memory allocated in fifth chunk
665: - r6 - memory allocated in sixth chunk
667: Synopsis:
668: 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)
670: Level: developer
672: Notes: Memory of first chunk is always allocated at least double aligned
674: .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4(), PetscFree5(), PetscFree6()
676: Concepts: memory allocation
678: M*/
679: #if defined(PETSC_USE_DEBUG)
680: #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))
681: #else
682: #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))
683: #endif
685: /*MC
686: PetscMalloc7 - Allocates 7 chunks of memory
688: Input Parameter:
689: + m1 - number of elements to allocate in 1st chunk (may be zero)
690: . t1 - type of first memory elements
691: . m2 - number of elements to allocate in 2nd chunk (may be zero)
692: . t2 - type of second memory elements
693: . m3 - number of elements to allocate in 3rd chunk (may be zero)
694: . t3 - type of third memory elements
695: . m4 - number of elements to allocate in 4th chunk (may be zero)
696: . t4 - type of fourth memory elements
697: . m5 - number of elements to allocate in 5th chunk (may be zero)
698: . t5 - type of fifth memory elements
699: . m6 - number of elements to allocate in 6th chunk (may be zero)
700: . t6 - type of sixth memory elements
701: . m7 - number of elements to allocate in 7th chunk (may be zero)
702: - t7 - type of sixth memory elements
704: Output Parameter:
705: + r1 - memory allocated in first chunk
706: . r2 - memory allocated in second chunk
707: . r3 - memory allocated in third chunk
708: . r4 - memory allocated in fourth chunk
709: . r5 - memory allocated in fifth chunk
710: . r6 - memory allocated in sixth chunk
711: - r7 - memory allocated in sixth chunk
713: Synopsis:
714: PetscErrorCode PetscMalloc7(size_t m1,type, t1,void **r1,size_t m2,type t2,void **r2,size_t m3,type t3,void **r3,size_t m4,type t4,void **r4,size_t m5,type t5,void **r5,size_t m6,type t6,void **r6,size_t m7,type t7,void **r7)
716: Level: developer
718: Notes: Memory of first chunk is always allocated at least double aligned
720: .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4(), PetscFree5(), PetscFree6(), PetscFree7()
722: Concepts: memory allocation
724: M*/
725: #if defined(PETSC_USE_DEBUG)
726: #define PetscMalloc7(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4,m5,t5,r5,m6,t6,r6,m7,t7,r7) (PetscMalloc((m1)*sizeof(t1),r1) || PetscMalloc((m2)*sizeof(t2),r2) || PetscMalloc((m3)*sizeof(t3),r3) || PetscMalloc((m4)*sizeof(t4),r4) || PetscMalloc((m5)*sizeof(t5),r5) || PetscMalloc((m6)*sizeof(t6),r6) || PetscMalloc((m7)*sizeof(t7),r7))
727: #else
728: #define PetscMalloc7(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4,m5,t5,r5,m6,t6,r6,m7,t7,r7) (PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3)+(m4)*sizeof(t4)+(m5)*sizeof(t5)+(m6)*sizeof(t6)+(m7)*sizeof(t7),r1) || (*(r2) = (t2*)(*(r1)+m1),*(r3) = (t3*)(*(r2)+m2),*(r4) = (t4*)(*(r3)+m3),*(r5) = (t5*)(*(r4)+m4),*(r6) = (t6*)(*(r5)+m5),*(r7) = (t7*)(*(r6)+m6),0))
729: #endif
731: /*MC
732: PetscNew - Allocates memory of a particular type, zeros the memory!
734: Input Parameter:
735: . type - structure name of space to be allocated. Memory of size sizeof(type) is allocated
737: Output Parameter:
738: . result - memory allocated
740: Synopsis:
741: PetscErrorCode PetscNew(struct type,((type *))result)
743: Level: beginner
745: .seealso: PetscFree(), PetscMalloc()
747: Concepts: memory allocation
749: M*/
750: #define PetscNew(A,b) (PetscMalloc(sizeof(A),(b)) || PetscMemzero(*(b),sizeof(A)))
752: /*MC
753: PetscFree - Frees memory
755: Input Parameter:
756: . memory - memory to free (the pointer is ALWAYS set to 0 upon sucess)
758: Synopsis:
759: PetscErrorCode PetscFree(void *memory)
761: Level: beginner
763: Notes: Memory must have been obtained with PetscNew() or PetscMalloc()
765: .seealso: PetscNew(), PetscMalloc(), PetscFreeVoid()
767: Concepts: memory allocation
769: M*/
770: #define PetscFree(a) ((a) ? ((*PetscTrFree)((a),__LINE__,__FUNCT__,__FILE__,__SDIR__) || ((a = 0),0)) : 0)
772: /*MC
773: PetscFreeVoid - Frees memory
775: Input Parameter:
776: . memory - memory to free
778: Synopsis:
779: void PetscFreeVoid(void *memory)
781: Level: beginner
783: Notes: This is different from PetscFree() in that no error code is returned
785: .seealso: PetscFree(), PetscNew(), PetscMalloc()
787: Concepts: memory allocation
789: M*/
790: #define PetscFreeVoid(a) ((*PetscTrFree)((a),__LINE__,__FUNCT__,__FILE__,__SDIR__),(a) = 0)
793: /*MC
794: PetscFree2 - Frees 2 chunks of memory obtained with PetscMalloc2()
796: Input Parameter:
797: + memory1 - memory to free
798: - memory2 - 2nd memory to free
801: Synopsis:
802: PetscErrorCode PetscFree2(void *memory1,void *memory2)
804: Level: developer
806: Notes: Memory must have been obtained with PetscMalloc2()
808: .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree()
810: Concepts: memory allocation
812: M*/
813: #if defined(PETSC_USE_DEBUG)
814: #define PetscFree2(m1,m2) (PetscFree(m2) || PetscFree(m1))
815: #else
816: #define PetscFree2(m1,m2) (PetscFree(m1))
817: #endif
819: /*MC
820: PetscFree3 - Frees 3 chunks of memory obtained with PetscMalloc3()
822: Input Parameter:
823: + memory1 - memory to free
824: . memory2 - 2nd memory to free
825: - memory3 - 3rd memory to free
828: Synopsis:
829: PetscErrorCode PetscFree3(void *memory1,void *memory2,void *memory3)
831: Level: developer
833: Notes: Memory must have been obtained with PetscMalloc3()
835: .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3()
837: Concepts: memory allocation
839: M*/
840: #if defined(PETSC_USE_DEBUG)
841: #define PetscFree3(m1,m2,m3) (PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
842: #else
843: #define PetscFree3(m1,m2,m3) (PetscFree(m1))
844: #endif
846: /*MC
847: PetscFree4 - Frees 4 chunks of memory obtained with PetscMalloc4()
849: Input Parameter:
850: + m1 - memory to free
851: . m2 - 2nd memory to free
852: . m3 - 3rd memory to free
853: - m4 - 4th memory to free
856: Synopsis:
857: PetscErrorCode PetscFree4(void *m1,void *m2,void *m3,void *m4)
859: Level: developer
861: Notes: Memory must have been obtained with PetscMalloc4()
863: .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4()
865: Concepts: memory allocation
867: M*/
868: #if defined(PETSC_USE_DEBUG)
869: #define PetscFree4(m1,m2,m3,m4) (PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
870: #else
871: #define PetscFree4(m1,m2,m3,m4) (PetscFree(m1))
872: #endif
874: /*MC
875: PetscFree5 - Frees 5 chunks of memory obtained with PetscMalloc5()
877: Input Parameter:
878: + m1 - memory to free
879: . m2 - 2nd memory to free
880: . m3 - 3rd memory to free
881: . m4 - 4th memory to free
882: - m5 - 5th memory to free
885: Synopsis:
886: PetscErrorCode PetscFree5(void *m1,void *m2,void *m3,void *m4,void *m5)
888: Level: developer
890: Notes: Memory must have been obtained with PetscMalloc5()
892: .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5()
894: Concepts: memory allocation
896: M*/
897: #if defined(PETSC_USE_DEBUG)
898: #define PetscFree5(m1,m2,m3,m4,m5) (PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
899: #else
900: #define PetscFree5(m1,m2,m3,m4,m5) (PetscFree(m1))
901: #endif
904: /*MC
905: PetscFree6 - Frees 6 chunks of memory obtained with PetscMalloc6()
907: Input Parameter:
908: + m1 - memory to free
909: . m2 - 2nd memory to free
910: . m3 - 3rd memory to free
911: . m4 - 4th memory to free
912: . m5 - 5th memory to free
913: - m6 - 6th memory to free
916: Synopsis:
917: PetscErrorCode PetscFree6(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6)
919: Level: developer
921: Notes: Memory must have been obtained with PetscMalloc6()
923: .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5(), PetscMalloc6()
925: Concepts: memory allocation
927: M*/
928: #if defined(PETSC_USE_DEBUG)
929: #define PetscFree6(m1,m2,m3,m4,m5,m6) (PetscFree(m6) || PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
930: #else
931: #define PetscFree6(m1,m2,m3,m4,m5,m6) (PetscFree(m1))
932: #endif
934: /*MC
935: PetscFree7 - Frees 7 chunks of memory obtained with PetscMalloc7()
937: Input Parameter:
938: + m1 - memory to free
939: . m2 - 2nd memory to free
940: . m3 - 3rd memory to free
941: . m4 - 4th memory to free
942: . m5 - 5th memory to free
943: . m6 - 6th memory to free
944: - m7 - 7th memory to free
947: Synopsis:
948: PetscErrorCode PetscFree7(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6,void *m7)
950: Level: developer
952: Notes: Memory must have been obtained with PetscMalloc7()
954: .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5(), PetscMalloc6(),
955: PetscMalloc7()
957: Concepts: memory allocation
959: M*/
960: #if defined(PETSC_USE_DEBUG)
961: #define PetscFree7(m1,m2,m3,m4,m5,m6,m7) (PetscFree(m7) || PetscFree(m6) || PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
962: #else
963: #define PetscFree7(m1,m2,m3,m4,m5,m6,m7) (PetscFree(m1))
964: #endif
966: EXTERN PetscErrorCode (*PetscTrMalloc)(size_t,int,const char[],const char[],const char[],void**);
967: EXTERN PetscErrorCode (*PetscTrFree)(void*,int,const char[],const char[],const char[]);
968: EXTERN PetscErrorCode PetscSetMalloc(PetscErrorCode (*)(size_t,int,const char[],const char[],const char[],void**),PetscErrorCode (*)(void*,int,const char[],const char[],const char[]));
969: EXTERN PetscErrorCode PetscClearMalloc(void);
971: /*
972: Routines for tracing memory corruption/bleeding with default PETSc
973: memory allocation
974: */
975: EXTERN PetscErrorCode PetscMallocDump(FILE *);
976: EXTERN PetscErrorCode PetscMallocDumpLog(FILE *);
977: EXTERN PetscErrorCode PetscMallocGetCurrentUsage(PetscLogDouble *);
978: EXTERN PetscErrorCode PetscMallocGetMaximumUsage(PetscLogDouble *);
979: EXTERN PetscErrorCode PetscMallocDebug(PetscTruth);
980: EXTERN PetscErrorCode PetscMallocValidate(int,const char[],const char[],const char[]);
981: EXTERN PetscErrorCode PetscMallocSetDumpLog(void);
984: /*
985: Variable type where we stash PETSc object pointers in Fortran.
986: On most machines size(pointer) == sizeof(long) - except windows
987: where its sizeof(long long)
988: */
990: #if (PETSC_SIZEOF_VOID_P) == (PETSC_SIZEOF_LONG)
991: #define PetscFortranAddr long
992: #elif (PETSC_SIZEOF_VOID_P) == (PETSC_SIZEOF_LONG_LONG)
993: #define PetscFortranAddr long long
994: #else
995: #error "Unknown size for PetscFortranAddr! Send us a bugreport at petsc-maint@mcs.anl.gov"
996: #endif
998: /*E
999: PetscDataType - Used for handling different basic data types.
1001: Level: beginner
1003: .seealso: PetscBinaryRead(), PetscBinaryWrite(), PetscDataTypeToMPIDataType(),
1004: PetscDataTypeGetSize()
1006: E*/
1007: typedef enum {PETSC_INT = 0,PETSC_DOUBLE = 1,PETSC_COMPLEX = 2, PETSC_LONG = 3 ,PETSC_SHORT = 4,PETSC_FLOAT = 5,
1008: PETSC_CHAR = 6,PETSC_LOGICAL = 7,PETSC_ENUM = 8,PETSC_TRUTH=9, PETSC_LONG_DOUBLE = 10} PetscDataType;
1011: #if defined(PETSC_USE_COMPLEX)
1012: #define PETSC_SCALAR PETSC_COMPLEX
1013: #else
1014: #if defined(PETSC_USE_SINGLE)
1015: #define PETSC_SCALAR PETSC_FLOAT
1016: #elif defined(PETSC_USE_LONG_DOUBLE)
1017: #define PETSC_SCALAR PETSC_LONG_DOUBLE
1018: #elif defined(PETSC_USE_INT)
1019: #define PETSC_SCALAR PETSC_INT
1020: #else
1021: #define PETSC_SCALAR PETSC_DOUBLE
1022: #endif
1023: #endif
1024: #if defined(PETSC_USE_SINGLE)
1025: #define PETSC_REAL PETSC_FLOAT
1026: #elif defined(PETSC_USE_LONG_DOUBLE)
1027: #define PETSC_REAL PETSC_LONG_DOUBLE
1028: #elif defined(PETSC_USE_INT)
1029: #define PETSC_REAL PETSC_INT
1030: #else
1031: #define PETSC_REAL PETSC_DOUBLE
1032: #endif
1033: #define PETSC_FORTRANADDR PETSC_LONG
1035: EXTERN PetscErrorCode PetscDataTypeToMPIDataType(PetscDataType,MPI_Datatype*);
1036: EXTERN PetscErrorCode PetscDataTypeGetSize(PetscDataType,PetscInt*);
1038: /*
1039: Basic memory and string operations. These are usually simple wrappers
1040: around the basic Unix system calls, but a few of them have additional
1041: functionality and/or error checking.
1042: */
1043: EXTERN PetscErrorCode PetscMemcpy(void*,const void *,size_t);
1044: EXTERN PetscErrorCode PetscBitMemcpy(void*,PetscInt,const void*,PetscInt,PetscInt,PetscDataType);
1045: EXTERN PetscErrorCode PetscMemmove(void*,void *,size_t);
1046: EXTERN PetscErrorCode PetscMemzero(void*,size_t);
1047: EXTERN PetscErrorCode PetscMemcmp(const void*,const void*,size_t,PetscTruth *);
1048: EXTERN PetscErrorCode PetscStrlen(const char[],size_t*);
1049: EXTERN PetscErrorCode PetscStrcmp(const char[],const char[],PetscTruth *);
1050: EXTERN PetscErrorCode PetscStrgrt(const char[],const char[],PetscTruth *);
1051: EXTERN PetscErrorCode PetscStrcasecmp(const char[],const char[],PetscTruth*);
1052: EXTERN PetscErrorCode PetscStrncmp(const char[],const char[],size_t,PetscTruth*);
1053: EXTERN PetscErrorCode PetscStrcpy(char[],const char[]);
1054: EXTERN PetscErrorCode PetscStrcat(char[],const char[]);
1055: EXTERN PetscErrorCode PetscStrncat(char[],const char[],size_t);
1056: EXTERN PetscErrorCode PetscStrncpy(char[],const char[],size_t);
1057: EXTERN PetscErrorCode PetscStrchr(const char[],char,char *[]);
1058: EXTERN PetscErrorCode PetscStrtolower(char[]);
1059: EXTERN PetscErrorCode PetscStrrchr(const char[],char,char *[]);
1060: EXTERN PetscErrorCode PetscStrstr(const char[],const char[],char *[]);
1061: EXTERN PetscErrorCode PetscStrrstr(const char[],const char[],char *[]);
1062: EXTERN PetscErrorCode PetscStrallocpy(const char[],char *[]);
1063: EXTERN PetscErrorCode PetscStrreplace(MPI_Comm,const char[],char[],size_t);
1064: #define PetscStrfree(a) ((a) ? PetscFree(a) : 0)
1066: /*S
1067: PetscToken - 'Token' used for managing tokenizing strings
1069: Level: intermediate
1071: .seealso: PetscTokenCreate(), PetscTokenFind(), PetscTokenDestroy()
1072: S*/
1073: typedef struct {char token;char *array;char *current;} PetscToken;
1075: EXTERN PetscErrorCode PetscTokenCreate(const char[],const char,PetscToken**);
1076: EXTERN PetscErrorCode PetscTokenFind(PetscToken*,char *[]);
1077: EXTERN PetscErrorCode PetscTokenDestroy(PetscToken*);
1079: /*
1080: These are MPI operations for MPI_Allreduce() etc
1081: */
1082: EXTERN MPI_Op PetscMaxSum_Op;
1083: #if defined(PETSC_USE_COMPLEX)
1084: EXTERN MPI_Op PetscSum_Op;
1085: #else
1086: #define PetscSum_Op MPI_SUM
1087: #endif
1088: EXTERN PetscErrorCode PetscMaxSum(MPI_Comm,const PetscInt[],PetscInt*,PetscInt*);
1090: /*S
1091: PetscObject - any PETSc object, PetscViewer, Mat, Vec, KSP etc
1093: Level: beginner
1095: Note: This is the base class from which all objects appear.
1097: .seealso: PetscObjectDestroy(), PetscObjectView(), PetscObjectGetName(), PetscObjectSetName()
1098: S*/
1099: typedef struct _p_PetscObject* PetscObject;
1101: /*S
1102: PetscFList - Linked list of functions, possibly stored in dynamic libraries, accessed
1103: by string name
1105: Level: advanced
1107: .seealso: PetscFListAdd(), PetscFListDestroy()
1108: S*/
1109: typedef struct _n_PetscFList *PetscFList;
1111: /*E
1112: PetscFileMode - Access mode for a file.
1114: Level: beginner
1116: FILE_MODE_READ - open a file at its beginning for reading
1118: FILE_MODE_WRITE - open a file at its beginning for writing (will create if the file does not exist)
1120: FILE_MODE_APPEND - open a file at end for writing
1122: FILE_MODE_UPDATE - open a file for updating, meaning for reading and writing
1124: FILE_MODE_APPEND_UPDATE - open a file for updating, meaning for reading and writing, at the end
1126: .seealso: PetscViewerFileSetMode()
1127: E*/
1128: typedef enum {FILE_MODE_READ, FILE_MODE_WRITE, FILE_MODE_APPEND, FILE_MODE_UPDATE, FILE_MODE_APPEND_UPDATE} PetscFileMode;
1130: #include petscviewer.h
1131: #include petscoptions.h
1133: #define PETSC_SMALLEST_COOKIE 1211211
1136: EXTERN PetscErrorCode PetscCookieRegister(PetscCookie *);
1138: /*
1139: Routines that get memory usage information from the OS
1140: */
1141: EXTERN PetscErrorCode PetscMemoryGetCurrentUsage(PetscLogDouble *);
1142: EXTERN PetscErrorCode PetscMemoryGetMaximumUsage(PetscLogDouble *);
1143: EXTERN PetscErrorCode PetscMemorySetGetMaximumUsage(void);
1144: EXTERN PetscErrorCode PetscMemoryShowUsage(PetscViewer,const char[]);
1146: EXTERN PetscErrorCode PetscInfoAllow(PetscTruth,const char []);
1147: EXTERN PetscErrorCode PetscGetTime(PetscLogDouble*);
1148: EXTERN PetscErrorCode PetscGetCPUTime(PetscLogDouble*);
1149: EXTERN PetscErrorCode PetscSleep(int);
1151: /*
1152: Initialization of PETSc
1153: */
1154: EXTERN PetscErrorCode PetscInitialize(int*,char***,const char[],const char[]);
1155: PetscPolymorphicSubroutine(PetscInitialize,(int *argc,char ***args),(argc,args,PETSC_NULL,PETSC_NULL))
1156: EXTERN PetscErrorCode PetscInitializeNoArguments(void);
1157: EXTERN PetscErrorCode PetscInitialized(PetscTruth *);
1158: EXTERN PetscErrorCode PetscFinalized(PetscTruth *);
1159: EXTERN PetscErrorCode PetscFinalize(void);
1160: EXTERN PetscErrorCode PetscInitializeFortran(void);
1161: EXTERN PetscErrorCode PetscGetArgs(int*,char ***);
1162: EXTERN PetscErrorCode PetscGetArguments(char ***args);
1163: EXTERN PetscErrorCode PetscFreeArguments(char **args);
1165: EXTERN PetscErrorCode PetscEnd(void);
1166: EXTERN PetscErrorCode PetscInitializePackage(const char[]);
1168: EXTERN PetscErrorCode PetscOpenMPMerge(PetscMPIInt);
1169: EXTERN PetscErrorCode PetscOpenMPSpawn(PetscMPIInt);
1170: EXTERN PetscErrorCode PetscOpenMPFinalize(void);
1171: EXTERN PetscErrorCode PetscOpenMPRun(MPI_Comm,PetscErrorCode (*)(MPI_Comm,void *),void*);
1172: EXTERN PetscErrorCode PetscOpenMPFree(MPI_Comm,void*);
1173: EXTERN PetscErrorCode PetscOpenMPNew(MPI_Comm,PetscInt,void**);
1175: /*
1177: function pointers. Since the regular C++ code expects its function pointers to be
1178: C++.
1179: */
1180: typedef void (**PetscVoidStarFunction)(void);
1181: typedef void (*PetscVoidFunction)(void);
1182: typedef PetscErrorCode (*PetscErrorCodeFunction)(void);
1184: /*
1185: PetscTryMethod - Queries an object for a method, if it exists then calls it.
1186: These are intended to be used only inside PETSc functions.
1187: */
1188: #define PetscTryMethod(obj,A,B,C) \
1189: 0;{ PetscErrorCode (*f)B, __ierr; \
1190: __PetscObjectQueryFunction((PetscObject)obj,#A,(PetscVoidStarFunction)&f);CHKERRQ(__ierr); \
1191: if (f) {__(*f)C;CHKERRQ(__ierr);}\
1192: }
1193: #define PetscUseMethod(obj,A,B,C) \
1194: 0;{ PetscErrorCode (*f)B, __ierr; \
1195: __PetscObjectQueryFunction((PetscObject)obj,A,(PetscVoidStarFunction)&f);CHKERRQ(__ierr); \
1196: if (f) {__(*f)C;CHKERRQ(__ierr);}\
1197: else {SETERRQ1(PETSC_ERR_SUP,"Cannot locate function %s in object",A);} \
1198: }
1199: /*
1200: Functions that can act on any PETSc object.
1201: */
1202: EXTERN PetscErrorCode PetscObjectCreate(MPI_Comm,PetscObject*);
1203: EXTERN PetscErrorCode PetscObjectCreateGeneric(MPI_Comm, PetscCookie, const char [], PetscObject *);
1204: EXTERN PetscErrorCode PetscObjectDestroy(PetscObject);
1205: EXTERN PetscErrorCode PetscObjectExists(PetscObject,PetscTruth*);
1206: EXTERN PetscErrorCode PetscObjectGetComm(PetscObject,MPI_Comm *);
1207: EXTERN PetscErrorCode PetscObjectGetCookie(PetscObject,PetscCookie *);
1208: EXTERN PetscErrorCode PetscObjectSetType(PetscObject,const char []);
1209: EXTERN PetscErrorCode PetscObjectGetType(PetscObject,const char *[]);
1210: EXTERN PetscErrorCode PetscObjectSetName(PetscObject,const char[]);
1211: EXTERN PetscErrorCode PetscObjectGetName(PetscObject,const char*[]);
1212: EXTERN PetscErrorCode PetscObjectReference(PetscObject);
1213: EXTERN PetscErrorCode PetscObjectGetReference(PetscObject,PetscInt*);
1214: EXTERN PetscErrorCode PetscObjectDereference(PetscObject);
1215: EXTERN PetscErrorCode PetscObjectGetNewTag(PetscObject,PetscMPIInt *);
1216: EXTERN PetscErrorCode PetscObjectView(PetscObject,PetscViewer);
1217: EXTERN PetscErrorCode PetscObjectCompose(PetscObject,const char[],PetscObject);
1218: EXTERN PetscErrorCode PetscObjectQuery(PetscObject,const char[],PetscObject *);
1219: EXTERN PetscErrorCode PetscObjectComposeFunction(PetscObject,const char[],const char[],void (*)(void));
1220: EXTERN PetscErrorCode PetscObjectSetFromOptions(PetscObject);
1221: EXTERN PetscErrorCode PetscObjectSetUp(PetscObject);
1222: EXTERN PetscErrorCode PetscCommGetNewTag(MPI_Comm,PetscMPIInt *);
1224: /*MC
1225: PetscObjectComposeFunctionDynamic - Associates a function with a given PETSc object.
1226:
1227: Collective on PetscObject
1229: Input Parameters:
1230: + obj - the PETSc object; this must be cast with a (PetscObject), for example,
1231: PetscObjectCompose((PetscObject)mat,...);
1232: . name - name associated with the child function
1233: . fname - name of the function
1234: - ptr - function pointer (or PETSC_NULL if using dynamic libraries)
1236: Level: advanced
1238: Synopsis:
1239: PetscErrorCode PetscObjectComposeFunctionDynamic(PetscObject obj,const char name[],const char fname[],void *ptr)
1241: Notes:
1242: To remove a registered routine, pass in a PETSC_NULL rname and fnc().
1244: PetscObjectComposeFunctionDynamic() can be used with any PETSc object (such as
1245: Mat, Vec, KSP, SNES, etc.) or any user-provided object.
1248: work in C++/complex with dynamic link libraries (config/configure.py options --with-shared --with-dynamic)
1249: enabled.
1251: Concepts: objects^composing functions
1252: Concepts: composing functions
1253: Concepts: functions^querying
1254: Concepts: objects^querying
1255: Concepts: querying objects
1257: .seealso: PetscObjectQueryFunction()
1258: M*/
1259: #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
1260: #define PetscObjectComposeFunctionDynamic(a,b,c,d) PetscObjectComposeFunction(a,b,c,0)
1261: #else
1262: #define PetscObjectComposeFunctionDynamic(a,b,c,d) PetscObjectComposeFunction(a,b,c,(PetscVoidFunction)(d))
1263: #endif
1265: EXTERN PetscErrorCode PetscObjectQueryFunction(PetscObject,const char[],void (**)(void));
1266: EXTERN PetscErrorCode PetscObjectSetOptionsPrefix(PetscObject,const char[]);
1267: EXTERN PetscErrorCode PetscObjectAppendOptionsPrefix(PetscObject,const char[]);
1268: EXTERN PetscErrorCode PetscObjectPrependOptionsPrefix(PetscObject,const char[]);
1269: EXTERN PetscErrorCode PetscObjectGetOptionsPrefix(PetscObject,const char*[]);
1270: EXTERN PetscErrorCode PetscObjectPublish(PetscObject);
1271: EXTERN PetscErrorCode PetscObjectChangeTypeName(PetscObject,const char[]);
1272: EXTERN PetscErrorCode PetscObjectRegisterDestroy(PetscObject);
1273: EXTERN PetscErrorCode PetscObjectRegisterDestroyAll(void);
1274: EXTERN PetscErrorCode PetscObjectName(PetscObject);
1275: EXTERN PetscErrorCode PetscTypeCompare(PetscObject,const char[],PetscTruth*);
1277: /*
1278: Defines PETSc error handling.
1279: */
1280: #include petscerror.h
1282: /*S
1283: PetscOList - Linked list of PETSc objects, accessable by string name
1285: Level: advanced
1287: .seealso: PetscOListAdd(), PetscOListDestroy(), PetscOListFind()
1288: S*/
1289: typedef struct _n_PetscOList *PetscOList;
1291: EXTERN PetscErrorCode PetscOListDestroy(PetscOList);
1292: EXTERN PetscErrorCode PetscOListFind(PetscOList,const char[],PetscObject*);
1293: EXTERN PetscErrorCode PetscOListReverseFind(PetscOList,PetscObject,char**);
1294: EXTERN PetscErrorCode PetscOListAdd(PetscOList *,const char[],PetscObject);
1295: EXTERN PetscErrorCode PetscOListDuplicate(PetscOList,PetscOList *);
1297: /*
1298: Dynamic library lists. Lists of names of routines in dynamic
1299: link libraries that will be loaded as needed.
1300: */
1301: EXTERN PetscErrorCode PetscFListAdd(PetscFList*,const char[],const char[],void (*)(void));
1302: EXTERN PetscErrorCode PetscFListDestroy(PetscFList*);
1303: EXTERN PetscErrorCode PetscFListFind(PetscFList,MPI_Comm,const char[],void (**)(void));
1304: EXTERN PetscErrorCode PetscFListPrintTypes(PetscFList,MPI_Comm,FILE*,const char[],const char[],const char[],const char[]);
1305: #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
1306: #define PetscFListAddDynamic(a,b,p,c) PetscFListAdd(a,b,p,0)
1307: #else
1308: #define PetscFListAddDynamic(a,b,p,c) PetscFListAdd(a,b,p,(void (*)(void))c)
1309: #endif
1310: EXTERN PetscErrorCode PetscFListDuplicate(PetscFList,PetscFList *);
1311: EXTERN PetscErrorCode PetscFListView(PetscFList,PetscViewer);
1312: EXTERN PetscErrorCode PetscFListConcat(const char [],const char [],char []);
1313: EXTERN PetscErrorCode PetscFListGet(PetscFList,char ***,int*);
1315: /*S
1316: PetscDLLibrary - Linked list of dynamics libraries to search for functions
1318: Level: advanced
1320: --with-shared --with-dynamic must be used with config/configure.py to use dynamic libraries
1322: .seealso: PetscDLLibraryOpen()
1323: S*/
1324: typedef struct _n_PetscDLLibrary *PetscDLLibrary;
1326: EXTERN PetscErrorCode PetscDLLibraryRetrieve(MPI_Comm,const char[],char *,int,PetscTruth *);
1327: EXTERN PetscErrorCode PetscDLLibraryOpen(MPI_Comm,const char[],void **);
1328: EXTERN PetscErrorCode PetscDLLibrarySym(MPI_Comm,PetscDLLibrary *,const char[],const char[],void **);
1329: EXTERN PetscErrorCode PetscDLLibraryAppend(MPI_Comm,PetscDLLibrary *,const char[]);
1330: EXTERN PetscErrorCode PetscDLLibraryPrepend(MPI_Comm,PetscDLLibrary *,const char[]);
1331: EXTERN PetscErrorCode PetscDLLibraryClose(PetscDLLibrary);
1332: EXTERN PetscErrorCode PetscDLLibraryPrintPath(void);
1333: EXTERN PetscErrorCode PetscDLLibraryGetInfo(void*,const char[],const char *[]);
1334: EXTERN PetscErrorCode PetscDLLibraryCCAAppend(MPI_Comm,PetscDLLibrary *,const char[]);
1336: /*
1337: Useful utility routines
1338: */
1339: EXTERN PetscErrorCode PetscSplitOwnership(MPI_Comm,PetscInt*,PetscInt*);
1340: EXTERN PetscErrorCode PetscSplitOwnershipBlock(MPI_Comm,PetscInt,PetscInt*,PetscInt*);
1341: EXTERN PetscErrorCode PetscSequentialPhaseBegin(MPI_Comm,PetscMPIInt);
1342: PetscPolymorphicSubroutine(PetscSequentialPhaseBegin,(MPI_Comm comm),(comm,1))
1343: PetscPolymorphicSubroutine(PetscSequentialPhaseBegin,(void),(PETSC_COMM_WORLD,1))
1344: EXTERN PetscErrorCode PetscSequentialPhaseEnd(MPI_Comm,PetscMPIInt);
1345: PetscPolymorphicSubroutine(PetscSequentialPhaseEnd,(MPI_Comm comm),(comm,1))
1346: PetscPolymorphicSubroutine(PetscSequentialPhaseEnd,(void),(PETSC_COMM_WORLD,1))
1347: EXTERN PetscErrorCode PetscBarrier(PetscObject);
1348: EXTERN PetscErrorCode PetscMPIDump(FILE*);
1350: #define PetscNot(a) ((a) ? PETSC_FALSE : PETSC_TRUE)
1351: /*
1352: Defines basic graphics available from PETSc.
1353: */
1354: #include petscdraw.h
1356: /*
1357: Defines the base data structures for all PETSc objects
1358: */
1359: #include private/petscimpl.h
1360: /*
1361: Defines PETSc profiling.
1362: */
1363: #include petsclog.h
1365: /*
1366: For locking, unlocking and destroying AMS memories associated with
1367: PETSc objects. Not currently used.
1368: */
1369: #define PetscPublishAll(v) 0
1370: #define PetscObjectTakeAccess(obj) 0
1371: #define PetscObjectGrantAccess(obj) 0
1372: #define PetscObjectDepublish(obj) 0
1376: /*
1377: This code allows one to pass a MPI communicator between
1378: C and Fortran. MPI 2.0 defines a standard API for doing this.
1379: The code here is provided to allow PETSc to work with MPI 1.1
1380: standard MPI libraries.
1381: */
1382: EXTERN PetscErrorCode MPICCommToFortranComm(MPI_Comm,int *);
1383: EXTERN PetscErrorCode MPIFortranCommToCComm(int,MPI_Comm*);
1385: /*
1386: Simple PETSc parallel IO for ASCII printing
1387: */
1388: EXTERN PetscErrorCode PetscFixFilename(const char[],char[]);
1389: EXTERN PetscErrorCode PetscFOpen(MPI_Comm,const char[],const char[],FILE**);
1390: EXTERN PetscErrorCode PetscFClose(MPI_Comm,FILE*);
1391: EXTERN PetscErrorCode PetscFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4);
1392: EXTERN PetscErrorCode PetscPrintf(MPI_Comm,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3);
1393: EXTERN PetscErrorCode PetscSNPrintf(char*,size_t,const char [],...);
1395: /* These are used internally by PETSc ASCII IO routines*/
1396: #include <stdarg.h>
1397: EXTERN PetscErrorCode PetscVSNPrintf(char*,size_t,const char[],va_list);
1398: EXTERN PetscErrorCode PetscVFPrintf(FILE*,const char[],va_list);
1400: /*MC
1401: PetscErrorPrintf - Prints error messages.
1403: Not Collective
1405: Synopsis:
1406: PetscErrorCode (*PetscErrorPrintf)(const char format[],...);
1408: Input Parameters:
1409: . format - the usual printf() format string
1411: Options Database Keys:
1412: + -error_output_stderr - cause error messages to be printed to stderr instead of the
1413: (default) stdout
1414: - -error_output_none to turn off all printing of error messages (does not change the way the
1415: error is handled.)
1417: Notes: Use
1418: PetscErrorPrintf = PetscErrorPrintfNone; to turn off all printing of error messages (does not change the way the
1419: error is handled.) and
1420: PetscErrorPrintf = PetscErrorPrintfDefault; to turn it back on
1423:
1425: Level: developer
1427: Fortran Note:
1428: This routine is not supported in Fortran.
1430: Concepts: error messages^printing
1431: Concepts: printing^error messages
1433: .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf()
1434: M*/
1435: EXTERN PetscErrorCode (*PetscErrorPrintf)(const char[],...);
1437: /*MC
1438: PetscHelpPrintf - Prints help messages.
1440: Not Collective
1442: Synopsis:
1443: PetscErrorCode (*PetscHelpPrintf)(const char format[],...);
1445: Input Parameters:
1446: . format - the usual printf() format string
1448: Level: developer
1450: Fortran Note:
1451: This routine is not supported in Fortran.
1453: Concepts: help messages^printing
1454: Concepts: printing^help messages
1456: .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscErrorPrintf()
1457: M*/
1458: EXTERN PetscErrorCode (*PetscHelpPrintf)(MPI_Comm,const char[],...);
1460: EXTERN PetscErrorCode PetscErrorPrintfDefault(const char [],...);
1461: EXTERN PetscErrorCode PetscErrorPrintfNone(const char [],...);
1462: EXTERN PetscErrorCode PetscHelpPrintfDefault(MPI_Comm,const char [],...);
1464: EXTERN PetscErrorCode PetscPOpen(MPI_Comm,const char[],const char[],const char[],FILE **);
1465: EXTERN PetscErrorCode PetscPClose(MPI_Comm,FILE*);
1466: EXTERN PetscErrorCode PetscSynchronizedPrintf(MPI_Comm,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3);
1467: EXTERN PetscErrorCode PetscSynchronizedFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4);
1468: EXTERN PetscErrorCode PetscSynchronizedFlush(MPI_Comm);
1469: EXTERN PetscErrorCode PetscSynchronizedFGets(MPI_Comm,FILE*,size_t,char[]);
1470: EXTERN PetscErrorCode PetscStartMatlab(MPI_Comm,const char[],const char[],FILE**);
1471: EXTERN PetscErrorCode PetscStartJava(MPI_Comm,const char[],const char[],FILE**);
1472: EXTERN PetscErrorCode PetscGetPetscDir(const char*[]);
1474: EXTERN PetscErrorCode PetscPopUpSelect(MPI_Comm,char*,char*,int,char**,int*);
1476: /*S
1477: PetscContainer - Simple PETSc object that contains a pointer to any required data
1479: Level: advanced
1481: .seealso: PetscObject, PetscContainerCreate()
1482: S*/
1484: typedef struct _p_PetscContainer* PetscContainer;
1485: EXTERN PetscErrorCode PetscContainerGetPointer(PetscContainer,void **);
1486: EXTERN PetscErrorCode PetscContainerSetPointer(PetscContainer,void *);
1487: EXTERN PetscErrorCode PetscContainerDestroy(PetscContainer);
1488: EXTERN PetscErrorCode PetscContainerCreate(MPI_Comm,PetscContainer *);
1489: EXTERN PetscErrorCode PetscContainerSetUserDestroy(PetscContainer, PetscErrorCode (*)(void*));
1491: /*
1492: For use in debuggers
1493: */
1497: EXTERN PetscErrorCode PetscIntView(PetscInt,PetscInt[],PetscViewer);
1498: EXTERN PetscErrorCode PetscRealView(PetscInt,PetscReal[],PetscViewer);
1499: EXTERN PetscErrorCode PetscScalarView(PetscInt,PetscScalar[],PetscViewer);
1501: /*
1502: Allows accessing Matlab Engine
1503: */
1504: #include petscmatlab.h
1506: /*
1507: Determine if some of the kernel computation routines use
1508: Fortran (rather than C) for the numerical calculations. On some machines
1509: and compilers (like complex numbers) the Fortran version of the routines
1510: is faster than the C/C++ versions. The flag --with-fortran-kernels
1511: should be used with config/configure.py to turn these on.
1512: */
1513: #if defined(PETSC_USE_FORTRAN_KERNELS)
1515: #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTCRL)
1516: #define PETSC_USE_FORTRAN_KERNEL_MULTCRL
1517: #endif
1519: #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTCSRPERM)
1520: #define PETSC_USE_FORTRAN_KERNEL_MULTCSRPERM
1521: #endif
1523: #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ)
1524: #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ
1525: #endif
1527: #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ)
1528: #define PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ
1529: #endif
1531: #if !defined(PETSC_USE_FORTRAN_KERNEL_NORM)
1532: #define PETSC_USE_FORTRAN_KERNEL_NORM
1533: #endif
1535: #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY)
1536: #define PETSC_USE_FORTRAN_KERNEL_MAXPY
1537: #endif
1539: #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ)
1540: #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ
1541: #endif
1543: #if !defined(PETSC_USE_FORTRAN_KERNEL_RELAXAIJ)
1544: #define PETSC_USE_FORTRAN_KERNEL_RELAXAIJ
1545: #endif
1547: #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ)
1548: #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ
1549: #endif
1551: #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ)
1552: #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ
1553: #endif
1555: #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT)
1556: #define PETSC_USE_FORTRAN_KERNEL_MDOT
1557: #endif
1559: #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY)
1560: #define PETSC_USE_FORTRAN_KERNEL_XTIMESY
1561: #endif
1563: #if !defined(PETSC_USE_FORTRAN_KERNEL_AYPX)
1564: #define PETSC_USE_FORTRAN_KERNEL_AYPX
1565: #endif
1567: #if !defined(PETSC_USE_FORTRAN_KERNEL_WAXPY)
1568: #define PETSC_USE_FORTRAN_KERNEL_WAXPY
1569: #endif
1571: #endif
1573: /*
1574: Macros for indicating code that should be compiled with a C interface,
1575: rather than a C++ interface. Any routines that are dynamically loaded
1576: (such as the PCCreate_XXX() routines) must be wrapped so that the name
1577: mangler does not change the functions symbol name. This just hides the
1579: */
1580: #if defined(__cplusplus)
1583: #else
1586: #endif
1588: /* --------------------------------------------------------------------*/
1590: /*MC
1591: size - integer variable used to contain the number of processors in
1592: the relevent MPI_Comm
1594: Level: beginner
1596: .seealso: rank, comm
1597: M*/
1599: /*MC
1600: rank - integer variable used to contain the number of this processor relative
1601: to all in the relevent MPI_Comm
1603: Level: beginner
1605: .seealso: size, comm
1606: M*/
1608: /*MC
1609: comm - MPI_Comm used in the current routine or object
1611: Level: beginner
1613: .seealso: size, rank
1614: M*/
1616: /*MC
1617: MPI_Comm - the basic object used by MPI to determine which processes are involved in a
1618: communication
1620: Level: beginner
1622: Note: This manual page is a place-holder because MPICH does not have a manual page for MPI_Comm
1624: .seealso: size, rank, comm, PETSC_COMM_WORLD, PETSC_COMM_SELF
1625: M*/
1627: /*MC
1628: PetscScalar - PETSc type that represents either a double precision real number,
1629: a double precision complex number, a single precision real number, a long double or an int
1630: if the code is configured with --with-scalar-type=complex,float,longdouble,int
1632: Level: beginner
1634: .seealso: PetscReal, PassiveReal, PassiveScalar
1635: M*/
1637: /*MC
1638: PetscReal - PETSc type that represents a real number version of PetscScalar
1640: Level: beginner
1642: .seealso: PetscScalar, PassiveReal, PassiveScalar
1643: M*/
1645: /*MC
1646: PassiveScalar - PETSc type that represents a PetscScalar
1647: Level: beginner
1649: This is the same as a PetscScalar except in code that is automatically differentiated it is
1650: treated as a constant (not an indendent or dependent variable)
1652: .seealso: PetscReal, PassiveReal, PetscScalar
1653: M*/
1655: /*MC
1656: PassiveReal - PETSc type that represents a PetscReal
1658: Level: beginner
1660: This is the same as a PetscReal except in code that is automatically differentiated it is
1661: treated as a constant (not an indendent or dependent variable)
1663: .seealso: PetscScalar, PetscReal, PassiveScalar
1664: M*/
1666: /*MC
1667: MPIU_SCALAR - MPI datatype corresponding to PetscScalar
1669: Level: beginner
1671: Note: In MPI calls that require an MPI datatype that matches a PetscScalar or array of PetscScalars
1672: pass this value
1674: .seealso: PetscReal, PassiveReal, PassiveScalar, PetscScalar
1675: M*/
1677: /*
1678: The IBM include files define hz, here we hide it so that it may be used
1679: as a regular user variable.
1680: */
1681: #if defined(hz)
1682: #undef hz
1683: #endif
1685: /* For arrays that contain filenames or paths */
1688: #if defined(PETSC_HAVE_LIMITS_H)
1689: #include <limits.h>
1690: #endif
1691: #if defined(PETSC_HAVE_SYS_PARAM_H)
1692: #include <sys/param.h>
1693: #endif
1694: #if defined(PETSC_HAVE_SYS_TYPES_H)
1695: #include <sys/types.h>
1696: #endif
1697: #if defined(MAXPATHLEN)
1698: # define PETSC_MAX_PATH_LEN MAXPATHLEN
1699: #elif defined(MAX_PATH)
1700: # define PETSC_MAX_PATH_LEN MAX_PATH
1701: #elif defined(_MAX_PATH)
1702: # define PETSC_MAX_PATH_LEN _MAX_PATH
1703: #else
1704: # define PETSC_MAX_PATH_LEN 4096
1705: #endif
1708: #endif