Skip to content
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

Fix minor HYPRE and ADIOS2 compilation issues #3022

Open
wants to merge 11 commits into
base: next
Choose a base branch
from
9 changes: 8 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ jobs:
-DBOUT_USE_PETSC=ON
-DBOUT_USE_SLEPC=ON
-DBOUT_USE_SUNDIALS=ON
-DBOUT_USE_HYPRE=ON
-DBOUT_USE_ADIOS2=ON
-DBOUT_ENABLE_PYTHON=ON
-DADIOS2_ROOT=/home/runner/local/adios2
-DADIOS2_ROOT=/home/runner/local
-DSUNDIALS_ROOT=/home/runner/local
-DPETSC_DIR=/home/runner/local/petsc
-DSLEPC_DIR=/home/runner/local/slepc"
Expand All @@ -74,6 +75,7 @@ jobs:
-DBOUT_USE_PETSC=ON
-DBOUT_USE_SLEPC=ON
-DBOUT_USE_SUNDIALS=ON
-DBOUT_USE_HYPRE=ON
-DSUNDIALS_ROOT=/home/runner/local"
on_cron: false

Expand All @@ -86,6 +88,7 @@ jobs:
-DBOUT_USE_PETSC=ON
-DBOUT_USE_SLEPC=ON
-DBOUT_USE_SUNDIALS=ON
-DBOUT_USE_HYPRE=ON
-DSUNDIALS_ROOT=/home/runner/local"
on_cron: false

Expand All @@ -97,6 +100,7 @@ jobs:
-DBOUT_USE_PETSC=ON
-DBOUT_USE_SLEPC=ON
-DBOUT_USE_SUNDIALS=ON
-DBOUT_USE_HYPRE=ON
-DBOUT_BUILD_DOCS=OFF
-DSUNDIALS_ROOT=/home/runner/local"
omp_num_threads: 2
Expand All @@ -110,6 +114,7 @@ jobs:
-DBOUT_USE_PETSC=ON
-DBOUT_USE_SLEPC=ON
-DBOUT_USE_SUNDIALS=ON
-DBOUT_USE_HYPRE=ON
-DBOUT_ENABLE_PYTHON=ON
-DSUNDIALS_ROOT=/home/runner/local"
omp_num_threads: 2
Expand All @@ -123,6 +128,7 @@ jobs:
-DBOUT_USE_PETSC=ON
-DBOUT_USE_SLEPC=ON
-DBOUT_USE_SUNDIALS=ON
-DBOUT_USE_HYPRE=ON
-DBOUT_ENABLE_PYTHON=ON
-DSUNDIALS_ROOT=/home/runner/local
-DPETSC_DIR=/home/runner/local/petsc
Expand Down Expand Up @@ -178,6 +184,7 @@ jobs:
slepc-dev
liblapack-dev
libparpack2-dev
libhypre-dev

- uses: actions/checkout@v4
with:
Expand Down
3 changes: 2 additions & 1 deletion cmake/FindHYPRE.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ include(FindPackageHandleStandardArgs)

find_package(HYPRE CONFIG QUIET)
if (HYPRE_FOUND)
message(STATUS "Found HYPRE: ${HYPRE_VERSION}")
return()
endif()

find_path(HYPRE_INCLUDE_DIR
NAMES HYPRE.h
DOC "HYPRE include directories"
REQUIRED
PATH_SUFFIXES include
PATH_SUFFIXES include include/hypre
)

find_library(HYPRE_LIBRARY
Expand Down
14 changes: 5 additions & 9 deletions cmake/SetupBOUTThirdParty.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ endif()
message(STATUS "NetCDF support: ${BOUT_USE_NETCDF}")
set(BOUT_HAS_NETCDF ${BOUT_USE_NETCDF})

option(BOUT_USE_ADIOS2 "Enable support for ADIOS output" ON)
option(BOUT_USE_ADIOS2 "Enable support for ADIOS output" OFF)
option(BOUT_DOWNLOAD_ADIOS2 "Download and build ADIOS2" OFF)
if (BOUT_USE_ADIOS2)
if (BOUT_DOWNLOAD_ADIOS2)
Expand All @@ -214,14 +214,10 @@ if (BOUT_USE_ADIOS2)
target_link_libraries(bout++ PUBLIC adios2::cxx11_mpi)
message(STATUS "ADIOS2 done configuring")
else()
find_package(ADIOS2)
if (ADIOS2_FOUND)
ENABLE_LANGUAGE(C)
find_package(MPI REQUIRED COMPONENTS C)
target_link_libraries(bout++ PUBLIC adios2::cxx11_mpi MPI::MPI_C)
else()
set(BOUT_USE_ADIOS2 OFF)
endif()
find_package(ADIOS2 REQUIRED)
enable_language(C)
find_package(MPI REQUIRED COMPONENTS C)
target_link_libraries(bout++ PUBLIC adios2::cxx11_mpi MPI::MPI_C)
endif()
endif()
message(STATUS "ADIOS2 support: ${BOUT_USE_ADIOS2}")
Expand Down
2 changes: 1 addition & 1 deletion include/bout/field3d.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ void checkData(const Field3D& f, const std::string& region = "RGN_NOBNDRY");
/// Ignored with disabled CHECK; Throw an exception if \p f is not
/// allocated or if any elements are non-finite (for CHECK > 2)
inline void checkData(const Field3D& UNUSED(f),
const std::string& UNUSED(region) = "RGN_NOBNDRY") {};
const std::string& UNUSED(region) = "RGN_NOBNDRY"){};
#endif

/// Fourier filtering, removes all except one mode
Expand Down
4 changes: 2 additions & 2 deletions include/bout/utils.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
#include <list>
#include <memory>
#include <set>
#include <string>
#include <sstream>
#include <string>

#ifdef _MSC_VER
// finite is not actually standard C++, it's a BSD extention for C
Expand Down Expand Up @@ -544,7 +544,7 @@ inline void checkData(BoutReal f) {
}
#else
/// Ignored with disabled CHECK; Throw an exception if \p f is not finite
inline void checkData(BoutReal UNUSED(f)) {};
inline void checkData(BoutReal UNUSED(f)){};
#endif

/*!
Expand Down
77 changes: 39 additions & 38 deletions src/invert/laplace/impls/hypre3d/hypre3d_laplace.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,23 @@ LaplaceHypre3d::LaplaceHypre3d(Options* opt, const CELL_LOC loc, Mesh* mesh_in,

// Checking flags are set to something which is not implemented
// This is done binary (which is possible as each flag is a power of 2)
if (global_flags & ~implemented_flags) {
if (isGlobalFlagSet(~implemented_flags)) {
throw BoutException("Attempted to set Laplacian inversion flag that is not "
"implemented in LaplaceHypre3d");
}
if (inner_boundary_flags & ~implemented_boundary_flags) {
if (isInnerBoundaryFlagSet(~implemented_boundary_flags)) {
throw BoutException("Attempted to set Laplacian inversion boundary flag that is not "
"implemented in LaplaceHypre3d");
}
if (outer_boundary_flags & ~implemented_boundary_flags) {
if (isOuterBoundaryFlagSet(~implemented_boundary_flags)) {
throw BoutException("Attempted to set Laplacian inversion boundary flag that is not "
"implemented in LaplaceHypre3d");
}
if (lower_boundary_flags & ~implemented_boundary_flags) {
if ((lower_boundary_flags & ~implemented_boundary_flags) != 0) {
throw BoutException("Attempted to set Laplacian inversion boundary flag that is not "
"implemented in LaplaceHypre3d");
}
if (upper_boundary_flags & ~implemented_boundary_flags) {
if ((upper_boundary_flags & ~implemented_boundary_flags) != 0) {
throw BoutException("Attempted to set Laplacian inversion boundary flag that is not "
"implemented in LaplaceHypre3d");
}
Expand Down Expand Up @@ -123,7 +123,7 @@ LaplaceHypre3d::LaplaceHypre3d(Options* opt, const CELL_LOC loc, Mesh* mesh_in,
}

BOUT_FOR_SERIAL(i, indexer->getRegionLowerY()) {
if (lower_boundary_flags & INVERT_AC_GRAD) {
if ((lower_boundary_flags & INVERT_AC_GRAD) != 0) {
// Neumann on lower Y boundary
operator3D(i, i) = -1. / coords->dy[i] / sqrt(coords->g_22[i]);
operator3D(i, i.yp()) = 1. / coords->dy[i] / sqrt(coords->g_22[i]);
Expand All @@ -135,7 +135,7 @@ LaplaceHypre3d::LaplaceHypre3d(Options* opt, const CELL_LOC loc, Mesh* mesh_in,
}

BOUT_FOR_SERIAL(i, indexer->getRegionUpperY()) {
if (upper_boundary_flags & INVERT_AC_GRAD) {
if ((upper_boundary_flags & INVERT_AC_GRAD) != 0) {
// Neumann on upper Y boundary
operator3D(i, i) = 1. / coords->dy[i] / sqrt(coords->g_22[i]);
operator3D(i, i.ym()) = -1. / coords->dy[i] / sqrt(coords->g_22[i]);
Expand Down Expand Up @@ -200,19 +200,19 @@ Field3D LaplaceHypre3d::solve(const Field3D& b_in, const Field3D& x0) {
}

BOUT_FOR_SERIAL(i, indexer->getRegionLowerY()) {
const BoutReal val = (lower_boundary_flags & INVERT_SET) ? x0[i] : 0.;
const BoutReal val = ((lower_boundary_flags & INVERT_SET) != 0) ? x0[i] : 0.;
ASSERT1(std::isfinite(val));
if (!(lower_boundary_flags & INVERT_RHS)) {
if ((lower_boundary_flags & INVERT_RHS) == 0) {
b[i] = val;
} else {
ASSERT1(std::isfinite(b[i]));
}
}

BOUT_FOR_SERIAL(i, indexer->getRegionUpperY()) {
const BoutReal val = (upper_boundary_flags & INVERT_SET) ? x0[i] : 0.;
const BoutReal val = ((upper_boundary_flags & INVERT_SET) != 0) ? x0[i] : 0.;
ASSERT1(std::isfinite(val));
if (!(upper_boundary_flags & INVERT_RHS)) {
if ((upper_boundary_flags & INVERT_RHS) == 0) {
b[i] = val;
} else {
ASSERT1(std::isfinite(b[i]));
Expand Down Expand Up @@ -277,7 +277,7 @@ void LaplaceHypre3d::updateMatrix3D() {
const Field3D dc_dx = issetC ? DDX(C2) : Field3D();
const Field3D dc_dy = issetC ? DDY(C2) : Field3D();
const Field3D dc_dz = issetC ? DDZ(C2) : Field3D();
const Field2D dJ_dy = DDY(coords->J / coords->g_22);
const auto dJ_dy = DDY(coords->J / coords->g_22);

// Set up the matrix for the internal points on the grid.
// Boundary conditions were set in the constructor.
Expand All @@ -286,7 +286,8 @@ void LaplaceHypre3d::updateMatrix3D() {
// avoid confusing it with the x-index.

// Calculate coefficients for the terms in the differential operator
BoutReal C_df_dx = coords->G1[l], C_df_dz = coords->G3[l];
BoutReal C_df_dx = coords->G1[l];
BoutReal C_df_dz = coords->G3[l];
if (issetD) {
C_df_dx *= D[l];
C_df_dz *= D[l];
Expand All @@ -304,9 +305,9 @@ void LaplaceHypre3d::updateMatrix3D() {
C_df_dz += Ez[l];
}

BoutReal C_d2f_dx2 = coords->g11[l],
C_d2f_dy2 = (coords->g22[l] - 1.0 / coords->g_22[l]),
C_d2f_dz2 = coords->g33[l];
BoutReal C_d2f_dx2 = coords->g11[l];
BoutReal C_d2f_dy2 = (coords->g22[l] - 1.0 / coords->g_22[l]);
BoutReal C_d2f_dz2 = coords->g33[l];
if (issetD) {
C_d2f_dx2 *= D[l];
C_d2f_dy2 *= D[l];
Expand Down Expand Up @@ -343,8 +344,8 @@ void LaplaceHypre3d::updateMatrix3D() {
// The values stored in the y-boundary are already interpolated
// up/down, so we don't want the matrix to do any such
// interpolation there.
const int yup = (l.y() == localmesh->yend && upperY.intersects(l.x())) ? -1 : 0,
ydown = (l.y() == localmesh->ystart && lowerY.intersects(l.x())) ? -1 : 0;
const int yup = (l.y() == localmesh->yend && upperY.intersects(l.x())) ? -1 : 0;
const int ydown = (l.y() == localmesh->ystart && lowerY.intersects(l.x())) ? -1 : 0;
operator3D.yup(yup)(l, l.yp()) = 0.0;
operator3D.ydown(ydown)(l, l.ym()) = 0.0;
operator3D.yup(yup)(l, l.xp().yp()) = 0.0;
Expand Down Expand Up @@ -376,7 +377,8 @@ void LaplaceHypre3d::updateMatrix3D() {
C_d2f_dy2 *= D[l];
}

BoutReal C_d2f_dxdy = 2 * coords->g12[l], C_d2f_dydz = 2 * coords->g23[l];
BoutReal C_d2f_dxdy = 2 * coords->g12[l];
BoutReal C_d2f_dydz = 2 * coords->g23[l];
if (issetD) {
C_d2f_dxdy *= D[l];
C_d2f_dydz *= D[l];
Expand All @@ -396,8 +398,8 @@ void LaplaceHypre3d::updateMatrix3D() {
// The values stored in the y-boundary are already interpolated
// up/down, so we don't want the matrix to do any such
// interpolation there.
const int yup = (l.y() == localmesh->yend && upperY.intersects(l.x())) ? -1 : 0,
ydown = (l.y() == localmesh->ystart && lowerY.intersects(l.x())) ? -1 : 0;
const int yup = (l.y() == localmesh->yend && upperY.intersects(l.x())) ? -1 : 0;
const int ydown = (l.y() == localmesh->ystart && lowerY.intersects(l.x())) ? -1 : 0;

operator3D.yup(yup)(l, l.yp()) += C_df_dy + C_d2f_dy2;
operator3D.ydown(ydown)(l, l.ym()) += -C_df_dy + C_d2f_dy2;
Expand Down Expand Up @@ -437,19 +439,15 @@ OperatorStencil<Ind3D> LaplaceHypre3d::getStencil(Mesh* localmesh,
OffsetInd3D zero;

// Add interior cells
const std::vector<OffsetInd3D> interpolatedUpElements = {zero.yp(), zero.xp().yp(),
zero.xm().yp(), zero.yp().zp(),
zero.yp().zm()},
interpolatedDownElements = {
zero.ym(), zero.xp().ym(), zero.xm().ym(),
zero.ym().zp(), zero.ym().zm()};
std::set<OffsetInd3D> interiorStencil = {zero, zero.xp(),
zero.xm(), zero.zp(),
zero.zm(), zero.xp().zp(),
zero.xp().zm(), zero.xm().zp(),
zero.xm().zm()},
lowerEdgeStencil = interiorStencil,
upperEdgeStencil = interiorStencil;
const std::vector<OffsetInd3D> interpolatedUpElements = {
zero.yp(), zero.xp().yp(), zero.xm().yp(), zero.yp().zp(), zero.yp().zm()};
const std::vector<OffsetInd3D> interpolatedDownElements = {
zero.ym(), zero.xp().ym(), zero.xm().ym(), zero.ym().zp(), zero.ym().zm()};
std::set<OffsetInd3D> interiorStencil = {
zero, zero.xp(), zero.xm(), zero.zp(), zero.zm(),
zero.xp().zp(), zero.xp().zm(), zero.xm().zp(), zero.xm().zm()};
std::set<OffsetInd3D> lowerEdgeStencil = interiorStencil;
std::set<OffsetInd3D> upperEdgeStencil = interiorStencil;

for (const auto& i : interpolatedDownElements) {
for (auto& j : interpPattern) {
Expand All @@ -466,9 +464,11 @@ OperatorStencil<Ind3D> LaplaceHypre3d::getStencil(Mesh* localmesh,
upperEdgeStencil.insert(i);
}
const std::vector<OffsetInd3D> interiorStencilVector(interiorStencil.begin(),
interiorStencil.end()),
lowerEdgeStencilVector(lowerEdgeStencil.begin(), lowerEdgeStencil.end()),
upperEdgeStencilVector(upperEdgeStencil.begin(), upperEdgeStencil.end());
interiorStencil.end());
const std::vector<OffsetInd3D> lowerEdgeStencilVector(lowerEdgeStencil.begin(),
lowerEdgeStencil.end());
const std::vector<OffsetInd3D> upperEdgeStencilVector(upperEdgeStencil.begin(),
upperEdgeStencil.end());

// If there is a lower y-boundary then create a part of the stencil
// for cells immediately adjacent to it.
Expand Down Expand Up @@ -536,7 +536,8 @@ OperatorStencil<Ind3D> LaplaceHypre3d::getStencil(Mesh* localmesh,
return stencil;
}

int LaplaceHypre3d::Hypre3dMonitor::call(Solver*, BoutReal, int, int) {
int LaplaceHypre3d::Hypre3dMonitor::call(Solver* /*solver*/, BoutReal /*time*/,
int /*iter*/, int /*nout*/) {
if (laplace.n_solves == 0) {
laplace.average_iterations = 0.0;
return 0;
Expand Down
11 changes: 4 additions & 7 deletions src/invert/laplace/impls/hypre3d/hypre3d_laplace.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -209,20 +209,17 @@ public:
public:
Hypre3dMonitor(LaplaceHypre3d& laplace_in) : laplace(laplace_in) {}

int call(Solver*, BoutReal, int, int) override;
int call(Solver* /*solver*/, BoutReal /*time*/, int /*iter*/, int /*nout*/) override;

private:
LaplaceHypre3d& laplace;
};
Hypre3dMonitor monitor;

bool use_precon; // Switch for preconditioning
bool rightprec; // Right preconditioning

// These are the implemented flags
static constexpr int implemented_flags = INVERT_START_NEW,
implemented_boundary_flags =
INVERT_AC_GRAD + INVERT_SET + INVERT_RHS;
static constexpr int implemented_flags = INVERT_START_NEW;
static constexpr int implemented_boundary_flags =
INVERT_AC_GRAD + INVERT_SET + INVERT_RHS;
};

#endif // BOUT_HAS_HYPRE
Expand Down
2 changes: 2 additions & 0 deletions src/invert/laplacexy2/laplacexy2.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@

#include <cmath>

namespace {
Ind2D index2d(Mesh* mesh, int x, int y) {
int ny = mesh->LocalNy;
return Ind2D(x * ny + y, ny, 1);
}
} // namespace

LaplaceXY2::LaplaceXY2(Mesh* m, Options* opt, const CELL_LOC loc)
: localmesh(m == nullptr ? bout::globals::mesh : m),
Expand Down
5 changes: 0 additions & 5 deletions src/invert/laplacexy2/laplacexy2_hypre.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ inline void gpuAssert(cudaError_t code, const char* file, int line, bool abort =
}
#endif

Ind2D index2d(Mesh* mesh, int x, int y) {
int ny = mesh->LocalNy;
return Ind2D(x * ny + y, ny, 1);
}

LaplaceXY2Hypre::LaplaceXY2Hypre(Mesh* m, Options* opt, const CELL_LOC loc)
: localmesh(m == nullptr ? bout::globals::mesh : m),
indexConverter(std::make_shared<GlobalIndexer<Field2D>>(
Expand Down
2 changes: 1 addition & 1 deletion src/physics/physicsmodel.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
#include <bout/physicsmodel.hxx>
#undef BOUT_NO_USING_NAMESPACE_BOUTGLOBALS

#include "bout/version.hxx"
#include <bout/mesh.hxx>
#include <bout/sys/timer.hxx>
#include <bout/vector2d.hxx>
#include <bout/vector3d.hxx>
#include "bout/version.hxx"

#include <fmt/core.h>

Expand Down
2 changes: 1 addition & 1 deletion src/sys/options/options_adios.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ bool readAttribute(adios2::IO& io, const std::string& name, const std::string& t
return false;
}

Options OptionsADIOS::read() {
Options OptionsADIOS::read([[maybe_unused]] bool lazy) {
Timer timer("io");

// Open file
Expand Down
Loading
Loading