Actual source code: ploginfo.c

  1: /*$Id: ploginfo.c,v 1.22 2001/03/23 23:20:50 balay Exp $*/
  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) && !defined(__cplusplus)
 14: #include <malloc.h>
 15: #endif
 16: #include "petscfix.h"

 18: extern PetscTruth PetscLogPrintInfo,PetscLogPrintInfoNull;
 19: extern int        PetscLogInfoFlags[];
 20: extern FILE       *PetscLogInfoFile;

 22: /*
 23:    If the option -log_history was used, then all printed PetscLogInfo() 
 24:   messages are also printed to the history file, called by default
 25:   .petschistory in ones home directory.
 26: */
 27: extern FILE *petsc_history;

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

 33:     Collective over PetscObject argument

 35:     Input Parameter:
 36: +   vobj - object most closely associated with the logging statement
 37: -   message - logging message, using standard "printf" format

 39:     Options Database Key:
 40: $    -log_info : activates printing of PetscLogInfo() messages 

 42:     Level: intermediate

 44:     Fortran Note:
 45:     This routine is not supported in Fortran.

 47:     Example of Usage:
 48: $
 49: $     Mat A
 50: $     double alpha
 51: $     PetscLogInfo(A,"Matrix uses parameter alpha=%gn",alpha);
 52: $

 54:    Concepts: runtime information

 56: .seealso: PetscLogInfoAllow()
 57: @*/
 58: int PetscLogInfo(void *vobj,const char message[],...)
 59: {
 60:   va_list     Argp;
 61:   int         rank,urank,len,ierr;
 62:   PetscObject obj = (PetscObject)vobj;
 63:   char        string[256];

 67:   if (!PetscLogPrintInfo) return(0);
 68:   if (!PetscLogPrintInfoNull && !vobj) return(0);
 69:   if (obj && !PetscLogInfoFlags[obj->cookie - PETSC_COOKIE - 1]) return(0);
 70:   if (!obj) rank = 0;
 71:   else      {MPI_Comm_rank(obj->comm,&rank);}
 72:   if (rank) return(0);

 74:   MPI_Comm_rank(MPI_COMM_WORLD,&urank);
 75:   va_start(Argp,message);
 76:   sprintf(string,"[%d]",urank);
 77:   PetscStrlen(string,&len);
 78: #if defined(PETSC_HAVE_VPRINTF_CHAR)
 79:   vsprintf(string+len,message,(char *)Argp);
 80: #else
 81:   vsprintf(string+len,message,Argp);
 82: #endif
 83:   fprintf(PetscLogInfoFile,"%s",string);
 84:   fflush(PetscLogInfoFile);
 85:   if (petsc_history) {
 86: #if defined(PETSC_HAVE_VPRINTF_CHAR)
 87:     vfprintf(petsc_history,message,(char *)Argp);
 88: #else
 89:     vfprintf(petsc_history,message,Argp);
 90: #endif
 91:   }
 92:   va_end(Argp);
 93:   return(0);
 94: }