Hi Matt,

Thanks! I think the third point is what I need to get this working correctly. I'll report back when I have this working (or not working).

Best,
David

From: Matthew Knepley <knepley@gmail.com>
Sent: Monday, November 20, 2023 10:00 AM
To: Wells, David <drwells@email.unc.edu>
Cc: petsc-users@mcs.anl.gov <petsc-users@mcs.anl.gov>
Subject: Re: [petsc-users] Logging object creation and destruction counts
 
On Mon, Nov 20, 2023 at 8:00 AM Wells, David <drwells@email.unc.edu> wrote:
Hi everyone,

I just upgraded to PETSc 3.20 and read up on the new logging infrastructure - its a very nice improvement over the old version.

I have some code which checks that every construction has a corresponding destruction via


PetscStageLog  stageLog;
ierr = PetscLogGetStageLog(&stageLog);
for (int i = 0; i < stageLog->stageInfo->classLog->numClasses; ++i)
      {
        if (stageLog->stageInfo->classLog->classInfo[i].destructions !=
            stageLog->stageInfo->classLog->classInfo[i].creations)
          {
            crash();
          }
      }


This no longer works and I can't figure out how to port it. In particular, it looks like I need to get a PetscLogEvent number for creation and another for destruction to retrieve the relevant PetscEventPerfInfo objects per-class - is there some straightforward way to do that for every registered PETSc class?

1. The above code seems to require that creation and destruction occur within the same stage, which might not be true.

2. https://petsc.org/main/manualpages/Profiling/PetscLogStateGetNumClasses/ gets the numbet of classes. You can recreate this loop with the code from PetscLogHandlerObjectCreate_Default() I think,
which is in logdefault.c. However, as I said, this will not properly match up across stages.

3. At logdefault.c:1657 we output all the creations and destructions, so you could copy these loops, but sum across stages.

4. You could register a callback that just increments and decrements for each classid, and then calls PetscLogHandlerObjectCreate/Destroy_Default(), which might be cleaner.

  Thanks,

     Matt
 
Best,
David Wells


--
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