SALSA Analysis Modules
Functions | Variables
tracing.c File Reference

Trace routines for the anamod package. More...

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include "petsc.h"
#include "anamod.h"
Include dependency graph for tracing.c:

Go to the source code of this file.

Functions

PetscErrorCode AnaModDeclareTraceFunction (PetscErrorCode(*fn)(void *, const char *, va_list))
PetscErrorCode AnaModDeclareTraceContext (void *ctx)
PetscErrorCode AnaModSetTraceArrays (PetscBool f)
PetscErrorCode AnaModTraceArrays (PetscBool *f)
PetscErrorCode AnaModTraceMessage (const char *fmt,...)
PetscErrorCode AnaModHasTrace (PetscBool *flg)

Variables

static PetscErrorCode(* anamodtrace )(void *, const char *fmt, va_list) = NULL
static size_t anamodtracectx = (size_t)NULL
static PetscBool anamodtracearrays = PETSC_FALSE

Detailed Description

Trace routines for the anamod package.

Tracing the analysis modules

The AnaMod package does not by default print out anything, other than severe error messages (Petsc macro SETERRQ) that accompany an abort.

However, you can specify a trace function, which can further be tuned by specifying a trace context.

See AnaModDeclareTraceFunction(), AnaModDeclareTraceContext(), AnaModTraceMessage(), AnaModSetTraceArrays(), AnaModTraceArrays().

Definition in file tracing.c.


Function Documentation

PetscErrorCode AnaModDeclareTraceContext ( void *  ctx)

Definition at line 69 of file tracing.c.

References anamodtracectx.

{
  PetscFunctionBegin;
  anamodtracectx = (size_t)ctx;
  PetscFunctionReturn(0);
}
PetscErrorCode AnaModDeclareTraceFunction ( PetscErrorCode(*)(void *, const char *, va_list)  fn)

Specify a trace function.

The trace function has a prototype

  PetscErrorCode tracefunction(void*,char*,va_list)

which means that it has an arbitrary number of arguments, much like printf. The first argument is a context, which can be set by AnaModDeclareTraceContext().

Here is an example of how you would write a trace function:

#include <stdarg.h>
PetscErrorCode tracefunction(void *ctx,char *fmt,va_list argp)
{
  char *prefix = (char*)ctx;
  PetscFunctionBegin;
  printf("%s ",prefix);
  vprintf(fmt, argp);
  PetscFunctionReturn(0);
}

Consult string.h (probably in /usr/include) to see which "v" versions of printf are available.

You can undeclare a trace function by passing NULL.

Definition at line 56 of file tracing.c.

References anamodtrace.

{
  PetscFunctionBegin;
  anamodtrace = fn;
  PetscFunctionReturn(0);
}
PetscErrorCode AnaModHasTrace ( PetscBool *  flg)

Test whether a trace function has been declared; see AnaModDeclareTraceFunction(). Normally you would use AnaModTraceMessage() which performs this test internally, but this function can be useful if a large amount of processing has to be performed to construct the trace message to begin with.

Definition at line 127 of file tracing.c.

References anamodtrace.

Referenced by ComputeOrRetrieveQuantity().

{
  PetscFunctionBegin;
  if (anamodtrace)
    *flg = PETSC_TRUE;
  else
    *flg = PETSC_FALSE;
  PetscFunctionReturn(0);
}
PetscErrorCode AnaModSetTraceArrays ( PetscBool  f)

Definition at line 82 of file tracing.c.

References anamodtracearrays.

{
  PetscFunctionBegin;
  anamodtracearrays = f;
  PetscFunctionReturn(0);
}
PetscErrorCode AnaModTraceArrays ( PetscBool *  f)

Definition at line 95 of file tracing.c.

References anamodtracearrays.

Referenced by ComputeOrRetrieveQuantity(), and ReportAnamodContent().

{
  PetscFunctionBegin;
  *f = anamodtracearrays;
  PetscFunctionReturn(0);
}
PetscErrorCode AnaModTraceMessage ( const char *  fmt,
  ... 
)

This function prints a trace message if a trace function has been declared; see AnaModDeclareTraceFunction().

Definition at line 107 of file tracing.c.

References anamodtrace, and anamodtracectx.

Referenced by compute_eigenvalues_petsc(), and ComputeOrRetrieveQuantity().

{
  va_list argp; PetscErrorCode ierr;
  PetscFunctionBegin;
  if (anamodtrace) {
    va_start(argp, fmt);
    ierr = (*anamodtrace)((void*)anamodtracectx,(char*)fmt,argp); CHKERRQ(ierr);
    va_end(argp);
  }
  PetscFunctionReturn(0);
}

Variable Documentation

PetscErrorCode(* anamodtrace)(void *, const char *fmt, va_list) = NULL [static]

Definition at line 23 of file tracing.c.

Referenced by AnaModDeclareTraceFunction(), AnaModHasTrace(), and AnaModTraceMessage().

PetscBool anamodtracearrays = PETSC_FALSE [static]

Definition at line 25 of file tracing.c.

Referenced by AnaModSetTraceArrays(), and AnaModTraceArrays().

size_t anamodtracectx = (size_t)NULL [static]

Definition at line 24 of file tracing.c.

Referenced by AnaModDeclareTraceContext(), and AnaModTraceMessage().