Actual source code: ploginfo.c

      1: #define PETSC_DLL
      2: /*
      3:       PetscLogInfo() is contained in a different file from the other profiling to
      4:    allow it to be replaced at link time by an alternative routine.
      5: */
     6:  #include petsc.h
      7: #include <stdarg.h>
      8: #include <sys/types.h>
     9:  #include petscsys.h
     10: #if defined(PETSC_HAVE_STDLIB_H)
     11: #include <stdlib.h>
     12: #endif
     13: #if defined(PETSC_HAVE_MALLOC_H)
     14: #include <malloc.h>
     15: #endif
     16: #include "petscfix.h"

     18: /*
     19:   The next three variables determine which, if any, PetscLogInfo() calls are used.
     20:   If PetscLogPrintInfo is zero, no info messages are printed.
     21:   If PetscLogPrintInfoNull is zero, no info messages associated with a null object are printed.

     23:   If PetscLogInfoFlags[OBJECT_COOKIE - PETSC_COOKIE] is zero, no messages related
     24:   to that object are printed. OBJECT_COOKIE is, for example, MAT_COOKIE.
     25: */
     26: PetscTruth PETSC_DLLEXPORT PetscLogPrintInfo     = PETSC_FALSE;
     27: PetscTruth PETSC_DLLEXPORT PetscLogPrintInfoNull = PETSC_FALSE;
     28: int        PetscLogInfoFlags[]   = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
     29:                                     1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
     30:                                     1,1,1,1,1,1,1,1,1,1,1,1};
     31: FILE      *PetscLogInfoFile      = PETSC_NULL;

     35: /*@C
     36:     PetscLogInfoAllow - Causes PetscLogInfo() messages to be printed to standard output.

     38:     Not Collective, each processor may call this seperately, but printing is only
     39:     turned on if the lowest processor number associated with the PetscObject associated
     40:     with the call to PetscLogInfo() has called this routine.

     42:     Input Parameter:
     43: +   flag - PETSC_TRUE or PETSC_FALSE
     44: -   filename - optional name of file to write output to (defaults to stdout)

     46:     Options Database Key:
     47: .   -log_info [optional filename] - Activates PetscLogInfoAllow()

     49:     Level: advanced

     51:    Concepts: debugging^detailed runtime information
     52:    Concepts: dumping detailed runtime information

     54: .seealso: PetscLogInfo()
     55: @*/
     56: PetscErrorCode PETSC_DLLEXPORT PetscLogInfoAllow(PetscTruth flag, const char filename[])
     57: {
     58:   char           fname[PETSC_MAX_PATH_LEN], tname[5];
     59:   PetscMPIInt    rank;

     63:   if (flag && filename) {
     64:     PetscFixFilename(filename, fname);
     65:     MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
     66:     sprintf(tname, ".%d", rank);
     67:     PetscStrcat(fname, tname);
     68:     PetscFOpen(MPI_COMM_SELF, fname, "w", &PetscLogInfoFile);
     69:     if (!PetscLogInfoFile) SETERRQ1(PETSC_ERR_FILE_OPEN, "Cannot open requested file for writing: %s",fname);
     70:   } else if (flag) {
     71:     PetscLogInfoFile = stdout;
     72:   }
     73:   PetscLogPrintInfo     = flag;
     74:   PetscLogPrintInfoNull = flag;
     75:   return(0);
     76: }

     80: /*@
     81:   PetscLogInfoDeactivateClass - Deactivates PlogInfo() messages for a PETSc object class.

     83:   Not Collective

     85:   Input Parameter:
     86: . objclass - The object class,  e.g., MAT_COOKIE, SNES_COOKIE, etc.

     88:   Notes:
     89:   One can pass 0 to deactivate all messages that are not associated with an object.

     91:   Level: developer

     93: .keywords: allow, information, printing, monitoring
     94: .seealso: PetscLogInfoActivateClass(), PetscLogInfo(), PetscLogInfoAllow()
     95: @*/
     96: PetscErrorCode PETSC_DLLEXPORT PetscLogInfoDeactivateClass(int objclass)
     97: {
     99:   if (!objclass) {
    100:     PetscLogPrintInfoNull = PETSC_FALSE;
    101:     return(0);
    102:   }
    103:   PetscLogInfoFlags[objclass - PETSC_COOKIE - 1] = 0;
    104:   return(0);
    105: }

    109: /*@
    110:   PetscLogInfoActivateClass - Activates PlogInfo() messages for a PETSc object class.

    112:   Not Collective

    114:   Input Parameter:
    115: . objclass - The object class, e.g., MAT_COOKIE, SNES_COOKIE, etc.

    117:   Notes:
    118:   One can pass 0 to activate all messages that are not associated with an object.

    120:   Level: developer

    122: .keywords: allow, information, printing, monitoring
    123: .seealso: PetscLogInfoDeactivateClass(), PetscLogInfo(), PetscLogInfoAllow()
    124: @*/
    125: PetscErrorCode PETSC_DLLEXPORT PetscLogInfoActivateClass(int objclass)
    126: {
    128:   if (!objclass) {
    129:     PetscLogPrintInfoNull = PETSC_TRUE;
    130:   } else {
    131:     PetscLogInfoFlags[objclass - PETSC_COOKIE - 1] = 1;
    132:   }
    133:   return(0);
    134: }

    136: /*
    137:    If the option -log_history was used, then all printed PetscLogInfo()
    138:   messages are also printed to the history file, called by default
    139:   .petschistory in ones home directory.
    140: */

    145: /*@C
    146:     PetscLogInfo - Logs informative data, which is printed to standard output
    147:     or a file when the option -log_info <file> is specified.

    149:     Collective over PetscObject argument

    151:    Synopsis:
    152:        PetscErrorCode PetscLogInfo((void *vobj, const char message[], ...))

    154:     Input Parameter:
    155: +   vobj - object most closely associated with the logging statement
    156: -   message - logging message, using standard "printf" format

    158:     Options Database Key:
    159: $    -log_info : activates printing of PetscLogInfo() messages

    161:     Level: intermediate

    163:     Note: Since this is a macro you must wrap the arguments in TWO sets of (())

    165:     Fortran Note: This routine is not supported in Fortran.

    167:     Example of Usage:
    168: $
    169: $     Mat A
    170: $     double alpha
    171: $     PetscLogInfo((A,"Matrix uses parameter alpha=%g\n",alpha));
    172: $

    174:    Concepts: runtime information

    176: .seealso: PetscLogInfoAllow()
    177: @*/
    178: PetscErrorCode PETSC_DLLEXPORT PetscLogInfo_Private(void *vobj, const char message[], ...)
    179: {
    180:   va_list        Argp;
    181:   PetscMPIInt    rank,urank;
    182:   size_t         len;
    183:   PetscObject    obj = (PetscObject)vobj;
    184:   char           string[8*1024];

    190:   if (!PetscLogPrintInfo) return(0);
    191:   if ((!PetscLogPrintInfoNull) && !vobj) return(0);
    192:   if (obj && !PetscLogInfoFlags[obj->cookie - PETSC_COOKIE - 1]) return(0);
    193:   if (!obj) {
    194:     rank = 0;
    195:   } else {
    196:     MPI_Comm_rank(obj->comm, &rank);
    197:   }
    198:   if (rank) return(0);

    200:   MPI_Comm_rank(MPI_COMM_WORLD, &urank);
    201:   va_start(Argp, message);
    202:   sprintf(string, "[%d]", urank);
    203:   PetscStrlen(string, &len);
    204:   PetscVSNPrintf(string+len, 8*1024-len,message, Argp);
    205:   PetscFPrintf(PETSC_COMM_SELF,PetscLogInfoFile, "%s", string);
    206:   fflush(PetscLogInfoFile);
    207:   if (petsc_history) {
    208:     PetscVFPrintf(petsc_history, message, Argp);
    209:   }
    210:   va_end(Argp);
    211:   return(0);
    212: }