Jed Brown avatar Jed Brown committed 817ea41

AO: fix erroneous processing of -ao_view and factor into AOViewFromOptions

AOCreate was calling -ao_view before ao->ops->view could be set, causing
SEGV. Move the dispatch to the convenience creation functions and
consolidate into AOViewFromOptions.

Reported-by: Shao-Ching Huang <huangsc@gmail.com>;

Comments (0)

Files changed (5)

include/petscao.h

 PETSC_EXTERN PetscErrorCode AOCreateMappingIS(IS,IS,AO*);
 
 PETSC_EXTERN PetscErrorCode AOView(AO,PetscViewer);
+PETSC_EXTERN PetscErrorCode AOViewFromOptions(AO,const char*,const char*);
 PETSC_EXTERN PetscErrorCode AODestroy(AO*);
 
 /* Dynamic creation and loading functions */

src/vec/is/ao/impls/basic/aobasic.c

   ierr   = AOCreate(comm,&ao);CHKERRQ(ierr);
   ierr   = AOSetIS(ao,isapp,ispetsc);CHKERRQ(ierr);
   ierr   = AOSetType(ao,AOBASIC);CHKERRQ(ierr);
+  ierr   = AOViewFromOptions(ao,NULL,"-ao_view");CHKERRQ(ierr);
   *aoout = ao;
   PetscFunctionReturn(0);
 }

src/vec/is/ao/impls/mapping/aomapping.c

   PetscMPIInt    size, rank,*lens, *disp,nnapp;
   PetscInt       N, start;
   PetscInt       i;
-  PetscBool      opt;
   PetscErrorCode ierr;
 
   PetscFunctionBegin;
   }
   ierr = PetscFree4(allapp,appPerm,allpetsc,petscPerm);CHKERRQ(ierr);
 
-  opt  = PETSC_FALSE;
-  ierr = PetscOptionsGetBool(NULL, "-ao_view", &opt,NULL);CHKERRQ(ierr);
-  if (opt) {
-    ierr = AOView(ao, PETSC_VIEWER_STDOUT_SELF);CHKERRQ(ierr);
-  }
+  ierr = AOViewFromOptions(ao,NULL,"-ao_view");CHKERRQ(ierr);
 
   *aoout = ao;
   PetscFunctionReturn(0);

src/vec/is/ao/impls/memscalable/aomemscalable.c

   ierr   = AOCreate(comm,&ao);CHKERRQ(ierr);
   ierr   = AOSetIS(ao,isapp,ispetsc);CHKERRQ(ierr);
   ierr   = AOSetType(ao,AOMEMORYSCALABLE);CHKERRQ(ierr);
+  ierr   = AOViewFromOptions(ao,NULL,"-ao_view");CHKERRQ(ierr);
   *aoout = ao;
   PetscFunctionReturn(0);
 }

src/vec/is/ao/interface/ao.c

 }
 
 #undef __FUNCT__
+#define __FUNCT__ "AOViewFromOptions"
+/*
+   AOViewFromOptions - Processes command line options to determine if/how an AO is to be viewed.
+
+   Collective
+
+   Input Arguments:
++  ao - the application ordering
+.  prefix - prefix to use for viewing, or NULL to use prefix of 'ao'
+-  optionname - option to activate viewing
+
+   Level: intermediate
+
+.keywords: AO, view, options, database
+.seealso: AOView(), VecViewFromOptions(), DMViewFromOptions()
+*/
+PetscErrorCode AOViewFromOptions(AO ao,const char *prefix,const char *optionname)
+{
+  PetscErrorCode    ierr;
+  PetscBool         flg;
+  PetscViewer       viewer;
+  PetscViewerFormat format;
+
+  PetscFunctionBegin;
+  if (prefix) {
+    ierr = PetscOptionsGetViewer(PetscObjectComm((PetscObject)ao),prefix,optionname,&viewer,&format,&flg);CHKERRQ(ierr);
+  } else {
+    ierr = PetscOptionsGetViewer(PetscObjectComm((PetscObject)ao),((PetscObject)ao)->prefix,optionname,&viewer,&format,&flg);CHKERRQ(ierr);
+  }
+  if (flg) {
+    ierr = PetscViewerPushFormat(viewer,format);CHKERRQ(ierr);
+    ierr = AOView(ao,viewer);CHKERRQ(ierr);
+    ierr = PetscViewerPopFormat(viewer);CHKERRQ(ierr);
+    ierr = PetscViewerDestroy(&viewer);CHKERRQ(ierr);
+  }
+  PetscFunctionReturn(0);
+}
+
+#undef __FUNCT__
 #define __FUNCT__ "AOCreate"
 /*@C
    AOCreate - Creates an application ordering.
 {
   PetscErrorCode ierr;
   AO             aonew;
-  PetscBool      opt;
 
   PetscFunctionBegin;
   PetscValidPointer(ao,2);
   ierr = PetscHeaderCreate(aonew,_p_AO,struct _AOOps,AO_CLASSID,"AO","Application Ordering","AO",comm,AODestroy,AOView);CHKERRQ(ierr);
   ierr = PetscMemzero(aonew->ops, sizeof(struct _AOOps));CHKERRQ(ierr);
   *ao  = aonew;
-
-  opt  = PETSC_FALSE;
-  ierr = PetscOptionsGetBool(NULL, "-ao_view", &opt,NULL);CHKERRQ(ierr);
-  if (opt) {
-    ierr = AOView(aonew, PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr);
-  }
   PetscFunctionReturn(0);
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.