SALSA Analysis Modules
Defines | Functions | Variables

Commandline options handling. More...

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

Go to the source code of this file.

Defines

#define VALUELEN   150

Functions

PetscErrorCode AnaModOptionsHandling ()
PetscErrorCode AnaModShowOptions (MPI_Comm comm)
PetscErrorCode AnaModHasForcedSequentialComputation (PetscTruth *flg)
PetscErrorCode AnaModGetSequentialMatrix (Mat A, Mat *Awork, PetscTruth *mem, PetscTruth *local, PetscTruth *global)
PetscErrorCode AnaModHasForcedExpensiveComputation (PetscTruth *flg)

Variables

static PetscTruth single_proc = PETSC_FALSE
static PetscTruth expensive = PETSC_FALSE

Detailed Description

Commandline options handling.

Definition in file options.c.


Define Documentation

#define VALUELEN   150

Referenced by AnaModOptionsHandling().


Function Documentation

PetscErrorCode AnaModGetSequentialMatrix ( Mat  A,
Mat *  Awork,
PetscTruth *  mem,
PetscTruth *  local,
PetscTruth *  global 
)

Collect the matrix on processor zero.

There is an implicit assumption here that processor zero is the one that will do the actual work.

Argument:

  • A : input matrix
  • Awork : pointer to the sequential matrix, this can be a pointer to the original matrix if it was already sequential; it is NULL if no forced sequential computation is asked (see Commandline options)
  • mem : true if Awork is newly allocated
  • local : true if this processor needs to do the work
  • global : true if any processor does work; this condition is false in the case of a distributed matrix and no forced sequential operation

Definition at line 192 of file options.c.

References AnaModHasForcedSequentialComputation().

Referenced by compute_tracea2(), MatCommutatorNormF(), and MatSymmPartNormInf().

{
  MPI_Comm comm; const MatType type; int mytid;
  PetscTruth flg; PetscErrorCode ierr;
  PetscFunctionBegin;

  ierr = PetscObjectGetComm((PetscObject)A,&comm); CHKERRQ(ierr);
  MPI_Comm_rank(comm,&mytid);
  ierr = MatGetType(A,&type); CHKERRQ(ierr);
  ierr = PetscStrcmp(type,MATSEQAIJ,&flg); CHKERRQ(ierr);
  if (flg) {
    *Awork = A; *mem = PETSC_FALSE;
    *local = PETSC_TRUE; *global = PETSC_TRUE;
  } else {
    ierr = AnaModHasForcedSequentialComputation(&flg); CHKERRQ(ierr);
    if (!flg) {
      *Awork = NULL;
      *mem = PETSC_FALSE; *local = PETSC_FALSE; *global = PETSC_FALSE;
      PetscFunctionReturn(0);
    }
    *global = PETSC_TRUE;
    {
      Mat *Arow; IS is[1]; int N,M;
      ierr = MatGetSize(A,&M,&N); CHKERRQ(ierr);
      if (mytid==0) {
        ierr = ISCreateStride(MPI_COMM_SELF,M,0,1,is); CHKERRQ(ierr);
        *local = PETSC_TRUE;
      } else {
        ierr = ISCreateStride(MPI_COMM_SELF,0,0,1,is); CHKERRQ(ierr);
        *local = PETSC_FALSE;
      }
      ierr = MatGetSubMatrices
        (A,1,is,is,MAT_INITIAL_MATRIX,&Arow); CHKERRQ(ierr);
      ierr = ISDestroy(is[0]); CHKERRQ(ierr);
      *Awork = Arow[0]; *mem = PETSC_TRUE;
    }
  }
  PetscFunctionReturn(0);
}

Here is the call graph for this function:

PetscErrorCode AnaModHasForcedExpensiveComputation ( PetscTruth *  flg)

Query whether certain expensive operations should be done regardless the cost.

Definition at line 238 of file options.c.

References expensive.

Referenced by MatCommutatorNormF_seq().

{
  PetscFunctionBegin;
  *flg = expensive;
  PetscFunctionReturn(0);
}
PetscErrorCode AnaModHasForcedSequentialComputation ( PetscTruth *  flg)

Query whether parallel modules should be done on processor zero.

Definition at line 165 of file options.c.

References single_proc.

Referenced by AnaModGetSequentialMatrix().

{
  PetscFunctionBegin;
  *flg = single_proc;
  PetscFunctionReturn(0);
}
PetscErrorCode AnaModOptionsHandling ( void  )

Process any commandline options that were given for AnaMod. These use the regular Petsc commandline options database.

This routine handles general options and module-specific options, so it has to be called after all modules have been declared.

See DeclareCategoryOptionFunction(),CategoryGetOptionFunction(), AnaModOptionsHandling() and section Commandline options.

Definition at line 60 of file options.c.

References CATCMP_SKIP_FROM_LOOPS, CategoryEnableByName(), CategoryGetOptionFunction(), expensive, GetCategories(), single_proc, and VALUELEN.

Referenced by main().

{
  PetscTruth flg; PetscErrorCode ierr;
  char *value;
  PetscFunctionBegin;

#define VALUELEN 150
  ierr = PetscMalloc(VALUELEN*sizeof(char),&value); CHKERRQ(ierr);

  {
    ierr = PetscOptionsHasName(PETSC_NULL,"-anamod_force",&flg); CHKERRQ(ierr);
    if (flg) {
      ierr = PetscOptionsGetString
        (PETSC_NULL,"-anamod_force",value,VALUELEN,&flg); CHKERRQ(ierr);
      if (flg) {
        char *c;
        c = strtok(value,",");
        while (c) {
          ierr = PetscStrcmp(c,"sequential",&flg); CHKERRQ(ierr);
          if (flg) single_proc = PETSC_TRUE;
          ierr = PetscStrcmp(c,"expensive",&flg); CHKERRQ(ierr);
          if (flg) expensive = PETSC_TRUE;
          c = strtok(NULL,",");
        }
      }
    }
  }

  {
    const char **categories; char *option; int icat,ncats;
    ierr = PetscMalloc(30*sizeof(char),&option); CHKERRQ(ierr);
    ierr = GetCategories(&ncats,&categories); CHKERRQ(ierr);
    for (icat=0; icat<ncats; icat++) {
      ierr = PetscMemzero(value,VALUELEN*sizeof(char)); CHKERRQ(ierr);      
      ierr = PetscMemzero(option,30*sizeof(char)); CHKERRQ(ierr);
      sprintf(option,"-anamod_%s",categories[icat]);
      ierr = PetscOptionsGetString
        (PETSC_NULL,option,value,VALUELEN,&flg); CHKERRQ(ierr);
      if (flg) {
        PetscErrorCode (*f)(char*);
        ierr = CategoryGetOptionFunction(categories[icat],&f); CHKERRQ(ierr);
        if (f) {
          ierr = (*f)(value); CHKERRQ(ierr);
        }
      }
    }
    ierr = PetscFree(option); CHKERRQ(ierr);
  }

  {
    ierr = PetscOptionsGetString
      (PETSC_NULL,"-anamod_use_only",value,VALUELEN,&flg); CHKERRQ(ierr);
    if (flg) {
      int ncats,icat; const char **cats;
      ierr = GetCategories(&ncats,&cats); CHKERRQ(ierr);
      for (icat=0; icat<ncats; icat++) {
        if (strcmp(value,cats[icat])) {
          ierr = CategoryEnableByName
            (cats[icat],CATCMP_SKIP_FROM_LOOPS); CHKERRQ(ierr);
        }
      }
    }
  }

  ierr = PetscFree(value); CHKERRQ(ierr);

  PetscFunctionReturn(0);
}

Here is the call graph for this function:

PetscErrorCode AnaModShowOptions ( MPI_Comm  comm)

Display all available options. This depends on the installed modules, so you need to do the various register calls first. See Use of the analysis modules.

For options see Commandline options.

Definition at line 136 of file options.c.

References GetCategories().

{
  PetscErrorCode ierr;
  PetscFunctionBegin;
  PetscPrintf(comm,"Available AnaMod options\n  Global:\n");
  PetscPrintf(comm,"  -anamod_use_only mod : use only the specified module\n");
  PetscPrintf(comm,"  -anamod_force sequential : do sequential computations\n  even in parallel runs\n");
  PetscPrintf(comm,"  -anamod_force expensive : do certain calculations no matter how expensive\n");
  PetscPrintf(comm,"\n  Categories and modules:\n");
  {
    const char **categories; char *option; int icat,ncats;
    ierr = PetscMalloc(30*sizeof(char),&option); CHKERRQ(ierr);
    ierr = GetCategories(&ncats,&categories); CHKERRQ(ierr);
    for (icat=0; icat<ncats; icat++) {
      ierr = PetscMemzero(option,30*sizeof(char)); CHKERRQ(ierr);
      PetscPrintf
        (comm,"  -anamod_%s : options for category %s\n",
         categories[icat],categories[icat]);
    }
    ierr = PetscFree(option); CHKERRQ(ierr);
  }
  PetscFunctionReturn(0);
}

Here is the call graph for this function:


Variable Documentation

PetscTruth expensive = PETSC_FALSE

Definition at line 46 of file options.c.

Referenced by AnaModHasForcedExpensiveComputation(), and AnaModOptionsHandling().

PetscTruth single_proc = PETSC_FALSE [static]

Definition at line 46 of file options.c.

Referenced by AnaModHasForcedSequentialComputation(), and AnaModOptionsHandling().