System Preprocessors
Data Structures | Defines | Typedefs | Functions | Variables
preprocess.c File Reference
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "petscmat.h"
#include "syspro.h"
#include "sysprotransform.h"
#include "syspro_impl.h"

Go to the source code of this file.

Data Structures

struct  PreprocessorsGlobalInfo_

Defines

#define NPREPROCESS   25

Typedefs

typedef struct
PreprocessorsGlobalInfo_
PreprocessorsGlobalInfo

Functions

static PetscErrorCode CreateGlobalInfo ()
PetscErrorCode SysProInitialize ()
PetscErrorCode SysProFinalize ()
PetscErrorCode DeclarePreprocessor (const char *name, PetscErrorCode(*this_preprocessor_setup)(), PetscErrorCode(*specific_setup)(NumericalProblem, SalsaTransform), PetscErrorCode(*specific_unset)(NumericalProblem), PetscErrorCode(*global_unset)(), PetscErrorCode(*ctxcreate)(NumericalProblem, void **), PetscErrorCode(*ctxdelete)(void *), PetscErrorCode(*start_function)(const char *, int, PetscTruth, NumericalProblem, NumericalProblem *, void *, void **, PetscTruth *), PetscErrorCode(*end_function)(const char *, PetscTruth, void *, void *, NumericalProblem, NumericalProblem, NumericalSolution, NumericalSolution))
PetscErrorCode SysProDeclareProblemMonitor (PetscErrorCode(*monitor)(NumericalProblem))
PetscErrorCode SysProDeclareErrorTracer (PetscErrorCode(*tracer)(NumericalProblem, NumericalSolution, const char *))
PetscErrorCode SysProGetErrorTracer (PetscErrorCode(**tracer)(NumericalProblem, NumericalSolution, const char *))
PetscErrorCode DeclarePreprocessorIntelligentChoice (const char *name, PetscErrorCode(*picker)(NumericalProblem, const char **, const char **))
PetscErrorCode NumericalProblemGetComm (NumericalProblem prob, MPI_Comm *comm)
PetscErrorCode SysProDeclareFunctions (PetscErrorCode(*classstaticsetup)(const char *), PetscErrorCode(*classdynamicsetup)(const char *, NumericalProblem), PetscErrorCode(*classproblemcloner)(const char *, const char *, int, NumericalProblem, NumericalProblem), PetscErrorCode(*problemsolver)(NumericalProblem, void *, NumericalSolution *), PetscErrorCode(*problemdelete)(NumericalProblem), PetscErrorCode(*solutioncreator)(NumericalProblem, NumericalSolution *), PetscErrorCode(*solutioncopy)(NumericalSolution, NumericalSolution), PetscErrorCode(*solutiondelete)(NumericalSolution), PetscErrorCode(*ctxcloner)(const char *, const char *, void *, void **), PetscErrorCode(*ctxfree)(void *), PetscErrorCode(*solutioncontextdelete)(NumericalSolution))
static PetscErrorCode SysProGetContextFunctions (PetscErrorCode(**ctxcloner)(const char *, const char *, void *, void **), PetscErrorCode(**ctxfree)(void *))
static PetscErrorCode SysProProblemCloneContext (const char *preprocessor, const char *type, NumericalProblem in, NumericalProblem out)
static PetscErrorCode SysProProblemDeleteContext (NumericalProblem problem)
static PetscErrorCode RegisterPreprocessorSetting (const char *preprocess, const char *type, int option)
PetscErrorCode PreprocessorGetSetting (const char *preprocess, const char **type, int *option)
PetscErrorCode RetrievePreprocessorChoice (int idx, const char **type, int *option)
PetscErrorCode PreprocessorGetIndex (const char *name, int *prenumber)
PetscErrorCode SystemPreprocessorGetByName (const char *name, SystemPreprocessor *pp)
PetscErrorCode TransformGetByName (const char *name, SalsaTransform *tf)
PetscErrorCode RegisterPreprocessorContext (const char *pre, void *ctx)
PetscErrorCode PreprocessorGetContext (const char *pre, void **ctx)
static PetscErrorCode PreprocessorSpecificSetup (const char *preprocess, NumericalProblem problem, PetscTruth user_choices)
static PetscErrorCode SysproPreprocessorStartFunction (SystemPreprocessor preprocessor, const char *type, int option, PetscTruth overwrite, NumericalProblem inproblem, NumericalProblem *outproblem, void *preprocessor_context, void **transform_context, PetscTruth *success)
static PetscErrorCode SysProPreprocessorEndFunction (SystemPreprocessor preprocessor, const char *pclassname, const char *type, PetscTruth do_not_keep_original, void *gctx, void *ctx, NumericalProblem next_problem, NumericalProblem problem, NumericalSolution next_solution, NumericalSolution *rsolution)
static PetscErrorCode ChooseFirstTransform (NumericalProblem problem, const char *preprocess, PetscTruth user_choices, PetscTruth exhaustive, SalsaTransform transform, SystemPreprocessor preprocessor, SalsaTransformObject *transformitem, PetscTruth *moretransform, const char **type)
PetscErrorCode PreprocessedSolution (const char *pclassname, NumericalProblem problem, void *prevctx, NumericalSolution *rsolution)
PetscErrorCode PreprocessedProblemSolving (NumericalProblem problem, NumericalSolution *solution)

Variables

SystemPreprocessorpreprocessors = NULL
const char ** currentpreprocessors
const char ** currentchoices = NULL
int * currentoptions = NULL
int npreprocess = 0
int preprocesslevel
static void ** preprocessorcontexts
static void * solutioncontext
static PetscErrorCode(** unsetpreprocessor )()
static PreprocessorsGlobalInfo GlobalInfo = NULL

Define Documentation

#define NPREPROCESS   25

Definition at line 157 of file preprocess.c.

Referenced by DeclarePreprocessor(), and SysProInitialize().


Typedef Documentation

Definition at line 198 of file preprocess.c.


Function Documentation

static PetscErrorCode ChooseFirstTransform ( NumericalProblem  problem,
const char *  preprocess,
PetscTruth  user_choices,
PetscTruth  exhaustive,
SalsaTransform  transform,
SystemPreprocessor  preprocessor,
SalsaTransformObject transformitem,
PetscTruth *  moretransform,
const char **  type 
) [static]
static PetscErrorCode CreateGlobalInfo ( ) [static]

Definition at line 203 of file preprocess.c.

References CHKERRQ(), and ierr.

Referenced by SysProInitialize().

PetscErrorCode DeclarePreprocessor ( const char *  name,
PetscErrorCode(*)()  this_preprocessor_setup,
PetscErrorCode(*)(NumericalProblem, SalsaTransform specific_setup,
PetscErrorCode(*)(NumericalProblem specific_unset,
PetscErrorCode(*)()  global_unset,
PetscErrorCode(*)(NumericalProblem, void **)  ctxcreate,
PetscErrorCode(*)(void *)  ctxdelete,
PetscErrorCode(*)(const char *, int, PetscTruth, NumericalProblem, NumericalProblem *, void *, void **, PetscTruth *)  start_function,
PetscErrorCode(*)(const char *, PetscTruth, void *, void *, NumericalProblem, NumericalProblem, NumericalSolution, NumericalSolution end_function 
)

Declare a preprocessor class, by specifing its various members.

The name argument should not contain the colon character.

Here is an explanation of the various function arguments.

this_preprocessor_setup() : this routine is called only once, inside this function. This is a good place for defining all the preprocessors in this class

specific_setup(NumericalProblem,SalsaTransform) : this is called at the start of a preprocessing stage; one could use this for computing matrix metadata.

global_unset(void) : this is called in SysProFinalize().

ctx_create(NumericalProblem,void**) : create an object that can be used for the duration of the application of this preprocessor

ctxdelete(void*) : delete the context again

start_function : this is the function that performs the forward transform of the problem. Prototype:

  PetscErrorCode start_function
    (char             *classmember,
     int               optionvalue,
     PetscTruth        overwrite,
     NumericalProblem  problem,
     NumericalProblem *transformedproblem,
     void             *globalcontext,
     void            **localcontext,
     PetscTruth       *success)

end_function : this is the backtransform. Its main task is copying or backtransforming the preprocessed solution to the original solution.

  PetscErrorCode end_function
    (char             *classmember,
     PetscTruth        overwrite,
     void             *globalcontext,
     void             *localcontext,
     NumericalProblem  pproblem,
     NumericalProblem  oproblem,
     NumericalSolution psolution,
     NumericalSolution osolution)

where pproblem and psolution are the preprocessed quantities, the end function has to unprocess them and leave the result in oproblem, osolution. Actually, oproblem is only for reference.

Definition at line 328 of file preprocess.c.

References CHKERRQ(), PreprocessorsGlobalInfo_::classstaticsetup, SystemPreprocessor_::ctxcreate, SystemPreprocessor_::ctxdelete, SystemPreprocessor_::end_function, SystemPreprocessor_::exhaustive, ierr, SystemPreprocessor_::name, NewTransform(), NPREPROCESS, npreprocess, SystemPreprocessor_::setup, SystemPreprocessor_::start_function, SystemPreprocessor_::transform, SystemPreprocessor_::unset, and unsetpreprocessor.

Referenced by DeclareApproximationPreprocessor(), DeclareDistributionPreprocessor(), DeclareFlipsignPreprocessor(), DeclareKSPPreprocessor(), DeclarePCPreprocessor(), DeclareScalingPreprocessor(), DeclareSingletonPreprocessor(), and main().

PetscErrorCode DeclarePreprocessorIntelligentChoice ( const char *  name,
PetscErrorCode(*)(NumericalProblem, const char **, const char **)  picker 
)

Install a function to pick the optimal choice for a preprocessor

Definition at line 412 of file preprocess.c.

References CHKERRQ(), ierr, SystemPreprocessor_::intelligence, and SystemPreprocessorGetByName().

Referenced by DeclareScalingPreprocessor().

PetscErrorCode NumericalProblemGetComm ( NumericalProblem  prob,
MPI_Comm *  comm 
)

Definition at line 424 of file preprocess.c.

References NumericalProblem_::comm.

Referenced by create_solver().

PetscErrorCode PreprocessedProblemSolving ( NumericalProblem  problem,
NumericalSolution solution 
)

Invoking this routine starts the preprocessing and ultimate solution of the numerical problem.

Definition at line 1028 of file preprocess.c.

References CHKERRQ(), PreprocessorsGlobalInfo_::errortracer, GetFirstPreprocessor(), ierr, PreprocessedSolution(), preprocesslevel, and PreprocessorsGlobalInfo_::problemsolver.

Referenced by main(), and PreprocessedLinearSystemSolution().

PetscErrorCode PreprocessedSolution ( const char *  pclassname,
NumericalProblem  problem,
void *  prevctx,
NumericalSolution rsolution 
)
PetscErrorCode PreprocessorGetContext ( const char *  pre,
void **  ctx 
)

Definition at line 681 of file preprocess.c.

References CHKERRQ(), ierr, preprocessorcontexts, PreprocessorGetIndex(), and solutioncontext.

Referenced by setup_ksp(), and setup_pc().

PetscErrorCode PreprocessorGetIndex ( const char *  name,
int *  prenumber 
)
PetscErrorCode PreprocessorGetSetting ( const char *  preprocess,
const char **  type,
int *  option 
)

Definition at line 559 of file preprocess.c.

References currentchoices, currentoptions, currentpreprocessors, and preprocesslevel.

Referenced by disable_ksps().

static PetscErrorCode PreprocessorSpecificSetup ( const char *  preprocess,
NumericalProblem  problem,
PetscTruth  user_choices 
) [static]

Setup actions that are particular to a specific class of preprocessors, such as scalings. This performs the following actions:

  • any user specified setup, for instance disqualifying preprocessors on purely logistical grounds.
  • subsequently, the suitability functions (Suitability functions) are evaluated for each preprocessor and the current problem. In the current implementation this is only used to disqualify preprocessors. We'll get more sophisticated later.

Definition at line 710 of file preprocess.c.

References CHKERRQ(), ierr, SalsaTransform_::n_objects, PreprocessorApplyAprioriSelection(), PreprocessorsGlobalInfo_::problemmonitor, ReportEnabledPreprocessors(), SystemPreprocessor_::setup, SystemPreprocessorGetByName(), TestSuitabilityContext(), TransformGetByName(), TransformObjectGetName(), TransformObjectGetSuitabilityFunction(), TransformObjectMark(), and SalsaTransform_::transformobjects.

Referenced by PreprocessedSolution().

PetscErrorCode RegisterPreprocessorContext ( const char *  pre,
void *  ctx 
)
static PetscErrorCode RegisterPreprocessorSetting ( const char *  preprocess,
const char *  type,
int  option 
) [static]

Definition at line 546 of file preprocess.c.

References currentchoices, currentoptions, currentpreprocessors, and preprocesslevel.

Referenced by PreprocessedSolution().

PetscErrorCode RetrievePreprocessorChoice ( int  idx,
const char **  type,
int *  option 
)

Definition at line 579 of file preprocess.c.

References currentchoices, and currentoptions.

Referenced by ContinueRetrievingCurrentPreprocessors().

PetscErrorCode SysProDeclareErrorTracer ( PetscErrorCode(*)(NumericalProblem, NumericalSolution, const char *)  tracer)

Definition at line 391 of file preprocess.c.

References PreprocessorsGlobalInfo_::errortracer.

PetscErrorCode SysProDeclareFunctions ( PetscErrorCode(*)(const char *)  classstaticsetup,
PetscErrorCode(*)(const char *, NumericalProblem classdynamicsetup,
PetscErrorCode(*)(const char *, const char *, int, NumericalProblem, NumericalProblem classproblemcloner,
PetscErrorCode(*)(NumericalProblem, void *, NumericalSolution *)  problemsolver,
PetscErrorCode(*)(NumericalProblem problemdelete,
PetscErrorCode(*)(NumericalProblem, NumericalSolution *)  solutioncreator,
PetscErrorCode(*)(NumericalSolution, NumericalSolution solutioncopy,
PetscErrorCode(*)(NumericalSolution solutiondelete,
PetscErrorCode(*)(const char *, const char *, void *, void **)  ctxcloner,
PetscErrorCode(*)(void *)  ctxfree,
PetscErrorCode(*)(NumericalSolution solutioncontextdelete 
)

Install various functions

  • classstaticsetup : this function is called on each processor as it is being created; see DeclarePreprocessor().
  • classdynamicsetup : this function is called as any invocation of a preprocessor starts; see PreprocessedSolution();
  • classproblemcloner : a function to clone the context : optional see Tracing the preprocessors for more details.
  • problemsolver : the ultimate problem solver : required
  • problemdelete : delete a problem object
  • solutioncreator : creates a solution object; optional, but required a preprocessor has an endfunction.
  • solutioncopy : guess what this does; optional
  • solutiondelete : optional, but needed if solutioncopy is used
  • contextcloner : problems can carry a context; this clones the context if a problem is copied; otherwise the pointer is simply duplicated
  • contextfree : used to delete cloned contexts
  • solutioncontextdelete : hm.

Definition at line 453 of file preprocess.c.

References PreprocessorsGlobalInfo_::classdynamicsetup, PreprocessorsGlobalInfo_::classproblemcloner, PreprocessorsGlobalInfo_::classstaticsetup, PreprocessorsGlobalInfo_::clonecontext, PreprocessorsGlobalInfo_::freecontext, PreprocessorsGlobalInfo_::problemdelete, PreprocessorsGlobalInfo_::problemsolver, PreprocessorsGlobalInfo_::solutioncontextdelete, PreprocessorsGlobalInfo_::solutioncopy, PreprocessorsGlobalInfo_::solutioncreator, and PreprocessorsGlobalInfo_::solutiondelete.

Referenced by main().

PetscErrorCode SysProDeclareProblemMonitor ( PetscErrorCode(*)(NumericalProblem monitor)

Definition at line 381 of file preprocess.c.

References PreprocessorsGlobalInfo_::problemmonitor.

PetscErrorCode SysProFinalize ( )
static PetscErrorCode SysProGetContextFunctions ( PetscErrorCode(**)(const char *, const char *, void *, void **)  ctxcloner,
PetscErrorCode(**)(void *)  ctxfree 
) [static]
PetscErrorCode SysProGetErrorTracer ( PetscErrorCode(**)(NumericalProblem, NumericalSolution, const char *)  tracer)

Definition at line 401 of file preprocess.c.

References PreprocessorsGlobalInfo_::errortracer.

PetscErrorCode SysProInitialize ( )

Allocate SysPro globals. See also SysProFinalize().

Definition at line 220 of file preprocess.c.

References CHKERRQ(), CreateGlobalInfo(), currentchoices, currentoptions, currentpreprocessors, ierr, NPREPROCESS, preprocessorcontexts, and unsetpreprocessor.

Referenced by main().

static PetscErrorCode SysProPreprocessorEndFunction ( SystemPreprocessor  preprocessor,
const char *  pclassname,
const char *  type,
PetscTruth  do_not_keep_original,
void *  gctx,
void *  ctx,
NumericalProblem  next_problem,
NumericalProblem  problem,
NumericalSolution  next_solution,
NumericalSolution rsolution 
) [static]
static PetscErrorCode SysproPreprocessorStartFunction ( SystemPreprocessor  preprocessor,
const char *  type,
int  option,
PetscTruth  overwrite,
NumericalProblem  inproblem,
NumericalProblem outproblem,
void *  preprocessor_context,
void **  transform_context,
PetscTruth *  success 
) [static]
static PetscErrorCode SysProProblemCloneContext ( const char *  preprocessor,
const char *  type,
NumericalProblem  in,
NumericalProblem  out 
) [static]

Definition at line 517 of file preprocess.c.

References CHKERRQ(), NumericalProblem_::ctx, ierr, and SysProGetContextFunctions().

Referenced by PreprocessedSolution().

static PetscErrorCode SysProProblemDeleteContext ( NumericalProblem  problem) [static]

Definition at line 529 of file preprocess.c.

References CHKERRQ(), ierr, and SysProGetContextFunctions().

Referenced by SysProPreprocessorEndFunction().

PetscErrorCode SystemPreprocessorGetByName ( const char *  name,
SystemPreprocessor pp 
)
PetscErrorCode TransformGetByName ( const char *  name,
SalsaTransform tf 
)

Variable Documentation

const char ** currentchoices = NULL
int* currentoptions = NULL
const char** currentpreprocessors

Definition at line 199 of file preprocess.c.

int npreprocess = 0
void** preprocessorcontexts [static]

Definition at line 158 of file preprocess.c.

Definition at line 162 of file preprocess.c.

Referenced by PreprocessorGetContext(), and RegisterPreprocessorContext().

PetscErrorCode(** unsetpreprocessor)() [static]

Definition at line 163 of file preprocess.c.

Referenced by DeclarePreprocessor(), SysProFinalize(), and SysProInitialize().