System Preprocessors
|
00001 #include <stdlib.h> 00002 #include <stdio.h> 00003 #include "syspro.h" 00004 #include "sysprotransform.h" 00005 #include "syspro_impl.h" 00006 00007 /*! \page options Command line options handling 00008 00009 Being based on Petsc, SysPro can tailor its workings by commandline options. 00010 Options are handled by PreprocessorsOptionsHandling(). 00011 This routine needs to be called 00012 explicitly by the user, after all calls to DeclarePreprocessor(). 00013 Commandline options can be set from the program source by the Petsc 00014 call PetscOptionsSetValue(). 00015 00016 The following commandline options are understood. 00017 - \c "-syspro_exhaustive" : every preprocessor is cycled exhaustively, 00018 unless otherwise limited. 00019 - \c "-syspro_someprocessor exhaustive" : the specified preprocessor 00020 is tested exhaustively. 00021 - \c "-syspro_someprocessor choice1,choice2,..." : the specified 00022 preprocessor takes on the specified values. This induces cycling on only 00023 the specified preprocessor; if the \c "-syspro_exhaustive" option 00024 for exhaustive cycling of all preprocessors is given, the limited cycling 00025 takes precedence. 00026 - \c "-syspro_someprocessor not,choice1,choice2,..." : limited cycling 00027 is setup, except that the the specified choices will not be used. 00028 (See TransformObjectsUseOnly() for details.) 00029 - \c "-syspro_someprocessor_somechoice_values v1,v2,v3,... " : if a 00030 preprocessor choice has option values, this sets the values. This is also 00031 induces exhaustive cycling over this preprocessor. Note: unless the 00032 cycling is explicitly limited `somechoice' (see the previous item), 00033 the exhaustive mode will cycle over all choices of this preprocessor. 00034 00035 Any preprocessor can declare its own option handler routine. The option 00036 names it handles can be anything, but should presumably not clash with 00037 the above formats. E.g., use \c "-syspro_pc_iterative" rather than 00038 \c "-syspro_pc iterative". 00039 */ 00040 00041 #undef __FUNCT__ 00042 #define __FUNCT__ "SysProShowOptions" 00043 /*! Display all available options. 00044 */ 00045 PetscErrorCode SysProShowOptions(MPI_Comm comm) 00046 { 00047 PetscErrorCode ierr; 00048 PetscFunctionBegin; 00049 PetscPrintf(comm,"Available SysPro options\n Global:\n"); 00050 PetscPrintf(comm," -syspro_exhaustive : fully exhaustive run\n"); 00051 PetscPrintf(comm,"\n Preprocessors and options:\n"); 00052 { 00053 const char *aclass,**types; int ntypes; PetscBool flg; 00054 ierr = StartRetrievingAllPreprocessors 00055 (&aclass,&types,&ntypes,&flg); CHKERRQ(ierr); 00056 while (flg) { 00057 PetscPrintf(comm," -syspro_%s : options for category %s\n",aclass,aclass); 00058 ierr = PetscFree(types); CHKERRQ(ierr); 00059 ierr = ContinueRetrievingAllPreprocessors 00060 (&aclass,&types,&ntypes,&flg); CHKERRQ(ierr); 00061 } 00062 } 00063 PetscPrintf(comm,"\n"); 00064 PetscFunctionReturn(0); 00065 } 00066 00067 #undef __FUNCT__ 00068 #define __FUNCT__ "PreprocessorsOptionsHandling" 00069 /*! Process commandline options that control the behaviour of SysPro. 00070 For more information see \ref options. 00071 */ 00072 PetscErrorCode PreprocessorsOptionsHandling() 00073 { 00074 SystemPreprocessor pp; char *preprocess; 00075 #define TYPELEN 200 00076 char type[TYPELEN],values[TYPELEN],option[100]; 00077 PetscBool exhaustive,flg; PetscErrorCode ierr; 00078 00079 PetscFunctionBegin; 00080 /* explicit exhaustive run */ 00081 ierr = PetscOptionsHasName 00082 (PETSC_NULL,"-syspro_exhaustive",&exhaustive); CHKERRQ(ierr); 00083 00084 /* loop over all preprocessors */ 00085 ierr = GetFirstPreprocessor((const char**)&preprocess); CHKERRQ(ierr); 00086 while (preprocess) { 00087 SalsaTransform transform; 00088 ierr = SystemPreprocessorGetByName(preprocess,&pp); CHKERRQ(ierr); 00089 ierr = TransformGetByName(preprocess,&transform); CHKERRQ(ierr); 00090 sprintf(option,"-syspro_%s",preprocess); 00091 ierr = PetscOptionsGetString 00092 (PETSC_NULL,option,type,TYPELEN,&flg); CHKERRQ(ierr); 00093 if (flg) { 00094 int n; 00095 /*printf("syspro option: <%s>=<%s>\n",preprocess,type);*/ 00096 ierr = PetscStrcmp(type,"exhaustive",&flg); CHKERRQ(ierr); 00097 if (flg) { 00098 pp->exhaustive = PETSC_TRUE; 00099 ierr = TransformSetUserChoices(transform,PETSC_FALSE); CHKERRQ(ierr); 00100 } else { 00101 ierr = TransformSetUserChoices(transform,PETSC_TRUE); CHKERRQ(ierr); 00102 ierr = TransformObjectsUseOnly(transform,type); CHKERRQ(ierr); 00103 ierr = TransformGetNUnmarked(transform,&n); CHKERRQ(ierr); 00104 pp->exhaustive = TRUTH(n>1); 00105 } 00106 } else { 00107 pp->exhaustive = exhaustive; 00108 ierr = TransformSetUserChoices(transform,PETSC_FALSE); CHKERRQ(ierr); 00109 } 00110 { /* handle options, for instance \c "-syspro_ksp_gmres_values 5,10,20" */ 00111 SalsaTransformObject to; 00112 ierr = TransformGetNextUnmarkedItem 00113 (transform,NULL,&to,&flg); CHKERRQ(ierr); 00114 while (flg) { 00115 const char *name; 00116 ierr = TransformObjectGetName(to,&name); CHKERRQ(ierr); 00117 sprintf(option,"-syspro_%s_%s_values",preprocess,name); CHKERRQ(ierr); 00118 ierr = PetscOptionsGetString 00119 (PETSC_NULL,option,values,TYPELEN,&flg); CHKERRQ(ierr); 00120 if (flg) { 00121 printf("syspro option values: <%s:%s>=<%s>\n",preprocess,name,values); 00122 ierr = TransformItemOptionsUseOnly(to,values); CHKERRQ(ierr); 00123 pp->exhaustive = PETSC_TRUE; 00124 } 00125 ierr = TransformGetNextUnmarkedItem 00126 (transform,name,&to,&flg); CHKERRQ(ierr); 00127 } 00128 } 00129 if (pp->optionshandling) { 00130 ierr = (pp->optionshandling)(); CHKERRQ(ierr); 00131 } 00132 ierr = PreprocessorSaveAprioriSelection(pp); CHKERRQ(ierr); 00133 ierr = ReportEnabledPreprocessors(preprocess); CHKERRQ(ierr); 00134 ierr = GetNextPreprocessor((const char**)&preprocess); CHKERRQ(ierr); 00135 } 00136 PetscFunctionReturn(0); 00137 } 00138