Actual source code: petscsys.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 ${PETSC_ARCH}/include/petscconf.h it is
10: found automatically by the compiler due to the -I${PETSC_DIR}/${PETSC_ARCH}/include
11: in the conf/variables definition of PETSC_INCLUDE
12: */
13: #include "petscconf.h"
14: #include "petscfix.h"
16: /* ========================================================================== */
17: /*
18: This facilitates using C version of PETSc from C++ and
19: C++ version from C. Use --with-c-support --with-clanguage=c++ with config/configure.py for the latter)
20: */
22: #error "PETSc configured with --with-clanguage=c++ and NOT --with-c-support - it can be used only with a C++ compiler"
23: #endif
28: #else
31: #endif
32: /* ========================================================================== */
33: /*
34: Current PETSc version number and release date. Also listed in
35: Web page
36: src/docs/tex/manual/intro.tex,
37: src/docs/tex/manual/manual.tex.
38: src/docs/website/index.html.
39: */
40: #include petscversion.h
41: #define PETSC_AUTHOR_INFO "\
42: The PETSc Team\n\
43: petsc-maint@mcs.anl.gov\n\
44: http://www.mcs.anl.gov/petsc/\n"
45: #if (PETSC_VERSION_RELEASE == 1)
46: #define PetscGetVersion(version,len) (PetscSNPrintf(version,len,"Petsc Release Version %d.%d.%d, Patch %d, ", \
47: PETSC_VERSION_MAJOR,PETSC_VERSION_MINOR, PETSC_VERSION_SUBMINOR, \
48: PETSC_VERSION_PATCH),PetscStrcat(version,PETSC_VERSION_PATCH_DATE))
49: #else
50: #define PetscGetVersion(version,len) (PetscSNPrintf(version,len,"Petsc Development"), \
51: PetscStrcat(version," HG revision: "),PetscStrcat(version,PETSC_VERSION_HG), \
52: PetscStrcat(version," HG Date: "),PetscStrcat(version,PETSC_VERSION_DATE_HG))
53: #endif
55: /*MC
56: PetscGetVersion - Gets the PETSc version information in a string.
58: Input Parameter:
59: . len - length of the string
61: Output Parameter:
62: . version - version string
64: Level: developer
66: Usage:
67: char version[256];
68: PetscGetVersion(version,256);CHKERRQ(ierr)
70: Fortran Note:
71: This routine is not supported in Fortran.
73: .seealso: PetscGetProgramName()
75: M*/
77: /* ========================================================================== */
79: /*
80: Currently cannot check formatting for PETSc print statements because we have our
81: own format %D and %G
82: */
83: #undef PETSC_PRINTF_FORMAT_CHECK
84: #define PETSC_PRINTF_FORMAT_CHECK(a,b)
85: #undef PETSC_FPRINTF_FORMAT_CHECK
86: #define PETSC_FPRINTF_FORMAT_CHECK(a,b)
88: /*
89: Fixes for config/configure.py time choices which impact our interface. Currently only
90: calling conventions and extra compiler checking falls under this category.
91: */
92: #if !defined(PETSC_STDCALL)
93: #define PETSC_STDCALL
94: #endif
95: #if !defined(PETSC_TEMPLATE)
96: #define PETSC_TEMPLATE
97: #endif
98: #if !defined(PETSC_HAVE_DLL_EXPORT)
99: #define PETSC_DLL_EXPORT
100: #define PETSC_DLL_IMPORT
101: #endif
102: #if !defined()
103: #define
104: #endif
105: #if !defined()
106: #define
107: #endif
108: #if !defined()
109: #define
110: #endif
111: #if !defined()
112: #define
113: #endif
114: #if !defined()
115: #define
116: #endif
117: #if !defined()
118: #define
119: #endif
120: #if !defined()
121: #define
122: #endif
123: #if !defined()
124: #define
125: #endif
126: /* ========================================================================== */
128: /*
129: Defines the interface to MPI allowing the use of all MPI functions.
131: PETSc does not use the C++ binding of MPI at ALL. The following flag
132: makes sure the C++ bindings are not included. The C++ bindings REQUIRE
133: putting mpi.h before ANY C++ include files, we cannot control this
134: with all PETSc users. Users who want to use the MPI C++ bindings can include
135: mpicxx.h directly in their code
136: */
137: #define MPICH_SKIP_MPICXX 1
138: #define OMPI_SKIP_MPICXX 1
139: #include "mpi.h"
141: /*
142: Yuck, we need to put stdio.h AFTER mpi.h for MPICH2 with C++ compiler
143: see the top of mpicxx.h in the MPICH2 distribution.
145: The MPI STANDARD HAS TO BE CHANGED to prevent this nonsense.
146: */
147: #include <stdio.h>
149: /* MSMPI on 32bit windows requires this yukky hack - that breaks MPI standard compliance */
150: #if !defined(MPIAPI)
151: #define MPIAPI
152: #endif
154: /*MC
155: PetscErrorCode - datatype used for return error code from all PETSc functions
157: Level: beginner
159: .seealso: CHKERRQ, SETERRQ
160: M*/
161: typedef int PetscErrorCode;
163: /*MC
165: PetscCookie - A unique id used to identify each PETSc object.
166: (internal integer in the data structure used for error
167: checking). These are all defined by an offset from the lowest
168: one, PETSC_SMALLEST_COOKIE.
170: Level: advanced
172: .seealso: PetscCookieRegister(), PetscLogEventRegister(), PetscHeaderCreate()
173: M*/
174: typedef int PetscCookie;
176: /*MC
177: PetscLogEvent - id used to identify PETSc or user events - primarily for logging
179: Level: intermediate
181: .seealso: PetscLogEventRegister(), PetscLogEventBegin(), PetscLogEventEnd(), PetscLogStage
182: M*/
183: typedef int PetscLogEvent;
185: /*MC
186: PetscLogStage - id used to identify user stages of runs - for logging
188: Level: intermediate
190: .seealso: PetscLogStageRegister(), PetscLogStageBegin(), PetscLogStageEnd(), PetscLogEvent
191: M*/
192: typedef int PetscLogStage;
194: /*MC
195: PetscBLASInt - datatype used to represent 'int' parameters to BLAS/LAPACK functions.
197: Level: intermediate
199: Notes: usually this is the same as PetscInt, but if PETSc was built with --with-64-bit-indices but
200: standard C/Fortran integers are 32 bit then this is NOT the same as PetscInt
202: .seealso: PetscMPIInt, PetscInt
204: M*/
205: typedef int PetscBLASInt;
207: /*MC
208: PetscMPIInt - datatype used to represent 'int' parameters to MPI functions.
210: Level: intermediate
212: Notes: usually this is the same as PetscInt, but if PETSc was built with --with-64-bit-indices but
213: standard C/Fortran integers are 32 bit then this is NOT the same as PetscInt
215: PetscBLASIntCheck(a) checks if the given PetscInt a will fit in a PetscBLASInt, if not it generates a
216: PETSC_ERR_ARG_OUTOFRANGE.
218: PetscBLASInt b = PetscBLASIntCast(a) checks if the given PetscInt a will fit in a PetscBLASInt, if not it
219: generates a PETSC_ERR_ARG_OUTOFRANGE
221: .seealso: PetscBLASInt, PetscInt
223: M*/
224: typedef int PetscMPIInt;
226: /*MC
227: PetscEnum - datatype used to pass enum types within PETSc functions.
229: Level: intermediate
231: PetscMPIIntCheck(a) checks if the given PetscInt a will fit in a PetscMPIInt, if not it generates a
232: PETSC_ERR_ARG_OUTOFRANGE.
234: PetscMPIInt b = PetscMPIIntCast(a) checks if the given PetscInt a will fit in a PetscMPIInt, if not it
235: generates a PETSC_ERR_ARG_OUTOFRANGE
237: .seealso: PetscOptionsGetEnum(), PetscOptionsEnum(), PetscBagRegisterEnum()
238: M*/
239: typedef enum { ENUM_DUMMY } PetscEnum;
241: /*MC
242: PetscInt - PETSc type that represents integer - used primarily to
243: represent size of objects. Its size can be configured with the option
244: --with-64-bit-indices - to be either 32bit or 64bit [default 32 bit ints]
246: Level: intermediate
249: .seealso: PetscScalar, PetscBLASInt, PetscMPIInt
250: M*/
251: #if defined(PETSC_USE_64BIT_INDICES)
252: typedef long long PetscInt;
253: #define MPIU_INT MPI_LONG_LONG_INT
254: #else
255: typedef int PetscInt;
256: #define MPIU_INT MPI_INT
257: #endif
259: /* add in MPIU type for size_t */
260: #if (PETSC_SIZEOF_SIZE_T) == (PETSC_SIZEOF_INT)
261: #define MPIU_SIZE_T MPI_INT
262: #elif (PETSC_SIZEOF_SIZE_T) == (PETSC_SIZEOF_LONG)
263: #define MPIU_SIZE_T MPI_LONG
264: #elif (PETSC_SIZEOF_SIZE_T) == (PETSC_SIZEOF_LONG_LONG)
265: #define MPIU_SIZE_T MPI_LONG_LONG_INT
266: #else
267: #error "Unknown size for size_t! Send us a bugreport at petsc-maint@mcs.anl.gov"
268: #endif
271: /*
272: You can use PETSC_STDOUT as a replacement of stdout. You can also change
273: the value of PETSC_STDOUT to redirect all standard output elsewhere
274: */
278: /*
279: You can use PETSC_STDERR as a replacement of stderr. You can also change
280: the value of PETSC_STDERR to redirect all standard error elsewhere
281: */
284: /*
285: PETSC_ZOPEFD is used to send data to the PETSc webpage. It can be used
286: in conjunction with PETSC_STDOUT, or by itself.
287: */
291: /*MC
292: PetscPolymorphicSubroutine - allows defining a C++ polymorphic version of
293: a PETSc function that remove certain optional arguments for a simplier user interface
295: Not collective
297: Synopsis:
298: PetscPolymorphicSubroutine(Functionname,(arguments of C++ function),(arguments of C function))
299:
300: Level: developer
302: Example:
303: PetscPolymorphicSubroutine(VecNorm,(Vec x,PetscReal *r),(x,NORM_2,r)) generates the new routine
304: PetscErrorCode VecNorm(Vec x,PetscReal *r) = VecNorm(x,NORM_2,r)
306: .seealso: PetscPolymorphicFunction()
308: M*/
309: #define PetscPolymorphicSubroutine(A,B,C) PETSC_STATIC_INLINE PetscErrorCode A B {return A C;}
311: /*MC
312: PetscPolymorphicScalar - allows defining a C++ polymorphic version of
313: a PETSc function that replaces a PetscScalar * argument with a PetscScalar argument
315: Not collective
317: Synopsis:
318: PetscPolymorphicScalar(Functionname,(arguments of C++ function),(arguments of C function))
319:
320: Level: developer
322: Example:
323: PetscPolymorphicScalar(VecAXPY,(PetscScalar _val,Vec x,Vec y),(&_Val,x,y)) generates the new routine
324: PetscErrorCode VecAXPY(PetscScalar _val,Vec x,Vec y) = {PetscScalar _Val = _val; return VecAXPY(&_Val,x,y);}
326: .seealso: PetscPolymorphicFunction(),PetscPolymorphicSubroutine()
328: M*/
329: #define PetscPolymorphicScalar(A,B,C) PETSC_STATIC_INLINE PetscErrorCode A B {PetscScalar _Val = _val; return A C;}
331: /*MC
332: PetscPolymorphicFunction - allows defining a C++ polymorphic version of
333: a PETSc function that remove certain optional arguments for a simplier user interface
334: and returns the computed value (istead of an error code)
336: Not collective
338: Synopsis:
339: PetscPolymorphicFunction(Functionname,(arguments of C++ function),(arguments of C function),return type,return variable name)
340:
341: Level: developer
343: Example:
344: PetscPolymorphicFunction(VecNorm,(Vec x,NormType t),(x,t,&r),PetscReal,r) generates the new routine
345: PetscReal VecNorm(Vec x,NormType t) = {PetscReal r; VecNorm(x,t,&r); return r;}
347: .seealso: PetscPolymorphicSubroutine()
349: M*/
350: #define PetscPolymorphicFunction(A,B,C,D,E) PETSC_STATIC_INLINE D A B {D E; A C;return E;}
352: #else
353: #define PetscPolymorphicSubroutine(A,B,C)
354: #define PetscPolymorphicScalar(A,B,C)
355: #define PetscPolymorphicFunction(A,B,C,D,E)
356: #endif
358: /*MC
359: PetscUnlikely - hints the compiler that the given condition is usually FALSE
361: Not Collective
363: Synopsis:
364: PetscTruth PetscUnlikely(PetscTruth cond)
366: Input Parameters:
367: . cond - condition or expression
369: Note: This returns the same truth value, it is only a hint to compilers that the resulting
370: branch is unlikely.
372: Level: advanced
374: .seealso: PetscLikely(), CHKERRQ
375: M*/
377: /*MC
378: PetscLikely - hints the compiler that the given condition is usually TRUE
380: Not Collective
382: Synopsis:
383: PetscTruth PetscUnlikely(PetscTruth cond)
385: Input Parameters:
386: . cond - condition or expression
388: Note: This returns the same truth value, it is only a hint to compilers that the resulting
389: branch is likely.
391: Level: advanced
393: .seealso: PetscUnlikely()
394: M*/
395: #if defined(PETSC_HAVE_BUILTIN_EXPECT)
396: # define PetscUnlikely(cond) __builtin_expect(!!(cond),0)
397: # define PetscLikely(cond) __builtin_expect(!!(cond),1)
398: #else
399: # define PetscUnlikely(cond) cond
400: # define PetscLikely(cond) cond
401: #endif
403: /*
404: Extern indicates a PETSc function defined elsewhere
405: */
406: #if !defined(EXTERN)
407: #define EXTERN extern
408: #endif
410: /*
411: Defines some elementary mathematics functions and constants.
412: */
413: #include petscmath.h
415: /*
417: */
421: /*
422: Basic PETSc constants
423: */
425: /*E
426: PetscTruth - Logical variable. Actually an integer
428: Level: beginner
430: E*/
431: typedef enum { PETSC_FALSE,PETSC_TRUE } PetscTruth;
434: /*MC
435: PETSC_FALSE - False value of PetscTruth
437: Level: beginner
439: Note: Zero integer
441: .seealso: PetscTruth, PETSC_TRUE
442: M*/
444: /*MC
445: PETSC_TRUE - True value of PetscTruth
447: Level: beginner
449: Note: Nonzero integer
451: .seealso: PetscTruth, PETSC_FALSE
452: M*/
454: /*MC
455: PETSC_YES - Alias for PETSC_TRUE
457: Level: beginner
459: Note: Zero integer
461: .seealso: PetscTruth, PETSC_TRUE, PETSC_FALSE, PETSC_NO
462: M*/
463: #define PETSC_YES PETSC_TRUE
465: /*MC
466: PETSC_NO - Alias for PETSC_FALSE
468: Level: beginner
470: Note: Nonzero integer
472: .seealso: PetscTruth, PETSC_TRUE, PETSC_FALSE, PETSC_YES
473: M*/
474: #define PETSC_NO PETSC_FALSE
476: /*MC
477: PETSC_NULL - standard way of passing in a null or array or pointer
479: Level: beginner
481: Notes: accepted by many PETSc functions to not set a parameter and instead use
482: some default
484: This macro does not exist in Fortran; you must use PETSC_NULL_INTEGER,
485: PETSC_NULL_DOUBLE_PRECISION etc
487: .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_IGNORE, PETSC_DETERMINE
489: M*/
490: #define PETSC_NULL 0
492: /*MC
493: PETSC_DECIDE - standard way of passing in integer or floating point parameter
494: where you wish PETSc to use the default.
496: Level: beginner
498: .seealso: PETSC_NULL, PETSC_DEFAULT, PETSC_IGNORE, PETSC_DETERMINE
500: M*/
501: #define PETSC_DECIDE -1
503: /*MC
504: PETSC_DEFAULT - standard way of passing in integer or floating point parameter
505: where you wish PETSc to use the default.
507: Level: beginner
509: Fortran Notes: You need to use PETSC_DEFAULT_INTEGER or PETSC_DEFAULT_DOUBLE_PRECISION.
511: .seealso: PETSC_DECIDE, PETSC_NULL, PETSC_IGNORE, PETSC_DETERMINE
513: M*/
514: #define PETSC_DEFAULT -2
517: /*MC
518: PETSC_IGNORE - same as PETSC_NULL, means PETSc will ignore this argument
520: Level: beginner
522: Note: accepted by many PETSc functions to not set a parameter and instead use
523: some default
525: Fortran Notes: This macro does not exist in Fortran; you must use PETSC_NULL_INTEGER,
526: PETSC_NULL_DOUBLE_PRECISION etc
528: .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_NULL, PETSC_DETERMINE
530: M*/
531: #define PETSC_IGNORE PETSC_NULL
533: /*MC
534: PETSC_DETERMINE - standard way of passing in integer or floating point parameter
535: where you wish PETSc to compute the required value.
537: Level: beginner
539: .seealso: PETSC_DECIDE, PETSC_DEFAULT, PETSC_IGNORE, PETSC_NULL, VecSetSizes()
541: M*/
542: #define PETSC_DETERMINE PETSC_DECIDE
544: /*MC
545: PETSC_COMM_WORLD - the equivalent of the MPI_COMM_WORLD communicator which represents
546: all the processs that PETSc knows about.
548: Level: beginner
550: Notes: By default PETSC_COMM_WORLD and MPI_COMM_WORLD are identical unless you wish to
551: run PETSc on ONLY a subset of MPI_COMM_WORLD. In that case create your new (smaller)
552: communicator, call it, say comm, and set PETSC_COMM_WORLD = comm BEFORE calling
553: PetscInitialize()
555: .seealso: PETSC_COMM_SELF
557: M*/
560: /*MC
561: PETSC_COMM_SELF - a duplicate of the MPI_COMM_SELF communicator which represents
562: the current process
564: Level: beginner
566: Notes: PETSC_COMM_SELF and MPI_COMM_SELF are equivalent.
568: .seealso: PETSC_COMM_WORLD
570: M*/
571: #define PETSC_COMM_SELF MPI_COMM_SELF
576: EXTERN PetscErrorCode PetscSetHelpVersionFunctions(PetscErrorCode (*)(MPI_Comm),PetscErrorCode (*)(MPI_Comm));
577: EXTERN PetscErrorCode PetscCommDuplicate(MPI_Comm,MPI_Comm*,int*);
578: EXTERN PetscErrorCode PetscCommDestroy(MPI_Comm*);
580: /*MC
581: PetscMalloc - Allocates memory
583: Input Parameter:
584: . m - number of bytes to allocate
586: Output Parameter:
587: . result - memory allocated
589: Synopsis:
590: PetscErrorCode PetscMalloc(size_t m,void **result)
592: Level: beginner
594: Notes: Memory is always allocated at least double aligned
596: If you request memory of zero size it will allocate no space and assign the pointer to 0; PetscFree() will
597: properly handle not freeing the null pointer.
599: .seealso: PetscFree(), PetscNew()
601: Concepts: memory allocation
603: M*/
604: #define PetscMalloc(a,b) ((a != 0) ? (*PetscTrMalloc)((a),__LINE__,__FUNCT__,__FILE__,__SDIR__,(void**)(b)) : (*(b) = 0,0) )
606: /*MC
607: PetscAddrAlign - Returns an address with PETSC_MEMALIGN alignment
609: Input Parameters:
610: . addr - address to align (any pointer type)
612: Synopsis:
613: void *PetscAddrAlign(void *addr)
615: Level: developer
617: .seealso: PetscMallocAlign()
619: Concepts: memory allocation
620: M*/
621: #if defined PETSC_UINTPTR_T
622: # define PetscAddrAlign(a) (void*)((((PETSC_UINTPTR_T)(a))+(PETSC_MEMALIGN-1)) & ~(PETSC_MEMALIGN-1))
623: #else
624: # define PetscAddrAlign(a) (void*)(a)
625: #endif
627: /*MC
628: PetscMalloc2 - Allocates 2 chunks of memory
630: Input Parameter:
631: + m1 - number of elements to allocate in 1st chunk (may be zero)
632: . t1 - type of first memory elements
633: . m2 - number of elements to allocate in 2nd chunk (may be zero)
634: - t2 - type of second memory elements
636: Output Parameter:
637: + r1 - memory allocated in first chunk
638: - r2 - memory allocated in second chunk
640: Synopsis:
641: PetscErrorCode PetscMalloc2(size_t m1,type, t1,void **r1,size_t m2,type t2,void **r2)
643: Level: developer
645: Notes: Memory of first chunk is always allocated at least double aligned
647: .seealso: PetscFree(), PetscNew(), PetscMalloc()
649: Concepts: memory allocation
651: M*/
652: #if defined(PETSC_USE_DEBUG)
653: #define PetscMalloc2(m1,t1,r1,m2,t2,r2) (PetscMalloc((m1)*sizeof(t1),r1) || PetscMalloc((m2)*sizeof(t2),r2))
654: #else
655: #define PetscMalloc2(m1,t1,r1,m2,t2,r2) ((*(r2) = 0,PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(PETSC_MEMALIGN-1),r1)) \
656: || (*(r2) = (t2*)PetscAddrAlign(*(r1)+m1),0))
657: #endif
659: /*MC
660: PetscMalloc3 - Allocates 3 chunks of memory
662: Input Parameter:
663: + m1 - number of elements to allocate in 1st chunk (may be zero)
664: . t1 - type of first memory elements
665: . m2 - number of elements to allocate in 2nd chunk (may be zero)
666: . t2 - type of second memory elements
667: . m3 - number of elements to allocate in 3rd chunk (may be zero)
668: - t3 - type of third memory elements
670: Output Parameter:
671: + r1 - memory allocated in first chunk
672: . r2 - memory allocated in second chunk
673: - r3 - memory allocated in third chunk
675: Synopsis:
676: PetscErrorCode PetscMalloc3(size_t m1,type, t1,void **r1,size_t m2,type t2,void **r2,size_t m3,type t3,void **r3)
678: Level: developer
680: Notes: Memory of first chunk is always allocated at least double aligned
682: .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3()
684: Concepts: memory allocation
686: M*/
687: #if defined(PETSC_USE_DEBUG)
688: #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))
689: #else
690: #define PetscMalloc3(m1,t1,r1,m2,t2,r2,m3,t3,r3) ((*(r2) = 0,*(r3) = 0,PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3)+2*(PETSC_MEMALIGN-1),r1)) \
691: || (*(r2) = (t2*)PetscAddrAlign(*(r1)+m1),*(r3) = (t3*)PetscAddrAlign(*(r2)+m2),0))
692: #endif
694: /*MC
695: PetscMalloc4 - Allocates 4 chunks of memory
697: Input Parameter:
698: + m1 - number of elements to allocate in 1st chunk (may be zero)
699: . t1 - type of first memory elements
700: . m2 - number of elements to allocate in 2nd chunk (may be zero)
701: . t2 - type of second memory elements
702: . m3 - number of elements to allocate in 3rd chunk (may be zero)
703: . t3 - type of third memory elements
704: . m4 - number of elements to allocate in 4th chunk (may be zero)
705: - t4 - type of fourth memory elements
707: Output Parameter:
708: + r1 - memory allocated in first chunk
709: . r2 - memory allocated in second chunk
710: . r3 - memory allocated in third chunk
711: - r4 - memory allocated in fourth chunk
713: Synopsis:
714: 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)
716: Level: developer
718: Notes: Memory of first chunk is always allocated at least double aligned
720: .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4()
722: Concepts: memory allocation
724: M*/
725: #if defined(PETSC_USE_DEBUG)
726: #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))
727: #else
728: #define PetscMalloc4(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4) \
729: ((*(r2) = 0, *(r3) = 0, *(r4) = 0,PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3)+(m4)*sizeof(t4)+3*(PETSC_MEMALIGN-1),r1)) \
730: || (*(r2) = (t2*)PetscAddrAlign(*(r1)+m1),*(r3) = (t3*)PetscAddrAlign(*(r2)+m2),*(r4) = (t4*)PetscAddrAlign(*(r3)+m3),0))
731: #endif
733: /*MC
734: PetscMalloc5 - Allocates 5 chunks of memory
736: Input Parameter:
737: + m1 - number of elements to allocate in 1st chunk (may be zero)
738: . t1 - type of first memory elements
739: . m2 - number of elements to allocate in 2nd chunk (may be zero)
740: . t2 - type of second memory elements
741: . m3 - number of elements to allocate in 3rd chunk (may be zero)
742: . t3 - type of third memory elements
743: . m4 - number of elements to allocate in 4th chunk (may be zero)
744: . t4 - type of fourth memory elements
745: . m5 - number of elements to allocate in 5th chunk (may be zero)
746: - t5 - type of fifth memory elements
748: Output Parameter:
749: + r1 - memory allocated in first chunk
750: . r2 - memory allocated in second chunk
751: . r3 - memory allocated in third chunk
752: . r4 - memory allocated in fourth chunk
753: - r5 - memory allocated in fifth chunk
755: Synopsis:
756: 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)
758: Level: developer
760: Notes: Memory of first chunk is always allocated at least double aligned
762: .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4(), PetscFree5()
764: Concepts: memory allocation
766: M*/
767: #if defined(PETSC_USE_DEBUG)
768: #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))
769: #else
770: #define PetscMalloc5(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4,m5,t5,r5) \
771: ((*(r2) = 0, *(r3) = 0, *(r4) = 0,*(r5) = 0,PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3)+(m4)*sizeof(t4)+(m5)*sizeof(t5)+4*(PETSC_MEMALIGN-1),r1)) \
772: || (*(r2) = (t2*)PetscAddrAlign(*(r1)+m1),*(r3) = (t3*)PetscAddrAlign(*(r2)+m2),*(r4) = (t4*)PetscAddrAlign(*(r3)+m3),*(r5) = (t5*)PetscAddrAlign(*(r4)+m4),0))
773: #endif
776: /*MC
777: PetscMalloc6 - Allocates 6 chunks of memory
779: Input Parameter:
780: + m1 - number of elements to allocate in 1st chunk (may be zero)
781: . t1 - type of first memory elements
782: . m2 - number of elements to allocate in 2nd chunk (may be zero)
783: . t2 - type of second memory elements
784: . m3 - number of elements to allocate in 3rd chunk (may be zero)
785: . t3 - type of third memory elements
786: . m4 - number of elements to allocate in 4th chunk (may be zero)
787: . t4 - type of fourth memory elements
788: . m5 - number of elements to allocate in 5th chunk (may be zero)
789: . t5 - type of fifth memory elements
790: . m6 - number of elements to allocate in 6th chunk (may be zero)
791: - t6 - type of sixth memory elements
793: Output Parameter:
794: + r1 - memory allocated in first chunk
795: . r2 - memory allocated in second chunk
796: . r3 - memory allocated in third chunk
797: . r4 - memory allocated in fourth chunk
798: . r5 - memory allocated in fifth chunk
799: - r6 - memory allocated in sixth chunk
801: Synopsis:
802: 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)
804: Level: developer
806: Notes: Memory of first chunk is always allocated at least double aligned
808: .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4(), PetscFree5(), PetscFree6()
810: Concepts: memory allocation
812: M*/
813: #if defined(PETSC_USE_DEBUG)
814: #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))
815: #else
816: #define PetscMalloc6(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4,m5,t5,r5,m6,t6,r6) \
817: ((*(r2) = 0, *(r3) = 0, *(r4) = 0,*(r5) = 0,*(r6) = 0,PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3)+(m4)*sizeof(t4)+(m5)*sizeof(t5)+(m6)*sizeof(t6)+5*(PETSC_MEMALIGN-1),r1)) \
818: || (*(r2) = (t2*)PetscAddrAlign(*(r1)+m1),*(r3) = (t3*)PetscAddrAlign(*(r2)+m2),*(r4) = (t4*)PetscAddrAlign(*(r3)+m3),*(r5) = (t5*)PetscAddrAlign(*(r4)+m4),*(r6) = (t6*)PetscAddrAlign(*(r5)+m5),0))
819: #endif
821: /*MC
822: PetscMalloc7 - Allocates 7 chunks of memory
824: Input Parameter:
825: + m1 - number of elements to allocate in 1st chunk (may be zero)
826: . t1 - type of first memory elements
827: . m2 - number of elements to allocate in 2nd chunk (may be zero)
828: . t2 - type of second memory elements
829: . m3 - number of elements to allocate in 3rd chunk (may be zero)
830: . t3 - type of third memory elements
831: . m4 - number of elements to allocate in 4th chunk (may be zero)
832: . t4 - type of fourth memory elements
833: . m5 - number of elements to allocate in 5th chunk (may be zero)
834: . t5 - type of fifth memory elements
835: . m6 - number of elements to allocate in 6th chunk (may be zero)
836: . t6 - type of sixth memory elements
837: . m7 - number of elements to allocate in 7th chunk (may be zero)
838: - t7 - type of sixth memory elements
840: Output Parameter:
841: + r1 - memory allocated in first chunk
842: . r2 - memory allocated in second chunk
843: . r3 - memory allocated in third chunk
844: . r4 - memory allocated in fourth chunk
845: . r5 - memory allocated in fifth chunk
846: . r6 - memory allocated in sixth chunk
847: - r7 - memory allocated in sixth chunk
849: Synopsis:
850: 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)
852: Level: developer
854: Notes: Memory of first chunk is always allocated at least double aligned
856: .seealso: PetscFree(), PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree3(), PetscFree4(), PetscFree5(), PetscFree6(), PetscFree7()
858: Concepts: memory allocation
860: M*/
861: #if defined(PETSC_USE_DEBUG)
862: #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))
863: #else
864: #define PetscMalloc7(m1,t1,r1,m2,t2,r2,m3,t3,r3,m4,t4,r4,m5,t5,r5,m6,t6,r6,m7,t7,r7) \
865: ((*(r2) = 0, *(r3) = 0, *(r4) = 0,*(r5) = 0,*(r6) = 0,*(r7) = 0,PetscMalloc((m1)*sizeof(t1)+(m2)*sizeof(t2)+(m3)*sizeof(t3)+(m4)*sizeof(t4)+(m5)*sizeof(t5)+(m6)*sizeof(t6)+(m7)*sizeof(t7)+6*(PETSC_MEMALIGN-1),r1)) \
866: || (*(r2) = (t2*)PetscAddrAlign(*(r1)+m1),*(r3) = (t3*)PetscAddrAlign(*(r2)+m2),*(r4) = (t4*)PetscAddrAlign(*(r3)+m3),*(r5) = (t5*)PetscAddrAlign(*(r4)+m4),*(r6) = (t6*)PetscAddrAlign(*(r5)+m5),*(r7) = (t7*)PetscAddrAlign(*(r6)+m6),0))
867: #endif
869: /*MC
870: PetscNew - Allocates memory of a particular type, zeros the memory!
872: Input Parameter:
873: . type - structure name of space to be allocated. Memory of size sizeof(type) is allocated
875: Output Parameter:
876: . result - memory allocated
878: Synopsis:
879: PetscErrorCode PetscNew(struct type,((type *))result)
881: Level: beginner
883: .seealso: PetscFree(), PetscMalloc()
885: Concepts: memory allocation
887: M*/
888: #define PetscNew(A,b) (PetscMalloc(sizeof(A),(b)) || PetscMemzero(*(b),sizeof(A)))
889: #define PetscNewLog(o,A,b) (PetscNew(A,b) || ((o) ? PetscLogObjectMemory(o,sizeof(A)) : 0))
891: /*MC
892: PetscFree - Frees memory
894: Input Parameter:
895: . memory - memory to free (the pointer is ALWAYS set to 0 upon sucess)
897: Synopsis:
898: PetscErrorCode PetscFree(void *memory)
900: Level: beginner
902: Notes: Memory must have been obtained with PetscNew() or PetscMalloc()
904: .seealso: PetscNew(), PetscMalloc(), PetscFreeVoid()
906: Concepts: memory allocation
908: M*/
909: #define PetscFree(a) ((a) ? ((*PetscTrFree)((void*)(a),__LINE__,__FUNCT__,__FILE__,__SDIR__) || ((a = 0),0)) : 0)
911: /*MC
912: PetscFreeVoid - Frees memory
914: Input Parameter:
915: . memory - memory to free
917: Synopsis:
918: void PetscFreeVoid(void *memory)
920: Level: beginner
922: Notes: This is different from PetscFree() in that no error code is returned
924: .seealso: PetscFree(), PetscNew(), PetscMalloc()
926: Concepts: memory allocation
928: M*/
929: #define PetscFreeVoid(a) ((*PetscTrFree)((a),__LINE__,__FUNCT__,__FILE__,__SDIR__),(a) = 0)
932: /*MC
933: PetscFree2 - Frees 2 chunks of memory obtained with PetscMalloc2()
935: Input Parameter:
936: + memory1 - memory to free
937: - memory2 - 2nd memory to free
940: Synopsis:
941: PetscErrorCode PetscFree2(void *memory1,void *memory2)
943: Level: developer
945: Notes: Memory must have been obtained with PetscMalloc2()
947: .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree()
949: Concepts: memory allocation
951: M*/
952: #if defined(PETSC_USE_DEBUG)
953: #define PetscFree2(m1,m2) (PetscFree(m2) || PetscFree(m1))
954: #else
955: #define PetscFree2(m1,m2) (PetscFree(m1))
956: #endif
958: /*MC
959: PetscFree3 - Frees 3 chunks of memory obtained with PetscMalloc3()
961: Input Parameter:
962: + memory1 - memory to free
963: . memory2 - 2nd memory to free
964: - memory3 - 3rd memory to free
967: Synopsis:
968: PetscErrorCode PetscFree3(void *memory1,void *memory2,void *memory3)
970: Level: developer
972: Notes: Memory must have been obtained with PetscMalloc3()
974: .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3()
976: Concepts: memory allocation
978: M*/
979: #if defined(PETSC_USE_DEBUG)
980: #define PetscFree3(m1,m2,m3) (PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
981: #else
982: #define PetscFree3(m1,m2,m3) (PetscFree(m1))
983: #endif
985: /*MC
986: PetscFree4 - Frees 4 chunks of memory obtained with PetscMalloc4()
988: Input Parameter:
989: + m1 - memory to free
990: . m2 - 2nd memory to free
991: . m3 - 3rd memory to free
992: - m4 - 4th memory to free
995: Synopsis:
996: PetscErrorCode PetscFree4(void *m1,void *m2,void *m3,void *m4)
998: Level: developer
1000: Notes: Memory must have been obtained with PetscMalloc4()
1002: .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4()
1004: Concepts: memory allocation
1006: M*/
1007: #if defined(PETSC_USE_DEBUG)
1008: #define PetscFree4(m1,m2,m3,m4) (PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
1009: #else
1010: #define PetscFree4(m1,m2,m3,m4) (PetscFree(m1))
1011: #endif
1013: /*MC
1014: PetscFree5 - Frees 5 chunks of memory obtained with PetscMalloc5()
1016: Input Parameter:
1017: + m1 - memory to free
1018: . m2 - 2nd memory to free
1019: . m3 - 3rd memory to free
1020: . m4 - 4th memory to free
1021: - m5 - 5th memory to free
1024: Synopsis:
1025: PetscErrorCode PetscFree5(void *m1,void *m2,void *m3,void *m4,void *m5)
1027: Level: developer
1029: Notes: Memory must have been obtained with PetscMalloc5()
1031: .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5()
1033: Concepts: memory allocation
1035: M*/
1036: #if defined(PETSC_USE_DEBUG)
1037: #define PetscFree5(m1,m2,m3,m4,m5) (PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
1038: #else
1039: #define PetscFree5(m1,m2,m3,m4,m5) (PetscFree(m1))
1040: #endif
1043: /*MC
1044: PetscFree6 - Frees 6 chunks of memory obtained with PetscMalloc6()
1046: Input Parameter:
1047: + m1 - memory to free
1048: . m2 - 2nd memory to free
1049: . m3 - 3rd memory to free
1050: . m4 - 4th memory to free
1051: . m5 - 5th memory to free
1052: - m6 - 6th memory to free
1055: Synopsis:
1056: PetscErrorCode PetscFree6(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6)
1058: Level: developer
1060: Notes: Memory must have been obtained with PetscMalloc6()
1062: .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5(), PetscMalloc6()
1064: Concepts: memory allocation
1066: M*/
1067: #if defined(PETSC_USE_DEBUG)
1068: #define PetscFree6(m1,m2,m3,m4,m5,m6) (PetscFree(m6) || PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
1069: #else
1070: #define PetscFree6(m1,m2,m3,m4,m5,m6) (PetscFree(m1))
1071: #endif
1073: /*MC
1074: PetscFree7 - Frees 7 chunks of memory obtained with PetscMalloc7()
1076: Input Parameter:
1077: + m1 - memory to free
1078: . m2 - 2nd memory to free
1079: . m3 - 3rd memory to free
1080: . m4 - 4th memory to free
1081: . m5 - 5th memory to free
1082: . m6 - 6th memory to free
1083: - m7 - 7th memory to free
1086: Synopsis:
1087: PetscErrorCode PetscFree7(void *m1,void *m2,void *m3,void *m4,void *m5,void *m6,void *m7)
1089: Level: developer
1091: Notes: Memory must have been obtained with PetscMalloc7()
1093: .seealso: PetscNew(), PetscMalloc(), PetscMalloc2(), PetscFree(), PetscMalloc3(), PetscMalloc4(), PetscMalloc5(), PetscMalloc6(),
1094: PetscMalloc7()
1096: Concepts: memory allocation
1098: M*/
1099: #if defined(PETSC_USE_DEBUG)
1100: #define PetscFree7(m1,m2,m3,m4,m5,m6,m7) (PetscFree(m7) || PetscFree(m6) || PetscFree(m5) || PetscFree(m4) || PetscFree(m3) || PetscFree(m2) || PetscFree(m1))
1101: #else
1102: #define PetscFree7(m1,m2,m3,m4,m5,m6,m7) (PetscFree(m1))
1103: #endif
1105: EXTERN PetscErrorCode (*PetscTrMalloc)(size_t,int,const char[],const char[],const char[],void**);
1106: EXTERN PetscErrorCode (*PetscTrFree)(void*,int,const char[],const char[],const char[]);
1107: EXTERN PetscErrorCode PetscMallocSet(PetscErrorCode (*)(size_t,int,const char[],const char[],const char[],void**),PetscErrorCode (*)(void*,int,const char[],const char[],const char[]));
1108: EXTERN PetscErrorCode PetscMallocClear(void);
1110: /*
1111: Routines for tracing memory corruption/bleeding with default PETSc
1112: memory allocation
1113: */
1114: EXTERN PetscErrorCode PetscMallocDump(FILE *);
1115: EXTERN PetscErrorCode PetscMallocDumpLog(FILE *);
1116: EXTERN PetscErrorCode PetscMallocGetCurrentUsage(PetscLogDouble *);
1117: EXTERN PetscErrorCode PetscMallocGetMaximumUsage(PetscLogDouble *);
1118: EXTERN PetscErrorCode PetscMallocDebug(PetscTruth);
1119: EXTERN PetscErrorCode PetscMallocValidate(int,const char[],const char[],const char[]);
1120: EXTERN PetscErrorCode PetscMallocSetDumpLog(void);
1123: /*
1124: Variable type where we stash PETSc object pointers in Fortran.
1125: On most machines size(pointer) == sizeof(long) - except windows
1126: where its sizeof(long long)
1127: */
1129: #if (PETSC_SIZEOF_VOID_P) == (PETSC_SIZEOF_LONG)
1130: #define PetscFortranAddr long
1131: #elif (PETSC_SIZEOF_VOID_P) == (PETSC_SIZEOF_LONG_LONG)
1132: #define PetscFortranAddr long long
1133: #else
1134: #error "Unknown size for PetscFortranAddr! Send us a bugreport at petsc-maint@mcs.anl.gov"
1135: #endif
1137: /*E
1138: PetscDataType - Used for handling different basic data types.
1140: Level: beginner
1142: Developer comment: It would be nice if we could always just use MPI Datatypes, why can we not?
1144: .seealso: PetscBinaryRead(), PetscBinaryWrite(), PetscDataTypeToMPIDataType(),
1145: PetscDataTypeGetSize()
1147: E*/
1148: typedef enum {PETSC_INT = 0,PETSC_DOUBLE = 1,PETSC_COMPLEX = 2, PETSC_LONG = 3 ,PETSC_SHORT = 4,PETSC_FLOAT = 5,
1149: PETSC_CHAR = 6,PETSC_LOGICAL = 7,PETSC_ENUM = 8,PETSC_TRUTH=9, PETSC_LONG_DOUBLE = 10, PETSC_QD_DD = 11} PetscDataType;
1152: #if defined(PETSC_USE_COMPLEX)
1153: #define PETSC_SCALAR PETSC_COMPLEX
1154: #else
1155: #if defined(PETSC_USE_SCALAR_SINGLE)
1156: #define PETSC_SCALAR PETSC_FLOAT
1157: #elif defined(PETSC_USE_SCALAR_LONG_DOUBLE)
1158: #define PETSC_SCALAR PETSC_LONG_DOUBLE
1159: #elif defined(PETSC_USE_SCALAR_INT)
1160: #define PETSC_SCALAR PETSC_INT
1161: #elif defined(PETSC_USE_SCALAR_QD_DD)
1162: #define PETSC_SCALAR PETSC_QD_DD
1163: #else
1164: #define PETSC_SCALAR PETSC_DOUBLE
1165: #endif
1166: #endif
1167: #if defined(PETSC_USE_SCALAR_SINGLE)
1168: #define PETSC_REAL PETSC_FLOAT
1169: #elif defined(PETSC_USE_SCALAR_LONG_DOUBLE)
1170: #define PETSC_REAL PETSC_LONG_DOUBLE
1171: #elif defined(PETSC_USE_SCALAR_INT)
1172: #define PETSC_REAL PETSC_INT
1173: #elif defined(PETSC_USE_SCALAR_QD_DD)
1174: #define PETSC_REAL PETSC_QD_DD
1175: #else
1176: #define PETSC_REAL PETSC_DOUBLE
1177: #endif
1178: #define PETSC_FORTRANADDR PETSC_LONG
1180: EXTERN PetscErrorCode PetscDataTypeToMPIDataType(PetscDataType,MPI_Datatype*);
1181: EXTERN PetscErrorCode PetscMPIDataTypeToPetscDataType(MPI_Datatype,PetscDataType*);
1182: EXTERN PetscErrorCode PetscDataTypeGetSize(PetscDataType,size_t*);
1184: /*
1185: Basic memory and string operations. These are usually simple wrappers
1186: around the basic Unix system calls, but a few of them have additional
1187: functionality and/or error checking.
1188: */
1189: EXTERN PetscErrorCode PetscBitMemcpy(void*,PetscInt,const void*,PetscInt,PetscInt,PetscDataType);
1190: EXTERN PetscErrorCode PetscMemmove(void*,void *,size_t);
1191: EXTERN PetscErrorCode PetscMemcmp(const void*,const void*,size_t,PetscTruth *);
1192: EXTERN PetscErrorCode PetscStrlen(const char[],size_t*);
1193: EXTERN PetscErrorCode PetscStrcmp(const char[],const char[],PetscTruth *);
1194: EXTERN PetscErrorCode PetscStrgrt(const char[],const char[],PetscTruth *);
1195: EXTERN PetscErrorCode PetscStrcasecmp(const char[],const char[],PetscTruth*);
1196: EXTERN PetscErrorCode PetscStrncmp(const char[],const char[],size_t,PetscTruth*);
1197: EXTERN PetscErrorCode PetscStrcpy(char[],const char[]);
1198: EXTERN PetscErrorCode PetscStrcat(char[],const char[]);
1199: EXTERN PetscErrorCode PetscStrncat(char[],const char[],size_t);
1200: EXTERN PetscErrorCode PetscStrncpy(char[],const char[],size_t);
1201: EXTERN PetscErrorCode PetscStrchr(const char[],char,char *[]);
1202: EXTERN PetscErrorCode PetscStrtolower(char[]);
1203: EXTERN PetscErrorCode PetscStrrchr(const char[],char,char *[]);
1204: EXTERN PetscErrorCode PetscStrstr(const char[],const char[],char *[]);
1205: EXTERN PetscErrorCode PetscStrrstr(const char[],const char[],char *[]);
1206: EXTERN PetscErrorCode PetscStrallocpy(const char[],char *[]);
1207: EXTERN PetscErrorCode PetscStrreplace(MPI_Comm,const char[],char[],size_t);
1208: #define PetscStrfree(a) ((a) ? PetscFree(a) : 0)
1211: /*S
1212: PetscToken - 'Token' used for managing tokenizing strings
1214: Level: intermediate
1216: .seealso: PetscTokenCreate(), PetscTokenFind(), PetscTokenDestroy()
1217: S*/
1218: typedef struct _p_PetscToken* PetscToken;
1220: EXTERN PetscErrorCode PetscTokenCreate(const char[],const char,PetscToken*);
1221: EXTERN PetscErrorCode PetscTokenFind(PetscToken,char *[]);
1222: EXTERN PetscErrorCode PetscTokenDestroy(PetscToken);
1224: /*
1225: These are MPI operations for MPI_Allreduce() etc
1226: */
1227: EXTERN MPI_Op PetscMaxSum_Op;
1228: #if defined(PETSC_USE_COMPLEX) && !defined(PETSC_HAVE_MPI_C_DOUBLE_COMPLEX)
1229: EXTERN MPI_Op MPIU_SUM;
1230: #else
1231: #define MPIU_SUM MPI_SUM
1232: #endif
1233: EXTERN PetscErrorCode PetscMaxSum(MPI_Comm,const PetscInt[],PetscInt*,PetscInt*);
1235: /*S
1236: PetscObject - any PETSc object, PetscViewer, Mat, Vec, KSP etc
1238: Level: beginner
1240: Note: This is the base class from which all objects appear.
1242: .seealso: PetscObjectDestroy(), PetscObjectView(), PetscObjectGetName(), PetscObjectSetName()
1243: S*/
1244: typedef struct _p_PetscObject* PetscObject;
1246: /*S
1247: PetscFList - Linked list of functions, possibly stored in dynamic libraries, accessed
1248: by string name
1250: Level: advanced
1252: .seealso: PetscFListAdd(), PetscFListDestroy()
1253: S*/
1254: typedef struct _n_PetscFList *PetscFList;
1256: /*E
1257: PetscFileMode - Access mode for a file.
1259: Level: beginner
1261: FILE_MODE_READ - open a file at its beginning for reading
1263: FILE_MODE_WRITE - open a file at its beginning for writing (will create if the file does not exist)
1265: FILE_MODE_APPEND - open a file at end for writing
1267: FILE_MODE_UPDATE - open a file for updating, meaning for reading and writing
1269: FILE_MODE_APPEND_UPDATE - open a file for updating, meaning for reading and writing, at the end
1271: .seealso: PetscViewerFileSetMode()
1272: E*/
1273: typedef enum {FILE_MODE_READ, FILE_MODE_WRITE, FILE_MODE_APPEND, FILE_MODE_UPDATE, FILE_MODE_APPEND_UPDATE} PetscFileMode;
1275: #include petscviewer.h
1276: #include petscoptions.h
1278: #define PETSC_SMALLEST_COOKIE 1211211
1281: EXTERN PetscErrorCode PetscCookieRegister(const char[],PetscCookie *);
1283: /*
1284: Routines that get memory usage information from the OS
1285: */
1286: EXTERN PetscErrorCode PetscMemoryGetCurrentUsage(PetscLogDouble *);
1287: EXTERN PetscErrorCode PetscMemoryGetMaximumUsage(PetscLogDouble *);
1288: EXTERN PetscErrorCode PetscMemorySetGetMaximumUsage(void);
1289: EXTERN PetscErrorCode PetscMemoryShowUsage(PetscViewer,const char[]);
1291: EXTERN PetscErrorCode PetscInfoAllow(PetscTruth,const char []);
1292: EXTERN PetscErrorCode PetscGetTime(PetscLogDouble*);
1293: EXTERN PetscErrorCode PetscGetCPUTime(PetscLogDouble*);
1294: EXTERN PetscErrorCode PetscSleep(PetscReal);
1296: /*
1297: Initialization of PETSc
1298: */
1299: EXTERN PetscErrorCode PetscInitialize(int*,char***,const char[],const char[]);
1300: PetscPolymorphicSubroutine(PetscInitialize,(int *argc,char ***args),(argc,args,PETSC_NULL,PETSC_NULL))
1301: EXTERN PetscErrorCode PetscInitializeNoArguments(void);
1302: EXTERN PetscErrorCode PetscInitialized(PetscTruth *);
1303: EXTERN PetscErrorCode PetscFinalized(PetscTruth *);
1304: EXTERN PetscErrorCode PetscFinalize(void);
1305: EXTERN PetscErrorCode PetscInitializeFortran(void);
1306: EXTERN PetscErrorCode PetscGetArgs(int*,char ***);
1307: EXTERN PetscErrorCode PetscGetArguments(char ***);
1308: EXTERN PetscErrorCode PetscFreeArguments(char **);
1310: EXTERN PetscErrorCode PetscEnd(void);
1311: EXTERN PetscErrorCode PetscInitializePackage(const char[]);
1314: EXTERN PetscErrorCode PetscOpenMPMerge(PetscMPIInt,PetscErrorCode (*)(void*),void*);
1315: EXTERN PetscErrorCode PetscOpenMPSpawn(PetscMPIInt);
1316: EXTERN PetscErrorCode PetscOpenMPFinalize(void);
1317: EXTERN PetscErrorCode PetscOpenMPRun(MPI_Comm,PetscErrorCode (*)(MPI_Comm,void *),void*);
1318: EXTERN PetscErrorCode PetscOpenMPRunCtx(MPI_Comm,PetscErrorCode (*)(MPI_Comm,void*,void *),void*);
1319: EXTERN PetscErrorCode PetscOpenMPFree(MPI_Comm,void*);
1320: EXTERN PetscErrorCode PetscOpenMPMalloc(MPI_Comm,size_t,void**);
1322: EXTERN PetscErrorCode PetscPythonInitialize(const char[],const char[]);
1323: EXTERN PetscErrorCode PetscPythonFinalize(void);
1325: /*
1327: function pointers. Since the regular C++ code expects its function pointers to be
1328: C++.
1329: */
1330: typedef void (**PetscVoidStarFunction)(void);
1331: typedef void (*PetscVoidFunction)(void);
1332: typedef PetscErrorCode (*PetscErrorCodeFunction)(void);
1334: /*
1335: PetscTryMethod - Queries an object for a method, if it exists then calls it.
1336: These are intended to be used only inside PETSc functions.
1337: */
1338: #define PetscTryMethod(obj,A,B,C) \
1339: 0;{ PetscErrorCode (*f)B, __ierr; \
1340: __PetscObjectQueryFunction((PetscObject)obj,A,(PetscVoidStarFunction)&f);CHKERRQ(__ierr); \
1341: if (f) {__(*f)C;CHKERRQ(__ierr);}\
1342: }
1343: #define PetscUseMethod(obj,A,B,C) \
1344: 0;{ PetscErrorCode (*f)B, __ierr; \
1345: __PetscObjectQueryFunction((PetscObject)obj,A,(PetscVoidStarFunction)&f);CHKERRQ(__ierr); \
1346: if (f) {__(*f)C;CHKERRQ(__ierr);}\
1347: else {SETERRQ1(PETSC_ERR_SUP,"Cannot locate function %s in object",A);} \
1348: }
1349: /*
1350: Functions that can act on any PETSc object.
1351: */
1352: EXTERN PetscErrorCode PetscObjectCreate(MPI_Comm,PetscObject*);
1353: EXTERN PetscErrorCode PetscObjectCreateGeneric(MPI_Comm, PetscCookie, const char [], PetscObject *);
1354: EXTERN PetscErrorCode PetscObjectDestroy(PetscObject);
1355: EXTERN PetscErrorCode PetscObjectExists(PetscObject,PetscTruth*);
1356: EXTERN PetscErrorCode PetscObjectGetComm(PetscObject,MPI_Comm *);
1357: EXTERN PetscErrorCode PetscObjectGetCookie(PetscObject,PetscCookie *);
1358: EXTERN PetscErrorCode PetscObjectSetType(PetscObject,const char []);
1359: EXTERN PetscErrorCode PetscObjectGetType(PetscObject,const char *[]);
1360: EXTERN PetscErrorCode PetscObjectSetName(PetscObject,const char[]);
1361: EXTERN PetscErrorCode PetscObjectGetName(PetscObject,const char*[]);
1362: EXTERN PetscErrorCode PetscObjectSetTabLevel(PetscObject,PetscInt);
1363: EXTERN PetscErrorCode PetscObjectGetTabLevel(PetscObject,PetscInt*);
1364: EXTERN PetscErrorCode PetscObjectIncrementTabLevel(PetscObject,PetscObject,PetscInt);
1365: EXTERN PetscErrorCode PetscObjectReference(PetscObject);
1366: EXTERN PetscErrorCode PetscObjectGetReference(PetscObject,PetscInt*);
1367: EXTERN PetscErrorCode PetscObjectDereference(PetscObject);
1368: EXTERN PetscErrorCode PetscObjectGetNewTag(PetscObject,PetscMPIInt *);
1369: EXTERN PetscErrorCode PetscObjectView(PetscObject,PetscViewer);
1370: EXTERN PetscErrorCode PetscObjectCompose(PetscObject,const char[],PetscObject);
1371: EXTERN PetscErrorCode PetscObjectQuery(PetscObject,const char[],PetscObject *);
1372: EXTERN PetscErrorCode PetscObjectComposeFunction(PetscObject,const char[],const char[],void (*)(void));
1373: EXTERN PetscErrorCode PetscObjectSetFromOptions(PetscObject);
1374: EXTERN PetscErrorCode PetscObjectSetUp(PetscObject);
1375: EXTERN PetscErrorCode PetscCommGetNewTag(MPI_Comm,PetscMPIInt *);
1377: /*MC
1378: PetscObjectComposeFunctionDynamic - Associates a function with a given PETSc object.
1379:
1380: Collective on PetscObject
1382: Input Parameters:
1383: + obj - the PETSc object; this must be cast with a (PetscObject), for example,
1384: PetscObjectCompose((PetscObject)mat,...);
1385: . name - name associated with the child function
1386: . fname - name of the function
1387: - ptr - function pointer (or PETSC_NULL if using dynamic libraries)
1389: Level: advanced
1391: Synopsis:
1392: PetscErrorCode PetscObjectComposeFunctionDynamic(PetscObject obj,const char name[],const char fname[],void *ptr)
1394: Notes:
1395: To remove a registered routine, pass in a PETSC_NULL rname and fnc().
1397: PetscObjectComposeFunctionDynamic() can be used with any PETSc object (such as
1398: Mat, Vec, KSP, SNES, etc.) or any user-provided object.
1401: work in C++/complex with dynamic link libraries (config/configure.py options --with-shared --with-dynamic)
1402: enabled.
1404: Concepts: objects^composing functions
1405: Concepts: composing functions
1406: Concepts: functions^querying
1407: Concepts: objects^querying
1408: Concepts: querying objects
1410: .seealso: PetscObjectQueryFunction()
1411: M*/
1412: #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
1413: #define PetscObjectComposeFunctionDynamic(a,b,c,d) PetscObjectComposeFunction(a,b,c,0)
1414: #else
1415: #define PetscObjectComposeFunctionDynamic(a,b,c,d) PetscObjectComposeFunction(a,b,c,(PetscVoidFunction)(d))
1416: #endif
1418: EXTERN PetscErrorCode PetscObjectQueryFunction(PetscObject,const char[],void (**)(void));
1419: EXTERN PetscErrorCode PetscObjectSetOptionsPrefix(PetscObject,const char[]);
1420: EXTERN PetscErrorCode PetscObjectAppendOptionsPrefix(PetscObject,const char[]);
1421: EXTERN PetscErrorCode PetscObjectPrependOptionsPrefix(PetscObject,const char[]);
1422: EXTERN PetscErrorCode PetscObjectGetOptionsPrefix(PetscObject,const char*[]);
1423: EXTERN PetscErrorCode PetscObjectPublish(PetscObject);
1424: EXTERN PetscErrorCode PetscObjectChangeTypeName(PetscObject,const char[]);
1425: EXTERN PetscErrorCode PetscObjectRegisterDestroy(PetscObject);
1426: EXTERN PetscErrorCode PetscObjectRegisterDestroyAll(void);
1427: EXTERN PetscErrorCode PetscObjectName(PetscObject);
1428: EXTERN PetscErrorCode PetscTypeCompare(PetscObject,const char[],PetscTruth*);
1429: EXTERN PetscErrorCode PetscRegisterFinalize(PetscErrorCode (*)(void));
1430: EXTERN PetscErrorCode PetscRegisterFinalizeAll(void);
1432: /*
1433: Defines PETSc error handling.
1434: */
1435: #include petscerror.h
1437: /*S
1438: PetscOList - Linked list of PETSc objects, accessable by string name
1440: Level: advanced
1442: .seealso: PetscOListAdd(), PetscOListDestroy(), PetscOListFind()
1443: S*/
1444: typedef struct _n_PetscOList *PetscOList;
1446: EXTERN PetscErrorCode PetscOListDestroy(PetscOList);
1447: EXTERN PetscErrorCode PetscOListFind(PetscOList,const char[],PetscObject*);
1448: EXTERN PetscErrorCode PetscOListReverseFind(PetscOList,PetscObject,char**);
1449: EXTERN PetscErrorCode PetscOListAdd(PetscOList *,const char[],PetscObject);
1450: EXTERN PetscErrorCode PetscOListDuplicate(PetscOList,PetscOList *);
1452: /*
1453: Dynamic library lists. Lists of names of routines in dynamic
1454: link libraries that will be loaded as needed.
1455: */
1456: EXTERN PetscErrorCode PetscFListAdd(PetscFList*,const char[],const char[],void (*)(void));
1457: EXTERN PetscErrorCode PetscFListDestroy(PetscFList*);
1458: EXTERN PetscErrorCode PetscFListFind(PetscFList,MPI_Comm,const char[],void (**)(void));
1459: EXTERN PetscErrorCode PetscFListPrintTypes(MPI_Comm,FILE*,const char[],const char[],const char[],const char[],PetscFList,const char[]);
1460: #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
1461: #define PetscFListAddDynamic(a,b,p,c) PetscFListAdd(a,b,p,0)
1462: #else
1463: #define PetscFListAddDynamic(a,b,p,c) PetscFListAdd(a,b,p,(void (*)(void))c)
1464: #endif
1465: EXTERN PetscErrorCode PetscFListDuplicate(PetscFList,PetscFList *);
1466: EXTERN PetscErrorCode PetscFListView(PetscFList,PetscViewer);
1467: EXTERN PetscErrorCode PetscFListConcat(const char [],const char [],char []);
1468: EXTERN PetscErrorCode PetscFListGet(PetscFList,char ***,int*);
1470: /*S
1471: PetscDLLibrary - Linked list of dynamics libraries to search for functions
1473: Level: advanced
1475: --with-shared --with-dynamic must be used with config/configure.py to use dynamic libraries
1477: .seealso: PetscDLLibraryOpen()
1478: S*/
1479: typedef struct _n_PetscDLLibrary *PetscDLLibrary;
1481: EXTERN PetscErrorCode PetscDLLibraryAppend(MPI_Comm,PetscDLLibrary *,const char[]);
1482: EXTERN PetscErrorCode PetscDLLibraryPrepend(MPI_Comm,PetscDLLibrary *,const char[]);
1483: EXTERN PetscErrorCode PetscDLLibrarySym(MPI_Comm,PetscDLLibrary *,const char[],const char[],void **);
1484: EXTERN PetscErrorCode PetscDLLibraryPrintPath(PetscDLLibrary);
1485: EXTERN PetscErrorCode PetscDLLibraryRetrieve(MPI_Comm,const char[],char *,size_t,PetscTruth *);
1486: EXTERN PetscErrorCode PetscDLLibraryOpen(MPI_Comm,const char[],PetscDLLibrary *);
1487: EXTERN PetscErrorCode PetscDLLibraryClose(PetscDLLibrary);
1488: EXTERN PetscErrorCode PetscDLLibraryCCAAppend(MPI_Comm,PetscDLLibrary *,const char[]);
1490: /*
1491: Useful utility routines
1492: */
1493: EXTERN PetscErrorCode PetscSplitOwnership(MPI_Comm,PetscInt*,PetscInt*);
1494: EXTERN PetscErrorCode PetscSplitOwnershipBlock(MPI_Comm,PetscInt,PetscInt*,PetscInt*);
1495: EXTERN PetscErrorCode PetscSequentialPhaseBegin(MPI_Comm,PetscMPIInt);
1496: PetscPolymorphicSubroutine(PetscSequentialPhaseBegin,(MPI_Comm comm),(comm,1))
1497: PetscPolymorphicSubroutine(PetscSequentialPhaseBegin,(void),(PETSC_COMM_WORLD,1))
1498: EXTERN PetscErrorCode PetscSequentialPhaseEnd(MPI_Comm,PetscMPIInt);
1499: PetscPolymorphicSubroutine(PetscSequentialPhaseEnd,(MPI_Comm comm),(comm,1))
1500: PetscPolymorphicSubroutine(PetscSequentialPhaseEnd,(void),(PETSC_COMM_WORLD,1))
1501: EXTERN PetscErrorCode PetscBarrier(PetscObject);
1502: EXTERN PetscErrorCode PetscMPIDump(FILE*);
1504: #define PetscNot(a) ((a) ? PETSC_FALSE : PETSC_TRUE)
1505: /*
1506: Defines basic graphics available from PETSc.
1507: */
1508: #include petscdraw.h
1510: /*
1511: Defines the base data structures for all PETSc objects
1512: */
1513: #include private/petscimpl.h
1514: /*
1515: Defines PETSc profiling.
1516: */
1517: #include petsclog.h
1520: /*
1521: For locking, unlocking and destroying AMS memories associated with
1522: PETSc objects. Not currently used.
1523: */
1524: #define PetscPublishAll(v) 0
1525: #define PetscObjectTakeAccess(obj) 0
1526: #define PetscObjectGrantAccess(obj) 0
1527: #define PetscObjectDepublish(obj) 0
1529: /*
1530: Simple PETSc parallel IO for ASCII printing
1531: */
1532: EXTERN PetscErrorCode PetscFixFilename(const char[],char[]);
1533: EXTERN PetscErrorCode PetscFOpen(MPI_Comm,const char[],const char[],FILE**);
1534: EXTERN PetscErrorCode PetscFClose(MPI_Comm,FILE*);
1535: EXTERN PetscErrorCode PetscFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4);
1536: EXTERN PetscErrorCode PetscPrintf(MPI_Comm,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3);
1537: EXTERN PetscErrorCode PetscSNPrintf(char*,size_t,const char [],...);
1539: /* These are used internally by PETSc ASCII IO routines*/
1540: #include <stdarg.h>
1541: EXTERN PetscErrorCode PetscVSNPrintf(char*,size_t,const char[],int*,va_list);
1542: EXTERN PetscErrorCode (*PetscVFPrintf)(FILE*,const char[],va_list);
1543: EXTERN PetscErrorCode PetscVFPrintfDefault(FILE*,const char[],va_list);
1545: /*MC
1546: PetscErrorPrintf - Prints error messages.
1548: Not Collective
1550: Synopsis:
1551: PetscErrorCode (*PetscErrorPrintf)(const char format[],...);
1553: Input Parameters:
1554: . format - the usual printf() format string
1556: Options Database Keys:
1557: + -error_output_stdout - cause error messages to be printed to stdout instead of the
1558: (default) stderr
1559: - -error_output_none to turn off all printing of error messages (does not change the way the
1560: error is handled.)
1562: Notes: Use
1563: $ PetscErrorPrintf = PetscErrorPrintfNone; to turn off all printing of error messages (does not change the way the
1564: $ error is handled.) and
1565: $ PetscErrorPrintf = PetscErrorPrintfDefault; to turn it back on
1567: Use
1568: PETSC_STDERR = FILE* obtained from a file open etc. to have stderr printed to the file.
1569: PETSC_STDOUT = FILE* obtained from a file open etc. to have stdout printed to the file.
1571: Use
1572: PetscPushErrorHandler() to provide your own error handler that determines what kind of messages to print
1574: Level: developer
1576: Fortran Note:
1577: This routine is not supported in Fortran.
1579: Concepts: error messages^printing
1580: Concepts: printing^error messages
1582: .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf(), PetscPrintf(), PetscErrorHandlerPush()
1583: M*/
1584: EXTERN PetscErrorCode (*PetscErrorPrintf)(const char[],...);
1586: /*MC
1587: PetscHelpPrintf - Prints help messages.
1589: Not Collective
1591: Synopsis:
1592: PetscErrorCode (*PetscHelpPrintf)(const char format[],...);
1594: Input Parameters:
1595: . format - the usual printf() format string
1597: Level: developer
1599: Fortran Note:
1600: This routine is not supported in Fortran.
1602: Concepts: help messages^printing
1603: Concepts: printing^help messages
1605: .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscErrorPrintf()
1606: M*/
1607: EXTERN PetscErrorCode (*PetscHelpPrintf)(MPI_Comm,const char[],...);
1609: EXTERN PetscErrorCode PetscErrorPrintfDefault(const char [],...);
1610: EXTERN PetscErrorCode PetscErrorPrintfNone(const char [],...);
1611: EXTERN PetscErrorCode PetscHelpPrintfDefault(MPI_Comm,const char [],...);
1613: #if defined(PETSC_HAVE_POPEN)
1614: EXTERN PetscErrorCode PetscPOpen(MPI_Comm,const char[],const char[],const char[],FILE **);
1615: EXTERN PetscErrorCode PetscPClose(MPI_Comm,FILE*);
1616: #endif
1618: EXTERN PetscErrorCode PetscSynchronizedPrintf(MPI_Comm,const char[],...) PETSC_PRINTF_FORMAT_CHECK(2,3);
1619: EXTERN PetscErrorCode PetscSynchronizedFPrintf(MPI_Comm,FILE*,const char[],...) PETSC_PRINTF_FORMAT_CHECK(3,4);
1620: EXTERN PetscErrorCode PetscSynchronizedFlush(MPI_Comm);
1621: EXTERN PetscErrorCode PetscSynchronizedFGets(MPI_Comm,FILE*,size_t,char[]);
1622: EXTERN PetscErrorCode PetscStartMatlab(MPI_Comm,const char[],const char[],FILE**);
1623: EXTERN PetscErrorCode PetscStartJava(MPI_Comm,const char[],const char[],FILE**);
1624: EXTERN PetscErrorCode PetscGetPetscDir(const char*[]);
1626: EXTERN PetscErrorCode PetscPopUpSelect(MPI_Comm,const char*,const char*,int,const char**,int*);
1628: /*S
1629: PetscContainer - Simple PETSc object that contains a pointer to any required data
1631: Level: advanced
1633: .seealso: PetscObject, PetscContainerCreate()
1634: S*/
1636: typedef struct _p_PetscContainer* PetscContainer;
1637: EXTERN PetscErrorCode PetscContainerGetPointer(PetscContainer,void **);
1638: EXTERN PetscErrorCode PetscContainerSetPointer(PetscContainer,void *);
1639: EXTERN PetscErrorCode PetscContainerDestroy(PetscContainer);
1640: EXTERN PetscErrorCode PetscContainerCreate(MPI_Comm,PetscContainer *);
1641: EXTERN PetscErrorCode PetscContainerSetUserDestroy(PetscContainer, PetscErrorCode (*)(void*));
1643: /*
1644: For use in debuggers
1645: */
1649: EXTERN PetscErrorCode PetscIntView(PetscInt,const PetscInt[],PetscViewer);
1650: EXTERN PetscErrorCode PetscRealView(PetscInt,const PetscReal[],PetscViewer);
1651: EXTERN PetscErrorCode PetscScalarView(PetscInt,const PetscScalar[],PetscViewer);
1653: #if defined(PETSC_HAVE_MEMORY_H)
1654: #include <memory.h>
1655: #endif
1656: #if defined(PETSC_HAVE_STDLIB_H)
1657: #include <stdlib.h>
1658: #endif
1659: #if defined(PETSC_HAVE_STRINGS_H)
1660: #include <strings.h>
1661: #endif
1662: #if defined(PETSC_HAVE_STRING_H)
1663: #include <string.h>
1664: #endif
1667: #if defined(PETSC_HAVE_XMMINTRIN_H)
1668: #include <xmmintrin.h>
1669: #endif
1670: #if defined(PETSC_HAVE_STDINT_H)
1671: #include <stdint.h>
1672: #endif
1674: /*@C
1675: PetscMemcpy - Copies n bytes, beginning at location b, to the space
1676: beginning at location a. The two memory regions CANNOT overlap, use
1677: PetscMemmove() in that case.
1679: Not Collective
1681: Input Parameters:
1682: + b - pointer to initial memory space
1683: - n - length (in bytes) of space to copy
1685: Output Parameter:
1686: . a - pointer to copy space
1688: Level: intermediate
1690: Compile Option:
1691: PETSC_PREFER_DCOPY_FOR_MEMCPY will cause the BLAS dcopy() routine to be used
1692: for memory copies on double precision values.
1693: PETSC_PREFER_COPY_FOR_MEMCPY will cause C code to be used
1694: for memory copies on double precision values.
1695: PETSC_PREFER_FORTRAN_FORMEMCPY will cause Fortran code to be used
1696: for memory copies on double precision values.
1698: Note:
1699: This routine is analogous to memcpy().
1701: Concepts: memory^copying
1702: Concepts: copying^memory
1703:
1704: .seealso: PetscMemmove()
1706: @*/
1707: PETSC_STATIC_INLINE PetscErrorCode PetscMemcpy(void *a,const void *b,size_t n)
1708: {
1709: #if defined(PETSC_USE_DEBUG)
1710: unsigned long al = (unsigned long) a,bl = (unsigned long) b;
1711: unsigned long nl = (unsigned long) n;
1712: if (n > 0 && !b) SETERRQ(PETSC_ERR_ARG_NULL,"Trying to copy from a null pointer");
1713: if (n > 0 && !a) SETERRQ(PETSC_ERR_ARG_NULL,"Trying to copy to a null pointer");
1714: #endif
1716: if (a != b) {
1717: #if defined(PETSC_USE_DEBUG)
1718: if ((al > bl && (al - bl) < nl) || (bl - al) < nl) {
1719: SETERRQ3(PETSC_ERR_ARG_INCOMP,"Memory regions overlap: either use PetscMemmov()\n\
1720: or make sure your copy regions and lengths are correct. \n\
1721: Length (bytes) %ld first address %ld second address %ld",nl,al,bl);
1722: }
1723: #endif
1724: #if (defined(PETSC_PREFER_DCOPY_FOR_MEMCPY) || defined(PETSC_PREFER_COPY_FOR_MEMCPY) || defined(PETSC_PREFER_FORTRAN_FORMEMCPY))
1725: if (!(((long) a) % sizeof(PetscScalar)) && !(n % sizeof(PetscScalar))) {
1726: size_t len = n/sizeof(PetscScalar);
1727: #if defined(PETSC_PREFER_DCOPY_FOR_MEMCPY)
1728: PetscBLASInt one = 1,blen = PetscBLASIntCast(len);
1729: BLAScopy_(&blen,(PetscScalar *)b,&one,(PetscScalar *)a,&one);
1730: #elif defined(PETSC_PREFER_FORTRAN_FORMEMCPY)
1731: fortrancopy_(&len,(PetscScalar*)b,(PetscScalar*)a);
1732: #else
1733: size_t i;
1734: PetscScalar *x = (PetscScalar*)b, *y = (PetscScalar*)a;
1735: for (i=0; i<len; i++) y[i] = x[i];
1736: #endif
1737: } else {
1738: memcpy((char*)(a),(char*)(b),n);
1739: }
1740: #elif defined(PETSC_HAVE__INTEL_FAST_MEMCPY)
1741: _intel_fast_memcpy((char*)(a),(char*)(b),n);
1742: #else
1743: memcpy((char*)(a),(char*)(b),n);
1744: #endif
1745: }
1746: return(0);
1747: }
1749: /*@C
1750: PetscMemzero - Zeros the specified memory.
1752: Not Collective
1754: Input Parameters:
1755: + a - pointer to beginning memory location
1756: - n - length (in bytes) of memory to initialize
1758: Level: intermediate
1760: Compile Option:
1761: PETSC_PREFER_BZERO - on certain machines (the IBM RS6000) the bzero() routine happens
1762: to be faster than the memset() routine. This flag causes the bzero() routine to be used.
1764: Concepts: memory^zeroing
1765: Concepts: zeroing^memory
1767: .seealso: PetscMemcpy()
1768: @*/
1769: PETSC_STATIC_INLINE PetscErrorCode PetscMemzero(void *a,size_t n)
1770: {
1771: if (n > 0) {
1772: #if defined(PETSC_USE_DEBUG)
1773: if (!a) SETERRQ(PETSC_ERR_ARG_NULL,"Trying to zero at a null pointer");
1774: #endif
1775: #if defined(PETSC_PREFER_ZERO_FOR_MEMZERO)
1776: if (!(((long) a) % sizeof(PetscScalar)) && !(n % sizeof(PetscScalar))) {
1777: size_t i,len = n/sizeof(PetscScalar);
1778: PetscScalar *x = (PetscScalar*)a;
1779: for (i=0; i<len; i++) x[i] = 0.0;
1780: } else {
1781: #elif defined(PETSC_PREFER_FORTRAN_FOR_MEMZERO)
1782: if (!(((long) a) % sizeof(PetscScalar)) && !(n % sizeof(PetscScalar))) {
1783: PetscInt len = n/sizeof(PetscScalar);
1784: fortranzero_(&len,(PetscScalar*)a);
1785: } else {
1786: #endif
1787: #if defined(PETSC_PREFER_BZERO)
1788: bzero((char *)a,n);
1789: #elif defined (PETSC_HAVE__INTEL_FAST_MEMSET)
1790: _intel_fast_memset((char*)a,0,n);
1791: #else
1792: memset((char*)a,0,n);
1793: #endif
1794: #if defined(PETSC_PREFER_ZERO_FOR_MEMZERO) || defined(PETSC_PREFER_FORTRAN_FOR_MEMZERO)
1795: }
1796: #endif
1797: }
1798: return 0;
1799: }
1801: /*MC
1802: PetscPrefetchBlock - Prefetches a block of memory
1804: Not Collective
1806: Input Parameters:
1807: + a - pointer to first element to fetch (any type but usually PetscInt or PetscScalar)
1808: . n - number of elements to fetch
1809: . rw - 1 if the memory will be written to, otherwise 0 (ignored by many processors)
1810: - t - temporal locality (0,1,2,3), see note
1812: Level: developer
1814: Synopsis:
1815: void PetscPrefetchBlock(const anytype *a,size_t n,int rw,int t)
1817: Notes:
1818: The last two arguments (rw and t) must be compile-time constants.
1820: There are four levels of temporal locality (not all architectures distinguish)
1821: + 0 - Non-temporal. Prefetches directly to L1, evicts to memory (skips higher level cache unless it was already there when prefetched).
1822: . 1 - Temporal with respect to high-level cache only. Only prefetches to high-level cache (not L1), kept at high levels after eviction from L1.
1823: . 2 - Same as 1, but keep in mid-level cache. (On most systems, 1 and 2 are equivalent.)
1824: - 3 - Fetch to all levels of cache and evict to the closest level. Use this when the memory will be reused regularly despite necessary eviction from L1.
1826: This function does nothing on architectures that do not support prefetch and never errors (even if passed an invalid
1827: address).
1829: Concepts: memory
1830: M*/
1831: #define PetscPrefetchBlock(a,n,rw,t) do { \
1832: const char *_p = (const char*)(a),*_end = (const char*)((a)+(n)); \
1833: for ( ; _p < _end; _p += PETSC_LEVEL1_DCACHE_LINESIZE) PETSC_Prefetch(_p,(rw),(t)); \
1834: } while (0)
1836: /*
1837: Allows accessing Matlab Engine
1838: */
1839: #include petscmatlab.h
1841: /*
1842: Determine if some of the kernel computation routines use
1843: Fortran (rather than C) for the numerical calculations. On some machines
1844: and compilers (like complex numbers) the Fortran version of the routines
1845: is faster than the C/C++ versions. The flag --with-fortran-kernels
1846: should be used with config/configure.py to turn these on.
1847: */
1848: #if defined(PETSC_USE_FORTRAN_KERNELS)
1850: #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTCRL)
1851: #define PETSC_USE_FORTRAN_KERNEL_MULTCRL
1852: #endif
1854: #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTCSRPERM)
1855: #define PETSC_USE_FORTRAN_KERNEL_MULTCSRPERM
1856: #endif
1858: #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTAIJ)
1859: #define PETSC_USE_FORTRAN_KERNEL_MULTAIJ
1860: #endif
1862: #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ)
1863: #define PETSC_USE_FORTRAN_KERNEL_MULTTRANSPOSEAIJ
1864: #endif
1866: #if !defined(PETSC_USE_FORTRAN_KERNEL_NORM)
1867: #define PETSC_USE_FORTRAN_KERNEL_NORM
1868: #endif
1870: #if !defined(PETSC_USE_FORTRAN_KERNEL_MAXPY)
1871: #define PETSC_USE_FORTRAN_KERNEL_MAXPY
1872: #endif
1874: #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ)
1875: #define PETSC_USE_FORTRAN_KERNEL_SOLVEAIJ
1876: #endif
1878: #if !defined(PETSC_USE_FORTRAN_KERNEL_RELAXAIJ)
1879: #define PETSC_USE_FORTRAN_KERNEL_RELAXAIJ
1880: #endif
1882: #if !defined(PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ)
1883: #define PETSC_USE_FORTRAN_KERNEL_SOLVEBAIJ
1884: #endif
1886: #if !defined(PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ)
1887: #define PETSC_USE_FORTRAN_KERNEL_MULTADDAIJ
1888: #endif
1890: #if !defined(PETSC_USE_FORTRAN_KERNEL_MDOT)
1891: #define PETSC_USE_FORTRAN_KERNEL_MDOT
1892: #endif
1894: #if !defined(PETSC_USE_FORTRAN_KERNEL_XTIMESY)
1895: #define PETSC_USE_FORTRAN_KERNEL_XTIMESY
1896: #endif
1898: #if !defined(PETSC_USE_FORTRAN_KERNEL_AYPX)
1899: #define PETSC_USE_FORTRAN_KERNEL_AYPX
1900: #endif
1902: #if !defined(PETSC_USE_FORTRAN_KERNEL_WAXPY)
1903: #define PETSC_USE_FORTRAN_KERNEL_WAXPY
1904: #endif
1906: #endif
1908: /*
1909: Macros for indicating code that should be compiled with a C interface,
1910: rather than a C++ interface. Any routines that are dynamically loaded
1911: (such as the PCCreate_XXX() routines) must be wrapped so that the name
1912: mangler does not change the functions symbol name. This just hides the
1914: */
1915: #if defined(__cplusplus)
1918: #else
1921: #endif
1923: /* --------------------------------------------------------------------*/
1925: /*MC
1926: MPI_Comm - the basic object used by MPI to determine which processes are involved in a
1927: communication
1929: Level: beginner
1931: Note: This manual page is a place-holder because MPICH does not have a manual page for MPI_Comm
1933: .seealso: PETSC_COMM_WORLD, PETSC_COMM_SELF
1934: M*/
1936: /*MC
1937: PetscScalar - PETSc type that represents either a double precision real number, a double precision
1938: complex number, a single precision real number, a long double or an int - if the code is configured
1939: with --with-scalar-type=real,complex --with-precision=single,double,longdouble,int,matsingle
1942: Level: beginner
1944: .seealso: PetscReal, PassiveReal, PassiveScalar, MPIU_SCALAR, PetscInt
1945: M*/
1947: /*MC
1948: PetscReal - PETSc type that represents a real number version of PetscScalar
1950: Level: beginner
1952: .seealso: PetscScalar, PassiveReal, PassiveScalar
1953: M*/
1955: /*MC
1956: PassiveScalar - PETSc type that represents a PetscScalar
1957: Level: beginner
1959: This is the same as a PetscScalar except in code that is automatically differentiated it is
1960: treated as a constant (not an indendent or dependent variable)
1962: .seealso: PetscReal, PassiveReal, PetscScalar
1963: M*/
1965: /*MC
1966: PassiveReal - PETSc type that represents a PetscReal
1968: Level: beginner
1970: This is the same as a PetscReal except in code that is automatically differentiated it is
1971: treated as a constant (not an indendent or dependent variable)
1973: .seealso: PetscScalar, PetscReal, PassiveScalar
1974: M*/
1976: /*MC
1977: MPIU_SCALAR - MPI datatype corresponding to PetscScalar
1979: Level: beginner
1981: Note: In MPI calls that require an MPI datatype that matches a PetscScalar or array of PetscScalars
1982: pass this value
1984: .seealso: PetscReal, PassiveReal, PassiveScalar, PetscScalar, MPIU_INT
1985: M*/
1987: #if defined(PETSC_HAVE_MPIIO)
1988: #if !defined(PETSC_WORDS_BIGENDIAN)
1991: #else
1992: #define MPIU_File_write_all(a,b,c,d,e) MPI_File_write_all(a,b,c,d,e)
1993: #define MPIU_File_read_all(a,b,c,d,e) MPI_File_read_all(a,b,c,d,e)
1994: #endif
1995: #endif
1997: /* the following petsc_static_inline require petscerror.h */
1999: /* Limit MPI to 32-bits */
2000: #define PETSC_MPI_INT_MAX 2147483647
2001: #define PETSC_MPI_INT_MIN -2147483647
2002: /* Limit BLAS to 32-bits */
2003: #define PETSC_BLAS_INT_MAX 2147483647
2004: #define PETSC_BLAS_INT_MIN -2147483647
2005: /* On 32 bit systems HDF5 is limited by size of integer, because hsize_t is defined as size_t */
2006: #define PETSC_HDF5_INT_MAX 2147483647
2007: #define PETSC_HDF5_INT_MIN -2147483647
2009: #if defined(PETSC_USE_64BIT_INDICES)
2010: #define PetscMPIIntCheck(a) if ((a) > PETSC_MPI_INT_MAX) SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Message too long for MPI")
2011: #define PetscBLASIntCheck(a) if ((a) > PETSC_BLAS_INT_MAX) SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Array too long for BLAS/LAPACK")
2012: #define PetscMPIIntCast(a) (a);PetscMPIIntCheck(a)
2013: #define PetscBLASIntCast(a) (a);PetscBLASIntCheck(a)
2015: #if (PETSC_SIZEOF_SIZE_T == 4)
2016: #define PetscHDF5IntCheck(a) if ((a) > PETSC_HDF5_INT_MAX) SETERRQ(PETSC_ERR_ARG_OUTOFRANGE,"Array too long for HDF5")
2017: #define PetscHDF5IntCast(a) (a);PetscHDF5IntCheck(a)
2018: #else
2019: #define PetscHDF5IntCheck(a)
2020: #define PetscHDF5IntCast(a) a
2021: #endif
2023: #else
2024: #define PetscMPIIntCheck(a)
2025: #define PetscBLASIntCheck(a)
2026: #define PetscHDF5IntCheck(a)
2027: #define PetscMPIIntCast(a) a
2028: #define PetscBLASIntCast(a) a
2029: #define PetscHDF5IntCast(a) a
2030: #endif
2033: /*
2034: The IBM include files define hz, here we hide it so that it may be used
2035: as a regular user variable.
2036: */
2037: #if defined(hz)
2038: #undef hz
2039: #endif
2041: /* For arrays that contain filenames or paths */
2044: #if defined(PETSC_HAVE_LIMITS_H)
2045: #include <limits.h>
2046: #endif
2047: #if defined(PETSC_HAVE_SYS_PARAM_H)
2048: #include <sys/param.h>
2049: #endif
2050: #if defined(PETSC_HAVE_SYS_TYPES_H)
2051: #include <sys/types.h>
2052: #endif
2053: #if defined(MAXPATHLEN)
2054: # define PETSC_MAX_PATH_LEN MAXPATHLEN
2055: #elif defined(MAX_PATH)
2056: # define PETSC_MAX_PATH_LEN MAX_PATH
2057: #elif defined(_MAX_PATH)
2058: # define PETSC_MAX_PATH_LEN _MAX_PATH
2059: #else
2060: # define PETSC_MAX_PATH_LEN 4096
2061: #endif
2063: /* Special support for C++ */
2064: #include petscsys.hh
2067: /*MC
2069: UsingFortran - Fortran can be used with PETSc in four distinct approaches
2071: $ 1) classic Fortran 77 style
2072: $#include "petscXXX.h" to work with material from the XXX component of PETSc
2073: $ XXX variablename
2074: $ You cannot use this approach if you wish to use the Fortran 90 specific PETSc routines
2075: $ which end in F90; such as VecGetArrayF90()
2076: $
2077: $ 2) classic Fortran 90 style
2078: $#include "petscXXX.h"
2079: $#include "petscXXX.h90" to work with material from the XXX component of PETSc
2080: $ XXX variablename
2081: $
2082: $ 3) Using Fortran modules
2083: $#include "petscXXXdef.h"
2084: $ use petscXXXX
2085: $ XXX variablename
2086: $
2087: $ 4) Use Fortran modules and Fortran data types for PETSc types
2088: $#include "petscXXXdef.h"
2089: $ use petscXXXX
2090: $ type(XXX) variablename
2091: $ To use this approach you must config/configure.py PETSc with the additional
2092: $ option --with-fortran-datatypes You cannot use the type(XXX) declaration approach without using Fortran modules
2094: Finally if you absolutely do not want to use any #include you can use either
2096: $ 3a) skip the #include BUT you cannot use any PETSc data type names like Vec, Mat, PetscInt, PetscErrorCode etc
2097: $ and you must declare the variables as integer, for example
2098: $ integer variablename
2099: $
2100: $ 4a) skip the #include, you use the object types like type(Vec) type(Mat) but cannot use the data type
2101: $ names like PetscErrorCode, PetscInt etc. again for those you must use integer
2103: We recommend either 2 or 3. Approaches 2 and 3 provide type checking for most PETSc function calls; 4 has type checking
2104: for only a few PETSc functions.
2106: Fortran type checking with interfaces is strick, this means you cannot pass a scalar value when an array value
2107: is expected (even though it is legal Fortran). For example when setting a single value in a matrix with MatSetValues()
2108: you cannot have something like
2109: $ PetscInt row,col
2110: $ PetscScalar val
2111: $ ...
2112: $ call MatSetValues(mat,1,row,1,col,val,INSERT_VALUES,ierr)
2113: You must instead have
2114: $ PetscInt row(1),col(1)
2115: $ PetscScalar val(1)
2116: $ ...
2117: $ call MatSetValues(mat,1,row,1,col,val,INSERT_VALUES,ierr)
2120: See the example src/vec/vec/examples/tutorials/ex20f90.F90 for an example that can use all four approaches
2122: Developer Notes: The finclude/petscXXXdef.h contain all the #defines (would be typedefs in C code) these
2123: automatically include their predecessors; for example finclude/petscvecdef.h includes finclude/petscisdef.h
2125: The finclude/petscXXXX.h contain all the parameter statements for that package. These automatically include
2126: their finclude/petscXXXdef.h file but DO NOT automatically include their predecessors; for example
2127: finclude/petscvec.h does NOT automatically include finclude/petscis.h
2129: The finclude/ftn-custom/petscXXXdef.h90 are not intended to be used directly in code, they define the
2130: Fortran data type type(XXX) (for example type(Vec)) when PETSc is config/configure.py with the --with-fortran-datatypes option.
2132: The finclude/ftn-custom/petscXXX.h90 (not included directly by code) contain interface definitions for
2133: the PETSc Fortran stubs that have different bindings then their C version (for example VecGetArrayF90).
2135: The finclude/ftn-auto/petscXXX.h90 (not included directly by code) contain interface definitions generated
2136: automatically by "make allfortranstubs".
2138: The finclude/petscXXX.h90 includes the custom finclude/ftn-custom/petscXXX.h90 and if config/configure.py
2139: was run with --with-fortran-interfaces it also includes the finclude/ftn-auto/petscXXX.h90 These DO NOT automatically
2140: include their predecessors
2142: Level: beginner
2144: M*/
2146: EXTERN PetscErrorCode PetscGetArchType(char[],size_t);
2147: EXTERN PetscErrorCode PetscGetHostName(char[],size_t);
2148: EXTERN PetscErrorCode PetscGetUserName(char[],size_t);
2149: EXTERN PetscErrorCode PetscGetProgramName(char[],size_t);
2150: EXTERN PetscErrorCode PetscSetProgramName(const char[]);
2151: EXTERN PetscErrorCode PetscGetDate(char[],size_t);
2153: EXTERN PetscErrorCode PetscSortInt(PetscInt,PetscInt[]);
2154: EXTERN PetscErrorCode PetscSortIntWithPermutation(PetscInt,const PetscInt[],PetscInt[]);
2155: EXTERN PetscErrorCode PetscSortStrWithPermutation(PetscInt,const char*[],PetscInt[]);
2156: EXTERN PetscErrorCode PetscSortIntWithArray(PetscInt,PetscInt[],PetscInt[]);
2157: EXTERN PetscErrorCode PetscSortMPIIntWithArray(PetscMPIInt,PetscMPIInt[],PetscMPIInt[]);
2158: EXTERN PetscErrorCode PetscSortIntWithScalarArray(PetscInt,PetscInt[],PetscScalar[]);
2159: EXTERN PetscErrorCode PetscSortReal(PetscInt,PetscReal[]);
2160: EXTERN PetscErrorCode PetscSortRealWithPermutation(PetscInt,const PetscReal[],PetscInt[]);
2161: EXTERN PetscErrorCode PetscSortSplit(PetscInt,PetscInt,PetscScalar[],PetscInt[]);
2162: EXTERN PetscErrorCode PetscSortSplitReal(PetscInt,PetscInt,PetscReal[],PetscInt[]);
2164: EXTERN PetscErrorCode PetscSetDisplay(void);
2165: EXTERN PetscErrorCode PetscGetDisplay(char[],size_t);
2167: /*E
2168: PetscRandomType - String with the name of a PETSc randomizer
2169: with an optional dynamic library name, for example
2170: http://www.mcs.anl.gov/petsc/lib.a:myrandcreate()
2172: Level: beginner
2174: Notes: to use the SPRNG you must have config/configure.py PETSc
2175: with the option --download-sprng
2177: .seealso: PetscRandomSetType(), PetscRandom
2178: E*/
2179: #define PetscRandomType char*
2180: #define PETSCRAND "rand"
2181: #define PETSCRAND48 "rand48"
2182: #define PETSCSPRNG "sprng"
2184: /* Logging support */
2187: EXTERN PetscErrorCode PetscRandomInitializePackage(const char[]);
2189: /*S
2190: PetscRandom - Abstract PETSc object that manages generating random numbers
2192: Level: intermediate
2194: Concepts: random numbers
2196: .seealso: PetscRandomCreate(), PetscRandomGetValue(), PetscRandomType
2197: S*/
2198: typedef struct _p_PetscRandom* PetscRandom;
2200: /* Dynamic creation and loading functions */
2204: EXTERN PetscErrorCode PetscRandomRegisterAll(const char []);
2205: EXTERN PetscErrorCode PetscRandomRegister(const char[],const char[],const char[],PetscErrorCode (*)(PetscRandom));
2206: EXTERN PetscErrorCode PetscRandomRegisterDestroy(void);
2207: EXTERN PetscErrorCode PetscRandomSetType(PetscRandom, const PetscRandomType);
2208: EXTERN PetscErrorCode PetscRandomSetFromOptions(PetscRandom);
2209: EXTERN PetscErrorCode PetscRandomGetType(PetscRandom, const PetscRandomType*);
2210: EXTERN PetscErrorCode PetscRandomViewFromOptions(PetscRandom,char*);
2211: EXTERN PetscErrorCode PetscRandomView(PetscRandom,PetscViewer);
2213: /*MC
2214: PetscRandomRegisterDynamic - Adds a new PetscRandom component implementation
2216: Synopsis:
2217: PetscErrorCode PetscRandomRegisterDynamic(char *name, char *path, char *func_name, PetscErrorCode (*create_func)(PetscRandom))
2219: Not Collective
2221: Input Parameters:
2222: + name - The name of a new user-defined creation routine
2223: . path - The path (either absolute or relative) of the library containing this routine
2224: . func_name - The name of routine to create method context
2225: - create_func - The creation routine itself
2227: Notes:
2228: PetscRandomRegisterDynamic() may be called multiple times to add several user-defined randome number generators
2230: If dynamic libraries are used, then the fourth input argument (routine_create) is ignored.
2232: Sample usage:
2233: .vb
2234: PetscRandomRegisterDynamic("my_rand","/home/username/my_lib/lib/libO/solaris/libmy.a", "MyPetscRandomtorCreate", MyPetscRandomtorCreate);
2235: .ve
2237: Then, your random type can be chosen with the procedural interface via
2238: .vb
2239: PetscRandomCreate(MPI_Comm, PetscRandom *);
2240: PetscRandomSetType(PetscRandom,"my_random_name");
2241: .ve
2242: or at runtime via the option
2243: .vb
2244: -random_type my_random_name
2245: .ve
2247: Notes: $PETSC_ARCH occuring in pathname will be replaced with appropriate values.
2249: For an example of the code needed to interface your own random number generator see
2250: src/sys/random/impls/rand/rand.c
2251:
2252: Level: advanced
2254: .keywords: PetscRandom, register
2255: .seealso: PetscRandomRegisterAll(), PetscRandomRegisterDestroy(), PetscRandomRegister()
2256: M*/
2257: #if defined(PETSC_USE_DYNAMIC_LIBRARIES)
2258: #define PetscRandomRegisterDynamic(a,b,c,d) PetscRandomRegister(a,b,c,0)
2259: #else
2260: #define PetscRandomRegisterDynamic(a,b,c,d) PetscRandomRegister(a,b,c,d)
2261: #endif
2263: EXTERN PetscErrorCode PetscRandomCreate(MPI_Comm,PetscRandom*);
2264: EXTERN PetscErrorCode PetscRandomGetValue(PetscRandom,PetscScalar*);
2265: EXTERN PetscErrorCode PetscRandomGetValueReal(PetscRandom,PetscReal*);
2266: EXTERN PetscErrorCode PetscRandomGetInterval(PetscRandom,PetscScalar*,PetscScalar*);
2267: EXTERN PetscErrorCode PetscRandomSetInterval(PetscRandom,PetscScalar,PetscScalar);
2268: EXTERN PetscErrorCode PetscRandomSetSeed(PetscRandom,unsigned long);
2269: EXTERN PetscErrorCode PetscRandomGetSeed(PetscRandom,unsigned long *);
2270: EXTERN PetscErrorCode PetscRandomSeed(PetscRandom);
2271: EXTERN PetscErrorCode PetscRandomDestroy(PetscRandom);
2273: EXTERN PetscErrorCode PetscGetFullPath(const char[],char[],size_t);
2274: EXTERN PetscErrorCode PetscGetRelativePath(const char[],char[],size_t);
2275: EXTERN PetscErrorCode PetscGetWorkingDirectory(char[],size_t);
2276: EXTERN PetscErrorCode PetscGetRealPath(const char[],char[]);
2277: EXTERN PetscErrorCode PetscGetHomeDirectory(char[],size_t);
2278: EXTERN PetscErrorCode PetscTestFile(const char[],char,PetscTruth*);
2279: EXTERN PetscErrorCode PetscTestDirectory(const char[],char,PetscTruth*);
2281: EXTERN PetscErrorCode PetscBinaryRead(int,void*,PetscInt,PetscDataType);
2282: EXTERN PetscErrorCode PetscBinarySynchronizedRead(MPI_Comm,int,void*,PetscInt,PetscDataType);
2283: EXTERN PetscErrorCode PetscBinarySynchronizedWrite(MPI_Comm,int,void*,PetscInt,PetscDataType,PetscTruth);
2284: EXTERN PetscErrorCode PetscBinaryWrite(int,void*,PetscInt,PetscDataType,PetscTruth);
2285: EXTERN PetscErrorCode PetscBinaryOpen(const char[],PetscFileMode,int *);
2286: EXTERN PetscErrorCode PetscBinaryClose(int);
2287: EXTERN PetscErrorCode PetscSharedTmp(MPI_Comm,PetscTruth *);
2288: EXTERN PetscErrorCode PetscSharedWorkingDirectory(MPI_Comm,PetscTruth *);
2289: EXTERN PetscErrorCode PetscGetTmp(MPI_Comm,char[],size_t);
2290: EXTERN PetscErrorCode PetscFileRetrieve(MPI_Comm,const char[],char[],size_t,PetscTruth*);
2291: EXTERN PetscErrorCode PetscLs(MPI_Comm,const char[],char[],size_t,PetscTruth*);
2292: EXTERN PetscErrorCode PetscOpenSocket(char*,int,int*);
2294: /*
2295: In binary files variables are stored using the following lengths,
2296: regardless of how they are stored in memory on any one particular
2297: machine. Use these rather then sizeof() in computing sizes for
2298: PetscBinarySeek().
2299: */
2300: #define PETSC_BINARY_INT_SIZE (32/8)
2301: #define PETSC_BINARY_FLOAT_SIZE (32/8)
2302: #define PETSC_BINARY_CHAR_SIZE (8/8)
2303: #define PETSC_BINARY_SHORT_SIZE (16/8)
2304: #define PETSC_BINARY_DOUBLE_SIZE (64/8)
2305: #define PETSC_BINARY_SCALAR_SIZE sizeof(PetscScalar)
2307: /*E
2308: PetscBinarySeekType - argument to PetscBinarySeek()
2310: Level: advanced
2312: .seealso: PetscBinarySeek(), PetscBinarySynchronizedSeek()
2313: E*/
2314: typedef enum {PETSC_BINARY_SEEK_SET = 0,PETSC_BINARY_SEEK_CUR = 1,PETSC_BINARY_SEEK_END = 2} PetscBinarySeekType;
2315: EXTERN PetscErrorCode PetscBinarySeek(int,off_t,PetscBinarySeekType,off_t*);
2316: EXTERN PetscErrorCode PetscBinarySynchronizedSeek(MPI_Comm,int,off_t,PetscBinarySeekType,off_t*);
2318: EXTERN PetscErrorCode PetscSetDebugTerminal(const char[]);
2319: EXTERN PetscErrorCode PetscSetDebugger(const char[],PetscTruth);
2320: EXTERN PetscErrorCode PetscSetDefaultDebugger(void);
2321: EXTERN PetscErrorCode PetscSetDebuggerFromString(char*);
2322: EXTERN PetscErrorCode PetscAttachDebugger(void);
2323: EXTERN PetscErrorCode PetscStopForDebugger(void);
2325: EXTERN PetscErrorCode PetscGatherNumberOfMessages(MPI_Comm,const PetscMPIInt[],const PetscMPIInt[],PetscMPIInt*);
2326: EXTERN PetscErrorCode PetscGatherMessageLengths(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],PetscMPIInt**,PetscMPIInt**);
2327: EXTERN PetscErrorCode PetscGatherMessageLengths2(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],const PetscMPIInt[],PetscMPIInt**,PetscMPIInt**,PetscMPIInt**);
2328: EXTERN PetscErrorCode PetscPostIrecvInt(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],const PetscMPIInt[],PetscInt***,MPI_Request**);
2329: EXTERN PetscErrorCode PetscPostIrecvScalar(MPI_Comm,PetscMPIInt,PetscMPIInt,const PetscMPIInt[],const PetscMPIInt[],PetscScalar***,MPI_Request**);
2331: EXTERN PetscErrorCode PetscSSEIsEnabled(MPI_Comm,PetscTruth *,PetscTruth *);
2333: /*E
2334: InsertMode - Whether entries are inserted or added into vectors or matrices
2336: Level: beginner
2338: .seealso: VecSetValues(), MatSetValues(), VecSetValue(), VecSetValuesBlocked(),
2339: VecSetValuesLocal(), VecSetValuesBlockedLocal(), MatSetValuesBlocked(),
2340: MatSetValuesBlockedLocal(), MatSetValuesLocal(), VecScatterBegin(), VecScatterEnd()
2341: E*/
2342: typedef enum {NOT_SET_VALUES, INSERT_VALUES, ADD_VALUES, MAX_VALUES} InsertMode;
2344: /*MC
2345: INSERT_VALUES - Put a value into a vector or matrix, overwrites any previous value
2347: Level: beginner
2349: .seealso: InsertMode, VecSetValues(), MatSetValues(), VecSetValue(), VecSetValuesBlocked(),
2350: VecSetValuesLocal(), VecSetValuesBlockedLocal(), MatSetValuesBlocked(), ADD_VALUES, INSERT_VALUES,
2351: MatSetValuesBlockedLocal(), MatSetValuesLocal(), VecScatterBegin(), VecScatterEnd()
2353: M*/
2355: /*MC
2356: ADD_VALUES - Adds a value into a vector or matrix, if there previously was no value, just puts the
2357: value into that location
2359: Level: beginner
2361: .seealso: InsertMode, VecSetValues(), MatSetValues(), VecSetValue(), VecSetValuesBlocked(),
2362: VecSetValuesLocal(), VecSetValuesBlockedLocal(), MatSetValuesBlocked(), ADD_VALUES, INSERT_VALUES,
2363: MatSetValuesBlockedLocal(), MatSetValuesLocal(), VecScatterBegin(), VecScatterEnd()
2365: M*/
2367: /*MC
2368: MAX_VALUES - Puts the maximum of the scattered/gathered value and the current value into each location
2370: Level: beginner
2372: .seealso: InsertMode, VecScatterBegin(), VecScatterEnd(), ADD_VALUES, INSERT_VALUES
2374: M*/
2376: /*E
2377: ScatterMode - Determines the direction of a scatter
2379: Level: beginner
2381: .seealso: VecScatter, VecScatterBegin(), VecScatterEnd()
2382: E*/
2383: typedef enum {SCATTER_FORWARD=0, SCATTER_REVERSE=1, SCATTER_FORWARD_LOCAL=2, SCATTER_REVERSE_LOCAL=3, SCATTER_LOCAL=2} ScatterMode;
2385: /*MC
2386: SCATTER_FORWARD - Scatters the values as dictated by the VecScatterCreate() call
2388: Level: beginner
2390: .seealso: VecScatter, ScatterMode, VecScatterCreate(), VecScatterBegin(), VecScatterEnd(), SCATTER_REVERSE, SCATTER_FORWARD_LOCAL,
2391: SCATTER_REVERSE_LOCAL
2393: M*/
2395: /*MC
2396: SCATTER_REVERSE - Moves the values in the opposite direction then the directions indicated in
2397: in the VecScatterCreate()
2399: Level: beginner
2401: .seealso: VecScatter, ScatterMode, VecScatterCreate(), VecScatterBegin(), VecScatterEnd(), SCATTER_FORWARD, SCATTER_FORWARD_LOCAL,
2402: SCATTER_REVERSE_LOCAL
2404: M*/
2406: /*MC
2407: SCATTER_FORWARD_LOCAL - Scatters the values as dictated by the VecScatterCreate() call except NO parallel communication
2408: is done. Any variables that have be moved between processes are ignored
2410: Level: developer
2412: .seealso: VecScatter, ScatterMode, VecScatterCreate(), VecScatterBegin(), VecScatterEnd(), SCATTER_REVERSE, SCATTER_FORWARD,
2413: SCATTER_REVERSE_LOCAL
2415: M*/
2417: /*MC
2418: SCATTER_REVERSE_LOCAL - Moves the values in the opposite direction then the directions indicated in
2419: in the VecScatterCreate() except NO parallel communication
2420: is done. Any variables that have be moved between processes are ignored
2422: Level: developer
2424: .seealso: VecScatter, ScatterMode, VecScatterCreate(), VecScatterBegin(), VecScatterEnd(), SCATTER_FORWARD, SCATTER_FORWARD_LOCAL,
2425: SCATTER_REVERSE
2427: M*/
2429: /*S
2430: PetscSubcomm - Context of MPI subcommunicators, used by PCREDUNDANT
2432: Level: advanced
2434: Concepts: communicator, create
2435: S*/
2436: typedef struct _n_PetscSubcomm* PetscSubcomm;
2438: struct _n_PetscSubcomm {
2439: MPI_Comm parent; /* parent communicator */
2440: MPI_Comm dupparent; /* duplicate parent communicator, under which the processors of this subcomm have contiguous rank */
2441: MPI_Comm comm; /* this communicator */
2442: PetscInt n; /* num of subcommunicators under the parent communicator */
2443: PetscInt color; /* color of processors belong to this communicator */
2444: };
2446: EXTERN PetscErrorCode PetscSubcommCreate(MPI_Comm,PetscInt,PetscSubcomm*);
2447: EXTERN PetscErrorCode PetscSubcommDestroy(PetscSubcomm);
2451: #endif