Skip to content

Fixes to Timer logic - #3488

Merged
garth-wells merged 5 commits into
mainfrom
garth/improve-timer-logic
Oct 30, 2024
Merged

Fixes to Timer logic#3488
garth-wells merged 5 commits into
mainfrom
garth/improve-timer-logic

Conversation

@garth-wells

@garth-wells garth-wells commented Oct 29, 2024

Copy link
Copy Markdown
Member

The logic behind the interaction between Timer and TimeLogger was messed up. This attempts to fix it without interface changes.

Improves and fixes tests.

@garth-wells garth-wells added the enhancement New feature or request label Oct 29, 2024
@garth-wells
garth-wells requested a review from jorgensd October 29, 2024 12:05
@jorgensd

Copy link
Copy Markdown
Member

Shouldn't "stop" imply a "flush" if we want to maintain the timing API?

There isn't a way to "pause" a timer, as "start" resets the accumulated time. Thus stop should imply flush.

@garth-wells

Copy link
Copy Markdown
Member Author

Shouldn't "stop" imply a "flush" if we want to maintain the timing API?

The logic has always been that durations are logged with the Timer is destroyed. flush forces this to happen earlier.

There isn't a way to "pause" a timer, as "start" resets the accumulated time. Thus stop should imply flush.

There was a resume - @schnellerhase removed it because it was untested. I could now be added back (I think it should).

@jorgensd

Copy link
Copy Markdown
Member

Shouldn't "stop" imply a "flush" if we want to maintain the timing API?

The logic has always been that durations are logged with the Timer is destroyed. flush forces this to happen earlier.

That is a bit tedious on the python side, as a user would manually have to delete a timer if it is not made with a context manager, or call flush explicitly. This assumption has at least never been documented on the Python-side of things.

I am ok with forcing a flush on the python side, but then that has to be documented as a prerequisite in the C++ and Python documentation of the timing function.

While looking through this, I also observe that the docs are wrong in C++:
https://github.com/FEniCS/dolfinx/blob/main/cpp/dolfinx/common/timing.h#L30-L34
as it still talks about a timing triplet.

@garth-wells

Copy link
Copy Markdown
Member Author

The Python wrappers could call stop and flush.

@schnellerhase

Copy link
Copy Markdown
Contributor

There was a resume - @schnellerhase removed it because it was untested. I could now be added back (I think it should).

This also allowed for one less state to manage in the Timer and thus simpler logic. I think keeping the states to a minimum is best here.

What do we need the resume/restart functionality for? Together with the TimeLogger I think we can do without.

@jorgensd

Copy link
Copy Markdown
Member

There was a resume - @schnellerhase removed it because it was untested. I could now be added back (I think it should).

This also allowed for one less state to manage in the Timer and thus simpler logic. I think keeping the states to a minimum is best here.

What do we need the resume/restart functionality for? Together with the TimeLogger I think we can do without.

If we use the TimeLogger for resuming timings, then stop should definitely flush, as there is no clear benefit of keeping the object around then?

@garth-wells garth-wells added this to the 0.10.0 milestone Oct 29, 2024
@garth-wells

garth-wells commented Oct 29, 2024

Copy link
Copy Markdown
Member Author

There was a resume - @schnellerhase removed it because it was untested. I could now be added back (I think it should).

This also allowed for one less state to manage in the Timer and thus simpler logic. I think keeping the states to a minimum is best here.
What do we need the resume/restart functionality for? Together with the TimeLogger I think we can do without.

If we use the TimeLogger for resuming timings, then stop should definitely flush, as there is no clear benefit of keeping the object around then?

There are users who use stop/resume. It wasn't covered by tests (it is now), but that doesn't mean it's not used.

Timings should only be logged to when finished (by the destructor, or when manually flushed), otherwise the logger counter get messed up.

@garth-wells
garth-wells added this pull request to the merge queue Oct 30, 2024
Merged via the queue into main with commit 1fbf7e1 Oct 30, 2024
@garth-wells
garth-wells deleted the garth/improve-timer-logic branch October 30, 2024 23:02
jorgensd added a commit to jorgensd/dolfinx_mpc that referenced this pull request Nov 17, 2024
jorgensd added a commit to jorgensd/dolfinx_mpc that referenced this pull request Nov 17, 2024
* Update CI versions and behavior

* Refactor timings, due to:
FEniCS/dolfinx#3487
FEniCS/dolfinx#3488

* API changes from:  FEniCS/dolfinx#3500

* Fix demo

* Install boost

* Set tag

* Only check docker on release branch

* Fixes for refernece value size

* More timing fixes

* Another round of timing changes

* Remove last old timing instance
schnellerhase pushed a commit to schnellerhase/fenics-dolfinx that referenced this pull request Dec 28, 2024
* Fix Timer logic

* Add missing include

* Fix typo

* Add Timer::resume

* Timer updates/fixes

---------

Co-authored-by: Jørgen S. Dokken <dokken@simula.no>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants