Skip to content

Commit

Permalink
Small fixes for hypre integration (#1)
Browse files Browse the repository at this point in the history
* use appropriate hypre init function

* properly handle hypre without device support

* don't add hypre preconditioner to factory if scalar type does not match
  • Loading branch information
akva2 authored and jakobtorben committed Dec 10, 2024
1 parent 6fa9c25 commit 3b67d6d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions opm/simulators/flow/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#endif

#if HAVE_HYPRE
#include <HYPRE_config.h>
#include <HYPRE_utilities.h>
#endif

Expand Down Expand Up @@ -173,7 +174,11 @@ void Main::initMPI()
#endif // HAVE_MPI

#if HAVE_HYPRE
#if HYPRE_RELEASE_NUMBER >= 22900
HYPRE_Initialize();
#else
HYPRE_Init();
#endif
#endif
}

Expand Down
5 changes: 4 additions & 1 deletion opm/simulators/linalg/HyprePreconditioner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class HyprePreconditioner : public Dune::PreconditionerWithUpdate<X,Y> {
use_gpu_ = prm_.get<bool>("use_gpu", false);

// Set memory location and execution policy
#if HYPRE_USING_CUDA || HYPRE_USING_HIP
if (use_gpu_) {
HYPRE_SetMemoryLocation(HYPRE_MEMORY_DEVICE);
HYPRE_SetExecutionPolicy(HYPRE_EXEC_DEVICE);
Expand All @@ -66,7 +67,9 @@ class HyprePreconditioner : public Dune::PreconditionerWithUpdate<X,Y> {
HYPRE_DeviceInitialize();
HYPRE_PrintDeviceInfo();
}
else {
else
#endif
{
HYPRE_SetMemoryLocation(HYPRE_MEMORY_HOST);
HYPRE_SetExecutionPolicy(HYPRE_EXEC_HOST);
}
Expand Down
3 changes: 2 additions & 1 deletion opm/simulators/linalg/PreconditionerFactory_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,8 @@ struct StandardPreconditioners<Operator, Dune::Amg::SequentialInformation> {
});
#if HAVE_HYPRE
// Only add Hypre for scalar matrices
if constexpr (M::block_type::rows == 1 && M::block_type::cols == 1) {
if constexpr (M::block_type::rows == 1 && M::block_type::cols == 1 &&
std::is_same_v<HYPRE_Real, typename V::field_type>) {
F::addCreator("hypre", [](const O& op, const P& prm, const std::function<V()>&, std::size_t) {
return std::make_shared<Hypre::HyprePreconditioner<M, V, V>>(op.getmat(), prm);
});
Expand Down

0 comments on commit 3b67d6d

Please sign in to comment.