Skip to content

Commit 54ffeed

Browse files
authored
Merge pull request #4035 from lindsayad/more-hypre-memory-manipulation
Do more comprehensive setting of the hypre memory location
2 parents 201eb69 + 26ba782 commit 54ffeed

2 files changed

Lines changed: 28 additions & 16 deletions

File tree

src/solvers/petsc_linear_solver.C

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
#include "libmesh/enum_solver_type.h"
3737
#include "libmesh/enum_convergence_flags.h"
3838

39+
#ifdef LIBMESH_HAVE_PETSC_HYPRE
40+
#include <HYPRE_utilities.h>
41+
#endif
42+
3943
// C++ includes
4044
#include <memory>
4145
#include <string.h>
@@ -571,6 +575,19 @@ PetscLinearSolver<T>::solve_base (SparseMatrix<T> * matrix,
571575
// Allow command line options to override anything set programmatically.
572576
LibmeshPetscCall(KSPSetFromOptions(_ksp));
573577

578+
#if defined(LIBMESH_HAVE_PETSC_HYPRE) && !PETSC_VERSION_LESS_THAN(3,12,0) && defined(PETSC_HAVE_HYPRE_DEVICE)
579+
{
580+
// Make sure hypre has been initialized
581+
LibmeshPetscCallExternal(HYPRE_Initialize);
582+
PetscScalar * dummyarray;
583+
PetscMemType mtype;
584+
LibmeshPetscCall(VecGetArrayAndMemType(solution->vec(), &dummyarray, &mtype));
585+
LibmeshPetscCall(VecRestoreArrayAndMemType(solution->vec(), &dummyarray));
586+
if (PetscMemTypeHost(mtype))
587+
LibmeshPetscCallExternal(HYPRE_SetMemoryLocation, HYPRE_MEMORY_HOST);
588+
}
589+
#endif
590+
574591
// If the SolverConfiguration object is provided, use it to override
575592
// solver options.
576593
if (this->_solver_configuration)

src/solvers/petsc_nonlinear_solver.C

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,22 +1073,17 @@ PetscNonlinearSolver<T>::solve (SparseMatrix<T> & pre_in, // System Preconditi
10731073
#endif
10741074
LibmeshPetscCall(SNESSetFromOptions(_snes));
10751075

1076-
#if defined(LIBMESH_HAVE_PETSC_HYPRE) && !PETSC_VERSION_LESS_THAN(3,12,0)
1077-
// The above call set our PC type. If we're a hypre type we have to ensure that hypre is deployed
1078-
// in the same memory space as our vector types
1079-
PC pc;
1080-
LibmeshPetscCall(KSPGetPC(ksp, &pc));
1081-
PetscBool is_hypre;
1082-
LibmeshPetscCall(PetscObjectTypeCompare((PetscObject)pc, PCHYPRE, &is_hypre));
1083-
if (is_hypre == PETSC_TRUE)
1084-
{
1085-
PetscScalar * dummyarray;
1086-
PetscMemType mtype;
1087-
LibmeshPetscCall(VecGetArrayAndMemType(x->vec(), &dummyarray, &mtype));
1088-
LibmeshPetscCall(VecRestoreArrayAndMemType(x->vec(), &dummyarray));
1089-
if (PetscMemTypeHost(mtype))
1090-
LibmeshPetscCallExternal(HYPRE_SetMemoryLocation, HYPRE_MEMORY_HOST);
1091-
}
1076+
#if defined(LIBMESH_HAVE_PETSC_HYPRE) && !PETSC_VERSION_LESS_THAN(3,12,0) && defined(PETSC_HAVE_HYPRE_DEVICE)
1077+
{
1078+
// Make sure hypre has been initialized
1079+
LibmeshPetscCallExternal(HYPRE_Initialize);
1080+
PetscScalar * dummyarray;
1081+
PetscMemType mtype;
1082+
LibmeshPetscCall(VecGetArrayAndMemType(x->vec(), &dummyarray, &mtype));
1083+
LibmeshPetscCall(VecRestoreArrayAndMemType(x->vec(), &dummyarray));
1084+
if (PetscMemTypeHost(mtype))
1085+
LibmeshPetscCallExternal(HYPRE_SetMemoryLocation, HYPRE_MEMORY_HOST);
1086+
}
10921087
#endif
10931088

10941089
if (this->user_presolve)

0 commit comments

Comments
 (0)