-
Notifications
You must be signed in to change notification settings - Fork 105
Track field operations for debugging #2889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
Changes from all commits
fee27c9
96da2e9
e56981c
6b2c132
df2d661
263f9fe
bac4ca9
708bdcb
d88b454
023bc41
affc995
71f5b6a
31fd461
17e46cf
9c0ae16
4a17b49
2f7c3c0
d611758
db96b7e
84bfcef
73265df
8ff388a
6724e75
28212c2
9cf0fba
97b67e1
77e08ec
ba6fc6c
3c0d6a8
8e578fc
d0669cd
291e4af
42fc8ff
c9c13d4
ff93406
a096cc5
27db46d
24610c3
f6db2df
d1c137f
ee8a9d6
00fbaac
12c6c00
e684304
b75d020
b824cfc
90815fa
69457b8
b265c90
9c47bb8
02cc7d1
9e4edd9
cb0d3f1
07d130c
f2ed814
e3f8923
873c94f
7e5c311
e5f2d37
751abc4
3cc061b
5230138
03283f4
fc2e28f
26651cc
f319c61
1519bf2
b61f815
eab6b03
508dcda
c9732b7
9b96dad
94f9ea6
6ec3917
6f19419
b04a242
7476e31
83cf779
bc86a19
cdd911c
3f31ab6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,11 +33,15 @@ class Field3D; | |
| #include "bout/field2d.hxx" | ||
| #include "bout/fieldperp.hxx" | ||
| #include "bout/region.hxx" | ||
| #include "bout/traits.hxx" | ||
|
|
||
| #include <memory> | ||
| #include <optional> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| class Mesh; | ||
| class Options; | ||
|
|
||
| /// Class for 3D X-Y-Z scalar fields | ||
| /*! | ||
|
|
@@ -291,6 +295,17 @@ public: | |
| /// cuts on closed field lines? | ||
| bool requiresTwistShift(bool twist_shift_enabled); | ||
|
|
||
| /// Enable a special tracking mode for debugging | ||
| /// Save all changes that, are done to the field, to tracking | ||
| Field3D& enableTracking(const std::string& name, std::weak_ptr<Options> tracking); | ||
dschwoerer marked this conversation as resolved.
Show resolved
Hide resolved
dschwoerer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /// Disable tracking | ||
| Field3D& disableTracking() { | ||
| tracking.reset(); | ||
| tracking_state = 0; | ||
| return *this; | ||
| } | ||
|
|
||
| ///////////////////////////////////////////////////////// | ||
| // Data access | ||
|
|
||
|
|
@@ -493,6 +508,8 @@ public: | |
|
|
||
| int size() const override { return nx * ny * nz; }; | ||
|
|
||
| std::weak_ptr<Options> getTracking() { return tracking; }; | ||
|
|
||
| private: | ||
| /// Array sizes (from fieldmesh). These are valid only if fieldmesh is not null | ||
| int nx{-1}, ny{-1}, nz{-1}; | ||
|
|
@@ -508,6 +525,22 @@ private: | |
|
|
||
| /// RegionID over which the field is valid | ||
| std::optional<size_t> regionID; | ||
|
|
||
| /// counter for tracking, to assign unique names to the variable names | ||
| int tracking_state{0}; | ||
dschwoerer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| std::weak_ptr<Options> tracking; | ||
| // name is changed if we assign to the variable, while selfname is a | ||
| // non-changing copy that is used for the variable names in the dump files | ||
| std::string selfname; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this if we already have
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added:
dschwoerer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| template <typename T> | ||
| void track(const T& change, const std::string& operation) { | ||
| if (tracking_state != 0) { | ||
| _track(change, operation); | ||
| } | ||
dschwoerer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| template <typename T, typename = bout::utils::EnableIfField<T>> | ||
dschwoerer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| void _track(const T& change, std::string operation); | ||
| void _track(const BoutReal& change, std::string operation); | ||
| }; | ||
|
|
||
| // Non-member overloaded operators | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,9 @@ | |
| #include <bout/globals.hxx> | ||
|
|
||
| #include <cmath> | ||
| #include <cpptrace/cpptrace.hpp> | ||
| #include <memory> | ||
| #include <utility> | ||
|
|
||
| #include "bout/parallel_boundary_op.hxx" | ||
| #include "bout/parallel_boundary_region.hxx" | ||
|
|
@@ -46,6 +49,8 @@ | |
| #include <bout/output.hxx> | ||
| #include <bout/utils.hxx> | ||
|
|
||
| #include "fmt/format.h" | ||
|
|
||
| /// Constructor | ||
| Field3D::Field3D(Mesh* localmesh, CELL_LOC location_in, DirectionTypes directions_in) | ||
| : Field(localmesh, location_in, directions_in) { | ||
|
|
@@ -235,6 +240,8 @@ Field3D& Field3D::operator=(const Field3D& rhs) { | |
| return (*this); // skip this assignment | ||
| } | ||
|
|
||
| track(rhs, "operator="); | ||
|
|
||
| // Copy base slice | ||
| Field::operator=(rhs); | ||
|
|
||
|
|
@@ -254,6 +261,7 @@ Field3D& Field3D::operator=(const Field3D& rhs) { | |
| } | ||
|
|
||
| Field3D& Field3D::operator=(Field3D&& rhs) { | ||
| track(rhs, "operator="); | ||
ZedThree marked this conversation as resolved.
Show resolved
Hide resolved
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really think this should be a macro that is only enabled at higher |
||
|
|
||
| // Move parallel slices or delete existing ones. | ||
| yup_fields = std::move(rhs.yup_fields); | ||
|
|
@@ -274,6 +282,7 @@ Field3D& Field3D::operator=(Field3D&& rhs) { | |
| } | ||
|
|
||
| Field3D& Field3D::operator=(const Field2D& rhs) { | ||
| track(rhs, "operator="); | ||
|
|
||
| /// Check that the data is allocated | ||
| ASSERT1(rhs.isAllocated()); | ||
|
|
@@ -318,6 +327,7 @@ void Field3D::operator=(const FieldPerp& rhs) { | |
| } | ||
|
|
||
| Field3D& Field3D::operator=(const BoutReal val) { | ||
| track(val, "operator="); | ||
|
|
||
| // Delete existing parallel slices. We don't copy parallel slices, so any | ||
| // that currently exist will be incorrect. | ||
|
|
@@ -831,3 +841,63 @@ Field3D::getValidRegionWithDefault(const std::string& region_name) const { | |
| void Field3D::setRegion(const std::string& region_name) { | ||
| regionID = fieldmesh->getRegionID(region_name); | ||
| } | ||
|
|
||
| Field3D& Field3D::enableTracking(const std::string& name, | ||
| std::weak_ptr<Options> _tracking) { | ||
dschwoerer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| tracking = std::move(_tracking); | ||
| tracking_state = 1; | ||
| selfname = name; | ||
| return *this; | ||
| } | ||
|
|
||
| template <typename T, typename> | ||
| void Field3D::_track(const T& change, std::string operation) { | ||
| if (tracking_state == 0) { | ||
| return; | ||
| } | ||
| auto locked = tracking.lock(); | ||
| if (locked == nullptr) { | ||
| return; | ||
| } | ||
| const std::string outname{fmt::format("track_{:s}_{:d}", selfname, tracking_state++)}; | ||
dschwoerer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| locked->set(outname, change, "tracking"); | ||
|
|
||
| const std::string trace = cpptrace::generate_trace().to_string(); | ||
|
|
||
| // Workaround for bug in gcc9.4 | ||
| #if BOUT_USE_TRACK | ||
| const std::string changename = change.name; | ||
| #endif | ||
| (*locked)[outname].setAttributes({ | ||
| {"operation", operation}, | ||
| #if BOUT_USE_TRACK | ||
| {"rhs.name", changename}, | ||
| #endif | ||
| {"trace", trace}, | ||
| }); | ||
| } | ||
|
|
||
| template void | ||
| Field3D::_track<Field3D, bout::utils::EnableIfField<Field3D>>(const Field3D&, | ||
| std::string); | ||
| template void Field3D::_track<Field2D>(const Field2D&, std::string); | ||
| template void Field3D::_track<>(const FieldPerp&, std::string); | ||
|
|
||
| void Field3D::_track(const BoutReal& change, std::string operation) { | ||
| if (tracking_state == 0) { | ||
| return; | ||
| } | ||
| auto locked = tracking.lock(); | ||
| if (locked == nullptr) { | ||
| return; | ||
| } | ||
| const std::string trace = cpptrace::generate_trace().to_string(); | ||
| const std::string outname{fmt::format("track_{:s}_{:d}", selfname, tracking_state++)}; | ||
| locked->set(outname, change, "tracking"); | ||
| (*locked)[outname].setAttributes({ | ||
| {"operation", operation}, | ||
| {"rhs.name", "BoutReal"}, | ||
| {"trace", trace}, | ||
| }); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.