Skip to content

WIP: Improve BoutExpr CPU performance#3403

Merged
bendudson merged 4 commits into
nextfrom
boutexpr-performance
Jun 26, 2026
Merged

WIP: Improve BoutExpr CPU performance#3403
bendudson merged 4 commits into
nextfrom
boutexpr-performance

Conversation

@bendudson

Copy link
Copy Markdown
Contributor

Some small improvements to encourage vectorization in BoutExpr::evaluate for common cases.

Not needed in current use, and may prevent vectorization.
If iterating over Field3D, the RegionID can be used to get the
Region and so the blocks. This avoids lookup of array indices
and helps vectorize simple loops.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

Comment thread include/bout/build_config.hxx Outdated
#define BOUT_FORCEINLINE inline
#endif

#if defined(_MSC_VER)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: preprocessor condition can be written more concisely using '#ifdef' [readability-use-concise-preprocessor-directives]

Suggested change
#if defined(_MSC_VER)
#ifdef _MSC_VER

Comment thread include/bout/build_config.hxx
Comment thread include/bout/field3d.hxx Outdated
Comment thread include/bout/field3d.hxx Outdated
Comment thread include/bout/build_config.hxx Outdated
Comment thread include/bout/build_config.hxx
Comment thread src/field/field3d.cxx
Comment on lines +932 to +939
const Region<Ind3D>& getField3DRegion(const Mesh* mesh, std::optional<size_t> regionID) {
ASSERT1(mesh != nullptr);

if (regionID.has_value()) {
return mesh->getRegion(regionID.value());
}
return mesh->getRegion("RGN_ALL");
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this just be in Mesh?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an unpleasant dependency loop: We can't call mesh->getRegion from fieldops.hxx directly, because Mesh is an incomplete type at this point. We therefore need a small helper function to call.

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Peter Hill <zed.three@gmail.com>

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions


#ifdef __has_cpp_attribute
#if __has_cpp_attribute(assume) >= 202207L
#define BOUT_ASSUME(condition) [[assume(condition)]]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: function-like macro 'BOUT_ASSUME' used; consider a 'constexpr' template function [cppcoreguidelines-macro-usage]

#define BOUT_ASSUME(condition) [[assume(condition)]]
        ^

@bendudson bendudson merged commit e9097e1 into next Jun 26, 2026
23 checks passed
@bendudson bendudson deleted the boutexpr-performance branch June 26, 2026 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants