Actual source code: petscimpl.h

petsc-master 2019-06-15
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: /* These are used internally by PETSc ASCII IO routines*/
 11: #include <stdarg.h>
 12: PETSC_EXTERN PetscErrorCode PetscVFPrintfDefault(FILE*,const char[],va_list);

 14: #if defined(PETSC_HAVE_CLOSURES)
 15: PETSC_EXTERN PetscErrorCode PetscVFPrintfSetClosure(int (^)(const char*));
 16: #endif


 19: #if defined(PETSC_HAVE_CUDA)
 20: #include <cuda.h>
 21: #include <cublas_v2.h>
 22: #endif

 24: /*
 25:    All major PETSc data structures have a common core; this is defined
 26:    below by PETSCHEADER.

 28:    PetscHeaderCreate() should be used whenever creating a PETSc structure.
 29: */

 31: /*
 32:    PetscOps: structure of core operations that all PETSc objects support.

 34:       getcomm()         - Gets the object's communicator.
 35:       view()            - Is the routine for viewing the entire PETSc object; for
 36:                           example, MatView() is the general matrix viewing routine.
 37:                           This is used by PetscObjectView((PetscObject)obj) to allow
 38:                           viewing any PETSc object.
 39:       destroy()         - Is the routine for destroying the entire PETSc object;
 40:                           for example,MatDestroy() is the general matrix
 41:                           destruction routine.
 42:                           This is used by PetscObjectDestroy((PetscObject*)&obj) to allow
 43:                           destroying any PETSc object.
 44:       compose()         - Associates a PETSc object with another PETSc object with a name
 45:       query()           - Returns a different PETSc object that has been associated
 46:                           with the first object using a name.
 47:       composefunction() - Attaches an a function to a PETSc object with a name.
 48:       queryfunction()   - Requests a registered function that has been attached to a PETSc object.
 49: */

 51: typedef struct {
 52:    PetscErrorCode (*getcomm)(PetscObject,MPI_Comm *);
 53:    PetscErrorCode (*view)(PetscObject,PetscViewer);
 54:    PetscErrorCode (*destroy)(PetscObject*);
 55:    PetscErrorCode (*compose)(PetscObject,const char[],PetscObject);
 56:    PetscErrorCode (*query)(PetscObject,const char[],PetscObject *);
 57:    PetscErrorCode (*composefunction)(PetscObject,const char[],void (*)(void));
 58:    PetscErrorCode (*queryfunction)(PetscObject,const char[],void (**)(void));
 59: } PetscOps;

 61: typedef enum {PETSC_FORTRAN_CALLBACK_CLASS,PETSC_FORTRAN_CALLBACK_SUBTYPE,PETSC_FORTRAN_CALLBACK_MAXTYPE} PetscFortranCallbackType;
 62: typedef int PetscFortranCallbackId;
 63: #define PETSC_SMALLEST_FORTRAN_CALLBACK ((PetscFortranCallbackId)1000)
 64: PETSC_EXTERN PetscErrorCode PetscFortranCallbackRegister(PetscClassId,const char*,PetscFortranCallbackId*);
 65: PETSC_EXTERN PetscErrorCode PetscFortranCallbackGetSizes(PetscClassId,PetscInt*,PetscInt*);

 67: typedef struct {
 68:   void (*func)(void);
 69:   void *ctx;
 70: } PetscFortranCallback;

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

117:   PetscInt             noptionhandler;
118:   PetscErrorCode       (*optionhandler[PETSC_MAX_OPTIONS_HANDLER])(PetscOptionItems*,PetscObject,void*);
119:   PetscErrorCode       (*optiondestroy[PETSC_MAX_OPTIONS_HANDLER])(PetscObject,void*);
120:   void                 *optionctx[PETSC_MAX_OPTIONS_HANDLER];
121:   PetscBool            optionsprinted;
122: #if defined(PETSC_HAVE_SAWS)
123:   PetscBool            amsmem;          /* if PETSC_TRUE then this object is registered with SAWs and visible to clients */
124:   PetscBool            amspublishblock; /* if PETSC_TRUE and publishing objects then will block at PetscObjectSAWsBlock() */
125: #endif
126:   PetscOptions         options;         /* options database used, NULL means default */
127:   PetscBool            donotPetscObjectPrintClassNamePrefixType;
128: } _p_PetscObject;

130: #define PETSCHEADER(ObjectOps) \
131:   _p_PetscObject hdr;          \
132:   ObjectOps      ops[1]

134: #define  PETSCFREEDHEADER -1

136: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode (*PetscObjectDestroyFunction)(PetscObject*); /* force cast in next macro to NEVER use extern "C" style */
137: PETSC_EXTERN_TYPEDEF typedef PetscErrorCode (*PetscObjectViewFunction)(PetscObject,PetscViewer);

139: /*@C
140:     PetscHeaderCreate - Creates a PETSc object of a particular class

142:     Input Parameters:
143: +   classid - the classid associated with this object (for example VEC_CLASSID)
144: .   class_name - string name of class; should be static (for example "Vec")
145: .   descr - string containing short description; should be static (for example "Vector")
146: .   mansec - string indicating section in manual pages; should be static (for example "Vec")
147: .   comm - the MPI Communicator
148: .   destroy - the destroy routine for this object (for example VecDestroy())
149: -   view - the view routine for this object (for example VecView())

151:     Output Parameter:
152: .   h - the newly created object

154:     Level: developer

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

158: @*/
159: #define PetscHeaderCreate(h,classid,class_name,descr,mansec,comm,destroy,view) \
160:   (PetscNew(&(h)) || \
161:    PetscHeaderCreate_Private((PetscObject)h,classid,class_name,descr,mansec,comm,(PetscObjectDestroyFunction)destroy,(PetscObjectViewFunction)view) || \
162:    PetscLogObjectCreate(h) || \
163:    PetscLogObjectMemory((PetscObject)h,sizeof(*(h))))

165: PETSC_EXTERN PetscErrorCode PetscComposedQuantitiesDestroy(PetscObject obj);
166: PETSC_EXTERN PetscErrorCode PetscHeaderCreate_Private(PetscObject,PetscClassId,const char[],const char[],const char[],MPI_Comm,PetscObjectDestroyFunction,PetscObjectViewFunction);

168: /*@C
169:     PetscHeaderDestroy - Final step in destroying a PetscObject

171:     Input Parameters:
172: .   h - the header created with PetscHeaderCreate()

174:     Level: developer

176: .seealso: PetscHeaderCreate()
177: @*/
178: #define PetscHeaderDestroy(h) (PetscHeaderDestroy_Private((PetscObject)(*h)) || PetscFree(*h))

180: PETSC_EXTERN PetscErrorCode PetscHeaderDestroy_Private(PetscObject);
181: PETSC_EXTERN PetscErrorCode PetscObjectCopyFortranFunctionPointers(PetscObject,PetscObject);
182: PETSC_EXTERN PetscErrorCode PetscObjectSetFortranCallback(PetscObject,PetscFortranCallbackType,PetscFortranCallbackId*,void(*)(void),void *ctx);
183: PETSC_EXTERN PetscErrorCode PetscObjectGetFortranCallback(PetscObject,PetscFortranCallbackType,PetscFortranCallbackId,void(**)(void),void **ctx);

185: PETSC_INTERN PetscErrorCode PetscCitationsInitialize(void);
186: PETSC_INTERN PetscErrorCode PetscFreeMPIResources(void);




192: /*
193:     Macros to test if a PETSc object is valid and if pointers are valid
194: */
195: #if !defined(PETSC_USE_DEBUG)


207: #else

209: /*  This check is for subtype methods such as DMDAGetCorners() that do not use the PetscTryMethod() or PetscUseMethod() paradigm */
211:   do {   \
212:     PetscErrorCode __ierr; \
213:     PetscBool      same; \
215:     __PetscObjectTypeCompare((PetscObject)h,t,&same);CHKERRQ(__ierr);      \
216:     if (!same) SETERRQ3(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Wrong subtype object:Parameter # %d must have implementation %s it is %s",arg,t,((PetscObject)h)->type_name); \
217:   } while (0)

220:   do {                                                                  \
221:     if (!h) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Null Object: Parameter # %d",arg); \
223:     if (((PetscObject)(h))->classid != ck) {                            \
224:       if (((PetscObject)(h))->classid == PETSCFREEDHEADER) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_CORRUPT,"Object already free: Parameter # %d",arg); \
225:       else SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Wrong type of object: Parameter # %d",arg); \
226:     }                                                                   \
227:   } while (0)

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

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

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

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

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

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

268:   do {                                                                  \
269:     if (!f) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_ARG_NULL,"Null Function Pointer: Parameter # %d",arg); \
270:   } while (0)

272: #endif

274: #if !defined(PETSC_USE_DEBUG)


289: #else

291: /*
292:     For example, in the dot product between two vectors,
293:   both vectors must be either Seq or MPI, not one of each
294: */
296:   do {                                                                  \
297:     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); \
298:   } while (0)
299: /*
300:     Check type_name
301: */
303:   do {                                                                  \
304:     PetscBool      __match;                                             \
305:     PetscErrorCode _7_ierr;                                             \
306:     _7_PetscObjectTypeCompare(((PetscObject)a),(type),&__match);CHKERRQ(_7_ierr); \
307:     if (!__match) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Object (%s) is not %s",(char*)(((PetscObject)a)->type_name),type); \
308:   } while (0)

311:   do {                                                                  \
312:     PetscBool       __match;                                            \
313:     PetscErrorCode _7_ierr;                                             \
314:     _7_PetscObjectTypeCompareAny(((PetscObject)a),&__match,(type1),(type2),"");CHKERRQ(_7_ierr); \
315:     if (!__match) SETERRQ3(PETSC_COMM_SELF,PETSC_ERR_ARG_WRONG,"Object (%s) is not %s or %s",(char*)(((PetscObject)a)->type_name),type1,type2); \
316:   } while (0)
317: /*
318:    Use this macro to check if the type is set
319: */
321:   do {                                                                  \
322:     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); \
323:   } while (0)
324: /*
325:    Sometimes object must live on same communicator to inter-operate
326: */
328:   do {                                                                  \
329:     PetscErrorCode _6_ierr,__flag;                                      \
330:     _6_MPI_Comm_compare(PetscObjectComm((PetscObject)a),PetscObjectComm((PetscObject)b),&__flag);CHKERRQ(_6_ierr);                                                   \
331:     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); \
332:   } while (0)

335:   do {                                                  \
338:   } while (0)

341:   do {                                                                  \
342:     PetscErrorCode _7_ierr;                                             \
343:     PetscReal b1[5],b2[5];                                              \
344:     if (PetscIsNanScalar(b)) {b1[4] = 1;} else {b1[4] = 0;};            \
345:     b1[0] = -PetscRealPart(b); b1[1] = PetscRealPart(b);b1[2] = -PetscImaginaryPart(b); b1[3] = PetscImaginaryPart(b);         \
346:     _7_MPI_Allreduce(b1,b2,5,MPIU_REAL,MPIU_MAX,PetscObjectComm((PetscObject)a));CHKERRQ(_7_ierr); \
347:     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); \
348:   } while (0)

351:   do {                                                                  \
352:     PetscErrorCode _7_ierr;                                             \
353:     PetscReal b1[3],b2[3];                                              \
354:     if (PetscIsNanReal(b)) {b1[2] = 1;} else {b1[2] = 0;};              \
355:     b1[0] = -b; b1[1] = b;                                              \
356:     _7_MPI_Allreduce(b1,b2,3,MPIU_REAL,MPIU_MAX,PetscObjectComm((PetscObject)a));CHKERRQ(_7_ierr); \
357:     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); \
358:   } while (0)

361:   do {                                                                  \
362:     PetscErrorCode _7_ierr;                                             \
363:     PetscInt b1[2],b2[2];                                               \
364:     b1[0] = -b; b1[1] = b;                                              \
365:     _7_MPIU_Allreduce(b1,b2,2,MPIU_INT,MPI_MAX,PetscObjectComm((PetscObject)a));CHKERRQ(_7_ierr); \
366:     if (-b2[0] != b2[1]) SETERRQ1(PetscObjectComm((PetscObject)a),PETSC_ERR_ARG_WRONG,"Int value must be same on all processes, argument # %d",c); \
367:   } while (0)


372:   do {                                                                  \
373:     PetscErrorCode _7_ierr;                                             \
374:     PetscMPIInt b1[2],b2[2];                                            \
375:     b1[0] = -(PetscMPIInt)b; b1[1] = (PetscMPIInt)b;                    \
376:     _7_MPIU_Allreduce(b1,b2,2,MPI_INT,MPI_MAX,PetscObjectComm((PetscObject)a));CHKERRQ(_7_ierr); \
377:     if (-b2[0] != b2[1]) SETERRQ1(PetscObjectComm((PetscObject)a),PETSC_ERR_ARG_WRONG,"Bool value must be same on all processes, argument # %d",c); \
378:   } while (0)

381:   do {                                                                  \
382:     PetscErrorCode _7_ierr;                                             \
383:     PetscMPIInt b1[2],b2[2];                                            \
384:     b1[0] = -(PetscMPIInt)b; b1[1] = (PetscMPIInt)b;                    \
385:     _7_MPIU_Allreduce(b1,b2,2,MPI_INT,MPI_MAX,PetscObjectComm((PetscObject)a));CHKERRQ(_7_ierr); \
386:     if (-b2[0] != b2[1]) SETERRQ1(PetscObjectComm((PetscObject)a),PETSC_ERR_ARG_WRONG,"Enum value must be same on all processes, argument # %d",c); \
387:   } while (0)

389: #endif

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

395:    Level: developer

397: .seealso: PetscUseMethod()
398: */
399: #define  PetscTryMethod(obj,A,B,C) \
400:   0; do { PetscErrorCode (*f)B, __ierr; \
401:     __PetscObjectQueryFunction((PetscObject)obj,A,&f);CHKERRQ(__ierr); \
402:     if (f) {__(*f)C;CHKERRQ(__ierr);} \
403:   } while(0)

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

409:    Level: developer

411: .seealso: PetscTryMethod()
412: */
413: #define  PetscUseMethod(obj,A,B,C) \
414:   0; do { PetscErrorCode (*f)B, __ierr; \
415:     __PetscObjectQueryFunction((PetscObject)obj,A,&f);CHKERRQ(__ierr); \
416:     if (f) {__(*f)C;CHKERRQ(__ierr);} \
417:     else SETERRQ1(PetscObjectComm((PetscObject)obj),PETSC_ERR_SUP,"Cannot locate function %s in object",A); \
418:   } while(0)

420: /*MC
421:    PetscObjectStateIncrease - Increases the state of any PetscObject

423:    Synopsis:
424:    #include "petsc/private/petscimpl.h"
425:    PetscErrorCode PetscObjectStateIncrease(PetscObject obj)

427:    Logically Collective

429:    Input Parameter:
430: .  obj - any PETSc object, for example a Vec, Mat or KSP. This must be
431:          cast with a (PetscObject), for example,
432:          PetscObjectStateIncrease((PetscObject)mat);

434:    Notes:
435:     object state is an integer which gets increased every time
436:    the object is changed internally. By saving and later querying the object state
437:    one can determine whether information about the object is still current.
438:    Currently, state is maintained for Vec and Mat objects.

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

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

447:    Level: developer

449:    seealso: PetscObjectStateGet()

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

454: PETSC_EXTERN PetscErrorCode PetscObjectStateGet(PetscObject,PetscObjectState*);
455: PETSC_EXTERN PetscErrorCode PetscObjectStateSet(PetscObject,PetscObjectState);
456: PETSC_EXTERN PetscErrorCode PetscObjectComposedDataRegister(PetscInt*);
457: PETSC_EXTERN PetscErrorCode PetscObjectComposedDataIncreaseInt(PetscObject);
458: PETSC_EXTERN PetscErrorCode PetscObjectComposedDataIncreaseIntstar(PetscObject);
459: PETSC_EXTERN PetscErrorCode PetscObjectComposedDataIncreaseReal(PetscObject);
460: PETSC_EXTERN PetscErrorCode PetscObjectComposedDataIncreaseRealstar(PetscObject);
461: PETSC_EXTERN PetscErrorCode PetscObjectComposedDataIncreaseScalar(PetscObject);
462: PETSC_EXTERN PetscErrorCode PetscObjectComposedDataIncreaseScalarstar(PetscObject);
463: PETSC_EXTERN PetscInt         PetscObjectComposedDataMax;
464: /*MC
465:    PetscObjectComposedDataSetInt - attach integer data to a PetscObject

467:    Synopsis:
468:    #include "petsc/private/petscimpl.h"
469:    PetscErrorCode PetscObjectComposedDataSetInt(PetscObject obj,int id,int data)

471:    Not collective

473:    Input parameters:
474: +  obj - the object to which data is to be attached
475: .  id - the identifier for the data
476: -  data - the data to  be attached

478:    Notes
479:    The data identifier can best be created through a call to  PetscObjectComposedDataRegister()

481:    Level: developer
482: M*/
483: #define PetscObjectComposedDataSetInt(obj,id,data)                                      \
484:   ((((obj)->int_idmax < PetscObjectComposedDataMax) && PetscObjectComposedDataIncreaseInt(obj)) ||  \
485:    ((obj)->intcomposeddata[id] = data,(obj)->intcomposedstate[id] = (obj)->state, 0))

487: /*MC
488:    PetscObjectComposedDataGetInt - retrieve integer data attached to an object

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

494:    Not collective

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

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

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

506:    Level: developer
507: M*/
508: #define PetscObjectComposedDataGetInt(obj,id,data,flag)                            \
509:   ((((obj)->intcomposedstate && ((obj)->intcomposedstate[id] == (obj)->state)) ?   \
510:    (data = (obj)->intcomposeddata[id],flag = PETSC_TRUE) : (flag = PETSC_FALSE)),0)

512: /*MC
513:    PetscObjectComposedDataSetIntstar - attach integer array data to a PetscObject

515:    Synopsis:
516:    #include "petsc/private/petscimpl.h"
517:    PetscErrorCode PetscObjectComposedDataSetIntstar(PetscObject obj,int id,int *data)

519:    Not collective

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

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

530:    Level: developer
531: M*/
532: #define PetscObjectComposedDataSetIntstar(obj,id,data)                                          \
533:   ((((obj)->intstar_idmax < PetscObjectComposedDataMax) && PetscObjectComposedDataIncreaseIntstar(obj)) ||  \
534:    ((obj)->intstarcomposeddata[id] = data,(obj)->intstarcomposedstate[id] = (obj)->state, 0))

536: /*MC
537:    PetscObjectComposedDataGetIntstar - retrieve integer array data
538:    attached to an object

540:    Synopsis:
541:    #include "petsc/private/petscimpl.h"
542:    PetscErrorCode PetscObjectComposedDataGetIntstar(PetscObject obj,int id,int *data,PetscBool  flag)

544:    Not collective

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

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

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

556:    Level: developer
557: M*/
558: #define PetscObjectComposedDataGetIntstar(obj,id,data,flag)                               \
559:   ((((obj)->intstarcomposedstate && ((obj)->intstarcomposedstate[id] == (obj)->state)) ?  \
560:    (data = (obj)->intstarcomposeddata[id],flag = PETSC_TRUE) : (flag = PETSC_FALSE)),0)

562: /*MC
563:    PetscObjectComposedDataSetReal - attach real data to a PetscObject

565:    Synopsis:
566:    #include "petsc/private/petscimpl.h"
567:    PetscErrorCode PetscObjectComposedDataSetReal(PetscObject obj,int id,PetscReal data)

569:    Not collective

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

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

580:    Level: developer
581: M*/
582: #define PetscObjectComposedDataSetReal(obj,id,data)                                       \
583:   ((((obj)->real_idmax < PetscObjectComposedDataMax) && PetscObjectComposedDataIncreaseReal(obj)) ||  \
584:    ((obj)->realcomposeddata[id] = data,(obj)->realcomposedstate[id] = (obj)->state, 0))

586: /*MC
587:    PetscObjectComposedDataGetReal - retrieve real data attached to an object

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

593:    Not collective

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

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

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

605:    Level: developer
606: M*/
607: #define PetscObjectComposedDataGetReal(obj,id,data,flag)                            \
608:   ((((obj)->realcomposedstate && ((obj)->realcomposedstate[id] == (obj)->state)) ?  \
609:    (data = (obj)->realcomposeddata[id],flag = PETSC_TRUE) : (flag = PETSC_FALSE)),0)

611: /*MC
612:    PetscObjectComposedDataSetRealstar - attach real array data to a PetscObject

614:    Synopsis:
615:    #include "petsc/private/petscimpl.h"
616:    PetscErrorCode PetscObjectComposedDataSetRealstar(PetscObject obj,int id,PetscReal *data)

618:    Not collective

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

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

629:    Level: developer
630: M*/
631: #define PetscObjectComposedDataSetRealstar(obj,id,data)                                           \
632:   ((((obj)->realstar_idmax < PetscObjectComposedDataMax) && PetscObjectComposedDataIncreaseRealstar(obj)) ||  \
633:    ((obj)->realstarcomposeddata[id] = data, (obj)->realstarcomposedstate[id] = (obj)->state, 0))

635: /*MC
636:    PetscObjectComposedDataGetRealstar - retrieve real array data
637:    attached to an object

639:    Synopsis:
640:    #include "petsc/private/petscimpl.h"
641:    PetscErrorCode PetscObjectComposedDataGetRealstar(PetscObject obj,int id,PetscReal *data,PetscBool  flag)

643:    Not collective

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

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

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

655:    Level: developer
656: M*/
657: #define PetscObjectComposedDataGetRealstar(obj,id,data,flag)                                \
658:   ((((obj)->realstarcomposedstate && ((obj)->realstarcomposedstate[id] == (obj)->state)) ?  \
659:    (data = (obj)->realstarcomposeddata[id],flag = PETSC_TRUE) : (flag = PETSC_FALSE)),0)

661: /*MC
662:    PetscObjectComposedDataSetScalar - attach scalar data to a PetscObject

664:    Synopsis:
665:    #include "petsc/private/petscimpl.h"
666:    PetscErrorCode PetscObjectComposedDataSetScalar(PetscObject obj,int id,PetscScalar data)

668:    Not collective

670:    Input parameters:
671: +  obj - the object to which data is to be attached
672: .  id - the identifier for the data
673: -  data - the data to  be attached

675:    Notes
676:    The data identifier can best be determined through a call to
677:    PetscObjectComposedDataRegister()

679:    Level: developer
680: M*/
681: #if defined(PETSC_USE_COMPLEX)
682: #define PetscObjectComposedDataSetScalar(obj,id,data)                                        \
683:   ((((obj)->scalar_idmax < PetscObjectComposedDataMax) && PetscObjectComposedDataIncreaseScalar(obj)) || \
684:    ((obj)->scalarcomposeddata[id] = data,(obj)->scalarcomposedstate[id] = (obj)->state, 0))
685: #else
686: #define PetscObjectComposedDataSetScalar(obj,id,data) \
687:         PetscObjectComposedDataSetReal(obj,id,data)
688: #endif
689: /*MC
690:    PetscObjectComposedDataGetScalar - retrieve scalar data attached to an object

692:    Synopsis:
693:    #include "petsc/private/petscimpl.h"
694:    PetscErrorCode PetscObjectComposedDataGetScalar(PetscObject obj,int id,PetscScalar data,PetscBool  flag)

696:    Not collective

698:    Input parameters:
699: +  obj - the object from which data is to be retrieved
700: -  id - the identifier for the data

702:    Output parameters
703: +  data - the data to be retrieved
704: -  flag - PETSC_TRUE if the data item exists and is valid, PETSC_FALSE otherwise

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

708:    Level: developer
709: M*/
710: #if defined(PETSC_USE_COMPLEX)
711: #define PetscObjectComposedDataGetScalar(obj,id,data,flag)                              \
712:   ((((obj)->scalarcomposedstate && ((obj)->scalarcomposedstate[id] == (obj)->state) ) ? \
713:    (data = (obj)->scalarcomposeddata[id],flag = PETSC_TRUE) : (flag = PETSC_FALSE)),0)
714: #else
715: #define PetscObjectComposedDataGetScalar(obj,id,data,flag)                             \
716:         PetscObjectComposedDataGetReal(obj,id,data,flag)
717: #endif

719: /*MC
720:    PetscObjectComposedDataSetScalarstar - attach scalar array data to a PetscObject

722:    Synopsis:
723:    #include "petsc/private/petscimpl.h"
724:    PetscErrorCode PetscObjectComposedDataSetScalarstar(PetscObject obj,int id,PetscScalar *data)

726:    Not collective

728:    Input parameters:
729: +  obj - the object to which data is to be attached
730: .  id - the identifier for the data
731: -  data - the data to  be attached

733:    Notes
734:    The data identifier can best be determined through a call to
735:    PetscObjectComposedDataRegister()

737:    Level: developer
738: M*/
739: #if defined(PETSC_USE_COMPLEX)
740: #define PetscObjectComposedDataSetScalarstar(obj,id,data)                                             \
741:   ((((obj)->scalarstar_idmax < PetscObjectComposedDataMax) && PetscObjectComposedDataIncreaseScalarstar(obj)) ||  \
742:    ((obj)->scalarstarcomposeddata[id] = data,(obj)->scalarstarcomposedstate[id] = (obj)->state, 0))
743: #else
744: #define PetscObjectComposedDataSetScalarstar(obj,id,data) \
745:         PetscObjectComposedDataSetRealstar(obj,id,data)
746: #endif
747: /*MC
748:    PetscObjectComposedDataGetScalarstar - retrieve scalar array data
749:    attached to an object

751:    Synopsis:
752:    #include "petsc/private/petscimpl.h"
753:    PetscErrorCode PetscObjectComposedDataGetScalarstar(PetscObject obj,int id,PetscScalar *data,PetscBool  flag)

755:    Not collective

757:    Input parameters:
758: +  obj - the object from which data is to be retrieved
759: -  id - the identifier for the data

761:    Output parameters
762: +  data - the data to be retrieved
763: -  flag - PETSC_TRUE if the data item exists and is valid, PETSC_FALSE otherwise

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

767:    Level: developer
768: M*/
769: #if defined(PETSC_USE_COMPLEX)
770: #define PetscObjectComposedDataGetScalarstar(obj,id,data,flag)                                 \
771:   ((((obj)->scalarstarcomposedstate && ((obj)->scalarstarcomposedstate[id] == (obj)->state)) ? \
772:        (data = (obj)->scalarstarcomposeddata[id],flag = PETSC_TRUE) : (flag = PETSC_FALSE)),0)
773: #else
774: #define PetscObjectComposedDataGetScalarstar(obj,id,data,flag)         \
775:         PetscObjectComposedDataGetRealstar(obj,id,data,flag)
776: #endif

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

780: PETSC_EXTERN PetscErrorCode PetscMonitorCompare(PetscErrorCode (*)(void),void *,PetscErrorCode (*)(void**),PetscErrorCode (*)(void),void *,PetscErrorCode (*)(void**),PetscBool *);

782: PETSC_EXTERN PetscMPIInt Petsc_Counter_keyval;
783: PETSC_EXTERN PetscMPIInt Petsc_InnerComm_keyval;
784: PETSC_EXTERN PetscMPIInt Petsc_OuterComm_keyval;
785: PETSC_EXTERN PetscMPIInt Petsc_Seq_keyval;
786: PETSC_EXTERN PetscMPIInt Petsc_ShmComm_keyval;

788: /*
789:   PETSc communicators have this attribute, see
790:   PetscCommDuplicate(), PetscCommDestroy(), PetscCommGetNewTag(), PetscObjectGetName()
791: */
792: typedef struct {
793:   PetscMPIInt tag;              /* next free tag value */
794:   PetscInt    refcount;         /* number of references, communicator can be freed when this reaches 0 */
795:   PetscInt    namecount;        /* used to generate the next name, as in Vec_0, Mat_1, ... */
796: } PetscCommCounter;

798: /*E
799:     PetscOffloadFlag - indicates which memory (CPU, GPU, or none contains valid vector

801:    PETSC_OFFLOAD_UNALLOCATED  - no memory contains valid matrix entries; NEVER used for vectors
802:    PETSC_OFFLOAD_GPU - GPU has valid vector/matrix entries
803:    PETSC_OFFLOAD_CPU - CPU has valid vector/matrix entries
804:    PETSC_OFFLOAD_BOTH - Both GPU and CPU have valid vector/matrix entries and they match

806:    Level: developer
807: E*/
808: typedef enum {PETSC_OFFLOAD_UNALLOCATED,PETSC_OFFLOAD_GPU,PETSC_OFFLOAD_CPU,PETSC_OFFLOAD_BOTH} PetscOffloadFlag;

810: typedef enum {STATE_BEGIN, STATE_PENDING, STATE_END} SRState;

812: typedef enum {PETSC_SR_REDUCE_SUM=0,PETSC_SR_REDUCE_MAX=1,PETSC_SR_REDUCE_MIN=2} PetscSRReductionType;

814: typedef struct {
815:   MPI_Comm    comm;
816:   MPI_Request request;
817:   PetscBool   async;
818:   PetscScalar *lvalues;     /* this are the reduced values before call to MPI_Allreduce() */
819:   PetscScalar *gvalues;     /* values after call to MPI_Allreduce() */
820:   void        **invecs;     /* for debugging only, vector/memory used with each op */
821:   PetscInt    *reducetype;  /* is particular value to be summed or maxed? */
822:   SRState     state;        /* are we calling xxxBegin() or xxxEnd()? */
823:   PetscInt    maxops;       /* total amount of space we have for requests */
824:   PetscInt    numopsbegin;  /* number of requests that have been queued in */
825:   PetscInt    numopsend;    /* number of requests that have been gotten by user */
826: } PetscSplitReduction;

828: PETSC_EXTERN PetscErrorCode PetscSplitReductionGet(MPI_Comm,PetscSplitReduction**);
829: PETSC_EXTERN PetscErrorCode PetscSplitReductionEnd(PetscSplitReduction*);
830: PETSC_EXTERN PetscErrorCode PetscSplitReductionExtend(PetscSplitReduction*);

832: #if !defined(PETSC_SKIP_SPINLOCK)
833: #if defined(PETSC_HAVE_THREADSAFETY)
834: #  if defined(PETSC_HAVE_CONCURRENCYKIT)
835: #if defined(__cplusplus)
836: /*  CK does not have extern "C" protection in their include files */
837: extern "C" {
838: #endif
839: #include <ck_spinlock.h>
840: #if defined(__cplusplus)
841: }
842: #endif
843: typedef ck_spinlock_t PetscSpinlock;
844: PETSC_STATIC_INLINE PetscErrorCode PetscSpinlockCreate(PetscSpinlock *ck_spinlock)
845: {
846:   ck_spinlock_init(ck_spinlock);
847:   return 0;
848: }
849: PETSC_STATIC_INLINE PetscErrorCode PetscSpinlockLock(PetscSpinlock *ck_spinlock)
850: {
851:   ck_spinlock_lock(ck_spinlock);
852:   return 0;
853: }
854: PETSC_STATIC_INLINE PetscErrorCode PetscSpinlockUnlock(PetscSpinlock *ck_spinlock)
855: {
856:   ck_spinlock_unlock(ck_spinlock);
857:   return 0;
858: }
859: PETSC_STATIC_INLINE PetscErrorCode PetscSpinlockDestroy(PetscSpinlock *ck_spinlock)
860: {
861:   return 0;
862: }
863: #  elif defined(PETSC_HAVE_OPENMP)

865: #include <omp.h>
866: typedef omp_lock_t PetscSpinlock;
867: PETSC_STATIC_INLINE PetscErrorCode PetscSpinlockCreate(PetscSpinlock *omp_lock)
868: {
869:   omp_init_lock(omp_lock);
870:   return 0;
871: }
872: PETSC_STATIC_INLINE PetscErrorCode PetscSpinlockLock(PetscSpinlock *omp_lock)
873: {
874:   omp_set_lock(omp_lock);
875:   return 0;
876: }
877: PETSC_STATIC_INLINE PetscErrorCode PetscSpinlockUnlock(PetscSpinlock *omp_lock)
878: {
879:   omp_unset_lock(omp_lock);
880:   return 0;
881: }
882: PETSC_STATIC_INLINE PetscErrorCode PetscSpinlockDestroy(PetscSpinlock *omp_lock)
883: {
884:   omp_destroy_lock(omp_lock);
885:   return 0;
886: }
887: #else
888: Thread safety requires either --with-openmp or --download-concurrencykit
889: #endif

891: #else
892: typedef int PetscSpinlock;
893: #define PetscSpinlockCreate(a)  0
894: #define PetscSpinlockLock(a)    0
895: #define PetscSpinlockUnlock(a)  0
896: #define PetscSpinlockDestroy(a) 0
897: #endif

899: #if defined(PETSC_HAVE_THREADSAFETY)
900: PETSC_INTERN PetscSpinlock PetscViewerASCIISpinLockOpen;
901: PETSC_INTERN PetscSpinlock PetscViewerASCIISpinLockStdout;
902: PETSC_INTERN PetscSpinlock PetscViewerASCIISpinLockStderr;
903: PETSC_INTERN PetscSpinlock PetscCommSpinLock;
904: #endif
905: #endif

907: PETSC_EXTERN PetscLogEvent PETSC_Barrier;
908: PETSC_EXTERN PetscLogEvent PETSC_BuildTwoSided;
909: PETSC_EXTERN PetscLogEvent PETSC_BuildTwoSidedF;

911: #if defined(PETSC_HAVE_ADIOS)
912: PETSC_EXTERN int64_t Petsc_adios_group;
913: #endif

915: #endif /* _PETSCHEAD_H */