[petsc-dev] Behaviour of PetscLogEventGetId() and PetscLogStageGetId()

Barry Smith bsmith at mcs.anl.gov
Fri Jun 19 17:29:23 CDT 2015


> On Jun 19, 2015, at 3:54 AM, Dave May <dave.mayhem23 at gmail.com> wrote:
> 
> I was wondering why there is different behaviour between 
>   PetscLogEventGetId()
> and
>   PetscLogStageGetId()
> 
> PetscLogEventGetId() returns -1 if the event isn't found, 
> whilst  PetscLogStageGetId() throws an error if the stage isn't found.

   Likely Matt had a few more beers between writing the first one and the second one.

> 
> My use case is that within one of my custom preconditioners, I wanted
> to call PetscLogStageRegister() during the creation phase, but obviously
> I can only register the stage once. To enable multiple instances of the 
> preconditioner to exist, I need to ensure that the stage is only registered once.
> Hence I would like to check for the existence of the stage prior to calling
> the register function.
> 
> Is there currently a way to check for the existence of a registered stage?

  No, we don't recommend doing it this way. The way we do it in PETSc is to have a static global variable that contains the stage ID and simply check the value of that id to determine if it has been set (set it to -1 at compile time) so your test can then just be that it is not -1. The stage register stuff goes through string comparisons so it should not be called a bunch of times.

  Barry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix-petscslogstagegetid.patch
Type: application/octet-stream
Size: 1310 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20150619/609bf270/attachment.obj>
-------------- next part --------------

> 
> 
> Cheers
>   Dave
> 
> 



More information about the petsc-dev mailing list