Actual source code: petscimpl.h
petsc-3.9.0 2018-04-07
2: /*
3: Defines the basic header of all PETSc objects.
4: */
6: #if !defined(_PETSCHEAD_H)
7: #define _PETSCHEAD_H
8: #include <petscsys.h>
10: /* These are used internally by PETSc ASCII IO routines*/
11: #include <stdarg.h>
12: PETSC_EXTERN PetscErrorCode PetscVSNPrintf(char*,size_t,const char[],size_t*,va_list);
13: PETSC_EXTERN PetscErrorCode (*PetscVFPrintf)(FILE*,const char[],va_list);
14: PETSC_EXTERN PetscErrorCode PetscVFPrintfDefault(FILE*,const char[],va_list);
16: #if defined(PETSC_HAVE_MATLAB_ENGINE)
17: PETSC_EXTERN PetscErrorCode PetscVFPrintf_Matlab(FILE*,const char[],va_list);
18: #endif
20: #if defined(PETSC_HAVE_CLOSURES)
21: PETSC_EXTERN PetscErrorCode PetscVFPrintfSetClosure(int (^)(const char*));
22: #endif
25: #if defined(PETSC_HAVE_CUDA)
26: #include <cuda.h>
27: #include <cublas_v2.h>
28: #endif
30: /*
31: All major PETSc data structures have a common core; this is defined
32: below by PETSCHEADER.
34: PetscHeaderCreate() should be used whenever creating a PETSc structure.
35: */
37: /*
38: PetscOps: structure of core operations that all PETSc objects support.
40: getcomm() - Gets the object's communicator.
41: view() - Is the routine for viewing the entire PETSc object; for
42: example, MatView() is the general matrix viewing routine.
43: This is used by PetscObjectView((PetscObject)obj) to allow
44: viewing any PETSc object.
45: destroy() - Is the routine for destroying the entire PETSc object;
46: for example,MatDestroy() is the general matrix
47: destruction routine.
48: This is used by PetscObjectDestroy((PetscObject*)&obj) to allow
49: destroying any PETSc object.
50: compose() - Associates a PETSc object with another PETSc object with a name
51: query() - Returns a different PETSc object that has been associated
52: with the first object using a name.
53: composefunction() - Attaches an a function to a PETSc object with a name.
54: queryfunction() - Requests a registered function that has been attached to a PETSc object.
55: */
57: typedef struct {
58: PetscErrorCode (*getcomm)(PetscObject,MPI_Comm *);
59: PetscErrorCode (*view)(PetscObject,PetscViewer);
60: PetscErrorCode (*destroy)(PetscObject*);
61: PetscErrorCode (*compose)(PetscObject,const char[],PetscObject);
62: PetscErrorCode (*query)(PetscObject,const char[],PetscObject *);
63: PetscErrorCode (*composefunction)(PetscObject,const char[],void (*)(void));
64: PetscErrorCode (*queryfunction)(PetscObject,const char[],void (**)(void));
65: } PetscOps;
67: typedef enum {PETSC_FORTRAN_CALLBACK_CLASS,PETSC_FORTRAN_CALLBACK_SUBTYPE,PETSC_FORTRAN_CALLBACK_MAXTYPE} PetscFortranCallbackType;
68: typedef int PetscFortranCallbackId;
69: #define PETSC_SMALLEST_FORTRAN_CALLBACK ((PetscFortranCallbackId)1000)
70: PETSC_EXTERN PetscErrorCode PetscFortranCallbackRegister(PetscClassId,const char*,PetscFortranCallbackId*);
71: PETSC_EXTERN PetscErrorCode PetscFortranCallbackGetSizes(PetscClassId,PetscInt*,PetscInt*);
73: typedef struct {
74: void (*func)(void);
75: void *ctx;
76: } PetscFortranCallback;
78: /*
79: All PETSc objects begin with the fields defined in PETSCHEADER.
80: The PetscObject is a way of examining these fields regardless of
81: the specific object. In C++ this could be a base abstract class
82: from which all objects are derived.
83: */
84: #define PETSC_MAX_OPTIONS_HANDLER 5
85: typedef struct _p_PetscObject {
86: PetscClassId classid;
87: PetscOps bops[1];
88: MPI_Comm comm;
89: PetscInt type;
90: PetscLogDouble flops,time,mem,memchildren;
91: PetscObjectId id;
92: PetscInt refct;
93: PetscMPIInt tag;
94: PetscFunctionList qlist;
95: PetscObjectList olist;
96: char *class_name; /* for example, "Vec" */
97: char *description;
98: char *mansec;
99: char *type_name; /* this is the subclass, for example VECSEQ which equals "seq" */
100: PetscObject parent;
101: PetscObjectId parentid;
102: char* name;
103: char *prefix;
104: PetscInt tablevel;
105: void *cpp;
106: PetscObjectState state;
107: PetscInt int_idmax, intstar_idmax;
108: PetscObjectState *intcomposedstate,*intstarcomposedstate;
109: PetscInt *intcomposeddata, **intstarcomposeddata;
110: PetscInt real_idmax, realstar_idmax;
111: PetscObjectState *realcomposedstate,*realstarcomposedstate;
112: PetscReal *realcomposeddata, **realstarcomposeddata;
113: PetscInt scalar_idmax, scalarstar_idmax;
114: PetscObjectState *scalarcomposedstate,*scalarstarcomposedstate;
115: PetscScalar *scalarcomposeddata, **scalarstarcomposeddata;
116: void (**fortran_func_pointers)(void); /* used by Fortran interface functions to stash user provided Fortran functions */
117: PetscInt num_fortran_func_pointers; /* number of Fortran function pointers allocated */
118: PetscFortranCallback *fortrancallback[PETSC_FORTRAN_CALLBACK_MAXTYPE];
119: PetscInt num_fortrancallback[PETSC_FORTRAN_CALLBACK_MAXTYPE];
120: void *python_context;
121: PetscErrorCode (*python_destroy)(void*);
123: PetscInt noptionhandler;
124: PetscErrorCode (*optionhandler[PETSC_MAX_OPTIONS_HANDLER])(PetscOptionItems*,PetscObject,void*);
125: PetscErrorCode (*optiondestroy[PETSC_MAX_OPTIONS_HANDLER])(PetscObject,void*);
126: void *optionctx[PETSC_MAX_OPTIONS_HANDLER];
127: PetscBool optionsprinted;
128: #if defined(PETSC_HAVE_SAWS)
129: PetscBool amsmem; /* if PETSC_TRUE then this object is registered with SAWs and visible to clients */
130: PetscBool amspublishblock; /* if PETSC_TRUE and publishing objects then will block at PetscObjectSAWsBlock() */
131: #endif
132: PetscOptions options; /* options database used, NULL means default */
133: PetscBool donotPetscObjectPrintClassNamePrefixType;
134: } _p_PetscObject;
136: #define PETSCHEADER(ObjectOps) \
137: _p_PetscObject hdr; \
138: ObjectOps ops[1]
140: #define PETSCFREEDHEADER -1
142: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode (*PetscObjectDestroyFunction)(PetscObject*); /* force cast in next macro to NEVER use extern "C" style */
143: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode (*PetscObjectViewFunction)(PetscObject,PetscViewer);
145: /*@C
146: PetscHeaderCreate - Creates a PETSc object of a particular class
148: Input Parameters:
149: + classid - the classid associated with this object (for example VEC_CLASSID)
150: . class_name - string name of class; should be static (for example "Vec")
151: . descr - string containing short description; should be static (for example "Vector")
152: . mansec - string indicating section in manual pages; should be static (for example "Vec")
153: . comm - the MPI Communicator
154: . destroy - the destroy routine for this object (for example VecDestroy())
155: - view - the view routine for this object (for example VecView())
157: Output Parameter:
158: . h - the newly created object
160: Level: developer
162: .seealso: PetscHeaderDestroy(), PetscClassIdRegister()
164: @*/
165: #define PetscHeaderCreate(h,classid,class_name,descr,mansec,comm,destroy,view) \
166: (PetscNew(&(h)) || \
167: PetscHeaderCreate_Private((PetscObject)h,classid,class_name,descr,mansec,comm,(PetscObjectDestroyFunction)destroy,(PetscObjectViewFunction)view) || \
168: PetscLogObjectCreate(h) || \
169: PetscLogObjectMemory((PetscObject)h,sizeof(*(h))))
171: PETSC_EXTERN PetscErrorCode PetscComposedQuantitiesDestroy(PetscObject obj);
172: PETSC_EXTERN PetscErrorCode PetscHeaderCreate_Private(PetscObject,PetscClassId,const char[],const char[],const char[],MPI_Comm,PetscObjectDestroyFunction,PetscObjectViewFunction);
174: /*@C
175: PetscHeaderDestroy - Final step in destroying a PetscObject
177: Input Parameters:
178: . h - the header created with PetscHeaderCreate()
180: Level: developer
182: .seealso: PetscHeaderCreate()
183: @*/
184: #define PetscHeaderDestroy(h) (PetscHeaderDestroy_Private((PetscObject)(*h)) || PetscFree(*h))
186: PETSC_EXTERN PetscErrorCode PetscHeaderDestroy_Private(PetscObject);
187: PETSC_EXTERN PetscErrorCode PetscObjectCopyFortranFunctionPointers(PetscObject,PetscObject);
188: PETSC_EXTERN PetscErrorCode PetscObjectSetFortranCallback(PetscObject,PetscFortranCallbackType,PetscFortranCallbackId*,void(*)(void),void *ctx);
189: PETSC_EXTERN PetscErrorCode PetscObjectGetFortranCallback(PetscObject,PetscFortranCallbackType,PetscFortranCallbackId,void(**)(void),void **ctx);
191: PETSC_INTERN PetscErrorCode PetscCitationsInitialize(void);
192: PETSC_INTERN PetscErrorCode PetscOptionsFindPair_Private(PetscOptions,const char[],const char[],char**,PetscBool*);
193: PETSC_INTERN PetscErrorCode PetscFreeMPIResources(void);
199: /*
200: Macros to test if a PETSc object is valid and if pointers are valid
201: */
202: #if !defined(PETSC_USE_DEBUG)
213: #else
216: do { \
217: if (!h) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Null Object: Parameter # %d",arg); \
219: if (((PetscObject)(h))->classid != ck) { \
220: if (((PetscObject)(h))->classid == PETSCFREEDHEADER) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_CORRUPT,"Object already free: Parameter # %d",arg); \
221: else SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Wrong type of object: Parameter # %d",arg); \
222: } \
223: } while (0)
226: do { \
227: if (!h) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Null Object: Parameter # %d",arg); \
229: if (((PetscObject)(h))->classid == PETSCFREEDHEADER) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_CORRUPT,"Object already free: Parameter # %d",arg); \
230: else if (((PetscObject)(h))->classid < PETSC_SMALLEST_CLASSID || ((PetscObject)(h))->classid > PETSC_LARGEST_CLASSID) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_CORRUPT,"Invalid type of object: Parameter # %d",arg); \
231: } while (0)
234: do { \
235: if (!h) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Null Pointer: Parameter # %d",arg); \
237: } while (0)
240: do { \
241: if (!h) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Null Pointer: Parameter # %d",arg);\
243: } while (0)
246: do { \
247: if (!h) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_BADPTR,"Null Pointer: Parameter # %d",arg); \
249: } while (0)
252: do { \
253: if (!h) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Null Pointer: Parameter # %d",arg); \
255: } while (0)
258: do { \
259: if (!h) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Null Pointer: Parameter # %d",arg); \
261: } while (0)
264: do { \
265: if (!f) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Null Function Pointer: Parameter # %d",arg); \
266: } while (0)
268: #endif
270: #if !defined(PETSC_USE_DEBUG)
285: #else
287: /*
288: For example, in the dot product between two vectors,
289: both vectors must be either Seq or MPI, not one of each
290: */
292: if (((PetscObject)a)->type != ((PetscObject)b)->type) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_NOTSAMETYPE,"Objects not of same type: Argument # %d and %d",arga,argb);
293: /*
294: Check type_name
295: */
297: do { \
298: PetscBool __match; \
299: PetscErrorCode _7_ierr; \
300: _7_PetscObjectTypeCompare(((PetscObject)a),(type),&__match);CHKERRQ(_7_ierr); \
301: if (!__match) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Object (%s) is not %s",(char*)(((PetscObject)a)->type_name),type); \
302: } while (0)
305: do { \
306: PetscBool __match; \
307: PetscErrorCode _7_ierr; \
308: _7_PetscObjectTypeCompareAny(((PetscObject)a),&__match,(type1),(type2),"");CHKERRQ(_7_ierr); \
309: if (!__match) SETERRQ3(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Object (%s) is not %s or %s",(char*)(((PetscObject)a)->type_name),type1,type2); \
310: } while (0)
311: /*
312: Use this macro to check if the type is set
313: */
315: if (!((PetscObject)a)->type_name) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONGSTATE,"%s object's type is not set: Argument # %d",((PetscObject)a)->class_name,arg);
316: /*
317: Sometimes object must live on same communicator to inter-operate
318: */
320: do { \
321: PetscErrorCode _6_ierr,__flag; \
322: _6_MPI_Comm_compare(PetscObjectComm((PetscObject)a),PetscObjectComm((PetscObject)b),&__flag);CHKERRQ(_6_ierr); \
323: if (__flag != MPI_CONGRUENT && __flag != MPI_IDENT) SETERRQ3(PETSC_COMM_SELF,PETSC_ERR_ARG_NOTSAMECOMM,"Different communicators in the two objects: Argument # %d and %d flag %d",arga,argb,__flag); \
324: } while (0)
327: do { \
330: } while (0)
333: do { \
334: PetscErrorCode _7_ierr; \
335: PetscReal b1[5],b2[5]; \
336: if (PetscIsNanScalar(b)) {b1[4] = 1;} else {b1[4] = 0;}; \
337: b1[0] = -PetscRealPart(b); b1[1] = PetscRealPart(b);b1[2] = -PetscImaginaryPart(b); b1[3] = PetscImaginaryPart(b); \
338: _7_MPI_Allreduce(b1,b2,5,MPIU_REAL,MPIU_MAX,PetscObjectComm((PetscObject)a));CHKERRQ(_7_ierr); \
339: if (!(b2[4] > 0) && !(PetscEqualReal(-b2[0],b2[1]) && PetscEqualReal(-b2[2],b2[3]))) SETERRQ1(PetscObjectComm((PetscObject)a),PETSC_ERR_ARG_WRONG,"Scalar value must be same on all processes, argument # %d",c); \
340: } while (0)
343: do { \
344: PetscErrorCode _7_ierr; \
345: PetscReal b1[3],b2[3]; \
346: if (PetscIsNanReal(b)) {b1[2] = 1;} else {b1[2] = 0;}; \
347: b1[0] = -b; b1[1] = b; \
348: _7_MPI_Allreduce(b1,b2,3,MPIU_REAL,MPIU_MAX,PetscObjectComm((PetscObject)a));CHKERRQ(_7_ierr); \
349: if (!(b2[2] > 0) && !PetscEqualReal(-b2[0],b2[1])) SETERRQ1(PetscObjectComm((PetscObject)a),PETSC_ERR_ARG_WRONG,"Real value must be same on all processes, argument # %d",c); \
350: } while (0)
353: do { \
354: PetscErrorCode _7_ierr; \
355: PetscInt b1[2],b2[2]; \
356: b1[0] = -b; b1[1] = b; \
357: _7_MPIU_Allreduce(b1,b2,2,MPIU_INT,MPI_MAX,PetscObjectComm((PetscObject)a));CHKERRQ(_7_ierr); \
358: if (-b2[0] != b2[1]) SETERRQ1(PetscObjectComm((PetscObject)a),PETSC_ERR_ARG_WRONG,"Int value must be same on all processes, argument # %d",c); \
359: } while (0)
364: do { \
365: PetscErrorCode _7_ierr; \
366: PetscMPIInt b1[2],b2[2]; \
367: b1[0] = -(PetscMPIInt)b; b1[1] = (PetscMPIInt)b; \
368: _7_MPIU_Allreduce(b1,b2,2,MPI_INT,MPI_MAX,PetscObjectComm((PetscObject)a));CHKERRQ(_7_ierr); \
369: if (-b2[0] != b2[1]) SETERRQ1(PetscObjectComm((PetscObject)a),PETSC_ERR_ARG_WRONG,"Bool value must be same on all processes, argument # %d",c); \
370: } while (0)
373: do { \
374: PetscErrorCode _7_ierr; \
375: PetscMPIInt b1[2],b2[2]; \
376: b1[0] = -(PetscMPIInt)b; b1[1] = (PetscMPIInt)b; \
377: _7_MPIU_Allreduce(b1,b2,2,MPI_INT,MPI_MAX,PetscObjectComm((PetscObject)a));CHKERRQ(_7_ierr); \
378: if (-b2[0] != b2[1]) SETERRQ1(PetscObjectComm((PetscObject)a),PETSC_ERR_ARG_WRONG,"Enum value must be same on all processes, argument # %d",c); \
379: } while (0)
381: #endif
383: /*
384: PetscTryMethod - Queries an object for a method, if it exists then calls it.
385: These are intended to be used only inside PETSc functions.
387: Level: developer
389: .seealso: PetscUseMethod()
390: */
391: #define PetscTryMethod(obj,A,B,C) \
392: 0;{ PetscErrorCode (*f)B, __ierr; \
393: __PetscObjectQueryFunction((PetscObject)obj,A,&f);CHKERRQ(__ierr); \
394: if (f) {__(*f)C;CHKERRQ(__ierr);}\
395: }
397: /*
398: PetscUseMethod - Queries an object for a method, if it exists then calls it, otherwise generates an error.
399: These are intended to be used only inside PETSc functions.
401: Level: developer
403: .seealso: PetscTryMethod()
404: */
405: #define PetscUseMethod(obj,A,B,C) \
406: 0;{ PetscErrorCode (*f)B, __ierr; \
407: __PetscObjectQueryFunction((PetscObject)obj,A,&f);CHKERRQ(__ierr); \
408: if (f) {__(*f)C;CHKERRQ(__ierr);}\
409: else SETERRQ1(PetscObjectComm((PetscObject)obj),PETSC_ERR_SUP,"Cannot locate function %s in object",A); \
410: }
412: /*MC
413: PetscObjectStateIncrease - Increases the state of any PetscObject
415: Synopsis:
416: #include "petsc/private/petscimpl.h"
417: PetscErrorCode PetscObjectStateIncrease(PetscObject obj)
419: Logically Collective
421: Input Parameter:
422: . obj - any PETSc object, for example a Vec, Mat or KSP. This must be
423: cast with a (PetscObject), for example,
424: PetscObjectStateIncrease((PetscObject)mat);
426: Notes: object state is an integer which gets increased every time
427: the object is changed internally. By saving and later querying the object state
428: one can determine whether information about the object is still current.
429: Currently, state is maintained for Vec and Mat objects.
431: This routine is mostly for internal use by PETSc; a developer need only
432: call it after explicit access to an object's internals. Routines such
433: as VecSet() or MatScale() already call this routine. It is also called, as a
434: precaution, in VecRestoreArray(), MatRestoreRow(), MatDenseRestoreArray().
436: This routine is logically collective because state equality comparison needs to be possible without communication.
438: Level: developer
440: seealso: PetscObjectStateGet()
442: Concepts: state
444: M*/
445: #define PetscObjectStateIncrease(obj) ((obj)->state++,0)
447: PETSC_EXTERN PetscErrorCode PetscObjectStateGet(PetscObject,PetscObjectState*);
448: PETSC_EXTERN PetscErrorCode PetscObjectStateSet(PetscObject,PetscObjectState);
449: PETSC_EXTERN PetscErrorCode PetscObjectComposedDataRegister(PetscInt*);
450: PETSC_EXTERN PetscErrorCode PetscObjectComposedDataIncreaseInt(PetscObject);
451: PETSC_EXTERN PetscErrorCode PetscObjectComposedDataIncreaseIntstar(PetscObject);
452: PETSC_EXTERN PetscErrorCode PetscObjectComposedDataIncreaseReal(PetscObject);
453: PETSC_EXTERN PetscErrorCode PetscObjectComposedDataIncreaseRealstar(PetscObject);
454: PETSC_EXTERN PetscErrorCode PetscObjectComposedDataIncreaseScalar(PetscObject);
455: PETSC_EXTERN PetscErrorCode PetscObjectComposedDataIncreaseScalarstar(PetscObject);
456: PETSC_EXTERN PetscInt PetscObjectComposedDataMax;
457: /*MC
458: PetscObjectComposedDataSetInt - attach integer data to a PetscObject
460: Synopsis:
461: #include "petsc/private/petscimpl.h"
462: PetscErrorCode PetscObjectComposedDataSetInt(PetscObject obj,int id,int data)
464: Not collective
466: Input parameters:
467: + obj - the object to which data is to be attached
468: . id - the identifier for the data
469: - data - the data to be attached
471: Notes
472: The data identifier can best be created through a call to PetscObjectComposedDataRegister()
474: Level: developer
475: M*/
476: #define PetscObjectComposedDataSetInt(obj,id,data) \
477: ((((obj)->int_idmax < PetscObjectComposedDataMax) && PetscObjectComposedDataIncreaseInt(obj)) || \
478: ((obj)->intcomposeddata[id] = data,(obj)->intcomposedstate[id] = (obj)->state, 0))
480: /*MC
481: PetscObjectComposedDataGetInt - retrieve integer data attached to an object
483: Synopsis:
484: #include "petsc/private/petscimpl.h"
485: PetscErrorCode PetscObjectComposedDataGetInt(PetscObject obj,int id,int data,PetscBool flag)
487: Not collective
489: Input parameters:
490: + obj - the object from which data is to be retrieved
491: - id - the identifier for the data
493: Output parameters
494: + data - the data to be retrieved
495: - flag - PETSC_TRUE if the data item exists and is valid, PETSC_FALSE otherwise
497: The 'data' and 'flag' variables are inlined, so they are not pointers.
499: Level: developer
500: M*/
501: #define PetscObjectComposedDataGetInt(obj,id,data,flag) \
502: ((((obj)->intcomposedstate && ((obj)->intcomposedstate[id] == (obj)->state)) ? \
503: (data = (obj)->intcomposeddata[id],flag = PETSC_TRUE) : (flag = PETSC_FALSE)),0)
505: /*MC
506: PetscObjectComposedDataSetIntstar - attach integer array data to a PetscObject
508: Synopsis:
509: #include "petsc/private/petscimpl.h"
510: PetscErrorCode PetscObjectComposedDataSetIntstar(PetscObject obj,int id,int *data)
512: Not collective
514: Input parameters:
515: + obj - the object to which data is to be attached
516: . id - the identifier for the data
517: - data - the data to be attached
519: Notes
520: The data identifier can best be determined through a call to
521: PetscObjectComposedDataRegister()
523: Level: developer
524: M*/
525: #define PetscObjectComposedDataSetIntstar(obj,id,data) \
526: ((((obj)->intstar_idmax < PetscObjectComposedDataMax) && PetscObjectComposedDataIncreaseIntstar(obj)) || \
527: ((obj)->intstarcomposeddata[id] = data,(obj)->intstarcomposedstate[id] = (obj)->state, 0))
529: /*MC
530: PetscObjectComposedDataGetIntstar - retrieve integer array data
531: attached to an object
533: Synopsis:
534: #include "petsc/private/petscimpl.h"
535: PetscErrorCode PetscObjectComposedDataGetIntstar(PetscObject obj,int id,int *data,PetscBool flag)
537: Not collective
539: Input parameters:
540: + obj - the object from which data is to be retrieved
541: - id - the identifier for the data
543: Output parameters
544: + data - the data to be retrieved
545: - flag - PETSC_TRUE if the data item exists and is valid, PETSC_FALSE otherwise
547: The 'data' and 'flag' variables are inlined, so they are not pointers.
549: Level: developer
550: M*/
551: #define PetscObjectComposedDataGetIntstar(obj,id,data,flag) \
552: ((((obj)->intstarcomposedstate && ((obj)->intstarcomposedstate[id] == (obj)->state)) ? \
553: (data = (obj)->intstarcomposeddata[id],flag = PETSC_TRUE) : (flag = PETSC_FALSE)),0)
555: /*MC
556: PetscObjectComposedDataSetReal - attach real data to a PetscObject
558: Synopsis:
559: #include "petsc/private/petscimpl.h"
560: PetscErrorCode PetscObjectComposedDataSetReal(PetscObject obj,int id,PetscReal data)
562: Not collective
564: Input parameters:
565: + obj - the object to which data is to be attached
566: . id - the identifier for the data
567: - data - the data to be attached
569: Notes
570: The data identifier can best be determined through a call to
571: PetscObjectComposedDataRegister()
573: Level: developer
574: M*/
575: #define PetscObjectComposedDataSetReal(obj,id,data) \
576: ((((obj)->real_idmax < PetscObjectComposedDataMax) && PetscObjectComposedDataIncreaseReal(obj)) || \
577: ((obj)->realcomposeddata[id] = data,(obj)->realcomposedstate[id] = (obj)->state, 0))
579: /*MC
580: PetscObjectComposedDataGetReal - retrieve real data attached to an object
582: Synopsis:
583: #include "petsc/private/petscimpl.h"
584: PetscErrorCode PetscObjectComposedDataGetReal(PetscObject obj,int id,PetscReal data,PetscBool flag)
586: Not collective
588: Input parameters:
589: + obj - the object from which data is to be retrieved
590: - id - the identifier for the data
592: Output parameters
593: + data - the data to be retrieved
594: - flag - PETSC_TRUE if the data item exists and is valid, PETSC_FALSE otherwise
596: The 'data' and 'flag' variables are inlined, so they are not pointers.
598: Level: developer
599: M*/
600: #define PetscObjectComposedDataGetReal(obj,id,data,flag) \
601: ((((obj)->realcomposedstate && ((obj)->realcomposedstate[id] == (obj)->state)) ? \
602: (data = (obj)->realcomposeddata[id],flag = PETSC_TRUE) : (flag = PETSC_FALSE)),0)
604: /*MC
605: PetscObjectComposedDataSetRealstar - attach real array data to a PetscObject
607: Synopsis:
608: #include "petsc/private/petscimpl.h"
609: PetscErrorCode PetscObjectComposedDataSetRealstar(PetscObject obj,int id,PetscReal *data)
611: Not collective
613: Input parameters:
614: + obj - the object to which data is to be attached
615: . id - the identifier for the data
616: - data - the data to be attached
618: Notes
619: The data identifier can best be determined through a call to
620: PetscObjectComposedDataRegister()
622: Level: developer
623: M*/
624: #define PetscObjectComposedDataSetRealstar(obj,id,data) \
625: ((((obj)->realstar_idmax < PetscObjectComposedDataMax) && PetscObjectComposedDataIncreaseRealstar(obj)) || \
626: ((obj)->realstarcomposeddata[id] = data, (obj)->realstarcomposedstate[id] = (obj)->state, 0))
628: /*MC
629: PetscObjectComposedDataGetRealstar - retrieve real array data
630: attached to an object
632: Synopsis:
633: #include "petsc/private/petscimpl.h"
634: PetscErrorCode PetscObjectComposedDataGetRealstar(PetscObject obj,int id,PetscReal *data,PetscBool flag)
636: Not collective
638: Input parameters:
639: + obj - the object from which data is to be retrieved
640: - id - the identifier for the data
642: Output parameters
643: + data - the data to be retrieved
644: - flag - PETSC_TRUE if the data item exists and is valid, PETSC_FALSE otherwise
646: The 'data' and 'flag' variables are inlined, so they are not pointers.
648: Level: developer
649: M*/
650: #define PetscObjectComposedDataGetRealstar(obj,id,data,flag) \
651: ((((obj)->realstarcomposedstate && ((obj)->realstarcomposedstate[id] == (obj)->state)) ? \
652: (data = (obj)->realstarcomposeddata[id],flag = PETSC_TRUE) : (flag = PETSC_FALSE)),0)
654: /*MC
655: PetscObjectComposedDataSetScalar - attach scalar data to a PetscObject
657: Synopsis:
658: #include "petsc/private/petscimpl.h"
659: PetscErrorCode PetscObjectComposedDataSetScalar(PetscObject obj,int id,PetscScalar data)
661: Not collective
663: Input parameters:
664: + obj - the object to which data is to be attached
665: . id - the identifier for the data
666: - data - the data to be attached
668: Notes
669: The data identifier can best be determined through a call to
670: PetscObjectComposedDataRegister()
672: Level: developer
673: M*/
674: #if defined(PETSC_USE_COMPLEX)
675: #define PetscObjectComposedDataSetScalar(obj,id,data) \
676: ((((obj)->scalar_idmax < PetscObjectComposedDataMax) && PetscObjectComposedDataIncreaseScalar(obj)) || \
677: ((obj)->scalarcomposeddata[id] = data,(obj)->scalarcomposedstate[id] = (obj)->state, 0))
678: #else
679: #define PetscObjectComposedDataSetScalar(obj,id,data) \
680: PetscObjectComposedDataSetReal(obj,id,data)
681: #endif
682: /*MC
683: PetscObjectComposedDataGetScalar - retrieve scalar data attached to an object
685: Synopsis:
686: #include "petsc/private/petscimpl.h"
687: PetscErrorCode PetscObjectComposedDataGetScalar(PetscObject obj,int id,PetscScalar data,PetscBool flag)
689: Not collective
691: Input parameters:
692: + obj - the object from which data is to be retrieved
693: - id - the identifier for the data
695: Output parameters
696: + data - the data to be retrieved
697: - flag - PETSC_TRUE if the data item exists and is valid, PETSC_FALSE otherwise
699: The 'data' and 'flag' variables are inlined, so they are not pointers.
701: Level: developer
702: M*/
703: #if defined(PETSC_USE_COMPLEX)
704: #define PetscObjectComposedDataGetScalar(obj,id,data,flag) \
705: ((((obj)->scalarcomposedstate && ((obj)->scalarcomposedstate[id] == (obj)->state) ) ? \
706: (data = (obj)->scalarcomposeddata[id],flag = PETSC_TRUE) : (flag = PETSC_FALSE)),0)
707: #else
708: #define PetscObjectComposedDataGetScalar(obj,id,data,flag) \
709: PetscObjectComposedDataGetReal(obj,id,data,flag)
710: #endif
712: /*MC
713: PetscObjectComposedDataSetScalarstar - attach scalar array data to a PetscObject
715: Synopsis:
716: #include "petsc/private/petscimpl.h"
717: PetscErrorCode PetscObjectComposedDataSetScalarstar(PetscObject obj,int id,PetscScalar *data)
719: Not collective
721: Input parameters:
722: + obj - the object to which data is to be attached
723: . id - the identifier for the data
724: - data - the data to be attached
726: Notes
727: The data identifier can best be determined through a call to
728: PetscObjectComposedDataRegister()
730: Level: developer
731: M*/
732: #if defined(PETSC_USE_COMPLEX)
733: #define PetscObjectComposedDataSetScalarstar(obj,id,data) \
734: ((((obj)->scalarstar_idmax < PetscObjectComposedDataMax) && PetscObjectComposedDataIncreaseScalarstar(obj)) || \
735: ((obj)->scalarstarcomposeddata[id] = data,(obj)->scalarstarcomposedstate[id] = (obj)->state, 0))
736: #else
737: #define PetscObjectComposedDataSetScalarstar(obj,id,data) \
738: PetscObjectComposedDataSetRealstar(obj,id,data)
739: #endif
740: /*MC
741: PetscObjectComposedDataGetScalarstar - retrieve scalar array data
742: attached to an object
744: Synopsis:
745: #include "petsc/private/petscimpl.h"
746: PetscErrorCode PetscObjectComposedDataGetScalarstar(PetscObject obj,int id,PetscScalar *data,PetscBool flag)
748: Not collective
750: Input parameters:
751: + obj - the object from which data is to be retrieved
752: - id - the identifier for the data
754: Output parameters
755: + data - the data to be retrieved
756: - flag - PETSC_TRUE if the data item exists and is valid, PETSC_FALSE otherwise
758: The 'data' and 'flag' variables are inlined, so they are not pointers.
760: Level: developer
761: M*/
762: #if defined(PETSC_USE_COMPLEX)
763: #define PetscObjectComposedDataGetScalarstar(obj,id,data,flag) \
764: ((((obj)->scalarstarcomposedstate && ((obj)->scalarstarcomposedstate[id] == (obj)->state)) ? \
765: (data = (obj)->scalarstarcomposeddata[id],flag = PETSC_TRUE) : (flag = PETSC_FALSE)),0)
766: #else
767: #define PetscObjectComposedDataGetScalarstar(obj,id,data,flag) \
768: PetscObjectComposedDataGetRealstar(obj,id,data,flag)
769: #endif
771: PETSC_EXTERN PetscErrorCode PetscObjectGetId(PetscObject,PetscObjectId*);
773: PETSC_EXTERN PetscErrorCode PetscMonitorCompare(PetscErrorCode (*)(void),void *,PetscErrorCode (*)(void**),PetscErrorCode (*)(void),void *,PetscErrorCode (*)(void**),PetscBool *);
775: PETSC_EXTERN PetscMPIInt Petsc_Counter_keyval;
776: PETSC_EXTERN PetscMPIInt Petsc_InnerComm_keyval;
777: PETSC_EXTERN PetscMPIInt Petsc_OuterComm_keyval;
778: PETSC_EXTERN PetscMPIInt Petsc_Seq_keyval;
779: PETSC_EXTERN PetscMPIInt Petsc_Shared_keyval;
781: /*
782: PETSc communicators have this attribute, see
783: PetscCommDuplicate(), PetscCommDestroy(), PetscCommGetNewTag(), PetscObjectGetName()
784: */
785: typedef struct {
786: PetscMPIInt tag; /* next free tag value */
787: PetscInt refcount; /* number of references, communicator can be freed when this reaches 0 */
788: PetscInt namecount; /* used to generate the next name, as in Vec_0, Mat_1, ... */
789: } PetscCommCounter;
791: /*E
792: PetscOffloadFlag - indicates which memory (CPU, GPU, or none contains valid vector
794: PETSC_OFFLOAD_UNALLOCATED - no memory contains valid matrix entries; NEVER used for vectors
795: PETSC_OFFLOAD_GPU - GPU has valid vector/matrix entries
796: PETSC_OFFLOAD_CPU - CPU has valid vector/matrix entries
797: PETSC_OFFLOAD_BOTH - Both GPU and CPU have valid vector/matrix entries and they match
799: Level: developer
800: E*/
801: typedef enum {PETSC_OFFLOAD_UNALLOCATED,PETSC_OFFLOAD_GPU,PETSC_OFFLOAD_CPU,PETSC_OFFLOAD_BOTH} PetscOffloadFlag;
803: typedef enum {STATE_BEGIN, STATE_PENDING, STATE_END} SRState;
805: #define REDUCE_SUM 0
806: #define REDUCE_MAX 1
807: #define REDUCE_MIN 2
809: typedef struct {
810: MPI_Comm comm;
811: MPI_Request request;
812: PetscBool async;
813: PetscScalar *lvalues; /* this are the reduced values before call to MPI_Allreduce() */
814: PetscScalar *gvalues; /* values after call to MPI_Allreduce() */
815: void **invecs; /* for debugging only, vector/memory used with each op */
816: PetscInt *reducetype; /* is particular value to be summed or maxed? */
817: SRState state; /* are we calling xxxBegin() or xxxEnd()? */
818: PetscInt maxops; /* total amount of space we have for requests */
819: PetscInt numopsbegin; /* number of requests that have been queued in */
820: PetscInt numopsend; /* number of requests that have been gotten by user */
821: } PetscSplitReduction;
823: PETSC_EXTERN PetscErrorCode PetscSplitReductionGet(MPI_Comm,PetscSplitReduction**);
824: PETSC_EXTERN PetscErrorCode PetscSplitReductionEnd(PetscSplitReduction*);
825: PETSC_EXTERN PetscErrorCode PetscSplitReductionExtend(PetscSplitReduction*);
827: #if !defined(PETSC_SKIP_SPINLOCK)
828: #if defined(PETSC_HAVE_THREADSAFETY)
829: # if defined(PETSC_HAVE_CONCURRENCYKIT)
830: #if defined(__cplusplus)
831: /* CK does not have extern "C" protection in their include files */
832: extern "C" {
833: #endif
834: #include <ck_spinlock.h>
835: #if defined(__cplusplus)
836: }
837: #endif
838: typedef ck_spinlock_t PetscSpinlock;
839: PETSC_STATIC_INLINE PetscErrorCode PetscSpinlockCreate(PetscSpinlock *ck_spinlock)
840: {
841: ck_spinlock_init(ck_spinlock);
842: return 0;
843: }
844: PETSC_STATIC_INLINE PetscErrorCode PetscSpinlockLock(PetscSpinlock *ck_spinlock)
845: {
846: ck_spinlock_lock(ck_spinlock);
847: return 0;
848: }
849: PETSC_STATIC_INLINE PetscErrorCode PetscSpinlockUnlock(PetscSpinlock *ck_spinlock)
850: {
851: ck_spinlock_unlock(ck_spinlock);
852: return 0;
853: }
854: PETSC_STATIC_INLINE PetscErrorCode PetscSpinlockDestroy(PetscSpinlock *ck_spinlock)
855: {
856: return 0;
857: }
858: # elif defined(PETSC_HAVE_OPENMP)
860: #include <omp.h>
861: typedef omp_lock_t PetscSpinlock;
862: PETSC_STATIC_INLINE PetscErrorCode PetscSpinlockCreate(PetscSpinlock *omp_lock)
863: {
864: omp_init_lock(omp_lock);
865: return 0;
866: }
867: PETSC_STATIC_INLINE PetscErrorCode PetscSpinlockLock(PetscSpinlock *omp_lock)
868: {
869: omp_set_lock(omp_lock);
870: return 0;
871: }
872: PETSC_STATIC_INLINE PetscErrorCode PetscSpinlockUnlock(PetscSpinlock *omp_lock)
873: {
874: omp_unset_lock(omp_lock);
875: return 0;
876: }
877: PETSC_STATIC_INLINE PetscErrorCode PetscSpinlockDestroy(PetscSpinlock *omp_lock)
878: {
879: omp_destroy_lock(omp_lock);
880: return 0;
881: }
882: #else
883: Thread safety requires either --with-openmp or --download-concurrencykit
884: #endif
886: #else
887: typedef int PetscSpinlock;
888: #define PetscSpinlockCreate(a) 0
889: #define PetscSpinlockLock(a) 0
890: #define PetscSpinlockUnlock(a) 0
891: #define PetscSpinlockDestroy(a) 0
892: #endif
894: #if defined(PETSC_HAVE_THREADSAFETY)
895: extern PetscSpinlock PetscViewerASCIISpinLockOpen;
896: extern PetscSpinlock PetscViewerASCIISpinLockStdout;
897: extern PetscSpinlock PetscViewerASCIISpinLockStderr;
898: extern PetscSpinlock PetscCommSpinLock;
899: #endif
900: #endif
902: #endif /* _PETSCHEAD_H */