LCOV - code coverage report
Current view: top level - var/lib/buildbot/slaves/linux-gnu-gcov/petsc/include - petsclog.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 11 11 100.0 %
Date: 2019-06-16 02:47:36 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :     Defines profile/logging in PETSc.
       3             : */
       4             : 
       5             : #if !defined(__PetscLog_H)
       6             : #define __PetscLog_H
       7             : #include <petscsys.h>
       8             : 
       9             : /* General logging of information; different from event logging */
      10             : PETSC_EXTERN PetscErrorCode PetscInfo_Private(const char[],void*,const char[],...);
      11             : #if defined(PETSC_USE_INFO)
      12             : #define PetscInfo(A,S)                       PetscInfo_Private(PETSC_FUNCTION_NAME,A,S)
      13             : #define PetscInfo1(A,S,a1)                   PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1)
      14             : #define PetscInfo2(A,S,a1,a2)                PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2)
      15             : #define PetscInfo3(A,S,a1,a2,a3)             PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2,a3)
      16             : #define PetscInfo4(A,S,a1,a2,a3,a4)          PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2,a3,a4)
      17             : #define PetscInfo5(A,S,a1,a2,a3,a4,a5)       PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2,a3,a4,a5)
      18             : #define PetscInfo6(A,S,a1,a2,a3,a4,a5,a6)    PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2,a3,a4,a5,a6)
      19             : #define PetscInfo7(A,S,a1,a2,a3,a4,a5,a6,a7) PetscInfo_Private(PETSC_FUNCTION_NAME,A,S,a1,a2,a3,a4,a5,a6,a7)
      20             : #else
      21             : #define PetscInfo(A,S)                       0
      22             : #define PetscInfo1(A,S,a1)                   0
      23             : #define PetscInfo2(A,S,a1,a2)                0
      24             : #define PetscInfo3(A,S,a1,a2,a3)             0
      25             : #define PetscInfo4(A,S,a1,a2,a3,a4)          0
      26             : #define PetscInfo5(A,S,a1,a2,a3,a4,a5)       0
      27             : #define PetscInfo6(A,S,a1,a2,a3,a4,a5,a6)    0
      28             : #define PetscInfo7(A,S,a1,a2,a3,a4,a5,a6,a7) 0
      29             : #endif
      30             : PETSC_EXTERN PetscErrorCode PetscInfoDeactivateClass(PetscClassId);
      31             : PETSC_EXTERN PetscErrorCode PetscInfoActivateClass(PetscClassId);
      32             : PETSC_EXTERN PetscBool PetscLogPrintInfo;  /* if true, indicates PetscInfo() is turned on */
      33             : 
      34             : /*MC
      35             :     PetscLogEvent - id used to identify PETSc or user events which timed portions (blocks of executable)
      36             :      code.
      37             : 
      38             :     Level: intermediate
      39             : 
      40             : .seealso: PetscLogEventRegister(), PetscLogEventBegin(), PetscLogEventEnd(), PetscLogStage
      41             : M*/
      42             : typedef int PetscLogEvent;
      43             : 
      44             : /*MC
      45             :     PetscLogStage - id used to identify user stages (phases, sections) of runs - for logging
      46             : 
      47             :     Level: intermediate
      48             : 
      49             : .seealso: PetscLogStageRegister(), PetscLogStagePush(), PetscLogStagePop(), PetscLogEvent
      50             : M*/
      51             : typedef int PetscLogStage;
      52             : 
      53             : #define PETSC_EVENT  1311311
      54             : PETSC_EXTERN PetscLogEvent PETSC_LARGEST_EVENT;
      55             : 
      56             : /* Global flop counter */
      57             : PETSC_EXTERN PetscLogDouble petsc_TotalFlops;
      58             : PETSC_EXTERN PetscLogDouble petsc_tmp_flops;
      59             : 
      60             : /* Global GPU counters */
      61             : #if defined(PETSC_HAVE_VIENNACL) || defined(PETSC_HAVE_CUDA) 
      62             : PETSC_EXTERN PetscLogDouble petsc_ctog_ct;
      63             : PETSC_EXTERN PetscLogDouble petsc_gtoc_ct;
      64             : PETSC_EXTERN PetscLogDouble petsc_ctog_sz;
      65             : PETSC_EXTERN PetscLogDouble petsc_gtoc_sz;
      66             : #endif
      67             : 
      68             : /* We must make the following structures available to access the event
      69             :      activation flags in the PetscLogEventBegin/End() macros. These are not part of the PETSc public
      70             :      API and are not intended to be used by other parts of PETSc or by users.
      71             : 
      72             :      The code that manipulates these structures is in src/sys/logging/utils.
      73             : */
      74             : typedef struct _n_PetscIntStack *PetscIntStack;
      75             : 
      76             : /* -----------------------------------------------------------------------------------------------------*/
      77             : /*
      78             :     PetscClassRegInfo, PetscClassPerfInfo - Each class has two data structures associated with it. The first has
      79             :        static information about it, the second collects statistics on how many objects of the class are created,
      80             :        how much memory they use, etc.
      81             : 
      82             :     PetscClassRegLog, PetscClassPerfLog - arrays of the PetscClassRegInfo and PetscClassPerfInfo for all classes.
      83             : */
      84             : typedef struct  {
      85             :   char           *name;   /* The class name */
      86             :   PetscClassId   classid; /* The integer identifying this class */
      87             : } PetscClassRegInfo;
      88             : 
      89             : typedef struct {
      90             :   PetscClassId   id;           /* The integer identifying this class */
      91             :   int            creations;    /* The number of objects of this class created */
      92             :   int            destructions; /* The number of objects of this class destroyed */
      93             :   PetscLogDouble mem;          /* The total memory allocated by objects of this class */
      94             :   PetscLogDouble descMem;      /* The total memory allocated by descendents of these objects */
      95             : } PetscClassPerfInfo;
      96             : 
      97             : typedef struct _n_PetscClassRegLog *PetscClassRegLog;
      98             : struct _n_PetscClassRegLog {
      99             :   int               numClasses; /* The number of classes registered */
     100             :   int               maxClasses; /* The maximum number of classes */
     101             :   PetscClassRegInfo *classInfo; /* The structure for class information (classids are monotonicly increasing) */
     102             : };
     103             : 
     104             : typedef struct _n_PetscClassPerfLog *PetscClassPerfLog;
     105             : struct _n_PetscClassPerfLog {
     106             :   int                numClasses; /* The number of logging classes */
     107             :   int                maxClasses; /* The maximum number of classes */
     108             :   PetscClassPerfInfo *classInfo; /* The structure for class information (classids are monotonicly increasing) */
     109             : };
     110             : /* -----------------------------------------------------------------------------------------------------*/
     111             : /*
     112             :     PetscEventRegInfo, PetscEventPerfInfo - Each event has two data structures associated with it. The first has
     113             :        static information about it, the second collects statistics on how many times the event is used, how
     114             :        much time it takes, etc.
     115             : 
     116             :     PetscEventRegLog, PetscEventPerfLog - an array of all PetscEventRegInfo and PetscEventPerfInfo for all events. There is one
     117             :       of these for each stage.
     118             : 
     119             : */
     120             : typedef struct {
     121             :   char         *name;         /* The name of this event */
     122             :   PetscClassId classid;       /* The class the event is associated with */
     123             :   PetscBool    collective;    /* Flag this event as collective */
     124             : #if defined (PETSC_HAVE_MPE)
     125             :   int          mpe_id_begin;  /* MPE IDs that define the event */
     126             :   int          mpe_id_end;
     127             : #endif
     128             : } PetscEventRegInfo;
     129             : 
     130             : typedef struct {
     131             :   int            id;            /* The integer identifying this event */
     132             :   PetscBool      active;        /* The flag to activate logging */
     133             :   PetscBool      visible;       /* The flag to print info in summary */
     134             :   int            depth;         /* The nesting depth of the event call */
     135             :   int            count;         /* The number of times this event was executed */
     136             :   PetscLogDouble flops, flops2, flopsTmp; /* The flops and flops^2 used in this event */
     137             :   PetscLogDouble time, time2, timeTmp;    /* The time and time^2 taken for this event */
     138             :   PetscLogDouble syncTime;                /* The synchronization barrier time */
     139             :   PetscLogDouble dof[8];        /* The number of degrees of freedom associated with this event */
     140             :   PetscLogDouble errors[8];     /* The errors (user-defined) associated with this event */
     141             :   PetscLogDouble numMessages;   /* The number of messages in this event */
     142             :   PetscLogDouble messageLength; /* The total message lengths in this event */
     143             :   PetscLogDouble numReductions; /* The number of reductions in this event */
     144             :   PetscLogDouble memIncrease;   /* How much the resident memory has increased in this event */
     145             :   PetscLogDouble mallocIncrease;/* How much the maximum malloced space has increased in this event */
     146             :   PetscLogDouble mallocSpace;   /* How much the space was malloced and kept during this event */
     147             :   PetscLogDouble mallocIncreaseEvent;  /* Maximum of the high water mark with in event minus memory available at the end of the event */
     148             :   #if defined(PETSC_HAVE_VIENNACL) || defined(PETSC_HAVE_CUDA) 
     149             :   PetscLogDouble CpuToGpuCount; /* The total number of CPU to GPU copies */
     150             :   PetscLogDouble GpuToCpuCount; /* The total number of GPU to CPU copies */
     151             :   PetscLogDouble CpuToGpuSize;  /* The total size of CPU to GPU copies */
     152             :   PetscLogDouble GpuToCpuSize;  /* The total size of GPU to CPU copies */
     153             :   #endif
     154             : } PetscEventPerfInfo;
     155             : 
     156             : typedef struct _n_PetscEventRegLog *PetscEventRegLog;
     157             : struct _n_PetscEventRegLog {
     158             :   int               numEvents;  /* The number of registered events */
     159             :   int               maxEvents;  /* The maximum number of events */
     160             :   PetscEventRegInfo *eventInfo; /* The registration information for each event */
     161             : };
     162             : 
     163             : typedef struct _n_PetscEventPerfLog *PetscEventPerfLog;
     164             : struct _n_PetscEventPerfLog {
     165             :   int                numEvents;  /* The number of logging events */
     166             :   int                maxEvents;  /* The maximum number of events */
     167             :   PetscEventPerfInfo *eventInfo; /* The performance information for each event */
     168             : };
     169             : /* ------------------------------------------------------------------------------------------------------------*/
     170             : /*
     171             :    PetscStageInfo - Contains all the information about a particular stage.
     172             : 
     173             :    PetscStageLog - An array of PetscStageInfo for each registered stage. There is a single one of these in the code.
     174             : */
     175             : typedef struct _PetscStageInfo {
     176             :   char               *name;     /* The stage name */
     177             :   PetscBool          used;      /* The stage was pushed on this processor */
     178             :   PetscEventPerfInfo perfInfo;  /* The stage performance information */
     179             :   PetscEventPerfLog  eventLog;  /* The event information for this stage */
     180             :   PetscClassPerfLog  classLog;  /* The class information for this stage */
     181             : } PetscStageInfo;
     182             : 
     183             : typedef struct _n_PetscStageLog *PetscStageLog;
     184             : struct _n_PetscStageLog {
     185             :   int              numStages;   /* The number of registered stages */
     186             :   int              maxStages;   /* The maximum number of stages */
     187             :   PetscIntStack    stack;       /* The stack for active stages */
     188             :   int              curStage;    /* The current stage (only used in macros so we don't call PetscIntStackTop) */
     189             :   PetscStageInfo   *stageInfo;  /* The information for each stage */
     190             :   PetscEventRegLog eventLog;    /* The registered events */
     191             :   PetscClassRegLog classLog;    /* The registered classes */
     192             : };
     193             : /* -----------------------------------------------------------------------------------------------------*/
     194             : 
     195             : PETSC_EXTERN PetscErrorCode PetscLogObjectParent(PetscObject,PetscObject);
     196             : PETSC_EXTERN PetscErrorCode PetscLogObjectMemory(PetscObject,PetscLogDouble);
     197             : 
     198             : #if defined(PETSC_USE_LOG)  /* --- Logging is turned on --------------------------------*/
     199             : PETSC_EXTERN PetscStageLog petsc_stageLog;
     200             : PETSC_EXTERN PetscErrorCode PetscLogGetStageLog(PetscStageLog*);
     201             : PETSC_EXTERN PetscErrorCode PetscStageLogGetCurrent(PetscStageLog,int*);
     202             : PETSC_EXTERN PetscErrorCode PetscStageLogGetEventPerfLog(PetscStageLog,int,PetscEventPerfLog*);
     203             : 
     204             : /*
     205             :    Flop counting:  We count each arithmetic operation (e.g., addition, multiplication) separately.
     206             : 
     207             :    For the complex numbers version, note that
     208             :        1 complex addition = 2 flops
     209             :        1 complex multiplication = 6 flops,
     210             :    where we define 1 flop as that for a double precision scalar.  We roughly approximate
     211             :    flop counting for complex numbers by multiplying the total flops by 4; this corresponds
     212             :    to the assumption that we're counting mostly additions and multiplications -- and
     213             :    roughly the same number of each.  More accurate counting could be done by distinguishing
     214             :    among the various arithmetic operations.
     215             :  */
     216             : 
     217             : #if defined(PETSC_USE_COMPLEX)
     218             : #define PETSC_FLOPS_PER_OP 4.0
     219             : #else
     220             : #define PETSC_FLOPS_PER_OP 1.0
     221             : #endif
     222             : 
     223     1210388 : PETSC_STATIC_INLINE PetscErrorCode PetscLogFlops(PetscLogDouble n)
     224             : {
     225     1210388 :   PetscFunctionBegin;
     226             : #if defined(PETSC_USE_DEBUG)
     227     1210388 :   if (n < 0) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_ARG_OUTOFRANGE,"Cannot log negative flops");
     228             : #endif
     229     1210388 :   petsc_TotalFlops += PETSC_FLOPS_PER_OP*n;
     230     1210388 :   PetscFunctionReturn(0);
     231             : }
     232             : 
     233             : #if defined(PETSC_HAVE_VIENNACL) || defined(PETSC_HAVE_CUDA)
     234             : PETSC_STATIC_INLINE PetscErrorCode PetscLogCpuToGpu(PetscLogDouble size){
     235             :   petsc_ctog_ct += 1;
     236             :   petsc_ctog_sz += size;
     237             :   PetscFunctionReturn(0);
     238             : }
     239             : PETSC_STATIC_INLINE PetscErrorCode PetscLogGpuToCpu(PetscLogDouble size){
     240             :   petsc_gtoc_ct += 1;
     241             :   petsc_gtoc_sz += size;
     242             :   PetscFunctionReturn(0);
     243             : }
     244             : #endif
     245             : 
     246             : PETSC_EXTERN PetscErrorCode PetscGetFlops(PetscLogDouble *);
     247             : 
     248             : #if defined (PETSC_HAVE_MPE)
     249             : PETSC_EXTERN PetscErrorCode PetscLogMPEBegin(void);
     250             : PETSC_EXTERN PetscErrorCode PetscLogMPEDump(const char[]);
     251             : #endif
     252             : 
     253             : PETSC_EXTERN PetscErrorCode (*PetscLogPLB)(PetscLogEvent,int,PetscObject,PetscObject,PetscObject,PetscObject);
     254             : PETSC_EXTERN PetscErrorCode (*PetscLogPLE)(PetscLogEvent,int,PetscObject,PetscObject,PetscObject,PetscObject);
     255             : PETSC_EXTERN PetscErrorCode (*PetscLogPHC)(PetscObject);
     256             : PETSC_EXTERN PetscErrorCode (*PetscLogPHD)(PetscObject);
     257             : 
     258             : #define PetscLogObjectParents(p,n,d)  0;do{int _i; for (_i=0; _i<(n); _i++) {ierr = PetscLogObjectParent((PetscObject)(p),(PetscObject)(d)[_i]);CHKERRQ(ierr);}}while(0)
     259             : #define PetscLogObjectCreate(h)      ((PetscLogPHC) ? (*PetscLogPHC)((PetscObject)(h)) : 0)
     260             : #define PetscLogObjectDestroy(h)     ((PetscLogPHD) ? (*PetscLogPHD)((PetscObject)(h)) : 0)
     261             : PETSC_EXTERN PetscErrorCode PetscLogObjectState(PetscObject, const char[], ...);
     262             : 
     263             : /* Initialization functions */
     264             : PETSC_EXTERN PetscErrorCode PetscLogDefaultBegin(void);
     265             : PETSC_EXTERN PetscErrorCode PetscLogAllBegin(void);
     266             : PETSC_EXTERN PetscErrorCode PetscLogNestedBegin(void);
     267             : PETSC_EXTERN PetscErrorCode PetscLogTraceBegin(FILE *);
     268             : PETSC_EXTERN PetscErrorCode PetscLogActions(PetscBool);
     269             : PETSC_EXTERN PetscErrorCode PetscLogObjects(PetscBool);
     270             : PETSC_EXTERN PetscErrorCode PetscLogSetThreshold(PetscLogDouble,PetscLogDouble*);
     271             : PETSC_EXTERN PetscErrorCode PetscLogSet(PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject),
     272             :                                         PetscErrorCode (*)(int, int, PetscObject, PetscObject, PetscObject, PetscObject));
     273             : 
     274             : /* Output functions */
     275             : PETSC_EXTERN PetscErrorCode PetscLogView(PetscViewer);
     276             : PETSC_EXTERN PetscErrorCode PetscLogViewFromOptions(void);
     277             : PETSC_EXTERN PetscErrorCode PetscLogDump(const char[]);
     278             : 
     279             : /* Stage functions */
     280             : PETSC_EXTERN PetscErrorCode PetscLogStageRegister(const char[],PetscLogStage*);
     281             : PETSC_EXTERN PetscErrorCode PetscLogStagePush(PetscLogStage);
     282             : PETSC_EXTERN PetscErrorCode PetscLogStagePop(void);
     283             : PETSC_EXTERN PetscErrorCode PetscLogStageSetActive(PetscLogStage,PetscBool);
     284             : PETSC_EXTERN PetscErrorCode PetscLogStageGetActive(PetscLogStage,PetscBool*);
     285             : PETSC_EXTERN PetscErrorCode PetscLogStageSetVisible(PetscLogStage,PetscBool);
     286             : PETSC_EXTERN PetscErrorCode PetscLogStageGetVisible(PetscLogStage,PetscBool*);
     287             : PETSC_EXTERN PetscErrorCode PetscLogStageGetId(const char[],PetscLogStage*);
     288             : 
     289             : /* Event functions */
     290             : PETSC_EXTERN PetscErrorCode PetscLogEventRegister(const char[],PetscClassId,PetscLogEvent*);
     291             : PETSC_EXTERN PetscErrorCode PetscLogEventSetCollective(PetscLogEvent,PetscBool);
     292             : PETSC_EXTERN PetscErrorCode PetscLogEventIncludeClass(PetscClassId);
     293             : PETSC_EXTERN PetscErrorCode PetscLogEventExcludeClass(PetscClassId);
     294             : PETSC_EXTERN PetscErrorCode PetscLogEventActivate(PetscLogEvent);
     295             : PETSC_EXTERN PetscErrorCode PetscLogEventDeactivate(PetscLogEvent);
     296             : PETSC_EXTERN PetscErrorCode PetscLogEventSetActiveAll(PetscLogEvent,PetscBool);
     297             : PETSC_EXTERN PetscErrorCode PetscLogEventActivateClass(PetscClassId);
     298             : PETSC_EXTERN PetscErrorCode PetscLogEventDeactivateClass(PetscClassId);
     299             : PETSC_EXTERN PetscErrorCode PetscLogEventGetId(const char[],PetscLogEvent*);
     300             : PETSC_EXTERN PetscErrorCode PetscLogEventGetPerfInfo(int,PetscLogEvent,PetscEventPerfInfo*);
     301             : PETSC_EXTERN PetscErrorCode PetscLogEventSetDof(PetscLogEvent, PetscInt, PetscLogDouble);
     302             : PETSC_EXTERN PetscErrorCode PetscLogEventSetError(PetscLogEvent, PetscInt, PetscLogDouble);
     303             : 
     304             : /* Global counters */
     305             : PETSC_EXTERN PetscLogDouble petsc_irecv_ct;
     306             : PETSC_EXTERN PetscLogDouble petsc_isend_ct;
     307             : PETSC_EXTERN PetscLogDouble petsc_recv_ct;
     308             : PETSC_EXTERN PetscLogDouble petsc_send_ct;
     309             : PETSC_EXTERN PetscLogDouble petsc_irecv_len;
     310             : PETSC_EXTERN PetscLogDouble petsc_isend_len;
     311             : PETSC_EXTERN PetscLogDouble petsc_recv_len;
     312             : PETSC_EXTERN PetscLogDouble petsc_send_len;
     313             : PETSC_EXTERN PetscLogDouble petsc_allreduce_ct;
     314             : PETSC_EXTERN PetscLogDouble petsc_gather_ct;
     315             : PETSC_EXTERN PetscLogDouble petsc_scatter_ct;
     316             : PETSC_EXTERN PetscLogDouble petsc_wait_ct;
     317             : PETSC_EXTERN PetscLogDouble petsc_wait_any_ct;
     318             : PETSC_EXTERN PetscLogDouble petsc_wait_all_ct;
     319             : PETSC_EXTERN PetscLogDouble petsc_sum_of_waits_ct;
     320             : 
     321             : PETSC_EXTERN PetscBool      PetscLogMemory;
     322             : 
     323             : PETSC_EXTERN PetscBool PetscLogSyncOn;  /* true if logging synchronization is enabled */
     324             : PETSC_EXTERN PetscErrorCode PetscLogEventSynchronize(PetscLogEvent, MPI_Comm);
     325             : 
     326             : #define PetscLogEventSync(e,comm) \
     327             :   (((PetscLogPLB && petsc_stageLog->stageInfo[petsc_stageLog->curStage].perfInfo.active && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? \
     328             :     PetscLogEventSynchronize((e),(comm)) : 0 ))
     329             : 
     330             : #define PetscLogEventBegin(e,o1,o2,o3,o4) \
     331             :   (((PetscLogPLB && petsc_stageLog->stageInfo[petsc_stageLog->curStage].perfInfo.active && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? \
     332             :     (*PetscLogPLB)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4)) : 0 ))
     333             : 
     334             : #define PetscLogEventEnd(e,o1,o2,o3,o4) \
     335             :   (((PetscLogPLE && petsc_stageLog->stageInfo[petsc_stageLog->curStage].perfInfo.active && petsc_stageLog->stageInfo[petsc_stageLog->curStage].eventLog->eventInfo[e].active) ? \
     336             :     (*PetscLogPLE)((e),0,(PetscObject)(o1),(PetscObject)(o2),(PetscObject)(o3),(PetscObject)(o4)) : 0 ))
     337             : 
     338             : PETSC_EXTERN PetscErrorCode PetscLogEventGetFlops(PetscLogEvent,PetscLogDouble*);
     339             : PETSC_EXTERN PetscErrorCode PetscLogEventZeroFlops(PetscLogEvent);
     340             : 
     341             : /*
     342             :      These are used internally in the PETSc routines to keep a count of MPI messages and
     343             :    their sizes.
     344             : 
     345             :      This does not work for MPI-Uni because our include/petsc/mpiuni/mpi.h file
     346             :    uses macros to defined the MPI operations.
     347             : 
     348             :      It does not work correctly from HP-UX because it processes the
     349             :    macros in a way that sometimes it double counts, hence
     350             :    PETSC_HAVE_BROKEN_RECURSIVE_MACRO
     351             : 
     352             :      It does not work with Windows because winmpich lacks MPI_Type_size()
     353             : */
     354             : #if !defined(__MPIUNI_H) && !defined(PETSC_HAVE_BROKEN_RECURSIVE_MACRO) && !defined (PETSC_HAVE_MPI_MISSING_TYPESIZE)
     355             : /*
     356             :    Logging of MPI activities
     357             : */
     358         124 : PETSC_STATIC_INLINE PetscErrorCode PetscMPITypeSize(PetscLogDouble *buff,PetscMPIInt count,MPI_Datatype type)
     359             : {
     360             :   PetscMPIInt mysize;
     361             :   PetscErrorCode _myierr;
     362         124 :   if (type == MPI_DATATYPE_NULL) return 0;
     363         124 :   _myierr = MPI_Type_size(type,&mysize);CHKERRQ(_myierr);
     364         124 :   *buff += (PetscLogDouble) (count*mysize);
     365         124 :   return 0;
     366             : }
     367             : 
     368             : PETSC_STATIC_INLINE PetscErrorCode PetscMPITypeSizeComm(MPI_Comm comm, PetscLogDouble *buff,PetscMPIInt *counts,MPI_Datatype type)
     369             : {
     370             :   PetscMPIInt mysize, commsize, p;
     371             :   PetscErrorCode _myierr;
     372             : 
     373             :   if (type == MPI_DATATYPE_NULL) return 0;
     374             :   _myierr = MPI_Comm_size(comm,&commsize);CHKERRQ(_myierr);
     375             :   _myierr = MPI_Type_size(type,&mysize);CHKERRQ(_myierr);
     376             :   for (p = 0; p < commsize; ++p) {
     377             :     *buff += (PetscLogDouble) (counts[p]*mysize);
     378             :   }
     379             :   return 0;
     380             : }
     381             : 
     382             : /*
     383             :     Returns 1 if the communicator is parallel else zero
     384             : */
     385             : PETSC_STATIC_INLINE int PetscMPIParallelComm(MPI_Comm comm)
     386             : {
     387     4958835 :   PetscMPIInt size; MPI_Comm_size(comm,&size); return size > 1;
     388             : }
     389             : 
     390             : #define MPI_Irecv(buf,count,datatype,source,tag,comm,request) \
     391             :   ((petsc_irecv_ct++,0) || PetscMPITypeSize(&(petsc_irecv_len),(count),(datatype)) || MPI_Irecv((buf),(count),(datatype),(source),(tag),(comm),(request)))
     392             : 
     393             : #define MPI_Isend(buf,count,datatype,dest,tag,comm,request) \
     394             :   ((petsc_isend_ct++,0) || PetscMPITypeSize(&(petsc_isend_len),(count),(datatype)) || MPI_Isend((buf),(count),(datatype),(dest),(tag),(comm),(request)))
     395             : 
     396             : #define MPI_Startall_irecv(count,datatype,number,requests) \
     397             :   ((petsc_irecv_ct += (PetscLogDouble)(number),0) || PetscMPITypeSize(&(petsc_irecv_len),(count),(datatype)) || ((number) && MPI_Startall((number),(requests))))
     398             : 
     399             : #define MPI_Startall_isend(count,datatype,number,requests) \
     400             :   ((petsc_isend_ct += (PetscLogDouble)(number),0) || PetscMPITypeSize(&(petsc_isend_len),(count),(datatype)) || ((number) && MPI_Startall((number),(requests))))
     401             : 
     402             : #define MPI_Start_isend(count,datatype,requests) \
     403             :   ((petsc_isend_ct++,0) || PetscMPITypeSize((&petsc_isend_len),(count),(datatype)) || MPI_Start((requests)))
     404             : 
     405             : #define MPI_Recv(buf,count,datatype,source,tag,comm,status) \
     406             :   ((petsc_recv_ct++,0) || PetscMPITypeSize((&petsc_recv_len),(count),(datatype)) || MPI_Recv((buf),(count),(datatype),(source),(tag),(comm),(status)))
     407             : 
     408             : #define MPI_Send(buf,count,datatype,dest,tag,comm) \
     409             :   ((petsc_send_ct++,0) || PetscMPITypeSize((&petsc_send_len),(count),(datatype)) || MPI_Send((buf),(count),(datatype),(dest),(tag),(comm)))
     410             : 
     411             : #define MPI_Wait(request,status) \
     412             :   ((petsc_wait_ct++,petsc_sum_of_waits_ct++,0) || MPI_Wait((request),(status)))
     413             : 
     414             : #define MPI_Waitany(a,b,c,d) \
     415             :   ((petsc_wait_any_ct++,petsc_sum_of_waits_ct++,0) || MPI_Waitany((a),(b),(c),(d)))
     416             : 
     417             : #define MPI_Waitall(count,array_of_requests,array_of_statuses) \
     418             :   ((petsc_wait_all_ct++,petsc_sum_of_waits_ct += (PetscLogDouble) (count),0) || MPI_Waitall((count),(array_of_requests),(array_of_statuses)))
     419             : 
     420             : #define MPI_Allreduce(sendbuf,recvbuf,count,datatype,op,comm) \
     421             :   ((petsc_allreduce_ct += PetscMPIParallelComm((comm)),0) || MPI_Allreduce((sendbuf),(recvbuf),(count),(datatype),(op),(comm)))
     422             : 
     423             : #define MPI_Bcast(buffer,count,datatype,root,comm) \
     424             :   ((petsc_allreduce_ct += PetscMPIParallelComm((comm)),0) || MPI_Bcast((buffer),(count),(datatype),(root),(comm)))
     425             : 
     426             : #define MPI_Reduce_scatter_block(sendbuf,recvbuf,recvcount,datatype,op,comm) \
     427             :   ((petsc_allreduce_ct += PetscMPIParallelComm((comm)),0) || MPI_Reduce_scatter_block((sendbuf),(recvbuf),(recvcount),(datatype),(op),(comm)))
     428             : 
     429             : #define MPI_Alltoall(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm) \
     430             :   ((petsc_allreduce_ct += PetscMPIParallelComm((comm)),0) || PetscMPITypeSize((&petsc_send_len),(sendcount),(sendtype)) || MPI_Alltoall((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(comm)))
     431             : 
     432             : #define MPI_Alltoallv(sendbuf,sendcnts,sdispls,sendtype,recvbuf,recvcnts,rdispls,recvtype,comm) \
     433             :   ((petsc_allreduce_ct += PetscMPIParallelComm((comm)),0) || PetscMPITypeSizeComm((comm),(&petsc_send_len),(sendcnts),(sendtype)) || MPI_Alltoallv((sendbuf),(sendcnts),(sdispls),(sendtype),(recvbuf),(recvcnts),(rdispls),(recvtype),(comm)))
     434             : 
     435             : #define MPI_Allgather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,comm) \
     436             :   ((petsc_gather_ct += PetscMPIParallelComm((comm)),0) || MPI_Allgather((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(comm)))
     437             : 
     438             : #define MPI_Allgatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,comm) \
     439             :   ((petsc_gather_ct += PetscMPIParallelComm((comm)),0) || MPI_Allgatherv((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(displs),(recvtype),(comm)))
     440             : 
     441             : #define MPI_Gather(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm) \
     442             :   ((petsc_gather_ct++,0) || PetscMPITypeSize((&petsc_send_len),(sendcount),(sendtype)) || MPI_Gather((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(root),(comm)))
     443             : 
     444             : #define MPI_Gatherv(sendbuf,sendcount,sendtype,recvbuf,recvcount,displs,recvtype,root,comm) \
     445             :   ((petsc_gather_ct++,0) || PetscMPITypeSize((&petsc_send_len),(sendcount),(sendtype)) || MPI_Gatherv((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(displs),(recvtype),(root),(comm)))
     446             : 
     447             : #define MPI_Scatter(sendbuf,sendcount,sendtype,recvbuf,recvcount,recvtype,root,comm) \
     448             :   ((petsc_scatter_ct++,0) || PetscMPITypeSize((&petsc_recv_len),(recvcount),(recvtype)) || MPI_Scatter((sendbuf),(sendcount),(sendtype),(recvbuf),(recvcount),(recvtype),(root),(comm)))
     449             : 
     450             : #define MPI_Scatterv(sendbuf,sendcount,displs,sendtype,recvbuf,recvcount,recvtype,root,comm) \
     451             :   ((petsc_scatter_ct++,0) || PetscMPITypeSize((&petsc_recv_len),(recvcount),(recvtype)) || MPI_Scatterv((sendbuf),(sendcount),(displs),(sendtype),(recvbuf),(recvcount),(recvtype),(root),(comm)))
     452             : 
     453             : #else
     454             : 
     455             : #define MPI_Startall_irecv(count,datatype,number,requests) \
     456             :   ((number) && MPI_Startall((number),(requests)))
     457             : 
     458             : #define MPI_Startall_isend(count,datatype,number,requests) \
     459             :   ((number) && MPI_Startall((number),(requests)))
     460             : 
     461             : #define MPI_Start_isend(count,datatype,requests) \
     462             :   (MPI_Start((requests)))
     463             : 
     464             : #endif /* !__MPIUNI_H && ! PETSC_HAVE_BROKEN_RECURSIVE_MACRO */
     465             : 
     466             : #else  /* ---Logging is turned off --------------------------------------------*/
     467             : 
     468             : #define PetscLogMemory                     PETSC_FALSE
     469             : 
     470             : #define PetscLogFlops(n)                   0
     471             : #define PetscGetFlops(a)                   (*(a) = 0.0,0)
     472             : 
     473             : #define PetscLogStageRegister(a,b)         0
     474             : #define PetscLogStagePush(a)               0
     475             : #define PetscLogStagePop()                 0
     476             : #define PetscLogStageSetActive(a,b)        0
     477             : #define PetscLogStageGetActive(a,b)        0
     478             : #define PetscLogStageGetVisible(a,b)       0
     479             : #define PetscLogStageSetVisible(a,b)       0
     480             : #define PetscLogStageGetId(a,b)            (*(b)=0,0)
     481             : 
     482             : #define PetscLogEventRegister(a,b,c)       0
     483             : #define PetscLogEventSetCollective(a,b)    0
     484             : #define PetscLogEventIncludeClass(a)       0
     485             : #define PetscLogEventExcludeClass(a)       0
     486             : #define PetscLogEventActivate(a)           0
     487             : #define PetscLogEventDeactivate(a)         0
     488             : #define PetscLogEventActivateClass(a)      0
     489             : #define PetscLogEventDeactivateClass(a)    0
     490             : #define PetscLogEventSetActiveAll(a,b)     0
     491             : #define PetscLogEventGetId(a,b)            (*(b)=0,0)
     492             : #define PetscLogEventGetPerfInfo(a,b,c)    0
     493             : #define PetscLogEventSetDof(a,b,c)         0
     494             : #define PetscLogEventSetError(a,b,c)       0
     495             : 
     496             : #define PetscLogPLB                        0
     497             : #define PetscLogPLE                        0
     498             : #define PetscLogPHC                        0
     499             : #define PetscLogPHD                        0
     500             : 
     501             : #define PetscLogObjectParents(p,n,c)       0
     502             : #define PetscLogObjectCreate(h)            0
     503             : #define PetscLogObjectDestroy(h)           0
     504             : PETSC_EXTERN PetscErrorCode PetscLogObjectState(PetscObject,const char[],...);
     505             : 
     506             : #define PetscLogDefaultBegin()             0
     507             : #define PetscLogAllBegin()                 0
     508             : #define PetscLogNestedBegin()              0
     509             : #define PetscLogTraceBegin(file)           0
     510             : #define PetscLogActions(a)                 0
     511             : #define PetscLogObjects(a)                 0
     512             : #define PetscLogSetThreshold(a,b)          0
     513             : #define PetscLogSet(lb,le)                 0
     514             : 
     515             : #define PetscLogView(viewer)               0
     516             : #define PetscLogViewFromOptions()          0
     517             : #define PetscLogDump(c)                    0
     518             : 
     519             : #define PetscLogEventSync(e,comm)          0
     520             : #define PetscLogEventBegin(e,o1,o2,o3,o4)  0
     521             : #define PetscLogEventEnd(e,o1,o2,o3,o4)    0
     522             : 
     523             : /* If PETSC_USE_LOG is NOT defined, these still need to be! */
     524             : #define MPI_Startall_irecv(count,datatype,number,requests) ((number) && MPI_Startall(number,requests))
     525             : #define MPI_Startall_isend(count,datatype,number,requests) ((number) && MPI_Startall(number,requests))
     526             : #define MPI_Start_isend(count,datatype,requests)           MPI_Start(requests)
     527             : 
     528             : #endif   /* PETSC_USE_LOG */
     529             : 
     530             : #define PetscPreLoadBegin(flag,name) \
     531             : do {\
     532             :   PetscBool      PetscPreLoading = flag;\
     533             :   int            PetscPreLoadMax,PetscPreLoadIt;\
     534             :   PetscLogStage  _stageNum;\
     535             :   PetscErrorCode _3_ierr; \
     536             :   _3_ierr = PetscOptionsGetBool(NULL,NULL,"-preload",&PetscPreLoading,NULL);CHKERRQ(_3_ierr); \
     537             :   PetscPreLoadMax = (int)(PetscPreLoading);\
     538             :   PetscPreLoadingUsed = PetscPreLoading ? PETSC_TRUE : PetscPreLoadingUsed;\
     539             :   for (PetscPreLoadIt=0; PetscPreLoadIt<=PetscPreLoadMax; PetscPreLoadIt++) {\
     540             :     PetscPreLoadingOn = PetscPreLoading;\
     541             :     _3_ierr = PetscBarrier(NULL);CHKERRQ(_3_ierr);\
     542             :     if (PetscPreLoadIt>0) {\
     543             :       _3_ierr = PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);\
     544             :     } else {\
     545             :       _3_ierr = PetscLogStageRegister(name,&_stageNum);CHKERRQ(_3_ierr); \
     546             :     }\
     547             :     _3_ierr = PetscLogStageSetActive(_stageNum,(PetscBool)(!PetscPreLoadMax || PetscPreLoadIt));\
     548             :     _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr);
     549             : 
     550             : #define PetscPreLoadEnd() \
     551             :     _3_ierr = PetscLogStagePop();CHKERRQ(_3_ierr);\
     552             :     PetscPreLoading = PETSC_FALSE;\
     553             :   }\
     554             : } while (0)
     555             : 
     556             : #define PetscPreLoadStage(name) do {                                         \
     557             :     _3_ierr = PetscLogStagePop();CHKERRQ(_3_ierr);                      \
     558             :     if (PetscPreLoadIt>0) {                                                  \
     559             :       _3_ierr = PetscLogStageGetId(name,&_stageNum);CHKERRQ(_3_ierr);   \
     560             :     } else {                                                            \
     561             :       _3_ierr = PetscLogStageRegister(name,&_stageNum);CHKERRQ(_3_ierr); \
     562             :     }                                                                   \
     563             :     _3_ierr = PetscLogStageSetActive(_stageNum,(PetscBool)(!PetscPreLoadMax || PetscPreLoadIt)); \
     564             :     _3_ierr = PetscLogStagePush(_stageNum);CHKERRQ(_3_ierr);            \
     565             :   } while (0)
     566             : 
     567             : /* some vars for logging */
     568             : PETSC_EXTERN PetscBool PetscPreLoadingUsed;       /* true if we are or have done preloading */
     569             : PETSC_EXTERN PetscBool PetscPreLoadingOn;         /* true if we are currently in a preloading calculation */
     570             : 
     571             : #endif

Generated by: LCOV version 1.13