module_functions.c File Reference

User functions for accessing the analysis modules. More...

#include <stdlib.h>
#include <string.h>
#include "anamod.h"
#include "anamodsalsamodules.h"
#include "petscmat.h"

Include dependency graph for module_functions.c:

Go to the source code of this file.

Defines

#define MXC   30
#define INC   7
#define TYPEii(icat, icmp)   types[icat][icmp]

Functions

PetscErrorCode AnaModInitialize ()
PetscErrorCode AnaModFinalize ()
PetscErrorCode AnaModGetTypeName (int id, char **name)
PetscErrorCode AnaModGetTypeMySQLName (int id, char **name)
PetscErrorCode RegisterModule (const char *cat, const char *cmp, AnalysisDataType type, PetscErrorCode(*f)(AnaModNumericalProblem, AnalysisItem *, int *, PetscTruth *))
PetscErrorCode DeRegisterCategory (char *cat)
PetscErrorCode DeregisterModules ()
PetscErrorCode GetCategories (char ***cats, int *n)
PetscErrorCode CategoryGetModules (char *cat, char ***ms, AnalysisDataType **t, int **id, int *n)
static PetscErrorCode GetCategoryIndex (char *cat, int *idx, PetscTruth *f)
static PetscErrorCode GetModuleIndex (int icat, char *cmp, int *idx, PetscTruth *f)
PetscErrorCode HasComputeCategory (char *cat, PetscTruth *f)
PetscErrorCode HasComputeModule (char *cat, char *cmp, PetscTruth *f)
PetscErrorCode DeclareCategoryOptionFunction (char *cat, PetscErrorCode(*f)(char *))
PetscErrorCode GetCategoryOptionFunction (char *cat, PetscErrorCode(**f)(char *))
PetscErrorCode ComputeQuantity (AnaModNumericalProblem prob, const char *cat, const char *cmp, AnalysisItem *res, int *rreslen, PetscTruth *success)
PetscErrorCode RetrieveQuantity (AnaModNumericalProblem prob, char *cat, char *cmp, AnalysisItem *res, PetscTruth *success)
PetscErrorCode HasQuantity (AnaModNumericalProblem prob, char *cat, char *cmp, PetscTruth *f)
PetscErrorCode HasQuantityByID (AnaModNumericalProblem prob, int id, AnalysisDataType type, PetscTruth *f)
PetscErrorCode RetrieveQuantityByID (AnaModNumericalProblem prob, int icat, int icmp, AnalysisItem *result, PetscTruth *f)
PetscErrorCode QuantityAsString (AnalysisItem *q, AnalysisDataType t, char **s)
PetscErrorCode GetDataID (const char *cat, const char *cmp, int *id, PetscTruth *flg)
PetscErrorCode GetDataType (const char *cat, const char *cmp, AnalysisDataType *t)

Variables

static int ncategories = 0
static int maxcategories = 30
static int * ncomponents = NULL
static int * maxcomponents = NULL
static PetscErrorCode(*** modules )(AnaModNumericalProblem, AnalysisItem *, int *, PetscTruth *) = NULL
static PetscErrorCode(** optionfunctions )(char *) = NULL
static PetscTruth ** hasval = NULL
static int ** ids = NULL
static char ** categories = NULL
static char *** components = NULL
static AnalysisDataType ** types = NULL
struct {
   int   id
   const char *   name
   const char *   mysqlname
anamodtypenames [5]
static int nAnaModTypeNames
static int AnaModIsInitialized = 0


Detailed Description

User functions for accessing the analysis modules.

\ Analysis modules need to be defined with RegisterModule(), after which they can be invoked with ComputeQuantity(). See also HasQuantity(). The functions AnaModRegisterStandardModules() installs all standard available modules.

There are utility functions for querying the existence of modules: GetCategories(), CategoryGetModules(), HasComputeCategory(), HasComputeModule().

Utility functions: QuantityAsString(), GetDataType(), GetDataID(), GetCategoryIndex(), GetModuleIndex().

Definition in file module_functions.c.


Define Documentation

#define INC   7

Definition at line 304 of file module_functions.c.

Referenced by RegisterModule().

#define MXC   30

Definition at line 303 of file module_functions.c.

Referenced by RegisterModule().

#define TYPEii ( icat,
icmp   )     types[icat][icmp]


Function Documentation

PetscErrorCode AnaModFinalize (  ) 

Definition at line 348 of file module_functions.c.

Referenced by main().

00349 {
00350   PetscFunctionBegin;
00351   PetscFunctionReturn(0);
00352 }

PetscErrorCode AnaModGetTypeMySQLName ( int  id,
char **  name 
)

Definition at line 372 of file module_functions.c.

References AnaModIsInitialized, anamodtypenames, mysqlname, and nAnaModTypeNames.

Referenced by main().

00373 {
00374   int i;
00375   PetscFunctionBegin;
00376   if (AnaModIsInitialized<1) 
00377     SETERRQ(1,"AnaMod has not been not formally initialized.\nInsert a call to AnaModInitialize() in your code");
00378   for (i=0; i<nAnaModTypeNames; i++) {
00379     if (id==anamodtypenames[i].id) {
00380       *name = (char*)anamodtypenames[i].mysqlname; goto exit;
00381     }
00382   }
00383   SETERRQ1(1,"Unknown AnaMod datatype %d",id);
00384  exit:
00385   PetscFunctionReturn(0);
00386 }

PetscErrorCode AnaModGetTypeName ( int  id,
char **  name 
)

Definition at line 356 of file module_functions.c.

References anamodtypenames, and nAnaModTypeNames.

00357 {
00358   int i;
00359   PetscFunctionBegin;
00360   for (i=0; i<nAnaModTypeNames; i++) {
00361     if (id==anamodtypenames[i].id) {
00362       *name = (char*)anamodtypenames[i].name; goto exit;
00363     }
00364   }
00365   SETERRQ1(1,"Unknown AnaMod datatype %d",id);
00366  exit:
00367   PetscFunctionReturn(0);
00368 }

PetscErrorCode AnaModInitialize (  ) 

Definition at line 319 of file module_functions.c.

References AnaModIsInitialized, anamodtypenames, and nAnaModTypeNames.

Referenced by main().

00320 {
00321   PetscFunctionBegin;
00322   anamodtypenames[0].id = NMDString;
00323   anamodtypenames[0].name="string"; 
00324   anamodtypenames[0].mysqlname="VARCHAR(256)";
00325 
00326   anamodtypenames[1].id = NMDInt;
00327   anamodtypenames[1].name="int"; 
00328   anamodtypenames[1].mysqlname="INTEGER";
00329 
00330   anamodtypenames[2].id = NMDReal;
00331   anamodtypenames[2].name="real"; 
00332   anamodtypenames[2].mysqlname="DOUBLE";
00333 
00334   anamodtypenames[3].id = NMDIntarray;
00335   anamodtypenames[3].name="intarray"; 
00336   anamodtypenames[3].mysqlname="VARCHAR(1024)";
00337 
00338   anamodtypenames[4].id = NMDRealarray;
00339   anamodtypenames[4].name="realarray";
00340   anamodtypenames[4].mysqlname="VARCHAR(1024)";
00341 
00342   AnaModIsInitialized = 1; nAnaModTypeNames = 5;
00343   PetscFunctionReturn(0);
00344 }

PetscErrorCode CategoryGetModules ( char *  cat,
char ***  ms,
AnalysisDataType **  t,
int **  id,
int *  n 
)

Query the modules in a specified category.

The category name has to exist. The routine will call the Petsc error handler if the name is invalid.

Parameters:

  • cat : the category that is being queried
  • ms (optional) : the names of the modules in the category
  • t (optional) : the corresponding list of datatypes
  • id (optional) : the list of module IDs (see RetrieveQuantityByID())
  • n (optional) : the number of modules in the category

See also GetCategories() and HasComputeCategory().

Definition at line 711 of file module_functions.c.

References categories, components, ids, ncategories, ncomponents, and types.

Referenced by analyze_matrix(), main(), and ReportAnamodContent().

00712 {
00713   int i; PetscErrorCode ierr;
00714   PetscFunctionBegin;
00715   *ms = NULL; *n = 0;
00716   for (i=0; i<ncategories; i++) {
00717     PetscTruth flg;
00718     ierr = PetscStrcmp(cat,categories[i],&flg); CHKERRQ(ierr);
00719     if (flg) {
00720       if (ms) *ms = components[i];
00721       if (t)  *t  = types[i];
00722       if (id) *id = ids[i];
00723       if (n)  *n  = ncomponents[i];
00724       PetscFunctionReturn(0);
00725     }
00726   }
00727   SETERRQ1(1,"Unknown category <%s>\n",cat);
00728 }

PetscErrorCode ComputeQuantity ( AnaModNumericalProblem  prob,
const char *  cat,
const char *  cmp,
AnalysisItem res,
int *  rreslen,
PetscTruth *  success 
)

Compute a computational module from a certain category.

Argument:

  1. the name of the category (see GetCategories())
  2. the name of the module (see CategoryGetModules())
  3. the matrix
  4. a pointer to the result. This is given as "(AnalysisItem*)&res" ; see types for the definition of the AnalysisItem data type
  5. the length of the result if the result is an array. This argument can be NULL.
  6. a success indicator. Failure can have obvious causes, such as breakdown of an internal routine, but the routine can also refuse to compute a quantity if doing so would be too expensive (see an example in the Estimates for the departure from normality category).

A call to this routine need not involve actual computation: the requested quantity can already be attached to the matrix object (see attached quantities for details). This mechanism is used in all the standard modules that come with the AnaMod package.

The workings of this function can be traced by specifying a trace function; see Tracing the analysis modules.

Definition at line 866 of file module_functions.c.

References ANALYSISINTARRAY, AnaModHasTrace(), AnaModTraceArrays(), AnaModTraceMessage(), GetCategoryIndex(), GetModuleIndex(), hasval, modules, QuantityAsString(), TYPEii, and types.

Referenced by analyze_matrix(), DepartureRuhe75(), LoBand(), MatrixComputeQuantity(), MaxEVbyImIm(), MaxEVbyImRe(), MaxEVbyMagIm(), MaxEVbyMagRe(), MaxEVbyRealIm(), MaxEVbyRealRe(), MinEVbyMagIm(), MinEVbyMagRe(), RelSymm(), and UpBand().

00868 {
00869   PetscTruth flg,trace;
00870   int icat,icmp,reslen; PetscErrorCode ierr;
00871   
00872   PetscFunctionBegin;
00873 
00874   /*
00875    * Get the location of the module for this quantity
00876    */
00877   ierr = GetCategoryIndex((char*)cat,&icat,&flg); CHKERRQ(ierr);
00878   if (!flg)
00879     SETERRQ1(1,"Could not find category <%s>",cat);
00880   ierr = GetModuleIndex(icat,(char*)cmp,&icmp,&flg); CHKERRQ(ierr);
00881   if (!flg)
00882     SETERRQ2(1,"Could not find module <%s:%s>",cat,cmp);
00883 
00884   /*
00885    * Compute
00886    */
00887   if (modules[icat][icmp]) {
00888     ierr = (modules[icat][icmp])(prob,res,&reslen,&flg); CHKERRQ(ierr);
00889   } else flg = PETSC_FALSE;
00890 
00891   hasval[icat][icmp] = flg;
00892 
00893   if (!flg) goto nosuccess;
00894   /*
00895    * Tracing
00896    */
00897   ierr = AnaModHasTrace(&trace); CHKERRQ(ierr);
00898   if (trace) {
00899     if (flg) {
00900       char *string; PetscTruth trace_arrays;
00901       AnalysisDataType t = TYPEii(icat,icmp);
00902 
00903       ierr = AnaModTraceArrays(&trace_arrays); CHKERRQ(ierr);
00904       if (t<ANALYSISINTARRAY || trace_arrays) {
00905         ierr = QuantityAsString
00906           (res,types[icat][icmp],&string); CHKERRQ(ierr);
00907         ierr = AnaModTraceMessage
00908           ("Anamod computed <%s:%s> = <%s>\n",cat,cmp,string); CHKERRQ(ierr);
00909         ierr = PetscFree(string); CHKERRQ(ierr);
00910       }
00911     } else {
00912       ierr = AnaModTraceMessage
00913         ("Anamod failed to compute <%s:%s>\n",cat,cmp); CHKERRQ(ierr);
00914     }
00915   }
00916 
00917   if (rreslen) *rreslen = reslen;
00918  nosuccess:
00919   if (success) *success = flg;
00920 
00921   PetscFunctionReturn(0);
00922 }

Here is the call graph for this function:

PetscErrorCode DeclareCategoryOptionFunction ( char *  cat,
PetscErrorCode(*)(char *)  f 
)

This function allows the module developer to give the user commandline options for control of a module.

See DeclareCategoryOptionFunction(),GetCategoryOptionFunction(), AnaModOptionsHandling() and section Commandline Options for Runtime Control.

Definition at line 807 of file module_functions.c.

References GetCategoryIndex(), and optionfunctions.

Referenced by RegisterSpectrumModules().

00808 {
00809   PetscTruth flg; int icat; PetscErrorCode ierr;
00810   PetscFunctionBegin;
00811   ierr = GetCategoryIndex(cat,&icat,&flg); CHKERRQ(ierr);
00812   if (flg) {
00813     optionfunctions[icat] = f;
00814   }
00815   PetscFunctionReturn(0);
00816 }

Here is the call graph for this function:

PetscErrorCode DeRegisterCategory ( char *  cat  ) 

Deallocate the storage for a particular category of analysis modules

Definition at line 612 of file module_functions.c.

References categories, components, hasval, ids, modules, ncategories, ncomponents, and types.

Referenced by DeregisterModules().

00613 {
00614   PetscTruth flg; int icat,i; PetscErrorCode ierr;
00615   PetscFunctionBegin;
00616 
00617   flg = PETSC_FALSE;
00618   for (i=0; i<ncategories && !flg; i++) {
00619     ierr = PetscStrcmp(cat,categories[i],&flg); CHKERRQ(ierr);
00620     if (flg) {
00621       icat = i; goto found;
00622     }
00623   }
00624   SETERRQ(1,"Trying to deregister unknown category");
00625  found:
00626 
00627   for (i=0; i<ncomponents[icat]; i++) {
00628     ierr = PetscFree(components[icat][i]); CHKERRQ(ierr);
00629   }
00630   ierr = PetscFree(categories[icat]); CHKERRQ(ierr);
00631   ierr = PetscFree(components[icat]); CHKERRQ(ierr);
00632   ierr = PetscFree(modules[icat]); CHKERRQ(ierr);
00633   ierr = PetscFree(types[icat]); CHKERRQ(ierr);
00634   ierr = PetscFree(hasval[icat]); CHKERRQ(ierr);
00635   ierr = PetscFree(ids[icat]); CHKERRQ(ierr);
00636 
00637   PetscFunctionReturn(0);
00638 }

PetscErrorCode DeregisterModules ( void   ) 

Definition at line 642 of file module_functions.c.

References categories, components, DeRegisterCategory(), GetCategories(), hasval, ids, maxcomponents, modules, ncategories, ncomponents, optionfunctions, and types.

00643 {
00644   int icat,ncat; char **cat;
00645   PetscErrorCode ierr;
00646   PetscFunctionBegin;
00647 
00648   /*  ierr = DeregisterSpectrumModules(); CHKERRQ(ierr); */
00649 
00650   ierr = GetCategories(&cat,&ncat); CHKERRQ(ierr);
00651   for (icat=0; icat<ncat; icat++) {
00652     ierr = DeRegisterCategory(cat[icat]); CHKERRQ(ierr);
00653   }
00654   ierr = PetscFree(categories); CHKERRQ(ierr);
00655   ncategories = 0; /* inelegant */
00656   ierr = PetscFree(maxcomponents); CHKERRQ(ierr);
00657   ierr = PetscFree(ncomponents); CHKERRQ(ierr);
00658   ierr = PetscFree(components); CHKERRQ(ierr);
00659   ierr = PetscFree(types); CHKERRQ(ierr);
00660   ierr = PetscFree(modules); CHKERRQ(ierr);
00661   ierr = PetscFree(optionfunctions); CHKERRQ(ierr);
00662   ierr = PetscFree(hasval); CHKERRQ(ierr);
00663   ierr = PetscFree(ids); CHKERRQ(ierr);
00664   PetscFunctionReturn(0);
00665 }

Here is the call graph for this function:

PetscErrorCode GetCategories ( char ***  cats,
int *  n 
)

Query the number of defined categories and their names.

Parameters:

  • cats (optional) output: list of category names
  • n output: number of currently installed categories

See also CategoryGetModules().

Definition at line 687 of file module_functions.c.

References categories, and ncategories.

Referenced by analyze_matrix(), AnaModOptionsHandling(), AnaModShowOptions(), DeregisterModules(), main(), and ReportAnamodContent().

00688 {
00689   PetscFunctionBegin;
00690   *n = ncategories; if (cats) *cats = categories;
00691   PetscFunctionReturn(0);
00692 }

static PetscErrorCode GetCategoryIndex ( char *  cat,
int *  idx,
PetscTruth *  f 
) [static]

Get the index of a stated category. Internal routine.

Definition at line 733 of file module_functions.c.

References categories, and ncategories.

Referenced by ComputeQuantity(), DeclareCategoryOptionFunction(), GetCategoryOptionFunction(), GetDataID(), GetDataType(), HasComputeCategory(), HasComputeModule(), and RetrieveQuantity().

00734 {
00735   PetscTruth flg; int i; PetscErrorCode ierr;
00736   PetscFunctionBegin;
00737 
00738   flg = PETSC_FALSE;
00739   for (i=0; i<ncategories; i++) {
00740     ierr = PetscStrcmp(cat,categories[i],&flg); CHKERRQ(ierr);
00741     if (flg) {
00742       *idx = i; break;
00743     }
00744   }
00745   *f = flg;
00746 
00747   PetscFunctionReturn(0);
00748 }

PetscErrorCode GetCategoryOptionFunction ( char *  cat,
PetscErrorCode(**)(char *)  f 
)

This function is called in AnaModOptionsHandling(). There is probably no reason for the user ever to call it.

See DeclareCategoryOptionFunction(),GetCategoryOptionFunction(), AnaModOptionsHandling() and section Commandline Options for Runtime Control.

Definition at line 827 of file module_functions.c.

References GetCategoryIndex(), and optionfunctions.

Referenced by AnaModOptionsHandling().

00828 {
00829   PetscTruth flg; int icat; PetscErrorCode ierr;
00830   PetscFunctionBegin;
00831   ierr = GetCategoryIndex(cat,&icat,&flg); CHKERRQ(ierr);
00832   if (flg) {
00833     *f = optionfunctions[icat];
00834   } else *f = NULL;
00835   PetscFunctionReturn(0);
00836 }

Here is the call graph for this function:

PetscErrorCode GetDataID ( const char *  cat,
const char *  cmp,
int *  id,
PetscTruth *  flg 
)

Get the numerical id under which a module is stored.

The flag parameter returns false if the category or cat/cmp does not exist. The flag parameter is optional, but the routine will exit if the cat/cmp is not found and the flag parameter is not provided.

This is not a user level function.

Definition at line 1164 of file module_functions.c.

References GetCategoryIndex(), GetModuleIndex(), and ids.

Referenced by AvgDiagDist(), AvgDistFromDiag(), AvgNnzpRow(), BlockSize(), ColourOffsets(), Colours(), ColourSizes(), ColVariability(), Commutator(), compute_dd(), compute_dummy_rows(), compute_eigenvalues(), compute_ellipse_from_Ritz_values(), compute_icm_splits(), compute_nnz_structure(), compute_posdiag(), compute_singularvalues(), compute_tracea2(), ComputeDiagonal(), computennz(), computetrace(), ComputeVariability(), Departure(), DepartureLee95(), DepartureLee96L(), DepartureLee96U(), DepartureRuhe75(), DiagDefinite(), DiagonalAverage(), DiagonalDominance(), DiagonalSign(), DiagonalVariance(), DiagZeroStart(), DummyRows(), DummyRowsKind(), eigenvaluecomp(), HasQuantity(), JonesPlassmannColouring(), Kappa(), LBandWidth(), Lee95bounds(), Lee96bounds(), LeftSkyline(), LoBand(), MatCommutatorNormF(), MatSymmPartNormInf(), MaxEVbyImIm(), MaxEVbyImRe(), MaxEVbyMagIm(), MaxEVbyMagRe(), MaxEVbyRealIm(), MaxEVbyRealRe(), MaxNNonZerosPerRow(), MinEVbyMagIm(), MinEVbyMagRe(), MinNNonZerosPerRow(), NColours(), NDiags(), NDummyRows(), NNonZeros(), Nnz(), NnzDia(), NnzLow(), NnzUp(), norm1(), normF(), normInf(), NRitzValues(), nRows(), NSplits(), NUnstruct(), PosFraction(), RBandWidth(), regularblocks(), RelSymm(), RightSkyline(), RitzValuesC(), RitzValuesR(), RowVariability(), SigmaDiagDist(), SigmaMax(), SigmaMin(), SpectrumAX(), SpectrumAY(), SpectrumCX(), SpectrumCY(), Splits(), Symmetry(), SymmetryANorm(), SymmetryFANorm(), SymmetryFSNorm(), SymmetrySNorm(), Trace(), TraceA2(), TraceAbs(), UpBand(), and Version().

01165 {
01166   PetscTruth f; int icat,icmp; PetscErrorCode ierr;
01167   PetscFunctionBegin;
01168   ierr = GetCategoryIndex((char*)cat,&icat,&f); CHKERRQ(ierr);
01169   if (!f) {
01170     goto out;
01171   }
01172   ierr = GetModuleIndex(icat,(char*)cmp,&icmp,&f); CHKERRQ(ierr);
01173   if (!f) {
01174     goto out;
01175   }
01176   *id = ids[icat][icmp];
01177  out:
01178   if (flg)
01179     *flg = f;
01180   else if (!f)
01181     SETERRQ2(1,"cat/cmp <%s;%s> not found, but no flag give to report this",
01182              cat,cmp);
01183   PetscFunctionReturn(0);
01184 }

Here is the call graph for this function:

PetscErrorCode GetDataType ( const char *  cat,
const char *  cmp,
AnalysisDataType t 
)

Retrieve the AnalysisDataType of a computational module

Definition at line 1191 of file module_functions.c.

References GetCategoryIndex(), GetModuleIndex(), and TYPEii.

Referenced by analyze_matrix(), and HasQuantity().

01192 {
01193   PetscTruth flg; int icat,icmp; PetscErrorCode ierr;
01194   PetscFunctionBegin;
01195   ierr = GetCategoryIndex((char*)cat,&icat,&flg); CHKERRQ(ierr);
01196   if (!flg) 
01197     SETERRQ(1,"Could not find category");
01198   ierr = GetModuleIndex(icat,(char*)cmp,&icmp,&flg); CHKERRQ(ierr);
01199   if (!flg) 
01200     SETERRQ(1,"Could not find module");
01201   *t = TYPEii(icat,icmp);
01202   PetscFunctionReturn(0);
01203 }

Here is the call graph for this function:

static PetscErrorCode GetModuleIndex ( int  icat,
char *  cmp,
int *  idx,
PetscTruth *  f 
) [static]

Get the index of a stated module inside a category. Internal routine.

Definition at line 753 of file module_functions.c.

References components, and ncomponents.

Referenced by ComputeQuantity(), GetDataID(), GetDataType(), HasComputeModule(), and RetrieveQuantity().

00754 {
00755   PetscTruth flg; int i; PetscErrorCode ierr;
00756   PetscFunctionBegin;
00757 
00758   flg = PETSC_FALSE;
00759   for (i=0; i<ncomponents[icat]; i++) {
00760     ierr = PetscStrcmp(cmp,components[icat][i],&flg); CHKERRQ(ierr);
00761     if (flg) {
00762       *idx = i; break;
00763     }
00764   }
00765   *f = flg;
00766 
00767   PetscFunctionReturn(0);
00768 }

PetscErrorCode HasComputeCategory ( char *  cat,
PetscTruth *  f 
)

Query whether a specified category has been declared.

Definition at line 773 of file module_functions.c.

References GetCategoryIndex().

00774 {
00775   int icat; PetscErrorCode ierr;
00776   PetscFunctionBegin;
00777   ierr = GetCategoryIndex(cat,&icat,f); CHKERRQ(ierr);
00778   PetscFunctionReturn(0);
00779 }

Here is the call graph for this function:

PetscErrorCode HasComputeModule ( char *  cat,
char *  cmp,
PetscTruth *  f 
)

Query whether a specified module exists inside a specified category. The category need not itself have been declared.

Definition at line 787 of file module_functions.c.

References GetCategoryIndex(), and GetModuleIndex().

Referenced by LoBand(), and UpBand().

00788 {
00789   int icat,icmp; PetscErrorCode ierr;
00790   PetscFunctionBegin;
00791   ierr = GetCategoryIndex(cat,&icat,f); CHKERRQ(ierr);
00792   if (*f) {
00793     ierr = GetModuleIndex(icat,cmp,&icmp,f); CHKERRQ(ierr);
00794   }
00795   PetscFunctionReturn(0);
00796 }

Here is the call graph for this function:

PetscErrorCode HasQuantity ( AnaModNumericalProblem  prob,
char *  cat,
char *  cmp,
PetscTruth *  f 
)

Check if a certain quantity is precomputed, meaning that it can be retrieved (with a call to ComputeQuantity()) at no computational cost.

The category and module names have to exist. The routine will call the Petsc error handler if either name is invalid. Use HasComputeModule() to test whether a category and module is known to the system.

See the page on attached quantities for an explanation of the mechanism behind this routine.

Definition at line 1017 of file module_functions.c.

References GetDataID(), GetDataType(), and HasQuantityByID().

Referenced by computennz().

01018 {
01019   AnalysisDataType t; int id; PetscErrorCode ierr;
01020   PetscFunctionBegin;
01021   ierr = GetDataID(cat,cmp,&id,f); CHKERRQ(ierr);
01022   if (!*f)
01023     SETERRQ2(1,">>>> Warning: undeclared module <%s:%s>\n",cat,cmp);
01024   ierr = GetDataType(cat,cmp,&t); CHKERRQ(ierr);
01025   ierr = HasQuantityByID(prob,id,t,f); CHKERRQ(ierr);
01026   PetscFunctionReturn(0);
01027 }

Here is the call graph for this function:

PetscErrorCode HasQuantityByID ( AnaModNumericalProblem  prob,
int  id,
AnalysisDataType  type,
PetscTruth *  f 
)

Auxiliary routine with lookup by ID, which is much faster than by string indexing.

Definition at line 1035 of file module_functions.c.

References ANALYSISDBLARRAY, ANALYSISDOUBLE, ANALYSISINTARRAY, and ANALYSISINTEGER.

Referenced by HasQuantity().

01036 {
01037   Mat A = (Mat)prob; PetscReal rv,*rsv; int iv,*isv;
01038   PetscErrorCode ierr;
01039   PetscFunctionBegin;
01040   switch (type) {
01041   case ANALYSISINTEGER :
01042     ierr = PetscObjectComposedDataGetInt
01043       ((PetscObject)A,id,iv,*f); CHKERRQ(ierr);
01044     break;
01045   case ANALYSISDOUBLE :
01046     ierr = PetscObjectComposedDataGetReal
01047       ((PetscObject)A,id,rv,*f); CHKERRQ(ierr);
01048     break;
01049   case ANALYSISINTARRAY :
01050     ierr = PetscObjectComposedDataGetIntstar
01051       ((PetscObject)A,id,isv,*f); CHKERRQ(ierr);
01052     break;
01053   case ANALYSISDBLARRAY :
01054     ierr = PetscObjectComposedDataGetRealstar
01055       ((PetscObject)A,id,rsv,*f); CHKERRQ(ierr);
01056     break;
01057   default : SETERRQ1(1,"Unknown data type %d",type);
01058   }
01059   PetscFunctionReturn(0);
01060 }

PetscErrorCode QuantityAsString ( AnalysisItem q,
AnalysisDataType  t,
char **  s 
)

Generate a character string for a given quantity.

Definition at line 1101 of file module_functions.c.

References ANALYSISDBLARRAY, ANALYSISDOUBLE, ANALYSISINTARRAY, ANALYSISINTEGER, ANALYSISSTRING, AnalysisItem::c, AnalysisItem::i, AnalysisItem::ii, AnalysisItem::len, AnalysisItem::r, and AnalysisItem::rr.

Referenced by ComputeQuantity(), ReportAnamodContent(), and RetrieveQuantity().

01102 {
01103   PetscErrorCode ierr; size_t l;
01104 
01105   PetscFunctionBegin;
01106   switch (t) {
01107   case ANALYSISINTEGER : 
01108     ierr = PetscMalloc(12*sizeof(char),s); CHKERRQ(ierr);
01109     ierr = PetscMemzero(*s,12*sizeof(char)); CHKERRQ(ierr);
01110     sprintf(*s,"%d",q->i);
01111     break;
01112   case ANALYSISDOUBLE : 
01113     ierr = PetscMalloc(22*sizeof(char),s); CHKERRQ(ierr);
01114     ierr = PetscMemzero(*s,22*sizeof(char)); CHKERRQ(ierr);
01115     sprintf(*s,"%e",q->r);
01116     break;
01117   case ANALYSISSTRING :
01118     ierr = PetscMalloc((strlen(q->c)+1)*sizeof(char),s); CHKERRQ(ierr);
01119     ierr = PetscMemzero(*s,(strlen(q->c)+1)*sizeof(char)); CHKERRQ(ierr);
01120     sprintf(*s,"%s",q->c);
01121     break;
01122   case ANALYSISINTARRAY :
01123     {
01124       int i,n,*iar;
01125       iar = q->ii;
01126       n = q->len;
01127       ierr = PetscMalloc((10*n+1)*sizeof(char),s); CHKERRQ(ierr);
01128       ierr = PetscMemzero(*s,(10*n+1)*sizeof(char)); CHKERRQ(ierr);
01129       for (i=0; i<=n; i++) {
01130         ierr = PetscStrlen(*s,&l); CHKERRQ(ierr);
01131         sprintf(*s+l,"%d,",iar[i]);
01132       }
01133     }
01134     break;
01135   case ANALYSISDBLARRAY :
01136     {
01137       int i,n; PetscReal *rar; 
01138       rar = q->rr;
01139       n = q->len;
01140       ierr = PetscMalloc((15*n+1)*sizeof(char),s); CHKERRQ(ierr);
01141       ierr = PetscMemzero(*s,(15*n+1)*sizeof(char)); CHKERRQ(ierr);
01142       for (i=0; i<=n; i++) {
01143         ierr = PetscStrlen(*s,&l); CHKERRQ(ierr);
01144         sprintf(*s+l,"%e,",rar[i]);
01145       }
01146     }
01147     break;
01148   default : SETERRQ1(1,"Cannot string quantity type %d",t);
01149   }
01150   PetscFunctionReturn(0);
01151 }

PetscErrorCode RegisterModule ( const char *  cat,
const char *  cmp,
AnalysisDataType  type,
PetscErrorCode(*)(AnaModNumericalProblem, AnalysisItem *, int *, PetscTruth *)  f 
)

Register a new computational module

This adds a computational routine (the f argument) into the modules database under the given category (cat) and module (cmp) label. If the category does not exist yet, it is created.

The available types are defined in anamodtypes.h

If the routine is NULL, only the category and component are created.

Routine prototype:

  • problem (input)
  • item (output)
  • array length (output)
  • success (output)

See also HasComputeModule(), ComputeQuantity(), DeregisterModules().

Definition at line 410 of file module_functions.c.

References categories, components, hasval, id, ids, INC, maxcategories, maxcomponents, modules, MXC, ncategories, ncomponents, optionfunctions, and types.

Referenced by RegisterICMKModules(), RegisterIprsModules(), RegisterJPLModules(), RegisterLapackModules(), RegisterNormalityModules(), RegisterSimpleModules(), RegisterSpectrumModules(), RegisterStatsModules(), RegisterStructureModules(), and RegisterVarianceModules().

00412 {
00413   PetscTruth flg; int i,icmp,icat,id; PetscErrorCode ierr;
00414   PetscFunctionBegin;
00415 
00416   /*
00417    * Check for illegal names
00418    */
00419   if (strchr(cat,':'))
00420     SETERRQ(1,"Illegal colon in category name");
00421   if (strchr(cmp,':'))
00422     SETERRQ(1,"Illegal colon in component name");
00423 
00424   /* initial setup */
00425   if (ncategories==0) {
00426     ierr = PetscMalloc
00427       (maxcategories*sizeof(char*),&categories); CHKERRQ(ierr);
00428     ierr = PetscMalloc
00429       (maxcategories*sizeof(int),&maxcomponents); CHKERRQ(ierr);
00430     ierr = PetscMalloc
00431       (maxcategories*sizeof(int),&ncomponents); CHKERRQ(ierr);
00432     ierr = PetscMalloc
00433       (maxcategories*sizeof(char**),&components); CHKERRQ(ierr);
00434     ierr = PetscMalloc
00435       (maxcategories*sizeof(AnalysisDataType*),&types); CHKERRQ(ierr);
00436     ierr = PetscMalloc
00437       (maxcategories*sizeof(PetscErrorCode(**)(Mat,AnalysisItem*,int*,PetscTruth*)),
00438        &modules); CHKERRQ(ierr);
00439     ierr = PetscMalloc
00440       (maxcategories*sizeof(PetscErrorCode(*)(char*)),
00441        &optionfunctions); CHKERRQ(ierr);
00442     ierr = PetscMalloc
00443       (maxcategories*sizeof(PetscTruth*),&hasval); CHKERRQ(ierr);
00444     ierr = PetscMalloc
00445       (maxcategories*sizeof(int*),&ids); CHKERRQ(ierr);
00446   }
00447 
00448   /* match this category, or allocate new */
00449   flg = PETSC_FALSE;
00450   for (i=0; i<ncategories; i++) {
00451     ierr = PetscStrcmp(cat,categories[i],&flg); CHKERRQ(ierr);
00452     if (flg) {
00453       icat = i; goto old_cat;
00454     }
00455   }
00456   icat=ncategories;
00457 
00458   /* 
00459    * reallocate categories if the array is overflowing
00460    */
00461   if (icat>=maxcategories) {
00462     int m = maxcategories;
00463     char **newcategories,***newcomponents; AnalysisDataType **newtypes;
00464     int *newmaxcomponents,*newncomponents;
00465     PetscErrorCode(***newmodules)(AnaModNumericalProblem,AnalysisItem*,int*,PetscTruth*);
00466     PetscErrorCode(**newoptionfunctions)(char*);
00467     PetscTruth **newhasval; int **newids;
00468     maxcategories += INC;
00469     /*printf("increasing categores from %d to %d components\n",m,maxcategories);*/
00470 
00471     ierr = PetscMalloc
00472       (maxcategories*sizeof(char*),&newcategories); CHKERRQ(ierr);
00473     ierr = PetscMalloc
00474       (maxcategories*sizeof(int),&newmaxcomponents); CHKERRQ(ierr);
00475     ierr = PetscMalloc
00476       (maxcategories*sizeof(int),&newncomponents); CHKERRQ(ierr);
00477     ierr = PetscMalloc
00478       (maxcategories*sizeof(char**),&newcomponents); CHKERRQ(ierr);
00479     ierr = PetscMalloc
00480       (maxcategories*sizeof(AnalysisDataType*),&newtypes); CHKERRQ(ierr);
00481     ierr = PetscMalloc
00482       (maxcategories*sizeof(PetscErrorCode(**)(Mat,AnalysisItem*,int*,PetscTruth*)),
00483        &newmodules); CHKERRQ(ierr);
00484     ierr = PetscMalloc
00485       (maxcategories*sizeof(PetscErrorCode(**)(char*)),
00486        &newoptionfunctions); CHKERRQ(ierr);
00487     ierr = PetscMalloc
00488       (maxcategories*sizeof(PetscTruth*),&newhasval); CHKERRQ(ierr);
00489     ierr = PetscMalloc
00490       (maxcategories*sizeof(int*),&newids); CHKERRQ(ierr);
00491 
00492     for (i=0; i<m; i++) {
00493       newcategories[i]      = categories[i];
00494       newmaxcomponents[i]   = maxcomponents[i];
00495       newncomponents[i]     = ncomponents[i];
00496       newcomponents[i]      = components[i];
00497       newtypes[i]           = types[i];
00498       newmodules[i]         = modules[i];
00499       newoptionfunctions[i] = optionfunctions[i];
00500       newhasval[i]          = hasval[i];
00501       newids[i]             = ids[i];
00502     }
00503 
00504     ierr = PetscFree(categories); CHKERRQ(ierr);
00505     ierr = PetscFree(maxcomponents); CHKERRQ(ierr);
00506     ierr = PetscFree(ncomponents); CHKERRQ(ierr);
00507     ierr = PetscFree(components); CHKERRQ(ierr);
00508     ierr = PetscFree(types); CHKERRQ(ierr);
00509     ierr = PetscFree(modules); CHKERRQ(ierr);
00510     ierr = PetscFree(optionfunctions); CHKERRQ(ierr);
00511     ierr = PetscFree(hasval); CHKERRQ(ierr);
00512     ierr = PetscFree(ids); CHKERRQ(ierr);
00513 
00514     categories      = newcategories;
00515     maxcomponents   = newmaxcomponents;
00516     ncomponents     = newncomponents;
00517     components      = newcomponents;
00518     types           = newtypes;
00519     modules         = newmodules;
00520     optionfunctions = newoptionfunctions;
00521     hasval          = newhasval;
00522     ids             = newids;
00523 
00524   }
00525 
00526   /*
00527    * Now that we are sure we have the space, insert this category
00528    */
00529   ierr = PetscStrallocpy(cat,categories+icat); CHKERRQ(ierr);
00530   maxcomponents[icat] = MXC; ncomponents[icat] = 0;
00531   ierr = PetscMalloc
00532     (maxcomponents[icat]*sizeof(char*),&(components[icat])); CHKERRQ(ierr);
00533   ierr = PetscMalloc
00534     (maxcomponents[icat]*sizeof(AnalysisDataType),&(types[icat])); CHKERRQ(ierr);
00535   ierr = PetscMalloc
00536     (maxcomponents[icat]*sizeof(int(*)(Mat,AnalysisItem*,int*,PetscTruth*)),
00537      &(modules[icat])); CHKERRQ(ierr);
00538   ierr = PetscMalloc
00539     (maxcomponents[icat]*sizeof(PetscTruth),&(hasval[icat])); CHKERRQ(ierr);
00540   ierr = PetscMalloc
00541     (maxcomponents[icat]*sizeof(int),&(ids[icat])); CHKERRQ(ierr);
00542   ncategories++;
00543 
00544   /*
00545    * component handling
00546    */
00547  old_cat:
00548 
00549   /* match this component or allocate new */
00550   flg = PETSC_FALSE;
00551   for (i=0; i<ncomponents[icat]; i++) {
00552     ierr = PetscStrcmp(cmp,components[icat][i],&flg); CHKERRQ(ierr);
00553     if (flg) {
00554       icmp = i; goto old_cmp;
00555     }
00556   }
00557   icmp=ncomponents[icat];
00558   /*printf("creating category element <%s:%s> @ %d,%d\n",cat,cmp,icat,icmp);*/
00559   if (icmp>=maxcomponents[icat]) {
00560     int m = maxcomponents[icat];
00561     char **newcomponents; AnalysisDataType *newtypes;
00562     int(**newmodules)(AnaModNumericalProblem,AnalysisItem*,int*,PetscTruth*);
00563     PetscTruth *newhasval; int *newids;
00564     maxcomponents[icat] += INC;
00565     /*printf("increasing category <%s> from %d to %d components\n",
00566       cat,m,maxcomponents[icat]);*/
00567     ierr = PetscMalloc
00568       (maxcomponents[icat]*sizeof(char*),&newcomponents); CHKERRQ(ierr);
00569     ierr = PetscMalloc
00570       (maxcomponents[icat]*sizeof(AnalysisDataType),&newtypes); CHKERRQ(ierr);
00571     ierr = PetscMalloc
00572       (maxcomponents[icat]*sizeof(int(*)(Mat,AnalysisItem*,int*,PetscTruth*)),&newmodules); CHKERRQ(ierr);
00573     ierr = PetscMalloc
00574       (maxcomponents[icat]*sizeof(PetscTruth),&newhasval); CHKERRQ(ierr);
00575     ierr = PetscMalloc
00576       (maxcomponents[icat]*sizeof(int),&newids); CHKERRQ(ierr);
00577 
00578     for (i=0; i<m; i++) {
00579       newcomponents[i] = components[icat][i];
00580       newtypes[i] = types[icat][i];
00581       newmodules[i] = modules[icat][i];
00582       newhasval[i] = hasval[icat][i];
00583       newids[i] = ids[icat][i];
00584     }
00585     ierr = PetscFree(components[icat]); CHKERRQ(ierr);
00586     ierr = PetscFree(types[icat]); CHKERRQ(ierr);
00587     ierr = PetscFree(modules[icat]); CHKERRQ(ierr);
00588     ierr = PetscFree(hasval[icat]); CHKERRQ(ierr);
00589     ierr = PetscFree(ids[icat]); CHKERRQ(ierr);
00590     components[icat] = newcomponents;
00591     types[icat]      = newtypes;
00592     modules[icat]    = newmodules;
00593     hasval[icat]     = newhasval;
00594     ids[icat]        = newids;
00595   }
00596   ierr = PetscStrallocpy(cmp,components[icat]+icmp); CHKERRQ(ierr);
00597   types[icat][icmp] = type;
00598   ncomponents[icat]++;
00599  old_cmp:
00600 
00601   /* insert this function */
00602   modules[icat][icmp] = f;
00603   ierr = PetscObjectComposedDataRegister(&id); CHKERRQ(ierr);
00604   ids[icat][icmp] = id;
00605 
00606   PetscFunctionReturn(0);
00607 }

PetscErrorCode RetrieveQuantity ( AnaModNumericalProblem  prob,
char *  cat,
char *  cmp,
AnalysisItem res,
PetscTruth *  success 
)

Retrieve an attached quantity. Note that this does not report the length of arrays; you have to know under which name this is stored.

Definition at line 931 of file module_functions.c.

References ANALYSISINTARRAY, AnaModHasTrace(), AnaModTraceArrays(), AnaModTraceMessage(), GetCategoryIndex(), GetModuleIndex(), hasval, QuantityAsString(), RetrieveQuantityByID(), TYPEii, and types.

00933 {
00934   PetscTruth flg,trace;
00935   int icat,icmp; PetscErrorCode ierr;
00936   
00937   PetscFunctionBegin;
00938 
00939   /*
00940    * Get the location of the module for this quantity
00941    */
00942   ierr = GetCategoryIndex(cat,&icat,&flg); CHKERRQ(ierr);
00943   if (!flg)
00944     SETERRQ1(1,"Could not find category <%s>",cat);
00945   ierr = GetModuleIndex(icat,cmp,&icmp,&flg); CHKERRQ(ierr);
00946   if (!flg)
00947     SETERRQ2(1,"Could not find module <%s:%s>",cat,cmp);
00948 
00949   /*
00950    * Compute
00951    */
00952   ierr = RetrieveQuantityByID(prob,icat,icmp,res,&flg); CHKERRQ(ierr);
00953 
00954   hasval[icat][icmp] = flg;
00955 
00956   if (!flg) goto nosuccess;
00957   /*
00958    * Tracing
00959    */
00960   ierr = AnaModHasTrace(&trace); CHKERRQ(ierr);
00961   if (trace) {
00962     if (flg) {
00963       char *string; PetscTruth trace_arrays;
00964       AnalysisDataType t = TYPEii(icat,icmp);
00965 
00966       ierr = AnaModTraceArrays(&trace_arrays); CHKERRQ(ierr);
00967       if (t<ANALYSISINTARRAY || trace_arrays) {
00968         ierr = QuantityAsString
00969           (res,types[icat][icmp],&string); CHKERRQ(ierr);
00970         ierr = AnaModTraceMessage
00971           ("Anamod retrieved <%s:%s> = <%s>\n",cat,cmp,string); CHKERRQ(ierr);
00972         ierr = PetscFree(string); CHKERRQ(ierr);
00973       }
00974     } else {
00975       ierr = AnaModTraceMessage
00976         ("Anamod failed to compute <%s:%s>\n",cat,cmp); CHKERRQ(ierr);
00977     }
00978   }
00979 
00980  nosuccess:
00981   if (success) *success = flg;
00982 
00983   PetscFunctionReturn(0);
00984 }

Here is the call graph for this function:

PetscErrorCode RetrieveQuantityByID ( AnaModNumericalProblem  prob,
int  icat,
int  icmp,
AnalysisItem result,
PetscTruth *  f 
)

See also HasQuantityByID()

Definition at line 1066 of file module_functions.c.

References ANALYSISDBLARRAY, ANALYSISDOUBLE, ANALYSISINTARRAY, ANALYSISINTEGER, AnalysisItem::i, ids, AnalysisItem::ii, AnalysisItem::r, AnalysisItem::rr, and TYPEii.

Referenced by RetrieveQuantity().

01068 {
01069   Mat A = (Mat)prob; AnalysisDataType type; int id = ids[icat][icmp];
01070   PetscErrorCode ierr;
01071   PetscFunctionBegin;
01072 
01073   type = TYPEii(icat,icmp);
01074   switch (type) {
01075   case ANALYSISINTEGER :
01076     ierr = PetscObjectComposedDataGetInt
01077       ((PetscObject)A,id,result->i,*f); CHKERRQ(ierr);
01078     break;
01079   case ANALYSISDOUBLE :
01080     ierr = PetscObjectComposedDataGetReal
01081       ((PetscObject)A,id,result->r,*f); CHKERRQ(ierr);
01082     break;
01083   case ANALYSISINTARRAY :
01084     ierr = PetscObjectComposedDataGetIntstar
01085       ((PetscObject)A,id,result->ii,*f); CHKERRQ(ierr);
01086     break;
01087   case ANALYSISDBLARRAY :
01088     ierr = PetscObjectComposedDataGetRealstar
01089       ((PetscObject)A,id,result->rr,*f); CHKERRQ(ierr);
01090     break;
01091   default : SETERRQ1(1,"Unknown data type %d",type);
01092   }
01093   PetscFunctionReturn(0);
01094 }


Variable Documentation

int AnaModIsInitialized = 0 [static]

Definition at line 315 of file module_functions.c.

Referenced by AnaModGetTypeMySQLName(), and AnaModInitialize().

struct { ... } anamodtypenames[5] [static]

char** categories = NULL [static]

char *** components = NULL [static]

PetscTruth** hasval = NULL [static]

int id

int** ids = NULL [static]

int maxcategories = 30 [static]

Definition at line 305 of file module_functions.c.

Referenced by RegisterModule().

int * maxcomponents = NULL [static]

Definition at line 306 of file module_functions.c.

Referenced by DeregisterModules(), and RegisterModule().

PetscErrorCode(*** modules)(AnaModNumericalProblem, AnalysisItem *, int *, PetscTruth *) = NULL [static]

const char * mysqlname

Definition at line 313 of file module_functions.c.

Referenced by AnaModGetTypeMySQLName().

const char* name

Definition at line 313 of file module_functions.c.

Referenced by AddToFeatureSet().

int nAnaModTypeNames [static]

Definition at line 314 of file module_functions.c.

Referenced by AnaModGetTypeMySQLName(), AnaModGetTypeName(), and AnaModInitialize().

int ncategories = 0 [static]

int * ncomponents = NULL [static]

PetscErrorCode(** optionfunctions)(char *) = NULL [static]

AnalysisDataType** types = NULL [static]


Generated on Sun Oct 4 04:01:15 2009 for SALSA Analysis Modules by  doxygen 1.5.9