<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
<div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
<div class="">Let me follow up discussion on creating/controlling viewers from options.</div>
<div class=""><br class="">
</div>
<div class="">Barry agrees to rename PetscOptionsGetViewer() to PetscViewerCreateFromOptions() in <a href="https://bitbucket.org/petsc/petsc/issues/291/" class="">Issue #291</a>.</div>
<div class=""><br class="">
</div>
<div class="">But now I can see a problem: it mixes Get and Create behavior, as it returns the singleton provided by PETSC_VIEWER_*_() if possible, otherwise creates a new viewer using PetscViewerCreate(). So actually both names PetscOptionsGetViewer() and
PetscViewerCreateFromOptions() are confusing.</div>
<div class=""><br class="">
</div>
<div class="">I think this design is unnecessarily complicated and not really useful.</div>
<div class="">I don't see any advantage of reusing the singleton in this context.</div>
<div class="">And leads to some IMHO unexpected behavior:</div>
<div class="">* -myviewer hdf5:: and -myviewer hdf5 is not the same! I didn't know that but hdf5:: creates a new viewer and hdf5 reuses the singleton.</div>
<div class="">* Any properties (including options prefix) set to the viewer returned by PetscOptionsGetViewer() actually affect the singleton and vice versa.</div>
<div class=""> (See <a href="https://bitbucket.org/petsc/petsc/commits/324f959" class="">https://bitbucket.org/petsc/petsc/commits/324f959</a>)</div>
<div class=""><br class="">
</div>
<div class="">So in my opinion PetscOptionsGetViewer()</div>
<div class="">* should really be renamed PetscViewerCreateFromOptions(),</div>
<div class="">* should _always_ return a new instance and call PetscViewerSetFromOptions() on it,</div>
<div class="">* could also set the passed prefix to the viewer, i.e. PetscViewerCreateFromOptions(comm, options, "pre_", ...) would result in the viewer having prefix pre_ </div>
<div class=""><br class="">
</div>
<div class="">Do you think it would break anything?</div>
<div class=""><br class="">
</div>
<div class="">Thanks,</div>
<div class="">Vaclav</div>
<div class=""><br class="">
</div>
<div class="">BTW all PETSC_VIEWER_XXX_() manpages say "Creates a XXX PetscViewer shared by all processors in a communicator."</div>
<div class="">This is apparently not true - they are singletons stashed to the communicator by MPI_Comm_set_attr() and next time reused if found using MPI_Comm_get_attr(), right?</div>
<div class="">So it should be Returns, not Creates.</div>
</div>
</body>
</html>