Skip to content

Conversation

@KAClough
Copy link
Member

@KAClough KAClough commented Aug 18, 2025

This addresses issue #111.

The main goal is to remove all of the vars objects and replace them with a wrapper that directly accesses the right grid data. This involves removing all the enum mapping things, and also rethinking how the derivatives work.

I am also trying to unify the way in which we use the Parallel4 loop, so that for users the examples are more easily copyable. For this reason I try to have it always call an operator() function of the class and to always pass in the full state and derive the cell data within the class (rather than passing in the cell data directly, which would then mean that you can't calculate derivatives for example). So it also addresses #8 and #128 (much to Miren's annoyance).

NB I have not tried to address flattening out the Tensor array here, but once this is done I think it should be relatively simple to implement.

Some questions/comments I had for discussion:

  1. Do we need to have a ConstCCZ4Vars and a CCZ4Vars class? I couldn't work out how to do it but probably there is a way.

  2. Is the method of storing the vars optimal? I end up creating a Tensor object, and then storing it, whereas I think I should be able to update the value directly. For some reason this didn't work. On the other hand, what I have now is very readable.

  3. We now have () brackets for the vars grid object access and [] brackets for Tensor objects like the derivatives. I am kind of ok with this because they are conceptually different and maybe this makes a useful distinction. On the other hand if they were all one or the other there might be less chance of making mistakes.

  4. There is a warning about const amrex::CellData<amrex::Real> &cell_data; references as data members that I don't know whether to suppress.

  5. The regression test fails but the differences are small, should we worry?

  6. Should we remove the option of BSSN?

@github-actions
Copy link

This PR modifies the following files which are ignored by .lint-ignore:

Source/BlackHoles/BinaryBHInitialData.impl.hpp
Source/BlackHoles/PunctureTracker.impl.hpp
Source/CCZ4/CCZ4RHS.impl.hpp
Source/CCZ4/Constraints.impl.hpp
Source/CCZ4/Weyl4.impl.hpp
Source/Matter/CCZ4RHSWithMatter.impl.hpp
Source/Matter/ConstraintsWithMatter.impl.hpp
Source/Matter/EMTensor.impl.hpp
Source/Matter/ScalarField.impl.hpp
Source/Matter/Weyl4WithMatter.impl.hpp

Please consider removing the corresponding patterns from .lint-ignore so that these files can be linted.

@KAClough KAClough marked this pull request as draft August 18, 2025 17:56
@github-actions
Copy link

github-actions bot commented Aug 18, 2025

Cpp-Linter Report ⚠️

Some files did not pass the configured checks!

clang-tidy (v19.1.1) reports: 28 concern(s)
  • Source/GRTeclynCore/GRAMRLevel.hpp:117:18: warning: [cppcoreguidelines-explicit-virtual-functions]

    'virtual' is redundant since the function is already declared 'override'

      117 |     virtual void errorEst(amrex::TagBoxArray &a_tag_box_array, int a_clearval,
          |     ~~~~~~~      ^
  • Source/Grids/DimensionDefinitions.hpp:20:9: warning: [cppcoreguidelines-macro-usage]

    function-like macro 'VAR_IDX' used; consider a 'constexpr' template function

       20 | #define VAR_IDX(ivar, i, j) ((ivar) + (i) + (j) + (((i) * (j) != 0) ? 1 : 0))
          |         ^
  • Source/Grids/DimensionDefinitions.hpp:23:9: warning: [cppcoreguidelines-macro-usage]

    function-like macro 'VAR_IDX0' used; consider a 'constexpr' template function

       23 | #define VAR_IDX0(i, j) VAR_IDX(0, (i), (j))
          |         ^
  • Source/Grids/FourthOrderDerivatives.hpp:9:10: error: [clang-diagnostic-error]

    'CCZ4Vars.hpp' file not found

        9 | #include "CCZ4Vars.hpp"
          |          ^~~~~~~~~~~~~~
  • Source/Grids/FourthOrderDerivatives.hpp:45:27: warning: [bugprone-easily-swappable-parameters]

    3 adjacent parameters of 'diff1' of similar type are easily swapped by mistake

       45 |     diff1(int ix, int iy, int iz, const amrex::Array4<const amrex::Real> &state,
          |                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       46 |           const int ivar) const
          |           ~~~~~~~~~~~~~~
    ../../Source/Grids/FourthOrderDerivatives.hpp:45:31: note: the first parameter in the range is 'iz'
       45 |     diff1(int ix, int iy, int iz, const amrex::Array4<const amrex::Real> &state,
          |                               ^~
    ../../Source/Grids/FourthOrderDerivatives.hpp:46:21: note: the last parameter in the range is 'ivar'
       46 |           const int ivar) const
          |                     ^~~~
    ../../Source/Grids/FourthOrderDerivatives.hpp:45:35: note: 'int' and 'const int &' parameters accept and bind the same kind of values
       45 |     diff1(int ix, int iy, int iz, const amrex::Array4<const amrex::Real> &state,
          |                                   ^
    ../../Source/Grids/FourthOrderDerivatives.hpp:46:11: note: 'const int &' and 'const int' parameters accept and bind the same kind of values
       46 |           const int ivar) const
          |           ^
  • Source/Grids/FourthOrderDerivatives.hpp:65:34: warning: [bugprone-easily-swappable-parameters]

    2 adjacent parameters of 'diff1_scalar' of similar type are easily swapped by mistake

       65 |     diff1_scalar(int ix, int iy, int iz,
          |                                  ^~~~~~~
       66 |                  const amrex::Array4<const amrex::Real> &state,
          |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ../../Source/Grids/FourthOrderDerivatives.hpp:65:38: note: the first parameter in the range is 'iz'
       65 |     diff1_scalar(int ix, int iy, int iz,
          |                                      ^~
    ../../Source/Grids/FourthOrderDerivatives.hpp:66:58: note: the last parameter in the range is 'state'
       66 |                  const amrex::Array4<const amrex::Real> &state,
          |                                                          ^~~~~
    ../../Source/Grids/FourthOrderDerivatives.hpp:66:18: note: 'int' and 'const int &' parameters accept and bind the same kind of values
       66 |                  const amrex::Array4<const amrex::Real> &state,
          |                  ^
  • Source/Grids/FourthOrderDerivatives.hpp:73:34: warning: [bugprone-easily-swappable-parameters]

    3 adjacent parameters of 'diff1_vector' of similar type are easily swapped by mistake

       73 |     diff1_vector(int ix, int iy, int iz,
          |                                  ^~~~~~~
       74 |                  const amrex::Array4<const amrex::Real> &state,
          |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       75 |                  const int ivar_0) const
          |                  ~~~~~~~~~~~~~~~~
    ../../Source/Grids/FourthOrderDerivatives.hpp:73:38: note: the first parameter in the range is 'iz'
       73 |     diff1_vector(int ix, int iy, int iz,
          |                                      ^~
    ../../Source/Grids/FourthOrderDerivatives.hpp:75:28: note: the last parameter in the range is 'ivar_0'
       75 |                  const int ivar_0) const
          |                            ^~~~~~
    ../../Source/Grids/FourthOrderDerivatives.hpp:74:18: note: 'int' and 'const int &' parameters accept and bind the same kind of values
       74 |                  const amrex::Array4<const amrex::Real> &state,
          |                  ^
    ../../Source/Grids/FourthOrderDerivatives.hpp:75:18: note: 'const int &' and 'const int' parameters accept and bind the same kind of values
       75 |                  const int ivar_0) const
          |                  ^
  • Source/Grids/FourthOrderDerivatives.hpp:92:34: warning: [bugprone-easily-swappable-parameters]

    3 adjacent parameters of 'diff1_tensor' of similar type are easily swapped by mistake

       92 |     diff1_tensor(int ix, int iy, int iz,
          |                                  ^~~~~~~
       93 |                  const amrex::Array4<const amrex::Real> &state,
          |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       94 |                  const int ivar_0) const
          |                  ~~~~~~~~~~~~~~~~
    ../../Source/Grids/FourthOrderDerivatives.hpp:92:38: note: the first parameter in the range is 'iz'
       92 |     diff1_tensor(int ix, int iy, int iz,
          |                                      ^~
    ../../Source/Grids/FourthOrderDerivatives.hpp:94:28: note: the last parameter in the range is 'ivar_0'
       94 |                  const int ivar_0) const
          |                            ^~~~~~
    ../../Source/Grids/FourthOrderDerivatives.hpp:93:18: note: 'int' and 'const int &' parameters accept and bind the same kind of values
       93 |                  const amrex::Array4<const amrex::Real> &state,
          |                  ^
    ../../Source/Grids/FourthOrderDerivatives.hpp:94:18: note: 'const int &' and 'const int' parameters accept and bind the same kind of values
       94 |                  const int ivar_0) const
          |                  ^
  • Source/Grids/FourthOrderDerivatives.hpp:112:37: warning: [bugprone-easily-swappable-parameters]

    2 adjacent parameters of 'diff1_state' of similar type are easily swapped by mistake

      112 |         diff1_state(int ix, int iy, int iz,
          |                                     ^~~~~~~
      113 |                     const amrex::Array4<const amrex::Real> &state) const
          |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ../../Source/Grids/FourthOrderDerivatives.hpp:112:41: note: the first parameter in the range is 'iz'
      112 |         diff1_state(int ix, int iy, int iz,
          |                                         ^~
    ../../Source/Grids/FourthOrderDerivatives.hpp:113:61: note: the last parameter in the range is 'state'
      113 |                     const amrex::Array4<const amrex::Real> &state) const
          |                                                             ^~~~~
    ../../Source/Grids/FourthOrderDerivatives.hpp:113:21: note: 'int' and 'const int &' parameters accept and bind the same kind of values
      113 |                     const amrex::Array4<const amrex::Real> &state) const
          |                     ^
  • Source/Grids/FourthOrderDerivatives.hpp:170:27: warning: [bugprone-easily-swappable-parameters]

    3 adjacent parameters of 'diff2' of similar type are easily swapped by mistake

      170 |     diff2(int ix, int iy, int iz, const amrex::Array4<amrex::Real const> &state,
          |                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      171 |           const int ivar) const
          |           ~~~~~~~~~~~~~~
    ../../Source/Grids/FourthOrderDerivatives.hpp:170:31: note: the first parameter in the range is 'iz'
      170 |     diff2(int ix, int iy, int iz, const amrex::Array4<amrex::Real const> &state,
          |                               ^~
    ../../Source/Grids/FourthOrderDerivatives.hpp:171:21: note: the last parameter in the range is 'ivar'
      171 |           const int ivar) const
          |                     ^~~~
    ../../Source/Grids/FourthOrderDerivatives.hpp:170:35: note: 'int' and 'const int &' parameters accept and bind the same kind of values
      170 |     diff2(int ix, int iy, int iz, const amrex::Array4<amrex::Real const> &state,
          |                                   ^
    ../../Source/Grids/FourthOrderDerivatives.hpp:171:11: note: 'const int &' and 'const int' parameters accept and bind the same kind of values
      171 |           const int ivar) const
          |           ^
  • Source/Grids/FourthOrderDerivatives.hpp:199:34: warning: [bugprone-easily-swappable-parameters]

    2 adjacent parameters of 'diff2_scalar' of similar type are easily swapped by mistake

      199 |     diff2_scalar(int ix, int iy, int iz,
          |                                  ^~~~~~~
      200 |                  const amrex::Array4<const amrex::Real> &state,
          |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ../../Source/Grids/FourthOrderDerivatives.hpp:199:38: note: the first parameter in the range is 'iz'
      199 |     diff2_scalar(int ix, int iy, int iz,
          |                                      ^~
    ../../Source/Grids/FourthOrderDerivatives.hpp:200:58: note: the last parameter in the range is 'state'
      200 |                  const amrex::Array4<const amrex::Real> &state,
          |                                                          ^~~~~
    ../../Source/Grids/FourthOrderDerivatives.hpp:200:18: note: 'int' and 'const int &' parameters accept and bind the same kind of values
      200 |                  const amrex::Array4<const amrex::Real> &state,
          |                  ^
  • Source/Grids/FourthOrderDerivatives.hpp:207:34: warning: [bugprone-easily-swappable-parameters]

    3 adjacent parameters of 'diff2_vector' of similar type are easily swapped by mistake

      207 |     diff2_vector(int ix, int iy, int iz,
          |                                  ^~~~~~~
      208 |                  const amrex::Array4<const amrex::Real> &state,
          |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      209 |                  const int ivar_0) const
          |                  ~~~~~~~~~~~~~~~~
    ../../Source/Grids/FourthOrderDerivatives.hpp:207:38: note: the first parameter in the range is 'iz'
      207 |     diff2_vector(int ix, int iy, int iz,
          |                                      ^~
    ../../Source/Grids/FourthOrderDerivatives.hpp:209:28: note: the last parameter in the range is 'ivar_0'
      209 |                  const int ivar_0) const
          |                            ^~~~~~
    ../../Source/Grids/FourthOrderDerivatives.hpp:208:18: note: 'int' and 'const int &' parameters accept and bind the same kind of values
      208 |                  const amrex::Array4<const amrex::Real> &state,
          |                  ^
    ../../Source/Grids/FourthOrderDerivatives.hpp:209:18: note: 'const int &' and 'const int' parameters accept and bind the same kind of values
      209 |                  const int ivar_0) const
          |                  ^
  • Source/Grids/FourthOrderDerivatives.hpp:226:34: warning: [bugprone-easily-swappable-parameters]

    3 adjacent parameters of 'diff2_tensor' of similar type are easily swapped by mistake

      226 |     diff2_tensor(int ix, int iy, int iz,
          |                                  ^~~~~~~
      227 |                  const amrex::Array4<const amrex::Real> &state,
          |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      228 |                  const int ivar_0) const
          |                  ~~~~~~~~~~~~~~~~
    ../../Source/Grids/FourthOrderDerivatives.hpp:226:38: note: the first parameter in the range is 'iz'
      226 |     diff2_tensor(int ix, int iy, int iz,
          |                                      ^~
    ../../Source/Grids/FourthOrderDerivatives.hpp:228:28: note: the last parameter in the range is 'ivar_0'
      228 |                  const int ivar_0) const
          |                            ^~~~~~
    ../../Source/Grids/FourthOrderDerivatives.hpp:227:18: note: 'int' and 'const int &' parameters accept and bind the same kind of values
      227 |                  const amrex::Array4<const amrex::Real> &state,
          |                  ^
    ../../Source/Grids/FourthOrderDerivatives.hpp:228:18: note: 'const int &' and 'const int' parameters accept and bind the same kind of values
      228 |                  const int ivar_0) const
          |                  ^
  • Source/Grids/FourthOrderDerivatives.hpp:247:37: warning: [bugprone-easily-swappable-parameters]

    2 adjacent parameters of 'diff2_state' of similar type are easily swapped by mistake

      247 |         diff2_state(int ix, int iy, int iz,
          |                                     ^~~~~~~
      248 |                     const amrex::Array4<const amrex::Real> &state) const
          |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ../../Source/Grids/FourthOrderDerivatives.hpp:247:41: note: the first parameter in the range is 'iz'
      247 |         diff2_state(int ix, int iy, int iz,
          |                                         ^~
    ../../Source/Grids/FourthOrderDerivatives.hpp:248:61: note: the last parameter in the range is 'state'
      248 |                     const amrex::Array4<const amrex::Real> &state) const
          |                                                             ^~~~~
    ../../Source/Grids/FourthOrderDerivatives.hpp:248:21: note: 'int' and 'const int &' parameters accept and bind the same kind of values
      248 |                     const amrex::Array4<const amrex::Real> &state) const
          |                     ^
  • Source/Grids/FourthOrderDerivatives.hpp:292:31: warning: [bugprone-easily-swappable-parameters]

    4 adjacent parameters of 'advection' of similar type are easily swapped by mistake

      292 |     advection(int ix, int iy, int iz,
          |                               ^~~~~~~
      293 |               const amrex::Array4<amrex::Real const> &state,
          |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      294 |               const Tensor<1, amrex::Real> &shift_vector, const int ivar) const
          |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ../../Source/Grids/FourthOrderDerivatives.hpp:292:35: note: the first parameter in the range is 'iz'
      292 |     advection(int ix, int iy, int iz,
          |                                   ^~
    ../../Source/Grids/FourthOrderDerivatives.hpp:294:69: note: the last parameter in the range is 'ivar'
      294 |               const Tensor<1, amrex::Real> &shift_vector, const int ivar) const
          |                                                                     ^~~~
    ../../Source/Grids/FourthOrderDerivatives.hpp:293:15: note: 'int' and 'const int &' parameters accept and bind the same kind of values
      293 |               const amrex::Array4<amrex::Real const> &state,
          |               ^
    ../../Source/Grids/FourthOrderDerivatives.hpp:294:59: note: 'const int &' and 'const int' parameters accept and bind the same kind of values
      294 |               const Tensor<1, amrex::Real> &shift_vector, const int ivar) const
          |                                                           ^
  • Source/Grids/FourthOrderDerivatives.hpp:315:25: warning: [bugprone-easily-swappable-parameters]

    4 adjacent parameters of 'advec_scalar' of similar type are easily swapped by mistake

      315 |         int ix, int iy, int iz, const amrex::Array4<amrex::Real const> &state,
          |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      316 |         const Tensor<1, amrex::Real> &shift_vector, const int ivar) const
          |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ../../Source/Grids/FourthOrderDerivatives.hpp:315:29: note: the first parameter in the range is 'iz'
      315 |         int ix, int iy, int iz, const amrex::Array4<amrex::Real const> &state,
          |                             ^~
    ../../Source/Grids/FourthOrderDerivatives.hpp:316:63: note: the last parameter in the range is 'ivar'
      316 |         const Tensor<1, amrex::Real> &shift_vector, const int ivar) const
          |                                                               ^~~~
    ../../Source/Grids/FourthOrderDerivatives.hpp:315:33: note: 'int' and 'const int &' parameters accept and bind the same kind of values
      315 |         int ix, int iy, int iz, const amrex::Array4<amrex::Real const> &state,
          |                                 ^
    ../../Source/Grids/FourthOrderDerivatives.hpp:316:53: note: 'const int &' and 'const int' parameters accept and bind the same kind of values
      316 |         const Tensor<1, amrex::Real> &shift_vector, const int ivar) const
          |                                                     ^
  • Source/Grids/FourthOrderDerivatives.hpp:322:5: warning: [readability-convert-member-functions-to-static]

    method 'advec_vector' can be made static

      321 |     [[nodiscard]] AMREX_GPU_DEVICE AMREX_FORCE_INLINE Tensor<1, amrex::Real>
          |                                    static 
      322 |     advec_vector(int ix, int iy, int iz,
          |     ^
      323 |                  const amrex::Array4<amrex::Real const> &state,
      324 |                  const Tensor<1, amrex::Real> &shift_vector,
      325 |                  const int ivar0) const
          |                                   ~~~~~
  • Source/Grids/FourthOrderDerivatives.hpp:322:34: warning: [bugprone-easily-swappable-parameters]

    4 adjacent parameters of 'advec_vector' of similar type are easily swapped by mistake

      322 |     advec_vector(int ix, int iy, int iz,
          |                                  ^~~~~~~
      323 |                  const amrex::Array4<amrex::Real const> &state,
          |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      324 |                  const Tensor<1, amrex::Real> &shift_vector,
          |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      325 |                  const int ivar0) const
          |                  ~~~~~~~~~~~~~~~
    ../../Source/Grids/FourthOrderDerivatives.hpp:322:38: note: the first parameter in the range is 'iz'
      322 |     advec_vector(int ix, int iy, int iz,
          |                                      ^~
    ../../Source/Grids/FourthOrderDerivatives.hpp:325:28: note: the last parameter in the range is 'ivar0'
      325 |                  const int ivar0) const
          |                            ^~~~~
    ../../Source/Grids/FourthOrderDerivatives.hpp:323:18: note: 'int' and 'const int &' parameters accept and bind the same kind of values
      323 |                  const amrex::Array4<amrex::Real const> &state,
          |                  ^
    ../../Source/Grids/FourthOrderDerivatives.hpp:325:18: note: 'const int &' and 'const int' parameters accept and bind the same kind of values
      325 |                  const int ivar0) const
          |                  ^
  • Source/Grids/FourthOrderDerivatives.hpp:338:5: warning: [readability-convert-member-functions-to-static]

    method 'advec_tensor' can be made static

      337 |     [[nodiscard]] AMREX_GPU_DEVICE AMREX_FORCE_INLINE Tensor<2, amrex::Real>
          |                                    static 
      338 |     advec_tensor(int ix, int iy, int iz,
          |     ^
      339 |                  const amrex::Array4<amrex::Real const> &state,
      340 |                  const Tensor<1, amrex::Real> &shift_vector,
      341 |                  const int ivar0) const
          |                                   ~~~~~
  • Source/Grids/FourthOrderDerivatives.hpp:338:34: warning: [bugprone-easily-swappable-parameters]

    4 adjacent parameters of 'advec_tensor' of similar type are easily swapped by mistake

      338 |     advec_tensor(int ix, int iy, int iz,
          |                                  ^~~~~~~
      339 |                  const amrex::Array4<amrex::Real const> &state,
          |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      340 |                  const Tensor<1, amrex::Real> &shift_vector,
          |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      341 |                  const int ivar0) const
          |                  ~~~~~~~~~~~~~~~
    ../../Source/Grids/FourthOrderDerivatives.hpp:338:38: note: the first parameter in the range is 'iz'
      338 |     advec_tensor(int ix, int iy, int iz,
          |                                      ^~
    ../../Source/Grids/FourthOrderDerivatives.hpp:341:28: note: the last parameter in the range is 'ivar0'
      341 |                  const int ivar0) const
          |                            ^~~~~
    ../../Source/Grids/FourthOrderDerivatives.hpp:339:18: note: 'int' and 'const int &' parameters accept and bind the same kind of values
      339 |                  const amrex::Array4<amrex::Real const> &state,
          |                  ^
    ../../Source/Grids/FourthOrderDerivatives.hpp:341:18: note: 'const int &' and 'const int' parameters accept and bind the same kind of values
      341 |                  const int ivar0) const
          |                  ^
  • Source/Grids/FourthOrderDerivatives.hpp:355:9: warning: [readability-convert-member-functions-to-static]

    method 'advec_state' can be made static

      354 |         AMREX_FORCE_INLINE amrex::GpuArray<amrex::Real, NUM_CCZ4_VARS>
          |         static 
      355 |         advec_state(int ix, int iy, int iz,
          |         ^
      356 |                     const amrex::Array4<const amrex::Real> &state,
      357 |                     const Tensor<1, amrex::Real> &shift_vector) const
          |                                                                 ~~~~~
  • Source/Grids/FourthOrderDerivatives.hpp:355:37: warning: [bugprone-easily-swappable-parameters]

    3 adjacent parameters of 'advec_state' of similar type are easily swapped by mistake

      355 |         advec_state(int ix, int iy, int iz,
          |                                     ^~~~~~~
      356 |                     const amrex::Array4<const amrex::Real> &state,
          |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      357 |                     const Tensor<1, amrex::Real> &shift_vector) const
          |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ../../Source/Grids/FourthOrderDerivatives.hpp:355:41: note: the first parameter in the range is 'iz'
      355 |         advec_state(int ix, int iy, int iz,
          |                                         ^~
    ../../Source/Grids/FourthOrderDerivatives.hpp:357:51: note: the last parameter in the range is 'shift_vector'
      357 |                     const Tensor<1, amrex::Real> &shift_vector) const
          |                                                   ^~~~~~~~~~~~
    ../../Source/Grids/FourthOrderDerivatives.hpp:356:21: note: 'int' and 'const int &' parameters accept and bind the same kind of values
      356 |                     const amrex::Array4<const amrex::Real> &state,
          |                     ^
  • Source/Grids/FourthOrderDerivatives.hpp:389:22: warning: [modernize-use-nodiscard]

    function 'calculate_dissipation' should be marked [[nodiscard]]

      389 |     AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real
          |                      ^
          |                      [[nodiscard]] 
    /home/runner/work/GRTeclyn/GRTeclyn/amrex/Src/Base/AMReX_Extension.H:110:28: note: expanded from macro 'AMREX_FORCE_INLINE'
      110 | #define AMREX_FORCE_INLINE inline __attribute__((always_inline))
          |                            ^
  • Source/Grids/FourthOrderDerivatives.hpp:390:43: warning: [bugprone-easily-swappable-parameters]

    2 adjacent parameters of 'calculate_dissipation' of similar type are easily swapped by mistake

      390 |     calculate_dissipation(int ix, int iy, int iz,
          |                                           ^~~~~~~
      391 |                           const amrex::Array4<amrex::Real const> &state,
          |                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ../../Source/Grids/FourthOrderDerivatives.hpp:390:47: note: the first parameter in the range is 'iz'
      390 |     calculate_dissipation(int ix, int iy, int iz,
          |                                               ^~
    ../../Source/Grids/FourthOrderDerivatives.hpp:391:67: note: the last parameter in the range is 'state'
      391 |                           const amrex::Array4<amrex::Real const> &state,
          |                                                                   ^~~~~
    ../../Source/Grids/FourthOrderDerivatives.hpp:391:27: note: 'int' and 'const int &' parameters accept and bind the same kind of values
      391 |                           const amrex::Array4<amrex::Real const> &state,
          |                           ^
  • Source/Grids/FourthOrderDerivatives.hpp:413:5: warning: [readability-convert-member-functions-to-static]

    method 'add_dissipation' can be made static

      412 |     AMREX_GPU_DEVICE AMREX_FORCE_INLINE void
          |                      static 
      413 |     add_dissipation(int ix, int iy, int iz,
          |     ^
      414 |                     const amrex::CellData<amrex::Real> &rhs,
      415 |                     const amrex::Array4<amrex::Real const> &state,
      416 |                     const double sigma_coeff, int num_vars = NUM_VARS) const
          |                                                                        ~~~~~
  • Source/Grids/FourthOrderDerivatives.hpp:420:25: warning: [cppcoreguidelines-init-variables]

    variable 'diss' is not initialized

       13 |             amrex::Real diss =
          |                         ^
          |                              = NAN
  • Source/Matter/ScalarFieldD2Vars.hpp:18:22: warning: [readability-redundant-inline-specifier]

    function 'ScalarFieldD2Vars' has inline specifier but is implicitly inlined

       18 |     AMREX_GPU_DEVICE inline ScalarFieldD2Vars(
          |                      ^~~~~~
  • Tests/CCZ4GeometryUnitTests/CCZ4GeometryUnitTest.cpp:30:1: warning: [readability-function-cognitive-complexity]

    function 'compute_ccz4_test_geometry' has cognitive complexity of 46 (threshold 40)

       30 | compute_ccz4_test_geometry(const amrex::Array4<amrex::Real> &a_array,
          | ^

Have any feedback or feature suggestions? Share it here.

@github-actions
Copy link

This PR modifies the following files which are ignored by .lint-ignore:

Source/BlackHoles/BinaryBHInitialData.impl.hpp
Source/BlackHoles/PunctureTracker.impl.hpp
Source/CCZ4/CCZ4RHS.impl.hpp
Source/CCZ4/Constraints.impl.hpp
Source/CCZ4/Weyl4.impl.hpp
Source/Matter/CCZ4RHSWithMatter.impl.hpp
Source/Matter/ConstraintsWithMatter.impl.hpp
Source/Matter/EMTensor.impl.hpp
Source/Matter/ScalarField.impl.hpp
Source/Matter/Weyl4WithMatter.impl.hpp
Tests/CCZ4GeometryUnitTests/CCZ4GeometryMathematicaValues.hpp

Please consider removing the corresponding patterns from .lint-ignore so that these files can be linted.

2 similar comments
@github-actions
Copy link

This PR modifies the following files which are ignored by .lint-ignore:

Source/BlackHoles/BinaryBHInitialData.impl.hpp
Source/BlackHoles/PunctureTracker.impl.hpp
Source/CCZ4/CCZ4RHS.impl.hpp
Source/CCZ4/Constraints.impl.hpp
Source/CCZ4/Weyl4.impl.hpp
Source/Matter/CCZ4RHSWithMatter.impl.hpp
Source/Matter/ConstraintsWithMatter.impl.hpp
Source/Matter/EMTensor.impl.hpp
Source/Matter/ScalarField.impl.hpp
Source/Matter/Weyl4WithMatter.impl.hpp
Tests/CCZ4GeometryUnitTests/CCZ4GeometryMathematicaValues.hpp

Please consider removing the corresponding patterns from .lint-ignore so that these files can be linted.

@github-actions
Copy link

This PR modifies the following files which are ignored by .lint-ignore:

Source/BlackHoles/BinaryBHInitialData.impl.hpp
Source/BlackHoles/PunctureTracker.impl.hpp
Source/CCZ4/CCZ4RHS.impl.hpp
Source/CCZ4/Constraints.impl.hpp
Source/CCZ4/Weyl4.impl.hpp
Source/Matter/CCZ4RHSWithMatter.impl.hpp
Source/Matter/ConstraintsWithMatter.impl.hpp
Source/Matter/EMTensor.impl.hpp
Source/Matter/ScalarField.impl.hpp
Source/Matter/Weyl4WithMatter.impl.hpp
Tests/CCZ4GeometryUnitTests/CCZ4GeometryMathematicaValues.hpp

Please consider removing the corresponding patterns from .lint-ignore so that these files can be linted.

@KAClough KAClough self-assigned this Aug 19, 2025
@github-actions
Copy link

This PR modifies the following files which are ignored by .lint-ignore:

Source/BlackHoles/BinaryBHInitialData.impl.hpp
Source/BlackHoles/PunctureTracker.impl.hpp
Source/CCZ4/CCZ4RHS.impl.hpp
Source/CCZ4/Constraints.impl.hpp
Source/CCZ4/Weyl4.impl.hpp
Source/Matter/CCZ4RHSWithMatter.impl.hpp
Source/Matter/ConstraintsWithMatter.impl.hpp
Source/Matter/EMTensor.impl.hpp
Source/Matter/ScalarField.impl.hpp
Source/Matter/Weyl4WithMatter.impl.hpp
Tests/CCZ4GeometryUnitTests/CCZ4GeometryMathematicaValues.hpp

Please consider removing the corresponding patterns from .lint-ignore so that these files can be linted.

@KAClough KAClough added enhancement New feature or request help wanted Extra attention is needed labels Aug 20, 2025
@julianakwan
Copy link
Contributor

Just reporting on some profiling that I did with the PVCs and AMD MI250Xs. For this test, I used the BinaryBH example with params_profile.txt and 1 MPI rank to 1 tile/GCD. Using TinyProfile, I found that BinaryBHLevel::specificEvalRHS() was about 3x slower on the PVCs on the enhancement/refactor_vars2 branch than the develop branch. However, I found that on the MI250Xs, the refactored branch was about 10% faster! Previously I had seen a 25% speed-up on both systems with the same setup using the enhancement/vars_removal branch. (These are all with exclusive nodes by the way, although I only used one tile/GCD in each test).

I did some more profiling with VTune, specifically Miren wanted to see the number of GPU cycles spent per line of code.
Specifically I used:

vtune -c gpu-hotspots -knob profiling-mode=source-analysis ...

I encountered some difficulties running the full test with params_profile.txt (I kept getting error messages saying that I had run out of GPU registers?) so I dropped max_levels to 6.

We know from TinyProfile that the RHS is the most significant kernel in terms of compute time. In VTune, I can zoom in on parts of the RHS that the profiler has ranked in terms of GPU execution time. I have pasted some screen shots with the hottest lines highlighted i.e. the lines where the GPU is spending the most time within the RHS calculation, for CCZ4RHS.impl.hpp and CCZ4Geometry.hpp.

Note that two of lines point to a left brace { and I don't know what that means. I do see some time is being spent in storing things the new way but not a significant amount, about sub-percent level. But maybe the total number of calls makes it significant? I'm not sure.

I also ran an analysis that specifically looked for stalls:

vtune -c gpu-hotspots -knob profiling-mode=source-analysis -knob source-analysis=stall-sampling ...

I saw what John Pennycook had reported earlier, namely that we were spending a lot of time (about 63% for develop) waiting for thread dependencies (called SBID stalls) to resolve. This happens when threads are waiting for a variable to updated by another thread before it can be used a calculation local to its own thread. It happens a lot for the derivatives because the stencil makes the calculations very much "non-local". Anyway, I only saw a 7% increase in the number of stalls from SBID dependencies in this branch.

I don't find the results super helpful. I think it would be more helpful to try to understand the difference between this current approach and the previous one which seemed to be better optimized, although messier.
Screen Shot 2025-08-26 at 10 50 46 AM
Screen Shot 2025-08-26 at 10 51 45 AM

@KAClough KAClough force-pushed the enhancement/refactor_vars2 branch from 23b358a to 4aa4c8f Compare September 16, 2025 08:28
@github-actions
Copy link

This PR modifies the following files which are ignored by .lint-ignore:

Source/BlackHoles/BinaryBHInitialData.impl.hpp
Source/BlackHoles/PunctureTracker.impl.hpp
Source/CCZ4/CCZ4RHS.impl.hpp
Source/CCZ4/Constraints.impl.hpp
Source/CCZ4/Weyl4.impl.hpp
Source/Matter/CCZ4RHSWithMatter.impl.hpp
Source/Matter/ConstraintsWithMatter.impl.hpp
Source/Matter/EMTensor.impl.hpp
Source/Matter/ScalarField.impl.hpp
Source/Matter/Weyl4WithMatter.impl.hpp
Tests/CCZ4GeometryUnitTests/CCZ4GeometryMathematicaValues.hpp

Please consider removing the corresponding patterns from .lint-ignore so that these files can be linted.

@mirenradia
Copy link
Member

I tested the speedup of enhancement/refactor_vars_speedup (actually I had to make some changes to fix CUDA compilation errors which I have done on test/refactor_vars_speedup_cuda_fixes @ 9a2f78a) vs develop at 76bb280 on the new Nvidia H100 node at COSMA (gn004 on this page) using CUDA 13.0 (first time trying this out as I've been using CUDA 12.X elsewhere). I ran the BinaryBH example using params_profile.txt with plot_interval = 0 and checkpoint_interval = 0. For each version of the code, I ran it three times and have averaged the results which are in the table below:

Code Time spent in RHS (s) RHS Speed-up Total time (s) Total Speed-up
develop @ 76bb280 41.30 1.0x 70.61 1.0x
refactor @ 9a2f78a 31.22 1.32x 61.90 1.14x

@KAClough
Copy link
Member Author

KAClough commented Sep 19, 2025

I tried to see what was causing the slowdown on GPUs. I don't think I got a lot of deep insight, but the following is a summary of what I found:

  1. It is not the creation of new tensor objects that is the problem, it is really the store_vars() functions that create a slowdown.
  2. Making the arguments a constant reference did not help.
  3. Refactoring the D1 vars so it calculates all the variables and accesses their elements with getters (as for CCZ4Vars) does not make any difference to the speed, but I like the way it looks so I will keep it. It is another move away from [] to () so that is more consistent.
  4. Refactoring the D2 vars so it calculates all the variables is a bad idea (presumably because it is a lot more work as most are not needed) and so we should not do it. I would like to create getters though to match the D1 format, which I hope won't break the speed up.

My next steps are to tidy up the enhancement/refactor_vars_speedup branch commit history, fix the matter classes and the tests, merge in @mirenradia 's CUDA fixes, and then merge that back here. At that point I think we should be ready to review it.

The upshot of this is that the storing of vars in the rhs cell data has to be done visibly as rhs[c_chi] = 1.0 which is fine for scalars but for tensors we need things like rhs[var_idx(c_h11,i,j)] = 1.0, which isn't as nice as rhs.store_h(rhs_h), but I don't see a way around it for now, so I think we will have to accept the reduced readability, as much as it pains me to say it.

@KAClough
Copy link
Member Author

I can answer most of these now:

NB I have not tried to address flattening out the Tensor array here, but once this is done I think it should be relatively simple to implement.

@julianakwan is working on this. It will mean that tensors are access with (i,j) not [i][j] which fits nicely with the style of the wrappers that are in this PR.

Some questions/comments I had for discussion:

  1. Do we need to have a ConstCCZ4Vars and a CCZ4Vars class? I couldn't work out how to do it but probably there is a way.

In the end we don't need this distinction as we store direct to the cell data, so all CCZ4Vars objects are const.

  1. Is the method of storing the vars optimal? I end up creating a Tensor object, and then storing it, whereas I think I should be able to update the value directly. For some reason this didn't work. On the other hand, what I have now is very readable.

It is not optimal, see above.

  1. We now have () brackets for the vars grid object access and [] brackets for Tensor objects like the derivatives. I am kind of ok with this because they are conceptually different and maybe this makes a useful distinction. On the other hand if they were all one or the other there might be less chance of making mistakes.

Due to the changes in the Tensor objects, this inconsistency should resolve itself.

  1. There is a warning about const amrex::CellData<amrex::Real> &cell_data; references as data members that I don't know whether to suppress.

I have suppressed it. I think that we really do want a reference as a data member and not a pointer. We definitely don't want a copy as that's the whole point of the wrapper.

  1. The regression test fails but the differences are small, should we worry?

I will check this again once we are done with the changes.

  1. Should we remove the option of BSSN?

Yes, or at least remove the branching as it slows things down a lot. But this is for another PR.

@julianakwan
Copy link
Contributor

I'm trying to benchmark the performance of this branch on Frontier and it annoying fails at start up when AMReX is trying to allocate memory to the Arena (although the develop branch is fine 🤔 ).

Here is the output:

[jkwan@login10.frontier BinaryBH]$ more BinaryBH-vars-removal-3766161.out
Unloading the cpe module is insufficient to restore the system defaults.
Please run 'source
/opt/cray/pe/cpe/24.11/restore_lmod_system_defaults.[csh|sh]'. 
 
Sourcing the above script is not necessary if swapping the cpe module with a
different version. 

The following have been reloaded with a version change:
  1) gcc-native/14.2 => gcc-native/13.2     2) rocm/6.4.0 => rocm/6.2.4

The following have been reloaded with a version change:
  1) rocm/6.2.4 => rocm/6.4.0

Currently Loaded Modules:
  1) libfabric/1.22.0     5) craype/2.7.33         9) cray-mpich/8.1.31
  2) craype-network-ofi   6) cray-dsmml/0.3.0     10) craype-accel-amd-gfx90a
  3) gcc-native/13.2      7) cray-libsci/24.11.0  11) rocm/6.4.0
  4) cpe/24.11            8) PrgEnv-gnu/8.6.0

 

appending parameters: amr.plot_nfiles = -1 amr.checkpoint_nfiles = -1 checkpoint_interval = -1 plot_inte
rval=-1 amrex.use_gpu_aware_mpi=1
Initializing AMReX (25.08-19-g9d2b74990c60)...
MPI initialized with 1 MPI processes
MPI initialized with thread support level 0
Initializing HIP...
HIP initialized with 1 device.
amrex::Abort::0::HIP error in file /lustre/orion/cos004/proj-shared/jkwan/amrex/Src/Base/AMReX_Arena.cpp
 line 257 out of memory !!!
SIGABRT
See Backtrace.0 file for details
MPICH ERROR [Rank 0] [job id 3766161.0] [Thu Sep 25 11:55:39 2025] [frontier03208] - Abort(6) (rank 0 in
 comm 0): application called MPI_Abort(MPI_COMM_WORLD, 6) - process 0

srun: error: frontier03208: task 0: Exited with exit code 6
srun: Terminating StepId=3766161.0

Here is Backtrace.0:

Host Name: frontier03208
=== If no file names and line numbers are shown below, one can run
            addr2line -Cpfie my_exefile my_line_address
    to convert `my_line_address` (e.g., 0x4a6b) into file name and line number.
    Or one can use amrex/Tools/Backtrace/parse_bt.py.

=== Please note that the line number reported by addr2line may not be accurate.
    One can use
            readelf -wl my_exefile | grep my_line_address'
    to find out the offset for that line.

 0: /lustre/orion/cos004/proj-shared/jkwan/GRTeclyn/Examples/BinaryBH/././main3d.hip.x86-trento.TPROF.MPI.HIP.ex() [0x45c226]
    amrex::BLBackTrace::print_backtrace_info(_IO_FILE*) at /lustre/orion/cos004/proj-shared/jkwan/amrex/Src/Base/AMReX_BLBackTrace.cpp:205

 1: /lustre/orion/cos004/proj-shared/jkwan/GRTeclyn/Examples/BinaryBH/././main3d.hip.x86-trento.TPROF.MPI.HIP.ex() [0x45be33]
    amrex::BLBackTrace::handler(int) at /lustre/orion/cos004/proj-shared/jkwan/amrex/Src/Base/AMReX_BLBackTrace.cpp:103

 2: /lustre/orion/cos004/proj-shared/jkwan/GRTeclyn/Examples/BinaryBH/././main3d.hip.x86-trento.TPROF.MPI.HIP.ex() [0x365241]
    std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_data() const at /usr/lib64/gcc/x86_64-suse-linux/13/../../../../include/c++/13/bits/basic_string.h:223
 (inlined by) std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_is_local() const at /usr/lib64/gcc/x86_64-suse-linux/13/../../../../include/c++/13/bits/basic_string.h:264
 (inlined by) std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_dispose() at /usr/lib64/gcc/x86_64-suse-linux/13/../../../../include/c++/13/bits/basic_string.h:282
 (inlined by) std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() at /usr/lib64/gcc/x86_64-suse-linux/13/../../../../include/c++/13/bits/basic_string.h:804
 (inlined by) amrex::Arena::allocate_system(unsigned long) at /lustre/orion/cos004/proj-shared/jkwan/amrex/Src/Base/AMReX_Arena.cpp:?

 3: /lustre/orion/cos004/proj-shared/jkwan/GRTeclyn/Examples/BinaryBH/././main3d.hip.x86-trento.TPROF.MPI.HIP.ex() [0x36a82a]
    amrex::CArena::alloc_protected(unsigned long) at /lustre/orion/cos004/proj-shared/jkwan/amrex/Src/Base/AMReX_CArena.cpp:?

 4: /lustre/orion/cos004/proj-shared/jkwan/GRTeclyn/Examples/BinaryBH/././main3d.hip.x86-trento.TPROF.MPI.HIP.ex() [0x36a599]
    amrex::CArena::alloc(unsigned long) at /lustre/orion/cos004/proj-shared/jkwan/amrex/Src/Base/AMReX_CArena.cpp:?

 5: /lustre/orion/cos004/proj-shared/jkwan/GRTeclyn/Examples/BinaryBH/././main3d.hip.x86-trento.TPROF.MPI.HIP.ex() [0x366d51]
    amrex::Arena::Initialize(bool) at /lustre/orion/cos004/proj-shared/jkwan/amrex/Src/Base/AMReX_Arena.cpp:409

 6: /lustre/orion/cos004/proj-shared/jkwan/GRTeclyn/Examples/BinaryBH/././main3d.hip.x86-trento.TPROF.MPI.HIP.ex() [0x2c0ff7]
    amrex::Initialize(int&, char**&, bool, int, std::function<void ()> const&, std::ostream&, std::ostream&, void (*)(char const*)) at /lustre/orion/cos004/proj-shared/jkwan/amrex/Src/Base/AMReX.cpp:678

 7: /lustre/orion/cos004/proj-shared/jkwan/GRTeclyn/Examples/BinaryBH/././main3d.hip.x86-trento.TPROF.MPI.HIP.ex() [0x5cf4a6]
    mainSetup(int, char**) at /lustre/orion/cos004/proj-shared/jkwan/GRTeclyn/Source/GRTeclynCore/SetupFunctions.hpp:40 (discriminator 8)

 8: /lustre/orion/cos004/proj-shared/jkwan/GRTeclyn/Examples/BinaryBH/././main3d.hip.x86-trento.TPROF.MPI.HIP.ex() [0x5cf92d]
    main at /lustre/orion/cos004/proj-shared/jkwan/GRTeclyn/Examples/BinaryBH/Main_BinaryBH.cpp:81

 9: /lib64/libc.so.6(+0x40e6c) [0x7fffcfcbce6c]

10: /lib64/libc.so.6(__libc_start_main+0x87) [0x7fffcfcbcf35]

11: /lustre/orion/cos004/proj-shared/jkwan/GRTeclyn/Examples/BinaryBH/././main3d.hip.x86-trento.TPROF.MPI.HIP.ex() [0x2bf961]
    _start
../sysdeps/x86_64/start.S:117


===== TinyProfilers ======

Not very helpful is it?

@mirenradia
Copy link
Member

@julianakwan, note that @KAClough has set amrex.the_arena_init_size explicitly in params_profile.txt. I'm not sure why this was committed but this is probably the cause of your out of memory error. You should remove it and let AMReX do its default thing (i.e. allocate 3/4 of the GPU memory).

@julianakwan
Copy link
Contributor

@julianakwan, note that @KAClough has set amrex.the_arena_init_size explicitly in params_profile.txt. I'm not sure why this was committed but this is probably the cause of your out of memory error. You should remove it and let AMReX do its default thing (i.e. allocate 3/4 of the GPU memory).

Yes I can confirm that this was the problem! There should really be a :face-palm: reaction as I should have checked params_profile.txt more carefully!

@julianakwan
Copy link
Contributor

julianakwan commented Sep 25, 2025

I have some benchmarks to report. This was done on Frontier with 1 MPI rank to 1 GCD and each result has been averaged over 3 runs:

Code Time spent in RHS (s) RHS Speed-up Total time (s) Total Speed-up
develop @ 76bb280 157.83 1.0x 198.46 1.0x
refactor_vars2 @ 72ffeba 112.73 1.4x 155.066 1.28x

This is comparable to the performance that I had measured previously on Frontier with the enhancement/vars_removal branch

@mirenradia
Copy link
Member

This is comparable to the performance that I had measured previously on Frontier with the enhancement/refactor_vars branch

Do you mean the enhancement/vars_removal branch? I think the enhancement/refactor_vars branch is an older version of the stuff on this branch that Katy worked on.

@KAClough
Copy link
Member Author

@julianakwan, note that @KAClough has set amrex.the_arena_init_size explicitly in params_profile.txt. I'm not sure why this was committed but this is probably the cause of your out of memory error. You should remove it and let AMReX do its default thing (i.e. allocate 3/4 of the GPU memory).

Yes I can confirm that this was the problem! There should really be a :face-palm: reaction as I should have checked params_profile.txt more carefully!

I'm sorry for this, it is me who shouldn't have committed it! It is a setting I have to use on the Cosma AMD GPU for reasons I have not understood. I will remove it when I next update the branch.

@julianakwan
Copy link
Contributor

This is comparable to the performance that I had measured previously on Frontier with the enhancement/refactor_vars branch

Do you mean the enhancement/vars_removal branch? I think the enhancement/refactor_vars branch is an older version of the stuff on this branch that Katy worked on.

Yes, I will correct the post.

@julianakwan
Copy link
Contributor

@julianakwan, note that @KAClough has set amrex.the_arena_init_size explicitly in params_profile.txt. I'm not sure why this was committed but this is probably the cause of your out of memory error. You should remove it and let AMReX do its default thing (i.e. allocate 3/4 of the GPU memory).

Yes I can confirm that this was the problem! There should really be a :face-palm: reaction as I should have checked params_profile.txt more carefully!

I'm sorry for this, it is me who shouldn't have committed it! It is a setting I have to use on the Cosma AMD GPU for reasons I have not understood. I will remove it when I next update the branch.

No problem! As I understand it, the Cosma8 MI300Xs are on a shared node in some kind of free-for-all Wild West configuration, so you probably had to manually request enough memory.

@julianakwan
Copy link
Contributor

I have some more benchmarks to report (yes I know this should be its own issue). Same set up as above on Frontier:

Code Time spent in RHS (s) RHS Speed-up Total time (s) Total Speed-up
develop @ 76bb280 157.83 1.0x 198.46 1.0x
refactor_tensors @ ce284cb 155.56 1.01x 196.2 1.01x

😞

@mirenradia mirenradia mentioned this pull request Oct 2, 2025
3 tasks
@mirenradia
Copy link
Member

I have some bad news to report.

I tested this branch @ 72ffeba vs develop at 76bb280 on a single GPU (Intel Data Center GPU Max 1550/PVC) on Dawn (2 MPI ranks so there is 1 per stack). I ran the BinaryBH example using params_profile.txt with plot_interval = 0 and checkpoint_interval = 0. For each version of the code, I ran it three times and have averaged the results which are in the table below:

Code Time spent in RHS (s) RHS Speed-up Total time (s) Total Speed-up
develop @ 76bb280 50.16 1.0x 77.89 1.0x
refactor @ 72ffeba 124.93 0.40x 150.5 0.52x

I think I would accept a small degradation in performance on PVCs since GRTeclyn is more likely to be run on Nvidia and AMD GPUs but I think this is probably too big to accept. I will try and investigate.

@mirenradia mirenradia changed the title Updates Vars and Matter classes to address issue #111 Refactor vars, make compute classes consistent and fix some variable names Feb 5, 2026
@mirenradia mirenradia linked an issue Feb 5, 2026 that may be closed by this pull request
6 tasks
compute(int i, int j, int k, const amrex::Array4<amrex::Real> &rhs,
const amrex::Array4<amrex::Real const> &state) const;
operator()(int ix, int iy, int iz,
const amrex::Array4<amrex::Real> &rhs_state,
Copy link
Member

Choose a reason for hiding this comment

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

Can we rename this back to rhs? I don't think rhs_state makes any sense since it's either the state (i.e. the variables on the grid) or the RHS.

Copy link
Member

Choose a reason for hiding this comment

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

This change should also be made in CCZ4RHSWithMatter.

Copy link
Member

Choose a reason for hiding this comment

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

I see now that you've used rhs for the amrex::CellData<...> you get from this amrex::Array4<...>. Maybe it makes sense to make that one rhs_cell_data for consistency with state_cell_data and then you can make the Array4<...> object just rhs.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd prefer to leave it as it is, as having rhs_cell_data all through the rhs code is more ugly. I don't see what is wrong with rhs_state being the rhs of the state, and I am sure people will figure it out.

Copy link
Member

Choose a reason for hiding this comment

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

It just seems quite inconsistent and confusing to me.

Copy link
Member

Choose a reason for hiding this comment

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

You're actually already using rhs_cell_data in some places!

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes I know

@KAClough KAClough force-pushed the enhancement/refactor_vars2 branch from 397d9ca to 64ca462 Compare February 5, 2026 17:31
@github-actions
Copy link

github-actions bot commented Feb 5, 2026

This PR modifies the following files which are ignored by .lint-ignore:

Source/BlackHoles/BinaryBHInitialData.impl.hpp
Source/BlackHoles/PunctureTracker.impl.hpp
Source/CCZ4/CCZ4RHS.impl.hpp
Source/CCZ4/Constraints.impl.hpp
Source/CCZ4/Weyl4.impl.hpp
Source/Matter/CCZ4RHSWithMatter.impl.hpp
Source/Matter/ConstraintsWithMatter.impl.hpp
Source/Matter/EMTensor.impl.hpp
Source/Matter/ScalarField.impl.hpp
Source/Matter/Weyl4WithMatter.impl.hpp
Tests/CCZ4GeometryUnitTests/CCZ4GeometryMathematicaValues.hpp

Please consider removing the corresponding patterns from .lint-ignore so that these files can be linted.

@KAClough KAClough removed the enhancement New feature or request label Feb 5, 2026
@KAClough KAClough force-pushed the enhancement/refactor_vars2 branch from 64ca462 to f51c902 Compare February 5, 2026 17:44
@github-actions
Copy link

github-actions bot commented Feb 5, 2026

This PR modifies the following files which are ignored by .lint-ignore:

Source/BlackHoles/BinaryBHInitialData.impl.hpp
Source/BlackHoles/PunctureTracker.impl.hpp
Source/CCZ4/CCZ4RHS.impl.hpp
Source/CCZ4/Constraints.impl.hpp
Source/CCZ4/Weyl4.impl.hpp
Source/Matter/CCZ4RHSWithMatter.impl.hpp
Source/Matter/ConstraintsWithMatter.impl.hpp
Source/Matter/EMTensor.impl.hpp
Source/Matter/ScalarField.impl.hpp
Source/Matter/Weyl4WithMatter.impl.hpp
Tests/CCZ4GeometryUnitTests/CCZ4GeometryMathematicaValues.hpp

Please consider removing the corresponding patterns from .lint-ignore so that these files can be linted.

@KAClough KAClough force-pushed the enhancement/refactor_vars2 branch from f51c902 to 6ea2616 Compare February 5, 2026 17:55
@github-actions
Copy link

github-actions bot commented Feb 5, 2026

This PR modifies the following files which are ignored by .lint-ignore:

Source/BlackHoles/BinaryBHInitialData.impl.hpp
Source/BlackHoles/PunctureTracker.impl.hpp
Source/CCZ4/CCZ4RHS.impl.hpp
Source/CCZ4/Constraints.impl.hpp
Source/CCZ4/Weyl4.impl.hpp
Source/Matter/CCZ4RHSWithMatter.impl.hpp
Source/Matter/ConstraintsWithMatter.impl.hpp
Source/Matter/EMTensor.impl.hpp
Source/Matter/ScalarField.impl.hpp
Source/Matter/Weyl4WithMatter.impl.hpp
Tests/CCZ4GeometryUnitTests/CCZ4GeometryMathematicaValues.hpp

Please consider removing the corresponding patterns from .lint-ignore so that these files can be linted.

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.

Replace loading and storing of variables in CCZ4RHS

4 participants