Small fixes for hypre integration (#1)

* use appropriate hypre init function

* properly handle hypre without device support

* don't add hypre preconditioner to factory if scalar type does not match
This commit is contained in:
Arne Morten Kvarving 2024-12-04 11:31:04 +01:00 committed by jakobtorben
parent 6fa9c25ba5
commit 3b67d6dc54
3 changed files with 11 additions and 2 deletions

View File

@ -36,6 +36,7 @@
#endif #endif
#if HAVE_HYPRE #if HAVE_HYPRE
#include <HYPRE_config.h>
#include <HYPRE_utilities.h> #include <HYPRE_utilities.h>
#endif #endif
@ -173,7 +174,11 @@ void Main::initMPI()
#endif // HAVE_MPI #endif // HAVE_MPI
#if HAVE_HYPRE #if HAVE_HYPRE
#if HYPRE_RELEASE_NUMBER >= 22900
HYPRE_Initialize(); HYPRE_Initialize();
#else
HYPRE_Init();
#endif
#endif #endif
} }

View File

@ -56,6 +56,7 @@ public:
use_gpu_ = prm_.get<bool>("use_gpu", false); use_gpu_ = prm_.get<bool>("use_gpu", false);
// Set memory location and execution policy // Set memory location and execution policy
#if HYPRE_USING_CUDA || HYPRE_USING_HIP
if (use_gpu_) { if (use_gpu_) {
HYPRE_SetMemoryLocation(HYPRE_MEMORY_DEVICE); HYPRE_SetMemoryLocation(HYPRE_MEMORY_DEVICE);
HYPRE_SetExecutionPolicy(HYPRE_EXEC_DEVICE); HYPRE_SetExecutionPolicy(HYPRE_EXEC_DEVICE);
@ -66,7 +67,9 @@ public:
HYPRE_DeviceInitialize(); HYPRE_DeviceInitialize();
HYPRE_PrintDeviceInfo(); HYPRE_PrintDeviceInfo();
} }
else { else
#endif
{
HYPRE_SetMemoryLocation(HYPRE_MEMORY_HOST); HYPRE_SetMemoryLocation(HYPRE_MEMORY_HOST);
HYPRE_SetExecutionPolicy(HYPRE_EXEC_HOST); HYPRE_SetExecutionPolicy(HYPRE_EXEC_HOST);
} }

View File

@ -549,7 +549,8 @@ struct StandardPreconditioners<Operator, Dune::Amg::SequentialInformation> {
}); });
#if HAVE_HYPRE #if HAVE_HYPRE
// Only add Hypre for scalar matrices // 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) { 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); return std::make_shared<Hypre::HyprePreconditioner<M, V, V>>(op.getmat(), prm);
}); });