Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
dc932cc
Support BOUT_FOR_RAJA GPU field operators
ggeorgakoudis Feb 25, 2025
b83d2b5
Working WIP
ggeorgakoudis May 27, 2025
9708709
WIP 2
ggeorgakoudis May 28, 2025
e20da9d
Working - WIP 3
ggeorgakoudis May 28, 2025
096f576
WIP 3
ggeorgakoudis May 28, 2025
34cba4d
WIP 4
ggeorgakoudis May 28, 2025
7d75b9d
Used managed array for indices
ggeorgakoudis May 28, 2025
b8e7e97
Better SFINAE for specializations
ggeorgakoudis May 28, 2025
d830f8d
Fix major bug in the binary expr operator() and add operators
ggeorgakoudis May 29, 2025
c5f9fd6
WIP
ggeorgakoudis May 30, 2025
4d64ad2
More operators
ggeorgakoudis May 31, 2025
5dfa66a
Add more operators
ggeorgakoudis May 31, 2025
026645a
More operators
ggeorgakoudis Jun 1, 2025
338920e
More operators
ggeorgakoudis Jun 1, 2025
6e88181
More operators and cleanup
ggeorgakoudis Jun 1, 2025
25d1272
More operators and cleanup
ggeorgakoudis Jun 1, 2025
56a8678
Cleanup
ggeorgakoudis Jun 1, 2025
3e3a0ea
Add __host__ to make evaluator host-callable, remove offset
ggeorgakoudis Jun 3, 2025
56fe675
Update
ggeorgakoudis Jun 4, 2025
b75103d
Add FFT GPU shiftZ
ggeorgakoudis Oct 24, 2025
40974a9
Fixup: add twiddle header in cmake
ggeorgakoudis Oct 24, 2025
ba5eabf
Default to pinned memory for performance
ggeorgakoudis Oct 24, 2025
c079bb6
Fixup: remove unused twiddles
ggeorgakoudis Oct 24, 2025
932f156
Fixup: cleanup and run GPU fft on its own stream
ggeorgakoudis Oct 24, 2025
b6c738c
Fixup: remove comments, avoid temp for inverse
ggeorgakoudis Oct 24, 2025
11ebfcd
Fixup: preprocessor guards, better variable naming
ggeorgakoudis Oct 24, 2025
cf5a882
Fixup: saner split with BOUT_HAS_CUDA
ggeorgakoudis Oct 24, 2025
9f42dcb
Fixup: remove redundant conditional
ggeorgakoudis Oct 25, 2025
35e6f42
Use streams to reduce synchronization overhead
ggeorgakoudis Nov 24, 2025
dc2117b
Merge branch 'next' into support-gpu-field-operators-lazy
bendudson Jun 18, 2026
f38dbd1
Fix non-CUDA builds
bendudson Jun 18, 2026
98b9e55
More fixes, remove duplications
bendudson Jun 18, 2026
b0fd981
More fixes
bendudson Jun 18, 2026
bb5b495
Unit tests compiling again
bendudson Jun 18, 2026
a06e450
Fix warnings coming from Field constructors
bendudson Jun 18, 2026
8018906
Fix unit tests
bendudson Jun 18, 2026
6cab892
BinaryExpr::operator[](IndType) indexing
bendudson Jun 18, 2026
1caebb6
SQ and mean for BinaryExpr
bendudson Jun 18, 2026
4e19f8e
Region::getLinearIndices
bendudson Jun 18, 2026
d676726
Fix BinaryExpr::operator[] for Field2D expressions
bendudson Jun 19, 2026
0b9dbf6
Reductions on BinaryExpr: Min/Max/Mean
bendudson Jun 19, 2026
9350715
Fieldops: Tidy Min,Max,Mean reductions
bendudson Jun 19, 2026
36c06ec
Formatting
bendudson Jun 19, 2026
09aaee6
BinaryExpr: Use Region::getLinearIndices
bendudson Jun 19, 2026
94cf70f
Options: Assignment from BinaryExpr
bendudson Jun 19, 2026
d3236d9
BinaryExpr: if_else and if_else_zero conditionals
bendudson Jun 19, 2026
f48cd51
BinaryExpr: FIELD_FUNC fuse expressions
bendudson Jun 19, 2026
ac1836b
Fixes for 3D metrics and unit tests
bendudson Jun 19, 2026
b9de118
Fixes and tidying
bendudson Jun 19, 2026
0fdeedb
evaluateBinaryExpr: Allocate full size Arrays
bendudson Jun 19, 2026
504fe6e
Merge branch 'next' into support-gpu-field-operators-lazy
bendudson Jun 19, 2026
250a566
Coordinates: Evaluate to FieldMetric
bendudson Jun 19, 2026
512e853
Clang tidying
bendudson Jun 19, 2026
7cb424f
BinaryExpr: Assignment operators propagate metadata
bendudson Jun 19, 2026
b0ff0c6
examples/elm-pb: Tidying and fix for BoutExpr
bendudson Jun 19, 2026
404e063
Updating documentation
bendudson Jun 19, 2026
c88908b
Remove unneeded BinaryExpr evaluations
bendudson Jun 19, 2026
ca94ba5
Fields: Move unary minus to headers
bendudson Jun 20, 2026
43c5050
BOUT_FORCEINLINE: Strengthen for CPU case
bendudson Jun 20, 2026
50839f1
Fields: Move move-assignment to headers
bendudson Jun 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ set(BOUT_SOURCES
./include/bout/field_accessor.hxx
./include/bout/field_data.hxx
./include/bout/field_factory.hxx
./include/bout/fieldops.hxx
./include/bout/fieldgroup.hxx
./include/bout/fieldperp.hxx
./include/bout/fv_ops.hxx
Expand Down Expand Up @@ -206,6 +207,7 @@ set(BOUT_SOURCES
./include/bout/template_combinations.hxx
./include/bout/tokamak_coordinates.hxx
./include/bout/traits.hxx
./include/bout/twiddle.hxx
./include/bout/unused.hxx
./include/bout/utils.hxx
./include/bout/vecops.hxx
Expand Down Expand Up @@ -430,10 +432,17 @@ if(BOUT_GENERATE_FIELDOPS)
"clang-format not found, but you have requested to generate code!"
)
endif()
if(BOUT_ENABLE_RAJA)
set(GEN_LOOP_EXEC "raja")
elseif(BOUT_ENABLE_OPENMP)
set(GEN_LOOP_EXEC "openmp")
else()
set(GEN_LOOP_EXEC "serial")
endif()
add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/field/generated_fieldops.cxx
COMMAND ${Python3_EXECUTABLE} gen_fieldops.py --filename
generated_fieldops.cxx.tmp
COMMAND ${Python3_EXECUTABLE} gen_fieldops.py --loop-exec ${GEN_LOOP_EXEC}
--filename generated_fieldops.cxx.tmp
COMMAND ${ClangFormat_BIN} generated_fieldops.cxx.tmp -i
COMMAND ${CMAKE_COMMAND} -E rename generated_fieldops.cxx.tmp
generated_fieldops.cxx
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Homepage found at [http://boutproject.github.io/](http://boutproject.github.io/)

BOUT++ needs the following:

* A C++17 compiler
* A C++20 compiler
* MPI
* NetCDF

Expand Down Expand Up @@ -113,7 +113,7 @@ You can convert the CITATION.cff file into a Bibtex file as follows:
See [CONTRIBUTING.md](CONTRIBUTING.md) and the [manual page](https://bout-dev.readthedocs.io/en/stable/developer_docs/contributing.html)

## License
Copyright 2010-2024 BOUT++ contributors
Copyright 2010-2026 BOUT++ contributors

BOUT++ is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
Expand Down
8 changes: 5 additions & 3 deletions examples/elm-pb-outerloop/elm_pb_outerloop.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,8 @@ class ELMpb : public PhysicsModel {
vacuum_trans *= pnorm;

// Transitions from 0 in core to 1 in vacuum
vac_mask = (1.0 - tanh((P0 - vacuum_pressure) / vacuum_trans)) / 2.0;
Field2D tanh_res = tanh((P0 - vacuum_pressure) / vacuum_trans);

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: variable 'tanh_res' of type 'Field2D' can be declared 'const' [misc-const-correctness]

Suggested change
Field2D tanh_res = tanh((P0 - vacuum_pressure) / vacuum_trans);
Field2D const tanh_res = tanh((P0 - vacuum_pressure) / vacuum_trans);

vac_mask = (1.0 - tanh_res) / 2.0;

if (spitzer_resist) {
// Use Spitzer resistivity
Expand Down Expand Up @@ -1169,7 +1170,7 @@ class ELMpb : public PhysicsModel {
// Only if not restarting: Check initial perturbation

// Set U to zero where P0 < vacuum_pressure
U = where(P0 - vacuum_pressure, U, 0.0);
U = where(Field2D{P0 - vacuum_pressure}, U, 0.0);

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: no header providing "where" is directly included [misc-include-cleaner]

examples/elm-pb-outerloop/elm_pb_outerloop.cxx:13:

- #define DISABLE_RAJA 0 // Turn off RAJA in this file?
+ #include "bout/where.hxx"
+ #define DISABLE_RAJA 0 // Turn off RAJA in this file?


if (constn0) {
ubyn = U;
Expand Down Expand Up @@ -1796,7 +1797,8 @@ class ELMpb : public PhysicsModel {
ddt(U) -= 0.5 * Upara2 * bracket(Pi0, Dperp2Phi, bm_exb) / B0;
Field3D B0phi = B0 * phi;
mesh->communicate(B0phi);
Field3D B0phi0 = B0 * phi0;
Field2D res = B0 * phi0;

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: variable 'res' of type 'Field2D' can be declared 'const' [misc-const-correctness]

Suggested change
Field2D res = B0 * phi0;
Field2D const res = B0 * phi0;

Field3D B0phi0 = res;
mesh->communicate(B0phi0);
ddt(U) += 0.5 * Upara2 * bracket(B0phi, Dperp2Pi0, bm_exb) / B0;
ddt(U) += 0.5 * Upara2 * bracket(B0phi0, Dperp2Pi, bm_exb) / B0;
Expand Down
20 changes: 13 additions & 7 deletions examples/elm-pb/elm_pb.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,22 @@
*******************************************************************************/

#include <bout/bout.hxx>
#include <bout/bout_types.hxx>
#include <bout/boutexception.hxx>
#include <bout/constants.hxx>
#include <bout/coordinates.hxx>
#include <bout/derivs.hxx>
#include <bout/difops.hxx>
#include <bout/field2d.hxx>
#include <bout/field3d.hxx>
#include <bout/field_factory.hxx>
#include <bout/fv_ops.hxx>
#include <bout/initialprofiles.hxx>
#include <bout/interpolation.hxx>
#include <bout/invert/laplacexy.hxx>
#include <bout/invert_laplace.hxx>
#include <bout/invert_parderiv.hxx>
#include <bout/output.hxx>
#include <bout/sourcex.hxx>
#include <bout/tokamak_coordinates.hxx>
#include <bout/utils.hxx>
Expand Down Expand Up @@ -246,8 +252,8 @@ class ELMpb : public PhysicsModel {
std::unique_ptr<Laplacian> phiSolver{nullptr};
std::unique_ptr<Laplacian> aparSolver{nullptr};

const Field2D N0tanh(BoutReal n0_height, BoutReal n0_ave, BoutReal n0_width,
BoutReal n0_center, BoutReal n0_bottom_x) {
Field2D N0tanh(BoutReal n0_height, BoutReal n0_ave, BoutReal n0_width,
BoutReal n0_center, BoutReal n0_bottom_x) {
Field2D result;
result.allocate();

Expand Down Expand Up @@ -1138,7 +1144,7 @@ class ELMpb : public PhysicsModel {
// Only if not restarting: Check initial perturbation

// Set U to zero where P0 < vacuum_pressure
U = where(P0 - vacuum_pressure, U, 0.0);
U = where(Field2D{P0 - vacuum_pressure}, U, 0.0);

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: no header providing "where" is directly included [misc-include-cleaner]

examples/elm-pb/elm_pb.cxx:7:

- #include <bout/bout.hxx>
+ #include "bout/where.hxx"
+ #include <bout/bout.hxx>


if (constn0) {
ubyn = U;
Expand Down Expand Up @@ -1202,7 +1208,7 @@ class ELMpb : public PhysicsModel {
// Perform communications
mesh->communicate(comms);

Coordinates* metric = mesh->getCoordinates();
const Coordinates* metric = mesh->getCoordinates();

////////////////////////////////////////////
// Transitions from 0 in core to 1 in vacuum
Expand Down Expand Up @@ -1698,10 +1704,10 @@ class ELMpb : public PhysicsModel {
// Vacuum solution
if (relax_j_vac) {
// Calculate the J and Psi profile we're aiming for
Field3D Jtarget = Jpar * (1.0 - vac_mask); // Zero in vacuum
const Field3D Jtarget = Jpar * (1.0 - vac_mask); // Zero in vacuum

// Invert laplacian for Psi
Field3D Psitarget = aparSolver->solve(Jtarget);
const Field3D Psitarget = aparSolver->solve(Jtarget);

// Add a relaxation term in the vacuum
ddt(Psi) =
Expand Down Expand Up @@ -1832,7 +1838,7 @@ class ELMpb : public PhysicsModel {
ddt(U) -= 0.5 * Upara2 * bracket(Pi0, Dperp2Phi, bm_exb) / B0;
Field3D B0phi = B0 * phi;
mesh->communicate(B0phi);
Field3D B0phi0 = B0 * phi0;
Field2D B0phi0 = B0 * phi0;
mesh->communicate(B0phi0);
ddt(U) += 0.5 * Upara2 * bracket(B0phi, Dperp2Pi0, bm_exb) / B0;
ddt(U) += 0.5 * Upara2 * bracket(B0phi0, Dperp2Pi, bm_exb) / B0;
Expand Down
2 changes: 1 addition & 1 deletion externalpackages/cpptrace
Submodule cpptrace updated 43 files
+257 −611 .github/workflows/ci.yml
+7 −2 .github/workflows/sonarlint.yml
+59 −43 CMakeLists.txt
+4 −5 README.md
+7 −42 ci/build-in-all-remaining-configs.py
+0 −97 ci/integration-test-windows.ps1
+0 −78 ci/integration-test.sh
+22 −30 ci/setup-prerequisites-mingw.ps1
+40 −45 ci/setup-prerequisites-unittest-macos.sh
+35 −40 ci/setup-prerequisites-unittest.sh
+22 −26 ci/setup-prerequisites.sh
+14 −55 ci/test-all-configs.py
+0 −3 ci/unittest.py
+1 −5 cmake/Autoconfig.cmake
+0 −40 cmake/FindLibunwind.cmake
+4 −6 cmake/InstallRules.cmake
+9 −5 cmake/OptionVariables.cmake
+1 −17 cmake/has_stackwalk.cpp
+6 −19 cmake/in/cpptrace-config-cmake.in
+2 −2 src/binary/module_base.cpp
+2 −2 src/binary/object.cpp
+5 −12 src/binary/pe.cpp
+1 −1 src/binary/pe.hpp
+10 −20 src/from_current.cpp
+2 −135 src/platform/memory_mapping.cpp
+2 −5 src/platform/memory_mapping.hpp
+1 −5 src/platform/platform.hpp
+1 −1 src/platform/program_name.hpp
+16 −61 src/prune_symbol.cpp
+84 −270 src/symbols/dwarf/dwarf_resolver.cpp
+2 −3 src/symbols/symbols_with_addr2line.cpp
+3 −6 src/unwind/unwind.hpp
+0 −14 src/unwind/unwind_with_libunwind.cpp
+0 −111 src/unwind/unwind_with_rtlvirtualunwind.cpp
+0 −10 src/utils/optional.hpp
+7 −5 src/utils/utils.cpp
+1 −3 src/utils/utils.hpp
+0 −4 test/CMakeLists.txt
+1 −2 test/add_subdirectory-integration/CMakeLists.txt
+2 −18 test/unit/main.cpp
+0 −133 test/unit/tracing/namespace_resolution.cpp
+4 −10 test/unit/tracing/raw_trace.cpp
+5 −15 test/unit/tracing/try_catch.cpp
1 change: 1 addition & 0 deletions include/bout/array.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ struct ArrayData {
auto& rm = umpire::ResourceManager::getInstance();
#if BOUT_HAS_CUDA
auto allocator = rm.getAllocator(umpire::resource::Pinned);
//auto allocator = rm.getAllocator(umpire::resource::Unified);
#else
auto allocator = rm.getAllocator("HOST");
#endif
Expand Down
7 changes: 4 additions & 3 deletions include/bout/assert.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
* Defines a macro ASSERT which throws a BoutException if a given
* condition is false. Whether the assertion is tested depends on
* the checking level, so assetions can be removed for optimised runs.
*
*
* ASSERT<level> ( condition )
*
* level - An integer known at compile time.
* condition tested if level >= CHECK
*
* condition - The expression to test
*
*
* e.g. ASSERT2( condition ) will only test condition if CHECK >= 2
*
*
*/

#ifndef BOUT_ASSERT_H
Expand Down Expand Up @@ -40,6 +40,7 @@
if (!(condition)) { \
throw BoutException("Assertion failed in {:s}, line {:d}: {:s}", __FILE__, __LINE__, \
#condition); \
abort(); \
}
#else // CHECKLEVEL >= 1
#define ASSERT1(condition)
Expand Down
19 changes: 16 additions & 3 deletions include/bout/bout_types.hxx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**************************************************************************
* Copyright 2010 B.D.Dudson, S.Farley, M.V.Umansky, X.Q.Xu
* Copyright 2010 - 2026 BOUT++ contributors
*
* Contact Ben Dudson, dudson2@llnl.gov
*
* Contact Ben Dudson, bd512@york.ac.uk
*
* This file is part of BOUT++.
*
* BOUT++ is free software: you can redistribute it and/or modify
Expand All @@ -22,6 +22,8 @@
#ifndef BOUT_TYPES_H
#define BOUT_TYPES_H

#include "bout/build_config.hxx"

#include <limits>
#include <string>

Expand Down Expand Up @@ -140,4 +142,15 @@ struct enumWrapper {
/// Boundary condition function
using FuncPtr = BoutReal (*)(BoutReal t, BoutReal x, BoutReal y, BoutReal z);

template <typename T>
struct Constant {
T val;
struct View {
T v;
View(T v) : v(v) {}
BOUT_HOST_DEVICE T operator()(int) const { return v; }

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: all parameters should be named in a function [readability-named-parameter]

Suggested change
BOUT_HOST_DEVICE T operator()(int) const { return v; }
BOUT_HOST_DEVICE T operator()(int /*unused*/) const { return v; }

};
operator View() const { return {val}; }
};

#endif // BOUT_TYPES_H
12 changes: 12 additions & 0 deletions include/bout/build_config.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,22 @@ constexpr auto use_msgstack = static_cast<bool>(BOUT_USE_MSGSTACK);
#define BOUT_HOST_DEVICE __host__ __device__
#define BOUT_HOST __host__
#define BOUT_DEVICE __device__
#define BOUT_FORCEINLINE __forceinline__
#elif defined(_MSC_VER)
#define BOUT_HOST_DEVICE
#define BOUT_HOST
#define BOUT_DEVICE
#define BOUT_FORCEINLINE __forceinline
#elif defined(__clang__) || defined(__GNUC__)
#define BOUT_HOST_DEVICE
#define BOUT_HOST
#define BOUT_DEVICE
#define BOUT_FORCEINLINE inline __attribute__((always_inline))
#else
#define BOUT_HOST_DEVICE
#define BOUT_HOST
#define BOUT_DEVICE
#define BOUT_FORCEINLINE inline
#endif

#endif // BOUT_BUILD_OPTIONS_HXX
2 changes: 1 addition & 1 deletion include/bout/coordinates_accessor.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
/// -> If Coordinates data is changed, the cache should be cleared
/// by calling CoordinatesAccessor::clear()
struct CoordinatesAccessor {
CoordinatesAccessor() = delete;
CoordinatesAccessor() {}

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: constructor does not initialize these fields: data, mesh_nz [cppcoreguidelines-pro-type-member-init]

include/bout/coordinates_accessor.hxx:87:

-   BoutReal* data;
-   int mesh_nz; ///< For converting from 3D to 2D index
+   BoutReal* data{};
+   int mesh_nz{}; ///< For converting from 3D to 2D index


/// Constructor from Coordinates
/// Copies data from coords, doesn't modify it
Expand Down
Loading
Loading