Actual source code: petscimpl.h

petsc-dev 2014-02-02
Report Typos and Errors
  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: /*
 11:    All major PETSc data structures have a common core; this is defined
 12:    below by PETSCHEADER.

 14:    PetscHeaderCreate() should be used whenever creating a PETSc structure.
 15: */

 17: /*
 18:    PetscOps: structure of core operations that all PETSc objects support.

 20:       getcomm()         - Gets the object's communicator.
 21:       view()            - Is the routine for viewing the entire PETSc object; for
 22:                           example, MatView() is the general matrix viewing routine.
 23:                           This is used by PetscObjectView((PetscObject)obj) to allow
 24:                           viewing any PETSc object.
 25:       destroy()         - Is the routine for destroying the entire PETSc object;
 26:                           for example,MatDestroy() is the general matrix
 27:                           destruction routine.
 28:                           This is used by PetscObjectDestroy((PetscObject*)&obj) to allow
 29:                           destroying any PETSc object.
 30:       compose()         - Associates a PETSc object with another PETSc object with a name
 31:       query()           - Returns a different PETSc object that has been associated
 32:                           with the first object using a name.
 33:       composefunction() - Attaches an a function to a PETSc object with a name.
 34:       queryfunction()   - Requests a registered function that has been attached to a PETSc object.
 35: */

 37: typedef struct {
 38:    PetscErrorCode (*getcomm)(PetscObject,MPI_Comm *);
 39:    PetscErrorCode (*view)(PetscObject,PetscViewer);
 40:    PetscErrorCode (*destroy)(PetscObject*);
 41:    PetscErrorCode (*compose)(PetscObject,const char[],PetscObject);
 42:    PetscErrorCode (*query)(PetscObject,const char[],PetscObject *);
 43:    PetscErrorCode (*composefunction)(PetscObject,const char[],void (*)(void));
 44:    PetscErrorCode (*queryfunction)(PetscObject,const char[],void (**)(void));
 45: } PetscOps;

 47: typedef enum {PETSC_FORTRAN_CALLBACK_CLASS,PETSC_FORTRAN_CALLBACK_SUBTYPE,PETSC_FORTRAN_CALLBACK_MAXTYPE} PetscFortranCallbackType;
 48: typedef int PetscFortranCallbackId;
 49: #define PETSC_SMALLEST_FORTRAN_CALLBACK ((PetscFortranCallbackId)1000)
 50: PETSC_EXTERN PetscErrorCode PetscFortranCallbackRegister(PetscClassId,const char*,PetscFortranCallbackId*);
 51: PETSC_EXTERN PetscErrorCode PetscFortranCallbackGetSizes(PetscClassId,PetscInt*,PetscInt*);

 53: typedef struct {
 54:   void (*func)(void);
 55:   void *ctx;
 56: } PetscFortranCallback;

 58: /*
 59:    All PETSc objects begin with the fields defined in PETSCHEADER.
 60:    The PetscObject is a way of examining these fields regardless of
 61:    the specific object. In C++ this could be a base abstract class
 62:    from which all objects are derived.
 63: */
 64: #define PETSC_MAX_OPTIONS_HANDLER 5
 65: typedef struct _p_PetscObject {
 66:   PetscClassId         classid;
 67:   PetscOps             *bops;
 68:   MPI_Comm             comm;
 69:   PetscInt             type;
 70:   PetscLogDouble       flops,time,mem,memchildren;
 71:   PetscObjectId        id;
 72:   PetscInt             refct;
 73:   PetscMPIInt          tag;
 74:   PetscFunctionList    qlist;
 75:   PetscObjectList      olist;
 76:   char                 *class_name;    /*  for example, "Vec" */
 77:   char                 *description;
 78:   char                 *mansec;
 79:   char                 *type_name;     /*  this is the subclass, for example VECSEQ which equals "seq" */
 80:   PetscObject          parent;
 81:   PetscObjectId        parentid;
 82:   char*                name;
 83:   char                 *prefix;
 84:   PetscInt             tablevel;
 85:   void                 *cpp;
 86:   PetscObjectState     state;
 87:   PetscInt             int_idmax,        intstar_idmax;
 88:   PetscObjectState     *intcomposedstate,*intstarcomposedstate;
 89:   PetscInt             *intcomposeddata, **intstarcomposeddata;
 90:   PetscInt             real_idmax,        realstar_idmax;
 91:   PetscObjectState     *realcomposedstate,*realstarcomposedstate;
 92:   PetscReal            *realcomposeddata, **realstarcomposeddata;
 93:   PetscInt             scalar_idmax,        scalarstar_idmax;
 94:   PetscObjectState     *scalarcomposedstate,*scalarstarcomposedstate;
 95:   PetscScalar          *scalarcomposeddata, **scalarstarcomposeddata;
 96:   void                 (**fortran_func_pointers)(void);                  /* used by Fortran interface functions to stash user provided Fortran functions */
 97:   PetscInt             num_fortran_func_pointers;                        /* number of Fortran function pointers allocated */
 98:   PetscFortranCallback *fortrancallback[PETSC_FORTRAN_CALLBACK_MAXTYPE];
 99:   PetscInt             num_fortrancallback[PETSC_FORTRAN_CALLBACK_MAXTYPE];
100:   void                 *python_context;
101:   PetscErrorCode       (*python_destroy)(void*);

103:   PetscInt             noptionhandler;
104:   PetscErrorCode       (*optionhandler[PETSC_MAX_OPTIONS_HANDLER])(PetscObject,void*);
105:   PetscErrorCode       (*optiondestroy[PETSC_MAX_OPTIONS_HANDLER])(PetscObject,void*);
106:   void                 *optionctx[PETSC_MAX_OPTIONS_HANDLER];
107:   PetscPrecision       precision;
108:   PetscBool            optionsprinted;
109: #if defined(PETSC_HAVE_SAWS)
110:   PetscBool            amsmem;          /* if PETSC_TRUE then this object is registered with SAWs and visible to clients */
111:   PetscBool            amspublishblock; /* if PETSC_TRUE and publishing objects then will block at PetscObjectSAWsBlock() */
112: #endif
113: } _p_PetscObject;

115: #define PETSCHEADER(ObjectOps) \
116:   _p_PetscObject hdr;          \
117:   ObjectOps      *ops

119: #define  PETSCFREEDHEADER -1

121: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode (*PetscObjectFunction)(PetscObject*); /* force cast in next macro to NEVER use extern "C" style */
122: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode (*PetscObjectViewerFunction)(PetscObject,PetscViewer);

124: /*@C
125:     PetscHeaderCreate - Creates a PETSc object of a particular class, indicated by tp

127:     Input Parameters:
128: +   tp - the data structure type of the object (for example _p_Vec)
129: .   pops - the data structure type of the objects operations (for example VecOps)
130: .   classid - the classid associated with this object (for example VEC_CLASSID)
131: .   class_name - string name of class; should be static (for example "Vec")
132: .   com - the MPI Communicator
133: .   des - the destroy routine for this object (for example VecDestroy())
134: -   vie - the view routine for this object (for example VecView())

136:     Output Parameter:
137: .   h - the newly created object

139:     Level: developer

141:    Developer Note: This currently is a CPP macro because it takes the types (for example _p_Vec and VecOps) as arguments

143: .seealso: PetscHeaderDestroy(), PetscClassIdRegister()

145: @*/
146: #define PetscHeaderCreate(h,tp,pops,classid,class_name,descr,mansec,com,des,vie) \
147:   (PetscNew(&(h)) ||                                                  \
148:    PetscNew(&(((PetscObject)(h))->bops)) ||                            \
149:    PetscNew(&((h)->ops)) ||                                                \
150:    PetscHeaderCreate_Private((PetscObject)h,classid,class_name,descr,mansec,com,(PetscObjectFunction)des,(PetscObjectViewerFunction)vie) || \
151:    PetscLogObjectCreate(h) ||                                                   \
152:    PetscLogObjectMemory((PetscObject)h, sizeof(struct tp) + sizeof(PetscOps) + sizeof(pops)))

154: PETSC_EXTERN PetscErrorCode PetscComposedQuantitiesDestroy(PetscObject obj);
155: PETSC_EXTERN PetscErrorCode PetscHeaderCreate_Private(PetscObject,PetscClassId,const char[],const char[],const char[],MPI_Comm,PetscErrorCode (*)(PetscObject*),PetscErrorCode (*)(PetscObject,PetscViewer));

157: /*@C
158:     PetscHeaderDestroy - Final step in destroying a PetscObject

160:     Input Parameters:
161: .   h - the header created with PetscHeaderCreate()

163:     Level: developer

165:    Developer Note: This currently is a CPP macro because it accesses (*h)->ops which is a field in the derived class but not the PetscObject base class

167: .seealso: PetscHeaderCreate()
168: @*/
169: #define PetscHeaderDestroy(h)                         \
170:   (PetscHeaderDestroy_Private((PetscObject)(*h)) ||   \
171:    PetscFree((*h)->ops) ||                            \
172:    PetscFree(*h))

174: PETSC_EXTERN PetscErrorCode PetscHeaderDestroy_Private(PetscObject);
175: PETSC_EXTERN PetscErrorCode PetscObjectCopyFortranFunctionPointers(PetscObject,PetscObject);
176: PETSC_EXTERN PetscErrorCode PetscObjectSetFortranCallback(PetscObject,PetscFortranCallbackType,PetscFortranCallbackId*,void(*)(void),void *ctx);
177: PETSC_EXTERN PetscErrorCode PetscObjectGetFortranCallback(PetscObject,PetscFortranCallbackType,PetscFortranCallbackId,void(**)(void),void **ctx);

179: PETSC_INTERN PetscErrorCode PetscCitationsInitialize(void);
180: PETSC_INTERN PetscErrorCode PetscOptionsFindPair_Private(const char[],const char[],char**,PetscBool*);


184: /*
185:     Macros to test if a PETSc object is valid and if pointers are valid
186: */
187: #if !defined(PETSC_USE_DEBUG)


197: #else

200:   do {                                                                  \
201:     if (!h) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Null Object: Parameter # %d",arg); \
203:     if (((PetscObject)(h))->classid != ck) {                            \
204:       if (((PetscObject)(h))->classid == PETSCFREEDHEADER) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_CORRUPT,"Object already free: Parameter # %d",arg); \
205:       else SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Wrong type of object: Parameter # %d",arg); \
206:     }                                                                   \
207:   } while (0)

210:   do {                                                                  \
211:     if (!h) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Null Object: Parameter # %d",arg); \
213:     if (((PetscObject)(h))->classid == PETSCFREEDHEADER) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_CORRUPT,"Object already free: Parameter # %d",arg); \
214:     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); \
215:   } while (0)

218:   do {                                                                  \
219:     if (!h) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Null Pointer: Parameter # %d",arg); \
221:   } while (0)

224:   do {                                                                  \
225:     if (!h) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Null Pointer: Parameter # %d",arg);\
227:   } while (0)

230:   do {                                                                  \
231:     if (!h) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_BADPTR,"Null Pointer: Parameter # %d",arg); \
233:   } while (0)

236:   do {                                                                  \
237:     if (!h) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Null Pointer: Parameter # %d",arg); \
239:   } while (0)

242:   do {                                                                  \
243:     if (!h) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Null Pointer: Parameter # %d",arg); \
245:   } while (0)

247: #endif

249: #if !defined(PETSC_USE_DEBUG)


261: #else

263: /*
264:     For example, in the dot product between two vectors,
265:   both vectors must be either Seq or MPI, not one of each
266: */
268:   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);
269: /*
270:    Use this macro to check if the type is set
271: */
273:   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);
274: /*
275:    Sometimes object must live on same communicator to inter-operate
276: */
278:   do {                                                                  \
279:     PetscErrorCode _6_ierr,__flag;                                      \
280:     _6_MPI_Comm_compare(PetscObjectComm((PetscObject)a),PetscObjectComm((PetscObject)b),&__flag);CHKERRQ(_6_ierr);                                                   \
281:     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); \
282:   } while (0)

285:   do {                                                  \
288:   } while (0)

291:   do {                                                                  \
292:     PetscErrorCode _7_ierr;                                             \
293:     PetscReal b1[2],b2[2];                                              \
294:     b1[0] = -PetscRealPart(b); b1[1] = PetscRealPart(b);                \
295:     _7_MPI_Allreduce(b1,b2,2,MPIU_REAL,MPIU_MAX,PetscObjectComm((PetscObject)a));CHKERRQ(_7_ierr); \
296:     if (-b2[0] != b2[1]) SETERRQ1(PetscObjectComm((PetscObject)a),PETSC_ERR_ARG_WRONG,"Scalar value must be same on all processes, argument # %d",c); \
297:   } while (0)

300:   do {                                                                  \
301:     PetscErrorCode _7_ierr;                                             \
302:     PetscReal b1[2],b2[2];                                              \
303:     b1[0] = -b; b1[1] = b;                                              \
304:     _7_MPI_Allreduce(b1,b2,2,MPIU_REAL,MPIU_MAX,PetscObjectComm((PetscObject)a));CHKERRQ(_7_ierr); \
305:     if (-b2[0] != b2[1]) SETERRQ1(PetscObjectComm((PetscObject)a),PETSC_ERR_ARG_WRONG,"Real value must be same on all processes, argument # %d",c); \
306:   } while (0)

309:   do {                                                                  \
310:     PetscErrorCode _7_ierr;                                             \
311:     PetscInt b1[2],b2[2];                                               \
312:     b1[0] = -b; b1[1] = b;                                              \
313:     _7_MPI_Allreduce(b1,b2,2,MPIU_INT,MPI_MAX,PetscObjectComm((PetscObject)a));CHKERRQ(_7_ierr); \
314:     if (-b2[0] != b2[1]) SETERRQ1(PetscObjectComm((PetscObject)a),PETSC_ERR_ARG_WRONG,"Int value must be same on all processes, argument # %d",c); \
315:   } while (0)

318:   do {                                                                  \
319:     PetscErrorCode _7_ierr;                                             \
320:     PetscMPIInt b1[2],b2[2];                                            \
321:     b1[0] = -(PetscMPIInt)b; b1[1] = (PetscMPIInt)b;                    \
322:     _7_MPI_Allreduce(b1,b2,2,MPI_INT,MPI_MAX,PetscObjectComm((PetscObject)a));CHKERRQ(_7_ierr); \
323:     if (-b2[0] != b2[1]) SETERRQ1(PetscObjectComm((PetscObject)a),PETSC_ERR_ARG_WRONG,"Bool value must be same on all processes, argument # %d",c); \
324:   } while (0)

327:   do {                                                                  \
328:     PetscErrorCode _7_ierr;                                             \
329:     PetscMPIInt b1[2],b2[2];                                            \
330:     b1[0] = -(PetscMPIInt)b; b1[1] = (PetscMPIInt)b;                    \
331:     _7_MPI_Allreduce(b1,b2,2,MPI_INT,MPI_MAX,PetscObjectComm((PetscObject)a));CHKERRQ(_7_ierr); \
332:     if (-b2[0] != b2[1]) SETERRQ1(PetscObjectComm((PetscObject)a),PETSC_ERR_ARG_WRONG,"Enum value must be same on all processes, argument # %d",c); \
333:   } while (0)

335: #endif

337: /*
338:    PetscTryMethod - Queries an object for a method, if it exists then calls it.
339:               These are intended to be used only inside PETSc functions.

341:    Level: developer

343: .seealso: PetscUseMethod()
344: */
345: #define  PetscTryMethod(obj,A,B,C) \
346:   0;{ PetscErrorCode (*f)B, __ierr; \
347:     __PetscObjectQueryFunction((PetscObject)obj,A,&f);CHKERRQ(__ierr); \
348:     if (f) {__(*f)C;CHKERRQ(__ierr);}\
349:   }

351: /*
352:    PetscUseMethod - Queries an object for a method, if it exists then calls it, otherwise generates an error.
353:               These are intended to be used only inside PETSc functions.

355:    Level: developer

357: .seealso: PetscTryMethod()
358: */
359: #define  PetscUseMethod(obj,A,B,C) \
360:   0;{ PetscErrorCode (*f)B, __ierr; \
361:     __PetscObjectQueryFunction((PetscObject)obj,A,&f);CHKERRQ(__ierr); \
362:     if (f) {__(*f)C;CHKERRQ(__ierr);}\
363:     else SETERRQ1(PetscObjectComm((PetscObject)obj),PETSC_ERR_SUP,"Cannot locate function %s in object",A); \
364:   }

366: /*MC
367:    PetscObjectStateIncrease - Increases the state of any PetscObject,
368:    regardless of the type.

370:    Synopsis:
371:    #include "petsc-private/petscimpl.h"
372:    PetscErrorCode PetscObjectStateIncrease(PetscObject obj)

374:    Logically Collective

376:    Input Parameter:
377: .  obj - any PETSc object, for example a Vec, Mat or KSP. This must be
378:          cast with a (PetscObject), for example,
379:          PetscObjectStateIncrease((PetscObject)mat);

381:    Notes: object state is an integer which gets increased every time
382:    the object is changed. By saving and later querying the object state
383:    one can determine whether information about the object is still current.
384:    Currently, state is maintained for Vec and Mat objects.

386:    This routine is mostly for internal use by PETSc; a developer need only
387:    call it after explicit access to an object's internals. Routines such
388:    as VecSet() or MatScale() already call this routine. It is also called, as a
389:    precaution, in VecRestoreArray(), MatRestoreRow(), MatDenseRestoreArray().

391:    This routine is logically collective because state equality comparison needs to be possible without communication.

393:    Level: developer

395:    seealso: PetscObjectStateGet()

397:    Concepts: state

399: M*/
400: #define PetscObjectStateIncrease(obj) ((obj)->state++,0)

402: PETSC_EXTERN PetscErrorCode PetscObjectStateGet(PetscObject,PetscObjectState*);
403: PETSC_EXTERN PetscErrorCode PetscObjectStateSet(PetscObject,PetscObjectState);
404: PETSC_EXTERN PetscErrorCode PetscObjectComposedDataRegister(PetscInt*);
405: PETSC_EXTERN PetscErrorCode PetscObjectComposedDataIncreaseInt(PetscObject);
406: PETSC_EXTERN PetscErrorCode PetscObjectComposedDataIncreaseIntstar(PetscObject);
407: PETSC_EXTERN PetscErrorCode PetscObjectComposedDataIncreaseReal(PetscObject);
408: PETSC_EXTERN PetscErrorCode PetscObjectComposedDataIncreaseRealstar(PetscObject);
409: PETSC_EXTERN PetscErrorCode PetscObjectComposedDataIncreaseScalar(PetscObject);
410: PETSC_EXTERN PetscErrorCode PetscObjectComposedDataIncreaseScalarstar(PetscObject);
411: PETSC_EXTERN PetscInt         PetscObjectComposedDataMax;
412: /*MC
413:    PetscObjectComposedDataSetInt - attach integer data to a PetscObject

415:    Synopsis:
416:    #include "petsc-private/petscimpl.h"
417:    PetscErrorCode PetscObjectComposedDataSetInt(PetscObject obj,int id,int data)

419:    Not collective

421:    Input parameters:
422: +  obj - the object to which data is to be attached
423: .  id - the identifier for the data
424: -  data - the data to  be attached

426:    Notes
427:    The data identifier can best be determined through a call to
428:    PetscObjectComposedDataRegister()

430:    Level: developer
431: M*/
432: #define PetscObjectComposedDataSetInt(obj,id,data)                                      \
433:   ((((obj)->int_idmax < PetscObjectComposedDataMax) && PetscObjectComposedDataIncreaseInt(obj)) ||  \
434:    ((obj)->intcomposeddata[id] = data,(obj)->intcomposedstate[id] = (obj)->state, 0))

436: /*MC
437:    PetscObjectComposedDataGetInt - retrieve integer data attached to an object

439:    Synopsis:
440:    #include "petsc-private/petscimpl.h"
441:    PetscErrorCode PetscObjectComposedDataGetInt(PetscObject obj,int id,int data,PetscBool  flag)

443:    Not collective

445:    Input parameters:
446: +  obj - the object from which data is to be retrieved
447: -  id - the identifier for the data

449:    Output parameters
450: +  data - the data to be retrieved
451: -  flag - PETSC_TRUE if the data item exists and is valid, PETSC_FALSE otherwise

453:    The 'data' and 'flag' variables are inlined, so they are not pointers.

455:    Level: developer
456: M*/
457: #define PetscObjectComposedDataGetInt(obj,id,data,flag)                            \
458:   ((((obj)->intcomposedstate && ((obj)->intcomposedstate[id] == (obj)->state)) ?   \
459:    (data = (obj)->intcomposeddata[id],flag = PETSC_TRUE) : (flag = PETSC_FALSE)),0)

461: /*MC
462:    PetscObjectComposedDataSetIntstar - attach integer array data to a PetscObject

464:    Synopsis:
465:    #include "petsc-private/petscimpl.h"
466:    PetscErrorCode PetscObjectComposedDataSetIntstar(PetscObject obj,int id,int *data)

468:    Not collective

470:    Input parameters:
471: +  obj - the object to which data is to be attached
472: .  id - the identifier for the data
473: -  data - the data to  be attached

475:    Notes
476:    The data identifier can best be determined through a call to
477:    PetscObjectComposedDataRegister()

479:    Level: developer
480: M*/
481: #define PetscObjectComposedDataSetIntstar(obj,id,data)                                          \
482:   ((((obj)->intstar_idmax < PetscObjectComposedDataMax) && PetscObjectComposedDataIncreaseIntstar(obj)) ||  \
483:    ((obj)->intstarcomposeddata[id] = data,(obj)->intstarcomposedstate[id] = (obj)->state, 0))

485: /*MC
486:    PetscObjectComposedDataGetIntstar - retrieve integer array data
487:    attached to an object

489:    Synopsis:
490:    #include "petsc-private/petscimpl.h"
491:    PetscErrorCode PetscObjectComposedDataGetIntstar(PetscObject obj,int id,int *data,PetscBool  flag)

493:    Not collective

495:    Input parameters:
496: +  obj - the object from which data is to be retrieved
497: -  id - the identifier for the data

499:    Output parameters
500: +  data - the data to be retrieved
501: -  flag - PETSC_TRUE if the data item exists and is valid, PETSC_FALSE otherwise

503:    The 'data' and 'flag' variables are inlined, so they are not pointers.

505:    Level: developer
506: M*/
507: #define PetscObjectComposedDataGetIntstar(obj,id,data,flag)                               \
508:   ((((obj)->intstarcomposedstate && ((obj)->intstarcomposedstate[id] == (obj)->state)) ?  \
509:    (data = (obj)->intstarcomposeddata[id],flag = PETSC_TRUE) : (flag = PETSC_FALSE)),0)

511: /*MC
512:    PetscObjectComposedDataSetReal - attach real data to a PetscObject

514:    Synopsis:
515:    #include "petsc-private/petscimpl.h"
516:    PetscErrorCode PetscObjectComposedDataSetReal(PetscObject obj,int id,PetscReal data)

518:    Not collective

520:    Input parameters:
521: +  obj - the object to which data is to be attached
522: .  id - the identifier for the data
523: -  data - the data to  be attached

525:    Notes
526:    The data identifier can best be determined through a call to
527:    PetscObjectComposedDataRegister()

529:    Level: developer
530: M*/
531: #define PetscObjectComposedDataSetReal(obj,id,data)                                       \
532:   ((((obj)->real_idmax < PetscObjectComposedDataMax) && PetscObjectComposedDataIncreaseReal(obj)) ||  \
533:    ((obj)->realcomposeddata[id] = data,(obj)->realcomposedstate[id] = (obj)->state, 0))

535: /*MC
536:    PetscObjectComposedDataGetReal - retrieve real data attached to an object

538:    Synopsis:
539:    #include "petsc-private/petscimpl.h"
540:    PetscErrorCode PetscObjectComposedDataGetReal(PetscObject obj,int id,PetscReal data,PetscBool  flag)

542:    Not collective

544:    Input parameters:
545: +  obj - the object from which data is to be retrieved
546: -  id - the identifier for the data

548:    Output parameters
549: +  data - the data to be retrieved
550: -  flag - PETSC_TRUE if the data item exists and is valid, PETSC_FALSE otherwise

552:    The 'data' and 'flag' variables are inlined, so they are not pointers.

554:    Level: developer
555: M*/
556: #define PetscObjectComposedDataGetReal(obj,id,data,flag)                            \
557:   ((((obj)->realcomposedstate && ((obj)->realcomposedstate[id] == (obj)->state)) ?  \
558:    (data = (obj)->realcomposeddata[id],flag = PETSC_TRUE) : (flag = PETSC_FALSE)),0)

560: /*MC
561:    PetscObjectComposedDataSetRealstar - attach real array data to a PetscObject

563:    Synopsis:
564:    #include "petsc-private/petscimpl.h"
565:    PetscErrorCode PetscObjectComposedDataSetRealstar(PetscObject obj,int id,PetscReal *data)

567:    Not collective

569:    Input parameters:
570: +  obj - the object to which data is to be attached
571: .  id - the identifier for the data
572: -  data - the data to  be attached

574:    Notes
575:    The data identifier can best be determined through a call to
576:    PetscObjectComposedDataRegister()

578:    Level: developer
579: M*/
580: #define PetscObjectComposedDataSetRealstar(obj,id,data)                                           \
581:   ((((obj)->realstar_idmax < PetscObjectComposedDataMax) && PetscObjectComposedDataIncreaseRealstar(obj)) ||  \
582:    ((obj)->realstarcomposeddata[id] = data, (obj)->realstarcomposedstate[id] = (obj)->state, 0))

584: /*MC
585:    PetscObjectComposedDataGetRealstar - retrieve real array data
586:    attached to an object

588:    Synopsis:
589:    #include "petsc-private/petscimpl.h"
590:    PetscErrorCode PetscObjectComposedDataGetRealstar(PetscObject obj,int id,PetscReal *data,PetscBool  flag)

592:    Not collective

594:    Input parameters:
595: +  obj - the object from which data is to be retrieved
596: -  id - the identifier for the data

598:    Output parameters
599: +  data - the data to be retrieved
600: -  flag - PETSC_TRUE if the data item exists and is valid, PETSC_FALSE otherwise

602:    The 'data' and 'flag' variables are inlined, so they are not pointers.

604:    Level: developer
605: M*/
606: #define PetscObjectComposedDataGetRealstar(obj,id,data,flag)                                \
607:   ((((obj)->realstarcomposedstate && ((obj)->realstarcomposedstate[id] == (obj)->state)) ?  \
608:    (data = (obj)->realstarcomposeddata[id],flag = PETSC_TRUE) : (flag = PETSC_FALSE)),0)

610: /*MC
611:    PetscObjectComposedDataSetScalar - attach scalar data to a PetscObject

613:    Synopsis:
614:    #include "petsc-private/petscimpl.h"
615:    PetscErrorCode PetscObjectComposedDataSetScalar(PetscObject obj,int id,PetscScalar data)

617:    Not collective

619:    Input parameters:
620: +  obj - the object to which data is to be attached
621: .  id - the identifier for the data
622: -  data - the data to  be attached

624:    Notes
625:    The data identifier can best be determined through a call to
626:    PetscObjectComposedDataRegister()

628:    Level: developer
629: M*/
630: #if defined(PETSC_USE_COMPLEX)
631: #define PetscObjectComposedDataSetScalar(obj,id,data)                                        \
632:   ((((obj)->scalar_idmax < PetscObjectComposedDataMax) && PetscObjectComposedDataIncreaseScalar(obj)) || \
633:    ((obj)->scalarcomposeddata[id] = data,(obj)->scalarcomposedstate[id] = (obj)->state, 0))
634: #else
635: #define PetscObjectComposedDataSetScalar(obj,id,data) \
636:         PetscObjectComposedDataSetReal(obj,id,data)
637: #endif
638: /*MC
639:    PetscObjectComposedDataGetScalar - retrieve scalar data attached to an object

641:    Synopsis:
642:    #include "petsc-private/petscimpl.h"
643:    PetscErrorCode PetscObjectComposedDataGetScalar(PetscObject obj,int id,PetscScalar data,PetscBool  flag)

645:    Not collective

647:    Input parameters:
648: +  obj - the object from which data is to be retrieved
649: -  id - the identifier for the data

651:    Output parameters
652: +  data - the data to be retrieved
653: -  flag - PETSC_TRUE if the data item exists and is valid, PETSC_FALSE otherwise

655:    The 'data' and 'flag' variables are inlined, so they are not pointers.

657:    Level: developer
658: M*/
659: #if defined(PETSC_USE_COMPLEX)
660: #define PetscObjectComposedDataGetScalar(obj,id,data,flag)                              \
661:   ((((obj)->scalarcomposedstate && ((obj)->scalarcomposedstate[id] == (obj)->state) ) ? \
662:    (data = (obj)->scalarcomposeddata[id],flag = PETSC_TRUE) : (flag = PETSC_FALSE)),0)
663: #else
664: #define PetscObjectComposedDataGetScalar(obj,id,data,flag)                             \
665:         PetscObjectComposedDataGetReal(obj,id,data,flag)
666: #endif

668: /*MC
669:    PetscObjectComposedDataSetScalarstar - attach scalar array data to a PetscObject

671:    Synopsis:
672:    #include "petsc-private/petscimpl.h"
673:    PetscErrorCode PetscObjectComposedDataSetScalarstar(PetscObject obj,int id,PetscScalar *data)

675:    Not collective

677:    Input parameters:
678: +  obj - the object to which data is to be attached
679: .  id - the identifier for the data
680: -  data - the data to  be attached

682:    Notes
683:    The data identifier can best be determined through a call to
684:    PetscObjectComposedDataRegister()

686:    Level: developer
687: M*/
688: #if defined(PETSC_USE_COMPLEX)
689: #define PetscObjectComposedDataSetScalarstar(obj,id,data)                                             \
690:   ((((obj)->scalarstar_idmax < PetscObjectComposedDataMax) && PetscObjectComposedDataIncreaseScalarstar(obj)) ||  \
691:    ((obj)->scalarstarcomposeddata[id] = data,(obj)->scalarstarcomposedstate[id] = (obj)->state, 0))
692: #else
693: #define PetscObjectComposedDataSetScalarstar(obj,id,data) \
694:         PetscObjectComposedDataSetRealstar(obj,id,data)
695: #endif
696: /*MC
697:    PetscObjectComposedDataGetScalarstar - retrieve scalar array data
698:    attached to an object

700:    Synopsis:
701:    #include "petsc-private/petscimpl.h"
702:    PetscErrorCode PetscObjectComposedDataGetScalarstar(PetscObject obj,int id,PetscScalar *data,PetscBool  flag)

704:    Not collective

706:    Input parameters:
707: +  obj - the object from which data is to be retrieved
708: -  id - the identifier for the data

710:    Output parameters
711: +  data - the data to be retrieved
712: -  flag - PETSC_TRUE if the data item exists and is valid, PETSC_FALSE otherwise

714:    The 'data' and 'flag' variables are inlined, so they are not pointers.

716:    Level: developer
717: M*/
718: #if defined(PETSC_USE_COMPLEX)
719: #define PetscObjectComposedDataGetScalarstar(obj,id,data,flag)                                 \
720:   ((((obj)->scalarstarcomposedstate && ((obj)->scalarstarcomposedstate[id] == (obj)->state)) ? \
721:        (data = (obj)->scalarstarcomposeddata[id],flag = PETSC_TRUE) : (flag = PETSC_FALSE)),0)
722: #else
723: #define PetscObjectComposedDataGetScalarstar(obj,id,data,flag)         \
724:         PetscObjectComposedDataGetRealstar(obj,id,data,flag)
725: #endif

727: PETSC_EXTERN PetscErrorCode PetscObjectGetId(PetscObject,PetscObjectId*);

729: PETSC_EXTERN PetscMPIInt Petsc_Counter_keyval;
730: PETSC_EXTERN PetscMPIInt Petsc_InnerComm_keyval;
731: PETSC_EXTERN PetscMPIInt Petsc_OuterComm_keyval;

733: /*
734:   PETSc communicators have this attribute, see
735:   PetscCommDuplicate(), PetscCommDestroy(), PetscCommGetNewTag(), PetscObjectGetName()
736: */
737: typedef struct {
738:   PetscMPIInt tag;              /* next free tag value */
739:   PetscInt    refcount;         /* number of references, communicator can be freed when this reaches 0 */
740:   PetscInt    namecount;        /* used to generate the next name, as in Vec_0, Mat_1, ... */
741: } PetscCommCounter;

743: #if defined(PETSC_HAVE_CUSP)
744: /*E
745:     PetscCUSPFlag - indicates which memory (CPU, GPU, or none contains valid vector

747:    PETSC_CUSP_UNALLOCATED  - no memory contains valid matrix entries; NEVER used for vectors
748:    PETSC_CUSP_GPU - GPU has valid vector/matrix entries
749:    PETSC_CUSP_CPU - CPU has valid vector/matrix entries
750:    PETSC_CUSP_BOTH - Both GPU and CPU have valid vector/matrix entries and they match

752:    Level: developer
753: E*/
754: typedef enum {PETSC_CUSP_UNALLOCATED,PETSC_CUSP_GPU,PETSC_CUSP_CPU,PETSC_CUSP_BOTH} PetscCUSPFlag;
755: #endif

757: #if defined(PETSC_HAVE_VIENNACL)
758: /*E
759:     PetscViennaCLFlag - indicates which memory (CPU, GPU, or none contains valid vector

761:    PETSC_VIENNACL_UNALLOCATED  - no memory contains valid matrix entries; NEVER used for vectors
762:    PETSC_VIENNACL_GPU - GPU has valid vector/matrix entries
763:    PETSC_VIENNACL_CPU - CPU has valid vector/matrix entries
764:    PETSC_VIENNACL_BOTH - Both GPU and CPU have valid vector/matrix entries and they match

766:    Level: developer
767: E*/
768: typedef enum {PETSC_VIENNACL_UNALLOCATED,PETSC_VIENNACL_GPU,PETSC_VIENNACL_CPU,PETSC_VIENNACL_BOTH} PetscViennaCLFlag;
769: #endif

771: #endif /* _PETSCHEAD_H */