Commits

Jed Brown committed 329d851 Merge

Merge branch 'barry/fix-xxxviewsetfromoptions'

* barry/fix-xxxviewsetfromoptions:
*ViewFromOptions: update documentation, providing disabled man pages
fixed bug where XXXViewFromOptions() used prefix of object rather than appropriate prefix of KSP or SNES

Comments (0)

Files changed (19)

 PETSC_EXTERN PetscErrorCode DMRestrict(DM,Mat,Vec,Mat,DM);
 PETSC_EXTERN PetscErrorCode DMInterpolate(DM,Mat,DM);
 PETSC_EXTERN PetscErrorCode DMSetFromOptions(DM);
-PETSC_EXTERN PetscErrorCode DMViewFromOptions(DM,const char[]);
+PETSC_EXTERN PetscErrorCode DMViewFromOptions(DM,const char[], const char[]);
 
 PETSC_EXTERN PetscErrorCode DMSetUp(DM);
 PETSC_EXTERN PetscErrorCode DMCreateInterpolationScale(DM,DM,Mat,Vec*);
 PETSC_EXTERN PetscErrorCode MatSetSizes(Mat,PetscInt,PetscInt,PetscInt,PetscInt);
 PETSC_EXTERN PetscErrorCode MatSetType(Mat,MatType);
 PETSC_EXTERN PetscErrorCode MatSetFromOptions(Mat);
-PETSC_EXTERN PetscErrorCode MatViewFromOptions(Mat,const char[]);
+PETSC_EXTERN PetscErrorCode MatViewFromOptions(Mat,const char[],const char[]);
 PETSC_EXTERN PetscErrorCode MatRegisterAll(void);
 PETSC_EXTERN PetscErrorCode MatRegister(const char[],PetscErrorCode(*)(Mat));
 PETSC_EXTERN PetscErrorCode MatRegisterBaseName(const char[],const char[],const char[]);
 PETSC_EXTERN PetscErrorCode PetscRandomSetType(PetscRandom, PetscRandomType);
 PETSC_EXTERN PetscErrorCode PetscRandomSetFromOptions(PetscRandom);
 PETSC_EXTERN PetscErrorCode PetscRandomGetType(PetscRandom, PetscRandomType*);
-PETSC_EXTERN PetscErrorCode PetscRandomViewFromOptions(PetscRandom,const char[]);
+ PETSC_EXTERN PetscErrorCode PetscRandomViewFromOptions(PetscRandom,const char[],const char[]);
 PETSC_EXTERN PetscErrorCode PetscRandomView(PetscRandom,PetscViewer);
 
 PETSC_EXTERN PetscErrorCode PetscRandomCreate(MPI_Comm,PetscRandom*);
 PETSC_EXTERN PetscErrorCode VecCreateMPIWithArray(MPI_Comm,PetscInt,PetscInt,PetscInt,const PetscScalar[],Vec*);
 PETSC_EXTERN PetscErrorCode VecCreateShared(MPI_Comm,PetscInt,PetscInt,Vec*);
 PETSC_EXTERN PetscErrorCode VecSetFromOptions(Vec);
-PETSC_EXTERN PetscErrorCode VecViewFromOptions(Vec,const char[]);
+PETSC_EXTERN PetscErrorCode VecViewFromOptions(Vec,const char[],const char[]);
 
 PETSC_EXTERN PetscErrorCode VecSetUp(Vec);
 PETSC_EXTERN PetscErrorCode VecDestroy(Vec*);

src/dm/examples/tutorials/ex3.c

     ierr = SetCoordinates3d(daf);CHKERRQ(ierr);
   }
   ierr = DMCreateInterpolation(dac,daf,&A,0);CHKERRQ(ierr);
-  ierr = MatViewFromOptions(A,"-mat_view");CHKERRQ(ierr);
+  ierr = MatViewFromOptions(A,NULL,"-mat_view");CHKERRQ(ierr);
 
 
   /* Free memory */
 
   ierr = DMSetFromOptions(da2);CHKERRQ(ierr);
   ierr = DMSetUp(da2);CHKERRQ(ierr);
-  ierr = DMViewFromOptions(da2,"-dm_view");CHKERRQ(ierr);
+  ierr = DMViewFromOptions(da2,NULL,"-dm_view");CHKERRQ(ierr);
 
   /* interpolate coordinates if they are set on the coarse grid */
   if (da->coordinates) {
 
   ierr = DMSetFromOptions(da2);CHKERRQ(ierr);
   ierr = DMSetUp(da2);CHKERRQ(ierr);
-  ierr = DMViewFromOptions(da2,"-dm_view");CHKERRQ(ierr);
+  ierr = DMViewFromOptions(da2,NULL,"-dm_view");CHKERRQ(ierr);
 
   /* inject coordinates if they are set on the fine grid */
   if (da->coordinates) {

src/dm/impls/da/da1.c

   /* This violates the behavior for other classes, but right now users expect negative dimensions to be handled this way */
   ierr = DMSetFromOptions(*da);CHKERRQ(ierr);
   ierr = DMSetUp(*da);CHKERRQ(ierr);
-  ierr = DMViewFromOptions(*da,"-dm_view");CHKERRQ(ierr);
+  ierr = DMViewFromOptions(*da,NULL,"-dm_view");CHKERRQ(ierr);
   PetscFunctionReturn(0);
 }

src/dm/impls/da/da2.c

   /* This violates the behavior for other classes, but right now users expect negative dimensions to be handled this way */
   ierr = DMSetFromOptions(*da);CHKERRQ(ierr);
   ierr = DMSetUp(*da);CHKERRQ(ierr);
-  ierr = DMViewFromOptions(*da,"-dm_view");CHKERRQ(ierr);
+  ierr = DMViewFromOptions(*da,NULL,"-dm_view");CHKERRQ(ierr);
   PetscFunctionReturn(0);
 }

src/dm/impls/da/da3.c

   /* This violates the behavior for other classes, but right now users expect negative dimensions to be handled this way */
   ierr = DMSetFromOptions(*da);CHKERRQ(ierr);
   ierr = DMSetUp(*da);CHKERRQ(ierr);
-  ierr = DMViewFromOptions(*da,"-dm_view");CHKERRQ(ierr);
+  ierr = DMViewFromOptions(*da,NULL,"-dm_view");CHKERRQ(ierr);
   PetscFunctionReturn(0);
 }

src/dm/interface/dm.c

 #undef __FUNCT__
 #define __FUNCT__ "DMViewFromOptions"
 /*
-  Processes command line options to determine if/how a dm
-  is to be viewed.
+  DMViewFromOptions - Processes command line options to determine if/how a DM is to be viewed.
 
+  Collective on Vec
+
+  Input Parameters:
++ dm   - the DM
+. prefix - prefix to use for viewing, or NULL to use prefix of 'rnd'
+- optionname - option to activate viewing
+
+  Level: intermediate
+
+.keywords: DM, view, options, database
+.seealso: VecViewFromOptions(), MatViewFromOptions()
 */
-PetscErrorCode  DMViewFromOptions(DM dm,const char optionname[])
+PetscErrorCode  DMViewFromOptions(DM dm,const char prefix[],const char optionname[])
 {
   PetscErrorCode    ierr;
   PetscBool         flg;
   PetscViewerFormat format;
 
   PetscFunctionBegin;
-  ierr = PetscOptionsGetViewer(PetscObjectComm((PetscObject)dm),((PetscObject)dm)->prefix,optionname,&viewer,&format,&flg);CHKERRQ(ierr);
+  if (prefix) {
+    ierr = PetscOptionsGetViewer(PetscObjectComm((PetscObject)dm),prefix,optionname,&viewer,&format,&flg);CHKERRQ(ierr);
+  } else {
+    ierr = PetscOptionsGetViewer(PetscObjectComm((PetscObject)dm),((PetscObject)dm)->prefix,optionname,&viewer,&format,&flg);CHKERRQ(ierr);
+  }
   if (flg) {
     ierr = PetscViewerPushFormat(viewer,format);CHKERRQ(ierr);
     ierr = DMView(dm,viewer);CHKERRQ(ierr);
   /* process any options handlers added with PetscObjectAddOptionsHandler() */
   ierr = PetscObjectProcessOptionsHandlers((PetscObject) dm);CHKERRQ(ierr);
   ierr = PetscOptionsEnd();CHKERRQ(ierr);
-  ierr = DMViewFromOptions(dm,"-dm_view");CHKERRQ(ierr);
+  ierr = DMViewFromOptions(dm,NULL,"-dm_view");CHKERRQ(ierr);
   PetscFunctionReturn(0);
 }
 

src/ksp/ksp/interface/itfunc.c

   ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)ksp),&rank);CHKERRQ(ierr);
 
   ierr = PCGetOperators(ksp->pc,&mat,&premat,NULL);CHKERRQ(ierr);
-  ierr = MatViewFromOptions(mat,"-ksp_view_mat");CHKERRQ(ierr);
-  ierr = MatViewFromOptions(premat,"-ksp_view_pmat");CHKERRQ(ierr);
-  ierr = VecViewFromOptions(ksp->vec_rhs,"-ksp_view_rhs");CHKERRQ(ierr);
+  ierr = MatViewFromOptions(mat,((PetscObject)ksp)->prefix,"-ksp_view_mat");CHKERRQ(ierr);
+  ierr = MatViewFromOptions(premat,((PetscObject)ksp)->prefix,"-ksp_view_pmat");CHKERRQ(ierr);
+  ierr = VecViewFromOptions(ksp->vec_rhs,((PetscObject)ksp)->prefix,"-ksp_view_rhs");CHKERRQ(ierr);
 
   flag1 = PETSC_FALSE;
   flag2 = PETSC_FALSE;
     Mat A,B;
     ierr = PCGetOperators(ksp->pc,&A,NULL,NULL);CHKERRQ(ierr);
     ierr = MatComputeExplicitOperator(A,&B);CHKERRQ(ierr);
-    ierr = MatViewFromOptions(B,"-ksp_view_mat_explicit");CHKERRQ(ierr);
+    ierr = MatViewFromOptions(B,((PetscObject)ksp)->prefix,"-ksp_view_mat_explicit");CHKERRQ(ierr);
     ierr = MatDestroy(&B);CHKERRQ(ierr);
   }
   ierr = PetscOptionsHasName(((PetscObject)ksp)->prefix,"-ksp_view_preconditioned_operator_explicit",&flag2);CHKERRQ(ierr);
   if (flag2) {
     Mat B;
     ierr = KSPComputeExplicitOperator(ksp,&B);CHKERRQ(ierr);
-    ierr = MatViewFromOptions(B,"-ksp_view_preconditioned_operator_explicit");CHKERRQ(ierr);
+    ierr = MatViewFromOptions(B,((PetscObject)ksp)->prefix,"-ksp_view_preconditioned_operator_explicit");CHKERRQ(ierr);
     ierr = MatDestroy(&B);CHKERRQ(ierr);
   }
   ierr = PetscOptionsGetViewer(PetscObjectComm((PetscObject)ksp),((PetscObject)ksp)->prefix,"-ksp_view",&viewer,&format,&flg);CHKERRQ(ierr);
     ierr = VecDestroy(&t);CHKERRQ(ierr);
     ierr = PetscPrintf(PetscObjectComm((PetscObject)ksp),"KSP final norm of residual %G\n",norm);CHKERRQ(ierr);
   }
-  ierr = VecViewFromOptions(ksp->vec_sol,"-ksp_view_solution");CHKERRQ(ierr);
+  ierr = VecViewFromOptions(ksp->vec_sol,((PetscObject)ksp)->prefix,"-ksp_view_solution");CHKERRQ(ierr);
 
   if (inXisinB) {
     ierr = VecCopy(x,b);CHKERRQ(ierr);

src/mat/impls/maij/maij.c

     B->ops->getsubmatrix = MatGetSubMatrix_MAIJ;
     ierr  = MatSetUp(B);CHKERRQ(ierr);
     *maij = B;
-    ierr  = MatViewFromOptions(B,"-mat_view");CHKERRQ(ierr);
+    ierr  = MatViewFromOptions(B,NULL,"-mat_view");CHKERRQ(ierr);
   }
   PetscFunctionReturn(0);
 }

src/mat/interface/matrix.c

 #undef __FUNCT__
 #define __FUNCT__ "MatViewFromOptions"
 /*
-    Processes command line options to determine if/how a matrix
-  is to be viewed. Called by MatAssemblyEnd() and MatLoad().
+  MatViewFromOptions - Processes command line options to determine if/how a matrix is to be viewed. Called from higher level packages.
+
+  Collective on Vec
+
+  Input Parameters:
++ mat   - the matrix
+. prefix - prefix to use for viewing, or NULL to use prefix of 'rnd'
+- optionname - option to activate viewing
+
+  Level: intermediate
+
+.keywords: Mat, view, options, database
+.seealso: MatViewFromOptions()
 */
-PetscErrorCode MatViewFromOptions(Mat mat,const char optionname[])
+PetscErrorCode MatViewFromOptions(Mat mat,const char prefix[],const char optionname[])
 {
   PetscErrorCode    ierr;
   PetscViewer       viewer;
   PetscFunctionBegin;
   if (incall) PetscFunctionReturn(0);
   incall = PETSC_TRUE;
-  ierr   = PetscOptionsGetViewer(PetscObjectComm((PetscObject)mat),((PetscObject)mat)->prefix,optionname,&viewer,&format,&flg);CHKERRQ(ierr);
+  if (prefix) {
+    ierr   = PetscOptionsGetViewer(PetscObjectComm((PetscObject)mat),prefix,optionname,&viewer,&format,&flg);CHKERRQ(ierr);
+  } else {
+    ierr   = PetscOptionsGetViewer(PetscObjectComm((PetscObject)mat),((PetscObject)mat)->prefix,optionname,&viewer,&format,&flg);CHKERRQ(ierr);
+  }
   if (flg) {
     ierr = PetscViewerPushFormat(viewer,format);CHKERRQ(ierr);
     ierr = MatView(mat,viewer);CHKERRQ(ierr);

src/mat/matfd/fdmatrix.c

 
 #undef __FUNCT__
 #define __FUNCT__ "MatFDColoringViewFromOptions"
-PetscErrorCode MatFDColoringViewFromOptions(MatFDColoring fd,const char optionname[])
+PetscErrorCode MatFDColoringViewFromOptions(MatFDColoring fd,const char prefix[],const char optionname[])
 {
   PetscErrorCode    ierr;
   PetscBool         flg;
   PetscViewerFormat format;
 
   PetscFunctionBegin;
-  ierr = PetscOptionsGetViewer(PetscObjectComm((PetscObject)fd),((PetscObject)fd)->prefix,optionname,&viewer,&format,&flg);CHKERRQ(ierr);
+  if (prefix) {
+    ierr = PetscOptionsGetViewer(PetscObjectComm((PetscObject)fd),prefix,optionname,&viewer,&format,&flg);CHKERRQ(ierr);
+  } else {
+    ierr = PetscOptionsGetViewer(PetscObjectComm((PetscObject)fd),((PetscObject)fd)->prefix,optionname,&viewer,&format,&flg);CHKERRQ(ierr);
+  }
   if (flg) {
     ierr = PetscViewerPushFormat(viewer,format);CHKERRQ(ierr);
     ierr = MatFDColoringView(fd,viewer);CHKERRQ(ierr);
   ierr = MatAssemblyEnd(J,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);
   ierr = PetscLogEventEnd(MAT_FDColoringApply,coloring,J,x1,0);CHKERRQ(ierr);
 
-  ierr = MatFDColoringViewFromOptions(coloring,"-mat_fd_coloring_view");CHKERRQ(ierr);
+  ierr = MatFDColoringViewFromOptions(coloring,NULL,"-mat_fd_coloring_view");CHKERRQ(ierr);
   PetscFunctionReturn(0);
 }

src/mat/order/sorder.c

   if (flg) {
     Mat tmat;
     ierr = MatPermute(mat,*rperm,*cperm,&tmat);CHKERRQ(ierr);
-    ierr = MatViewFromOptions(tmat,"-mat_view_ordering");CHKERRQ(ierr);
+    ierr = MatViewFromOptions(tmat,((PetscObject)mat)->prefix,"-mat_view_ordering");CHKERRQ(ierr);
     ierr = MatDestroy(&tmat);CHKERRQ(ierr);
   }
   PetscFunctionReturn(0);

src/snes/impls/test/snestest.c

 
   if (complete_print) {
     ierr = PetscViewerASCIIPrintf(viewer,"    Finite difference Jacobian\n");CHKERRQ(ierr);
-    ierr = MatViewFromOptions(B,"-snes_check_jacobian_view");CHKERRQ(ierr);
+    ierr = MatViewFromOptions(B,((PetscObject)snes)->prefix,"-snes_check_jacobian_view");CHKERRQ(ierr);
   }
   /* compare */
   ierr = MatAYPX(B,-1.0,A,DIFFERENT_NONZERO_PATTERN);CHKERRQ(ierr);
   ierr = MatNorm(A,NORM_FROBENIUS,&gnorm);CHKERRQ(ierr);
   if (complete_print) {
     ierr = PetscViewerASCIIPrintf(viewer,"    Hand-coded Jacobian\n");CHKERRQ(ierr);
-    ierr = MatViewFromOptions(A,"-snes_check_jacobian_view");CHKERRQ(ierr);
+    ierr = MatViewFromOptions(A,((PetscObject)snes)->prefix,"-snes_check_jacobian_view");CHKERRQ(ierr);
     ierr = PetscViewerASCIIPrintf(viewer,"    Hand-coded minus finite difference Jacobian\n");CHKERRQ(ierr);
-    ierr = MatViewFromOptions(B,"-snes_check_jacobian_view");CHKERRQ(ierr);
+    ierr = MatViewFromOptions(B,((PetscObject)snes)->prefix,"-snes_check_jacobian_view");CHKERRQ(ierr);
   }
   if (!gnorm) gnorm = 1; /* just in case */
   ierr = PetscViewerASCIIPrintf(viewer,"    %g = ||J - Jfd||//J|| %g  = ||J - Jfd||\n",(double)(nrm/gnorm),(double)nrm);CHKERRQ(ierr);

src/snes/interface/snes.c

     ierr = PetscViewerPopFormat(viewer);CHKERRQ(ierr);
     ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
   }
-  ierr = VecViewFromOptions(snes->vec_sol,"-snes_view_solution");CHKERRQ(ierr);
+  ierr = VecViewFromOptions(snes->vec_sol,((PetscObject)snes)->prefix,"-snes_view_solution");CHKERRQ(ierr);
 
   ierr = VecDestroy(&xcreated);CHKERRQ(ierr);
   ierr = PetscObjectAMSBlock((PetscObject)snes);CHKERRQ(ierr);

src/sys/classes/random/interface/randomc.c

     ierr = PetscRandomSeed(rnd);CHKERRQ(ierr);
   }
   ierr = PetscOptionsEnd();CHKERRQ(ierr);
-  ierr = PetscRandomViewFromOptions(rnd, "-random_view");CHKERRQ(ierr);
+  ierr = PetscRandomViewFromOptions(rnd,NULL, "-random_view");CHKERRQ(ierr);
   PetscFunctionReturn(0);
 }
 
 
 #undef  __FUNCT__
 #define __FUNCT__ "PetscRandomViewFromOptions"
-/*@
+/*
   PetscRandomViewFromOptions - This function visualizes the type and the seed of the generated random numbers based upon user options.
 
   Collective on PetscRandom
 
   Input Parameters:
-. rnd   - The random number generator context
-. title - The title
++ rnd   - The random number generator context
+. prefix - prefix to use for viewing, or NULL to use prefix of 'rnd'
+- optionname - option to activate viewing
 
   Level: intermediate
 
 .keywords: PetscRandom, view, options, database
 .seealso: PetscRandomSetFromOptions()
-@*/
-PetscErrorCode  PetscRandomViewFromOptions(PetscRandom rnd, const char optionname[])
+*/
+PetscErrorCode  PetscRandomViewFromOptions(PetscRandom rnd, const char prefix[], const char optionname[])
 {
   PetscBool         flg;
   PetscViewer       viewer;
   PetscViewerFormat format;
 
   PetscFunctionBegin;
-  ierr = PetscOptionsGetViewer(PetscObjectComm((PetscObject)rnd),((PetscObject)rnd)->prefix,optionname,&viewer,&format,&flg);CHKERRQ(ierr);
+  if (prefix) {
+    ierr = PetscOptionsGetViewer(PetscObjectComm((PetscObject)rnd),prefix,optionname,&viewer,&format,&flg);CHKERRQ(ierr);
+  } else {
+    ierr = PetscOptionsGetViewer(PetscObjectComm((PetscObject)rnd),((PetscObject)rnd)->prefix,optionname,&viewer,&format,&flg);CHKERRQ(ierr);
+  }
   if (flg) {
     ierr = PetscViewerPushFormat(viewer,format);CHKERRQ(ierr);
     ierr = PetscRandomView(rnd,viewer);CHKERRQ(ierr);

src/vec/vec/interface/vector.c

 #undef __FUNCT__
 #define __FUNCT__ "VecViewFromOptions"
 /*
-  Processes command line options to determine if/how a matrix
-  is to be viewed. Called by VecAssemblyEnd() and VecLoad()
+  VecViewFromOptions - Processes command line options to determine if/how a vector is to be viewed. Called from higher level packages.
 
-.seealso: MatViewFromOptions()
+  Collective on Vec
 
+  Input Parameters:
++ vec   - the vector
+. prefix - prefix to use for viewing, or NULL to use prefix of 'rnd'
+- optionname - option to activate viewing
+
+  Level: intermediate
+
+.keywords: Vec, view, options, database
+.seealso: MatViewFromOptions()
 */
-PetscErrorCode  VecViewFromOptions(Vec vec,const char optionname[])
+PetscErrorCode  VecViewFromOptions(Vec vec,const char prefix[],const char optionname[])
 {
   PetscErrorCode    ierr;
   PetscBool         flg;
   PetscViewerFormat format;
 
   PetscFunctionBegin;
-  ierr = PetscOptionsGetViewer(PetscObjectComm((PetscObject)vec),((PetscObject)vec)->prefix,optionname,&viewer,&format,&flg);CHKERRQ(ierr);
+  if (prefix) {
+    ierr = PetscOptionsGetViewer(PetscObjectComm((PetscObject)vec),prefix,optionname,&viewer,&format,&flg);CHKERRQ(ierr);
+  } else {
+    ierr = PetscOptionsGetViewer(PetscObjectComm((PetscObject)vec),((PetscObject)vec)->prefix,optionname,&viewer,&format,&flg);CHKERRQ(ierr);
+  }
   if (flg) {
     ierr = PetscViewerPushFormat(viewer,format);CHKERRQ(ierr);
     ierr = VecView(vec,viewer);CHKERRQ(ierr);