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

Matthew Knepley knepley at gmail.com
Sun Jun 21 09:47:16 CDT 2015


On Sun, Jun 21, 2015 at 9:33 AM, Dave May <dave.mayhem23 at gmail.com> wrote:

> Hi Barry,
>
>
>    Likely Matt had a few more beers between writing the first one and the
>> second one.
>>
>
> Heh - thanks for providing the patch to make both functions behave in the
> same manner.
>
>
>>
>> >
>> > 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.
>>
>>
> Okay, thanks for the advice on how best to do this.
> I did notice that typical usage in petsc was via a static global variable,
> but as a general rule, I try to not introduce global variables into my
> code base.
>

There is no reason it has to be global, but the pattern is to use -1 until
it is initialized.


> Is the string comparison for an event/stage name really that bad a thing
> to do?
> I mean, can it be worse than processing the enormous list of command line
> arguments
> every time XXXSetFromOptions() is called?
>

I am sanguine for a string comparison since these are only called at setup
time. I did this
for the C++ version you can see in the old code.

   Matt


> Cheers,
>   Dave
>
>
>
>>   Barry
>>
>>
>> >
>> >
>> > Cheers
>> >   Dave
>> >
>> >
>>
>>
>>
>


-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20150621/652db329/attachment.html>


More information about the petsc-dev mailing list