#include <stdlib.h>
#include <string.h>
#include "anamod.h"
#include "petsc.h"
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 |
"-anamod_force <option>"
where option
issequential
expensive
"-anamod_<module name> <option>"
. If the module has declared a function to handle such options, that function is called here. This implies that the AnaModOptionsHandling() function needs to be called after all modules have been declared. Definition in file options.c.
#define VALUELEN 150 |
Referenced by AnaModOptionsHandling().
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 matrixAwork
: 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 allocatedlocal
: true if this processor needs to do the workglobal
: 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 154 of file options.c.
References AnaModHasForcedSequentialComputation().
Referenced by compute_tracea2(), MatCommutatorNormF(), and MatSymmPartNormInf().
00155 { 00156 MPI_Comm comm; const MatType type; int mytid; 00157 PetscTruth flg; PetscErrorCode ierr; 00158 PetscFunctionBegin; 00159 00160 ierr = PetscObjectGetComm((PetscObject)A,&comm); CHKERRQ(ierr); 00161 MPI_Comm_rank(comm,&mytid); 00162 ierr = MatGetType(A,&type); CHKERRQ(ierr); 00163 ierr = PetscStrcmp(type,MATSEQAIJ,&flg); CHKERRQ(ierr); 00164 if (flg) { 00165 *Awork = A; *mem = PETSC_FALSE; 00166 *local = PETSC_TRUE; *global = PETSC_TRUE; 00167 } else { 00168 ierr = AnaModHasForcedSequentialComputation(&flg); CHKERRQ(ierr); 00169 if (!flg) { 00170 *Awork = NULL; 00171 *mem = PETSC_FALSE; *local = PETSC_FALSE; *global = PETSC_FALSE; 00172 PetscFunctionReturn(0); 00173 } 00174 *global = PETSC_TRUE; 00175 { 00176 Mat *Arow; IS is[1]; int N,M; 00177 ierr = MatGetSize(A,&M,&N); CHKERRQ(ierr); 00178 if (mytid==0) { 00179 ierr = ISCreateStride(MPI_COMM_SELF,M,0,1,is); CHKERRQ(ierr); 00180 *local = PETSC_TRUE; 00181 } else { 00182 ierr = ISCreateStride(MPI_COMM_SELF,0,0,1,is); CHKERRQ(ierr); 00183 *local = PETSC_FALSE; 00184 } 00185 ierr = MatGetSubMatrices 00186 (A,1,is,is,MAT_INITIAL_MATRIX,&Arow); CHKERRQ(ierr); 00187 ierr = ISDestroy(is[0]); CHKERRQ(ierr); 00188 *Awork = Arow[0]; *mem = PETSC_TRUE; 00189 } 00190 } 00191 PetscFunctionReturn(0); 00192 }
PetscErrorCode AnaModHasForcedExpensiveComputation | ( | PetscTruth * | flg | ) |
Query whether certain expensive operations should be done regardless the cost.
Definition at line 200 of file options.c.
References expensive.
Referenced by MatCommutatorNormF_seq().
00201 { 00202 PetscFunctionBegin; 00203 *flg = expensive; 00204 PetscFunctionReturn(0); 00205 }
PetscErrorCode AnaModHasForcedSequentialComputation | ( | PetscTruth * | flg | ) |
Query whether parallel modules should be done on processor zero.
Definition at line 127 of file options.c.
References single_proc.
Referenced by AnaModGetSequentialMatrix().
00128 { 00129 PetscFunctionBegin; 00130 *flg = single_proc; 00131 PetscFunctionReturn(0); 00132 }
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(),GetCategoryOptionFunction(), AnaModOptionsHandling() and section Commandline Options for Runtime Control.
Definition at line 38 of file options.c.
References categories, expensive, GetCategories(), GetCategoryOptionFunction(), single_proc, and VALUELEN.
00039 { 00040 PetscTruth flg; PetscErrorCode ierr; 00041 char *value; 00042 PetscFunctionBegin; 00043 00044 #define VALUELEN 150 00045 ierr = PetscMalloc(VALUELEN*sizeof(char),&value); CHKERRQ(ierr); 00046 00047 { 00048 ierr = PetscOptionsHasName(PETSC_NULL,"-anamod_force",&flg); CHKERRQ(ierr); 00049 if (flg) { 00050 ierr = PetscOptionsGetString 00051 (PETSC_NULL,"-anamod_force",value,VALUELEN,&flg); CHKERRQ(ierr); 00052 if (flg) { 00053 char *c; 00054 c = strtok(value,","); 00055 while (c) { 00056 ierr = PetscStrcmp(c,"sequential",&flg); CHKERRQ(ierr); 00057 if (flg) single_proc = PETSC_TRUE; 00058 ierr = PetscStrcmp(c,"expensive",&flg); CHKERRQ(ierr); 00059 if (flg) expensive = PETSC_TRUE; 00060 c = strtok(NULL,","); 00061 } 00062 } 00063 } 00064 } 00065 00066 { 00067 char **categories,*option; int icat,ncats; 00068 ierr = PetscMalloc(30*sizeof(char),&option); CHKERRQ(ierr); 00069 ierr = GetCategories(&categories,&ncats); CHKERRQ(ierr); 00070 for (icat=0; icat<ncats; icat++) { 00071 ierr = PetscMemzero(value,VALUELEN*sizeof(char)); CHKERRQ(ierr); 00072 ierr = PetscMemzero(option,30*sizeof(char)); CHKERRQ(ierr); 00073 sprintf(option,"-anamod_%s",categories[icat]); 00074 ierr = PetscOptionsGetString 00075 (PETSC_NULL,option,value,VALUELEN,&flg); CHKERRQ(ierr); 00076 if (flg) { 00077 PetscErrorCode (*f)(char*); 00078 ierr = GetCategoryOptionFunction(categories[icat],&f); CHKERRQ(ierr); 00079 if (f) { 00080 ierr = (*f)(value); CHKERRQ(ierr); 00081 } 00082 } 00083 } 00084 ierr = PetscFree(option); CHKERRQ(ierr); 00085 } 00086 00087 ierr = PetscFree(value); CHKERRQ(ierr); 00088 00089 PetscFunctionReturn(0); 00090 }
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 for Runtime Control.
Definition at line 99 of file options.c.
References categories, and GetCategories().
00100 { 00101 PetscErrorCode ierr; 00102 PetscFunctionBegin; 00103 PetscPrintf(comm,"Available AnaMod options\n Global:\n"); 00104 PetscPrintf(comm," -anamod_force sequential : do sequential computations\n even in parallel runs\n"); 00105 PetscPrintf(comm," -anamod_force expensive : do certain calculations no matter how expensive\n"); 00106 PetscPrintf(comm,"\n Categories and modules:\n"); 00107 { 00108 char **categories,*option; int icat,ncats; 00109 ierr = PetscMalloc(30*sizeof(char),&option); CHKERRQ(ierr); 00110 ierr = GetCategories(&categories,&ncats); CHKERRQ(ierr); 00111 for (icat=0; icat<ncats; icat++) { 00112 ierr = PetscMemzero(option,30*sizeof(char)); CHKERRQ(ierr); 00113 PetscPrintf 00114 (comm," -anamod_%s : options for category %s\n", 00115 categories[icat],categories[icat]); 00116 } 00117 ierr = PetscFree(option); CHKERRQ(ierr); 00118 } 00119 PetscFunctionReturn(0); 00120 }
PetscTruth expensive = PETSC_FALSE [static] |
Definition at line 24 of file options.c.
Referenced by AnaModHasForcedExpensiveComputation(), and AnaModOptionsHandling().
PetscTruth single_proc = PETSC_FALSE [static] |
Definition at line 24 of file options.c.
Referenced by AnaModHasForcedSequentialComputation(), and AnaModOptionsHandling().