suppressing some command line options?

Satish Balay balay at mcs.anl.gov
Fri Oct 13 15:12:06 CDT 2006


ops - forgot the attachment. [attached now]

Satish

On Fri, 13 Oct 2006, Satish Balay wrote:

> I'm attaching a patch that can be applied to petsc-2.3.2 for this to
> work.
> 
> cd petsc-2.3.2-p3
> patch -Np1 < opt.patch
> 
> Alternatively petsc-dev should have it
> http://www-unix.mcs.anl.gov/petsc/petsc-as/developers/index.html
> 
> Let us know if this works.
> Satish
> 
> On Mon, 18 Sep 2006, Barry Smith wrote:
> 
> > 
> >  Boyce,
> > 
> >    Satish is working on this right now. It is a problem that we 
> > never properly resolved in that past and it needs to be solved.
> > Unfortunately we won't be able to get it into the current petsc release,
> > it will have to go in petsc-dev.
> > 
> >    Thanks for reminding us of this problem,
> > 
> >    Barry
> > 
> > 
> > On Mon, 18 Sep 2006, Boyce Griffith wrote:
> > 
> > > Hi, Folks --
> > > 
> > > I have an application in which, for better or for worse, I generate a huge
> > > number of sequential sparse AIJ matrices.  I was wondering if it was possible
> > > to suppress the command line options affiliated with those objects.  (I am
> > > using MatCreateSeqAIJ, and I am not using MatSetFromOptions.)
> > > 
> > > The basic issue is that when a user runs the program with the '-help' flag,
> > > the options associated with these matrices tend to overwhelm all of the other
> > > command line options, e.g., KSP settings.
> > > 
> > > Thanks in advance for any suggestions,
> > > 
> > > -- Boyce Griffith
> > > 
> > > 
> > 
> > 
> 
> 
-------------- next part --------------
diff -r f5f14c217157875403b3b6ad5183d34fdf2a2a69 src/sys/objects/aoptions.c
--- a/src/sys/objects/aoptions.c	Tue Oct 10 11:01:54 2006 -0500
+++ b/src/sys/objects/aoptions.c	Fri Oct 13 00:29:31 2006 -0500
@@ -33,14 +33,98 @@ struct _p_Options {
   PetscOptions next;
 };
 
+typedef struct _p_OptionsHelp* OptionsHelp;
+struct _p_OptionsHelp {
+  char        *prefix;
+  char        *title;
+  char        *mansec;
+  OptionsHelp next;
+};
+
 static struct {
   PetscOptions    next;
   char            *prefix,*mprefix;  
   char            *title;
   MPI_Comm        comm;
-  PetscTruth      printhelp,changedmethod;
+  PetscTruth      printhelp,changedmethod,alreadyprinted;
+  OptionsHelp     help;
 }                                   PetscOptionsObject;
 PetscInt                            PetscOptionsPublishCount = 0;
+
+
+#undef __FUNCT__
+#define __FUNCT__ "PetscOptionsHelpAddList"
+PetscErrorCode PetscOptionsHelpAddList(const char prefix[],const char title[],const char mansec[])
+{
+  int          ierr;
+  OptionsHelp  newhelp;
+  PetscFunctionBegin;
+  ierr = PetscNew(struct _p_OptionsHelp,&newhelp);CHKERRQ(ierr);
+  ierr = PetscStrallocpy(prefix,&newhelp->prefix);CHKERRQ(ierr);
+  ierr = PetscStrallocpy(title,&newhelp->title);CHKERRQ(ierr);
+  ierr = PetscStrallocpy(mansec,&newhelp->mansec);CHKERRQ(ierr);
+  newhelp->next = 0;
+
+  if (!PetscOptionsObject.help) {
+    PetscOptionsObject.help = newhelp;
+  } else {
+    newhelp->next = PetscOptionsObject.help;
+    PetscOptionsObject.help = newhelp;
+  }
+  PetscFunctionReturn(0);
+}
+
+#undef __FUNCT__
+#define __FUNCT__ "PetscOptionsHelpDestroyList"
+PetscErrorCode PetscOptionsHelpDestroyList(void)
+{
+  PetscErrorCode ierr;
+  OptionsHelp    help = PetscOptionsObject.help, next;
+
+  PetscFunctionBegin;
+  while (help) {
+    next = help->next;
+    ierr = PetscStrfree(help->prefix);CHKERRQ(ierr);
+    ierr = PetscStrfree(help->title);CHKERRQ(ierr);
+    ierr = PetscStrfree(help->mansec);CHKERRQ(ierr);
+    ierr = PetscFree(help);CHKERRQ(ierr);
+    help = next;
+  }
+  PetscFunctionReturn(0);
+}
+  
+
+#undef __FUNCT__
+#define __FUNCT__ "PetscOptionsHelpFindList"
+PetscErrorCode PetscOptionsHelpFindList(const char prefix[],const char title[],const char mansec[],PetscTruth *flg)
+{
+  PetscErrorCode ierr;
+  PetscTruth     flg1,flg2,flg3;
+  PetscFunctionBegin;
+  OptionsHelp help = PetscOptionsObject.help;
+  while (help) {
+    ierr = PetscStrcmp(help->prefix,prefix,&flg1);CHKERRQ(ierr);
+    ierr = PetscStrcmp(help->title,title,&flg2);CHKERRQ(ierr);
+    ierr = PetscStrcmp(help->mansec,mansec,&flg3);CHKERRQ(ierr);
+    if (flg1 && flg2 && flg3) {
+      *flg = 1;
+      break;
+    }
+    help = help->next;
+  }
+  PetscFunctionReturn(0);
+
+}
+
+#undef __FUNCT__
+#define __FUNCT__ "PetscOptionsHelpCheckAddList"
+PetscErrorCode PetscOptionsHelpCheckAddList(const char prefix[],const char title[],const char mansec[],PetscTruth *flg)
+{
+  PetscFunctionBegin;
+  PetscOptionsHelpFindList(prefix,title,mansec,flg);
+  if (!(*flg)) PetscOptionsHelpAddList(prefix,title,mansec);
+  PetscFunctionReturn(0);
+}
 
 #undef __FUNCT__  
 #define __FUNCT__ "PetscOptionsBegin_Private"
@@ -60,7 +144,10 @@ PetscErrorCode PetscOptionsBegin_Private
 
   ierr = PetscOptionsHasName(PETSC_NULL,"-help",&PetscOptionsObject.printhelp);CHKERRQ(ierr);
   if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) {
-    ierr = (*PetscHelpPrintf)(comm,"%s -------------------------------------------------\n",title);CHKERRQ(ierr);
+    ierr = PetscOptionsHelpCheckAddList(prefix,title,mansec,&PetscOptionsObject.alreadyprinted);
+    if (!PetscOptionsObject.alreadyprinted) {
+      ierr = (*PetscHelpPrintf)(comm,"%s -------------------------------------------------\n",title);CHKERRQ(ierr);
+    }
   }
   PetscFunctionReturn(0);
 }
@@ -82,6 +169,7 @@ static int PetscOptionsCreate_Private(co
   (*amsopt)->type  = t;
   (*amsopt)->data  = 0;
   (*amsopt)->edata = 0;
+
   ierr             = PetscStrallocpy(text,&(*amsopt)->text);CHKERRQ(ierr);
   ierr             = PetscStrallocpy(opt,&(*amsopt)->option);CHKERRQ(ierr);
   ierr             = PetscStrallocpy(man,&(*amsopt)->man);CHKERRQ(ierr);
@@ -144,6 +232,8 @@ PetscErrorCode PetscOptionsEnd_Private(v
 
   /* reset counter to -2; this updates the screen with the new options for the selected method */
   if (PetscOptionsObject.changedmethod) PetscOptionsPublishCount = -2; 
+  /* reset alreadyprinted flag */
+  PetscOptionsObject.alreadyprinted = PETSC_FALSE;
 
   while (PetscOptionsObject.next) { 
     if (PetscOptionsObject.next->set) {
@@ -469,7 +559,7 @@ PetscErrorCode PETSC_DLLEXPORT PetscOpti
 
   PetscFunctionBegin;
   ierr = PetscOptionsHasName(PetscOptionsObject.prefix,opt,flg);CHKERRQ(ierr);
-  if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1) {
+  if (PetscOptionsObject.printhelp && PetscOptionsPublishCount == 1 && !PetscOptionsObject.alreadyprinted) {
     ierr = (*PetscHelpPrintf)(PetscOptionsObject.comm,"  -%s%s: %s (%s)\n",PetscOptionsObject.prefix?PetscOptionsObject.prefix:"",opt+1,text,man);CHKERRQ(ierr);
   }
   PetscFunctionReturn(0);
diff -r f5f14c217157875403b3b6ad5183d34fdf2a2a69 src/sys/objects/pinit.c
--- a/src/sys/objects/pinit.c	Tue Oct 10 11:01:54 2006 -0500
+++ b/src/sys/objects/pinit.c	Fri Oct 13 00:24:06 2006 -0500
@@ -20,6 +20,7 @@ EXTERN PetscErrorCode PetscSequentialPha
 EXTERN PetscErrorCode PetscSequentialPhaseBegin_Private(MPI_Comm,int);
 EXTERN PetscErrorCode PetscSequentialPhaseEnd_Private(MPI_Comm,int);
 EXTERN PetscErrorCode PetscLogCloseHistoryFile(FILE **);
+EXTERN PetscErrorCode PetscOptionsHelpDestroyList(void);
 
 /* this is used by the _, __, and ___ macros (see include/petscerror.h) */
 PetscErrorCode __gierr = 0;
@@ -622,6 +623,7 @@ PetscErrorCode PETSC_DLLEXPORT PetscFina
     PETSC_VIEWER_XXX_().
   */
   ierr = PetscObjectRegisterDestroyAll();CHKERRQ(ierr);  
+  ierr = PetscOptionsHelpDestroyList();CHKERRQ(ierr);
 
 #if defined(PETSC_USE_DEBUG)
   if (PetscStackActive) {
diff --git a/src/sys/objects/aoptions.c b/src/sys/objects/aoptions.c
--- a/src/sys/objects/aoptions.c	Fri Oct 13 14:52:55 2006
+++ b/src/sys/objects/aoptions.c	Fri Oct 13 19:32:04 2006
@@ -107,7 +107,7 @@
     ierr = PetscStrcmp(help->title,title,&flg2);CHKERRQ(ierr);
     ierr = PetscStrcmp(help->mansec,mansec,&flg3);CHKERRQ(ierr);
     if (flg1 && flg2 && flg3) {
-      *flg = 1;
+      *flg = PETSC_TRUE;
       break;
     }
     help = help->next;


More information about the petsc-users mailing list